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.

65 lines
1003 B

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