aewl
view util.c @ 541:08d3d329270a
using MASTER 600 again, it is definately better, and using urxvtc for the moment (it doesn't flickers on refreshes, but this is not because of Marc Lehmann, it is because of the original rxvt code)
author | arg@mig29 |
---|---|
date | Thu, 26 Oct 2006 12:13:41 +0200 |
parents | 740c4bfc3124 |
children | e90bf387bf6f |
line source
1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4 #include "dwm.h"
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/wait.h>
9 #include <unistd.h>
11 /* extern */
13 void *
14 emallocz(unsigned int size) {
15 void *res = calloc(1, size);
17 if(!res)
18 eprint("fatal: could not malloc() %u bytes\n", size);
19 return res;
20 }
22 void
23 eprint(const char *errstr, ...) {
24 va_list ap;
26 va_start(ap, errstr);
27 vfprintf(stderr, errstr, ap);
28 va_end(ap);
29 exit(EXIT_FAILURE);
30 }
32 void *
33 erealloc(void *ptr, unsigned int size) {
34 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";
47 if(!arg->cmd)
48 return;
49 /* The double-fork construct avoids zombie processes and keeps the code
50 * clean from stupid signal handlers. */
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 }