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.

62 lines
933 B

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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. va_list ap;
  29. va_start(ap, errstr);
  30. vfprintf(stderr, errstr, ap);
  31. va_end(ap);
  32. exit(EXIT_FAILURE);
  33. }
  34. void
  35. spawn(Arg *arg)
  36. {
  37. char **argv = (char **)arg->argv;
  38. if(!argv || !argv[0])
  39. return;
  40. if(fork() == 0) {
  41. if(fork() == 0) {
  42. if(dpy)
  43. close(ConnectionNumber(dpy));
  44. setsid();
  45. execvp(argv[0], argv);
  46. fprintf(stderr, "dwm: execvp %s", argv[0]);
  47. perror(" failed");
  48. }
  49. exit(0);
  50. }
  51. wait(0);
  52. }