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.

67 lines
1022 B

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 <stdarg.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <sys/wait.h>
  10. #include <unistd.h>
  11. #include "dwm.h"
  12. void
  13. error(const char *errstr, ...) {
  14. va_list ap;
  15. va_start(ap, errstr);
  16. vfprintf(stderr, errstr, ap);
  17. va_end(ap);
  18. exit(1);
  19. }
  20. static void
  21. bad_malloc(unsigned int size)
  22. {
  23. fprintf(stderr, "fatal: could not malloc() %d bytes\n",
  24. (int) size);
  25. exit(1);
  26. }
  27. void *
  28. emallocz(unsigned int size)
  29. {
  30. void *res = calloc(1, size);
  31. if(!res)
  32. bad_malloc(size);
  33. return res;
  34. }
  35. void
  36. swap(void **p1, void **p2)
  37. {
  38. void *tmp = *p1;
  39. *p1 = *p2;
  40. *p2 = tmp;
  41. }
  42. void
  43. spawn(Arg *arg)
  44. {
  45. char **argv = (char **)arg->argv;
  46. if(!argv || !argv[0])
  47. return;
  48. if(fork() == 0) {
  49. if(fork() == 0) {
  50. if(dpy)
  51. close(ConnectionNumber(dpy));
  52. setsid();
  53. execvp(argv[0], argv);
  54. fprintf(stderr, "dwm: execvp %s", argv[0]);
  55. perror(" failed");
  56. }
  57. exit (0);
  58. }
  59. wait(0);
  60. }