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.

64 lines
983 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. fprintf(stderr, "fatal: could not malloc() %d bytes\n",
  16. (int) size);
  17. exit(EXIT_FAILURE);
  18. }
  19. /* extern */
  20. void *
  21. emallocz(unsigned int size)
  22. {
  23. void *res = calloc(1, size);
  24. if(!res)
  25. bad_malloc(size);
  26. return res;
  27. }
  28. void
  29. eprint(const char *errstr, ...) {
  30. va_list ap;
  31. va_start(ap, errstr);
  32. vfprintf(stderr, errstr, ap);
  33. va_end(ap);
  34. exit(EXIT_FAILURE);
  35. }
  36. void
  37. spawn(Arg *arg)
  38. {
  39. char **argv = (char **)arg->argv;
  40. if(!argv || !argv[0])
  41. return;
  42. if(fork() == 0) {
  43. if(fork() == 0) {
  44. if(dpy)
  45. close(ConnectionNumber(dpy));
  46. setsid();
  47. execvp(argv[0], argv);
  48. fprintf(stderr, "dwm: execvp %s", argv[0]);
  49. perror(" failed");
  50. }
  51. exit(EXIT_FAILURE);
  52. }
  53. wait(0);
  54. }