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.

53 lines
1.0 KiB

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