Mercurial > hg > index.fcgi > dwm > dwm-3.6.1-11pba
view util.c @ 8:e749c30135e9
add tag_n_view()
author | paulo@thepaulopc |
---|---|
date | Tue, 14 Jun 2011 00:33:07 -0700 |
parents | 7024076fa948 |
children |
line source
1 /* (C)opyright MMVI-MMVII 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 spawn(Arg *arg) {
34 static char *shell = NULL;
36 if(!shell && !(shell = getenv("SHELL")))
37 shell = "/bin/sh";
38 if(!arg->cmd)
39 return;
40 /* The double-fork construct avoids zombie processes and keeps the code
41 * clean from stupid signal handlers. */
42 if(fork() == 0) {
43 if(fork() == 0) {
44 if(dpy)
45 close(ConnectionNumber(dpy));
46 setsid();
47 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
48 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
49 perror(" failed");
50 }
51 exit(0);
52 }
53 wait(0);
54 }
56 void
57 spawn_insert(Arg *arg) {
58 func_insert(spawn, arg);
59 }