annotate util.c @ 134:eb8580a97d56
s/0.5/0.6/ - my steps are wider than the reality
author |
arg@10ksloc.org |
date |
Fri, 21 Jul 2006 10:18:12 +0200 |
parents |
4bee0aa5b286 |
children |
c1185dc7a36e |
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
|
garbeam@2
|
7 #include <stdarg.h>
|
garbeam@2
|
8 #include <stdio.h>
|
garbeam@2
|
9 #include <stdlib.h>
|
garbeam@5
|
10 #include <sys/wait.h>
|
garbeam@5
|
11 #include <unistd.h>
|
garbeam@5
|
12
|
garbeam@84
|
13 /* static */
|
garbeam@2
|
14
|
garbeam@3
|
15 static void
|
garbeam@3
|
16 bad_malloc(unsigned int size)
|
garbeam@3
|
17 {
|
garbeam@3
|
18 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
|
garbeam@3
|
19 (int) size);
|
garbeam@92
|
20 exit(EXIT_FAILURE);
|
garbeam@3
|
21 }
|
garbeam@3
|
22
|
garbeam@84
|
23 /* extern */
|
garbeam@76
|
24
|
garbeam@3
|
25 void *
|
garbeam@3
|
26 emallocz(unsigned int size)
|
garbeam@3
|
27 {
|
garbeam@3
|
28 void *res = calloc(1, size);
|
arg@123
|
29
|
garbeam@3
|
30 if(!res)
|
garbeam@3
|
31 bad_malloc(size);
|
garbeam@3
|
32 return res;
|
garbeam@3
|
33 }
|
garbeam@3
|
34
|
garbeam@3
|
35 void
|
garbeam@76
|
36 eprint(const char *errstr, ...) {
|
garbeam@76
|
37 va_list ap;
|
arg@123
|
38
|
garbeam@76
|
39 va_start(ap, errstr);
|
garbeam@76
|
40 vfprintf(stderr, errstr, ap);
|
garbeam@76
|
41 va_end(ap);
|
garbeam@92
|
42 exit(EXIT_FAILURE);
|
garbeam@76
|
43 }
|
garbeam@76
|
44
|
garbeam@76
|
45 void
|
garbeam@49
|
46 spawn(Arg *arg)
|
garbeam@5
|
47 {
|
garbeam@49
|
48 char **argv = (char **)arg->argv;
|
arg@123
|
49
|
garbeam@14
|
50 if(!argv || !argv[0])
|
garbeam@5
|
51 return;
|
garbeam@5
|
52 if(fork() == 0) {
|
garbeam@5
|
53 if(fork() == 0) {
|
garbeam@5
|
54 if(dpy)
|
garbeam@5
|
55 close(ConnectionNumber(dpy));
|
garbeam@9
|
56 setsid();
|
garbeam@14
|
57 execvp(argv[0], argv);
|
garbeam@34
|
58 fprintf(stderr, "dwm: execvp %s", argv[0]);
|
garbeam@5
|
59 perror(" failed");
|
garbeam@5
|
60 }
|
garbeam@92
|
61 exit(EXIT_FAILURE);
|
garbeam@5
|
62 }
|
garbeam@5
|
63 wait(0);
|
garbeam@5
|
64 }
|