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.

66 lines
1.1 KiB

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. /* extern */
  12. void *
  13. emallocz(unsigned int size)
  14. {
  15. void *res = calloc(1, size);
  16. if(!res)
  17. eprint("fatal: could not malloc() %u bytes\n", size);
  18. return res;
  19. }
  20. void
  21. eprint(const char *errstr, ...)
  22. {
  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. erealloc(void *ptr, unsigned int size)
  31. {
  32. void *res = realloc(ptr, size);
  33. if(!res)
  34. eprint("fatal: could not malloc() %u bytes\n", size);
  35. return res;
  36. }
  37. void
  38. spawn(Arg *arg)
  39. {
  40. static char *shell = NULL;
  41. if(!shell && !(shell = getenv("SHELL")))
  42. shell = "/bin/sh";
  43. if(!arg->cmd)
  44. return;
  45. if(fork() == 0) {
  46. if(fork() == 0) {
  47. if(dpy)
  48. close(ConnectionNumber(dpy));
  49. setsid();
  50. execl(shell, shell, "-c", arg->cmd, (char *)NULL);
  51. fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
  52. perror(" failed");
  53. }
  54. exit(0);
  55. }
  56. wait(0);
  57. }