dwm-meillo

view util.c @ 528:c0fffe6c207e

changing MASTER value from percent into per mill
author Anselm R. Garbe <arg@10kloc.org>
date Thu, 05 Oct 2006 18:18:47 +0200
parents 9d23330a5268
children 651f2c868b31
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 /* extern */
14 void *
15 emallocz(unsigned int size) {
16 void *res = calloc(1, size);
18 if(!res)
19 eprint("fatal: could not malloc() %u bytes\n", size);
20 return res;
21 }
23 void
24 eprint(const char *errstr, ...) {
25 va_list ap;
27 va_start(ap, errstr);
28 vfprintf(stderr, errstr, ap);
29 va_end(ap);
30 exit(EXIT_FAILURE);
31 }
33 void *
34 erealloc(void *ptr, unsigned int size) {
35 void *res = realloc(ptr, size);
36 if(!res)
37 eprint("fatal: could not malloc() %u bytes\n", size);
38 return res;
39 }
41 void
42 spawn(Arg *arg) {
43 static char *shell = NULL;
45 if(!shell && !(shell = getenv("SHELL")))
46 shell = "/bin/sh";
48 if(!arg->cmd)
49 return;
50 /* The double-fork construct avoids zombie processes and keeps the code
51 * clean from stupid signal handlers. */
52 if(fork() == 0) {
53 if(fork() == 0) {
54 if(dpy)
55 close(ConnectionNumber(dpy));
56 setsid();
57 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
58 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
59 perror(" failed");
60 }
61 exit(0);
62 }
63 wait(0);
64 }