You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
  2. * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
  3. * © 2006-2007 Jukka Salmi <jukka at salmi dot ch>
  4. * © 2007 Premysl Hruby <dfenze at gmail dot com>
  5. * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
  6. * See LICENSE file for license details. */
  7. #include "dwm.h"
  8. #include <stdarg.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <sys/wait.h>
  12. #include <unistd.h>
  13. /* extern */
  14. void *
  15. emallocz(unsigned int size) {
  16. void *res = calloc(1, size);
  17. if(!res)
  18. eprint("fatal: could not malloc() %u bytes\n", size);
  19. return res;
  20. }
  21. void
  22. eprint(const char *errstr, ...) {
  23. va_list ap;
  24. va_start(ap, errstr);
  25. vfprintf(stderr, errstr, ap);
  26. va_end(ap);
  27. exit(EXIT_FAILURE);
  28. }
  29. void
  30. spawn(const char *arg) {
  31. static char *shell = NULL;
  32. if(!shell && !(shell = getenv("SHELL")))
  33. shell = "/bin/sh";
  34. if(!arg)
  35. return;
  36. /* The double-fork construct avoids zombie processes and keeps the code
  37. * clean from stupid signal handlers. */
  38. if(fork() == 0) {
  39. if(fork() == 0) {
  40. if(dpy)
  41. close(ConnectionNumber(dpy));
  42. setsid();
  43. execl(shell, shell, "-c", arg, (char *)NULL);
  44. fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg);
  45. perror(" failed");
  46. }
  47. exit(0);
  48. }
  49. wait(0);
  50. }