dwm-meillo

view util.c @ 181:03cb4cc41818

applied Jukka's diff
author arg@10ksloc.org
date Thu, 03 Aug 2006 15:05:34 +0200
parents c1185dc7a36e
children 41f8ee33771e
line source
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>
12 /* static */
14 static void
15 bad_malloc(unsigned int size)
16 {
17 eprint("fatal: could not malloc() %u bytes\n", size);
18 }
20 /* extern */
22 void *
23 emallocz(unsigned int size)
24 {
25 void *res = calloc(1, size);
27 if(!res)
28 bad_malloc(size);
29 return res;
30 }
32 void
33 eprint(const char *errstr, ...) {
34 va_list ap;
36 va_start(ap, errstr);
37 vfprintf(stderr, errstr, ap);
38 va_end(ap);
39 exit(EXIT_FAILURE);
40 }
42 void
43 spawn(Arg *arg)
44 {
45 char **argv = (char **)arg->argv;
47 if(!argv || !argv[0])
48 return;
49 if(fork() == 0) {
50 if(fork() == 0) {
51 if(dpy)
52 close(ConnectionNumber(dpy));
53 setsid();
54 execvp(argv[0], argv);
55 fprintf(stderr, "dwm: execvp %s", argv[0]);
56 perror(" failed");
57 }
58 exit(0);
59 }
60 wait(0);
61 }