annotate util.c @ 461:9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
author |
Anselm R. Garbe <arg@10kloc.org> |
date |
Tue, 12 Sep 2006 10:57:28 +0200 |
parents |
44a55e6e46bf |
children |
740c4bfc3124 |
rev |
line source |
garbeam@2
|
1 /*
|
garbeam@2
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@2
|
3 * See LICENSE file for license details.
|
garbeam@2
|
4 */
|
garbeam@76
|
5 #include "dwm.h"
|
garbeam@2
|
6 #include <stdarg.h>
|
garbeam@2
|
7 #include <stdio.h>
|
garbeam@2
|
8 #include <stdlib.h>
|
garbeam@5
|
9 #include <sys/wait.h>
|
garbeam@5
|
10 #include <unistd.h>
|
garbeam@5
|
11
|
garbeam@84
|
12 /* extern */
|
garbeam@76
|
13
|
garbeam@3
|
14 void *
|
arg@461
|
15 emallocz(unsigned int size) {
|
garbeam@3
|
16 void *res = calloc(1, size);
|
arg@123
|
17
|
garbeam@3
|
18 if(!res)
|
arg@325
|
19 eprint("fatal: could not malloc() %u bytes\n", size);
|
garbeam@3
|
20 return res;
|
garbeam@3
|
21 }
|
garbeam@3
|
22
|
garbeam@3
|
23 void
|
arg@461
|
24 eprint(const char *errstr, ...) {
|
garbeam@76
|
25 va_list ap;
|
arg@123
|
26
|
garbeam@76
|
27 va_start(ap, errstr);
|
garbeam@76
|
28 vfprintf(stderr, errstr, ap);
|
garbeam@76
|
29 va_end(ap);
|
garbeam@92
|
30 exit(EXIT_FAILURE);
|
garbeam@76
|
31 }
|
garbeam@76
|
32
|
arg@270
|
33 void *
|
arg@461
|
34 erealloc(void *ptr, unsigned int size) {
|
arg@270
|
35 void *res = realloc(ptr, size);
|
arg@270
|
36 if(!res)
|
arg@325
|
37 eprint("fatal: could not malloc() %u bytes\n", size);
|
arg@270
|
38 return res;
|
arg@270
|
39 }
|
arg@270
|
40
|
garbeam@76
|
41 void
|
arg@461
|
42 spawn(Arg *arg) {
|
arg@189
|
43 static char *shell = NULL;
|
arg@123
|
44
|
arg@189
|
45 if(!shell && !(shell = getenv("SHELL")))
|
arg@189
|
46 shell = "/bin/sh";
|
arg@189
|
47
|
arg@189
|
48 if(!arg->cmd)
|
garbeam@5
|
49 return;
|
arg@373
|
50 /* the double-fork construct avoids zombie processes */
|
garbeam@5
|
51 if(fork() == 0) {
|
garbeam@5
|
52 if(fork() == 0) {
|
garbeam@5
|
53 if(dpy)
|
garbeam@5
|
54 close(ConnectionNumber(dpy));
|
garbeam@9
|
55 setsid();
|
arg@338
|
56 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
|
arg@217
|
57 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
|
garbeam@5
|
58 perror(" failed");
|
garbeam@5
|
59 }
|
arg@138
|
60 exit(0);
|
garbeam@5
|
61 }
|
garbeam@5
|
62 wait(0);
|
garbeam@5
|
63 }
|