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.

52 lines
997 B

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