dwm-meillo
view util.c @ 465:590575d080fe
offscreen client appearance fixes
author | arg@mmvi |
---|---|
date | Fri, 15 Sep 2006 10:54:32 +0200 |
parents | 44a55e6e46bf |
children | 740c4bfc3124 |
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 */
51 if(fork() == 0) {
52 if(fork() == 0) {
53 if(dpy)
54 close(ConnectionNumber(dpy));
55 setsid();
56 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
57 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
58 perror(" failed");
59 }
60 exit(0);
61 }
62 wait(0);
63 }