author | Anselm R. Garbe <arg@suckless.org> |
Wed, 30 May 2007 12:19:28 +0200 | |
changeset 910 | c13cb8c6b7a5 |
parent 909 | 8a8b7a413e66 |
permissions | -rw-r--r-- |
910
c13cb8c6b7a5
referred to LICENSE file
Anselm R. Garbe <arg@suckless.org>
parents:
909
diff
changeset
|
1 |
/* See LICENSE file for copyright and license details. */ |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
2 |
#include "dwm.h" |
2 | 3 |
#include <stdarg.h> |
4 |
#include <stdio.h> |
|
5 |
#include <stdlib.h> |
|
5 | 6 |
#include <sys/wait.h> |
7 |
#include <unistd.h> |
|
8 |
||
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
76
diff
changeset
|
9 |
/* extern */ |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
10 |
|
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
11 |
void * |
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)
Anselm R. Garbe <arg@10kloc.org>
parents:
373
diff
changeset
|
12 |
emallocz(unsigned int size) { |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
13 |
void *res = calloc(1, size); |
123 | 14 |
|
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
15 |
if(!res) |
325
58c09c533d3f
removed badmalloc (thx for the pointer to Uriel)
Anselm R. Garbe <arg@10kloc.org>
parents:
317
diff
changeset
|
16 |
eprint("fatal: could not malloc() %u bytes\n", size); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
17 |
return res; |
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
18 |
} |
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
19 |
|
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
20 |
void |
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)
Anselm R. Garbe <arg@10kloc.org>
parents:
373
diff
changeset
|
21 |
eprint(const char *errstr, ...) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
22 |
va_list ap; |
123 | 23 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
24 |
va_start(ap, errstr); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
25 |
vfprintf(stderr, errstr, ap); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
26 |
va_end(ap); |
92
4bee0aa5b286
using EXIT_stuff in exit() now
Anselm R. Garbe <garbeam@wmii.de>
parents:
84
diff
changeset
|
27 |
exit(EXIT_FAILURE); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
28 |
} |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
29 |
|
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
30 |
void |
823
fb5cbf0bd923
replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents:
813
diff
changeset
|
31 |
spawn(const char *arg) { |
189
523df4a3c1c4
using execl now, argv changed, using cmd and const char defs directly in the KEYS struct
arg@10ksloc.org
parents:
187
diff
changeset
|
32 |
static char *shell = NULL; |
123 | 33 |
|
189
523df4a3c1c4
using execl now, argv changed, using cmd and const char defs directly in the KEYS struct
arg@10ksloc.org
parents:
187
diff
changeset
|
34 |
if(!shell && !(shell = getenv("SHELL"))) |
523df4a3c1c4
using execl now, argv changed, using cmd and const char defs directly in the KEYS struct
arg@10ksloc.org
parents:
187
diff
changeset
|
35 |
shell = "/bin/sh"; |
823
fb5cbf0bd923
replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents:
813
diff
changeset
|
36 |
if(!arg) |
5 | 37 |
return; |
471 | 38 |
/* The double-fork construct avoids zombie processes and keeps the code |
39 |
* clean from stupid signal handlers. */ |
|
5 | 40 |
if(fork() == 0) { |
41 |
if(fork() == 0) { |
|
42 |
if(dpy) |
|
43 |
close(ConnectionNumber(dpy)); |
|
9
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
6
diff
changeset
|
44 |
setsid(); |
823
fb5cbf0bd923
replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents:
813
diff
changeset
|
45 |
execl(shell, shell, "-c", arg, (char *)NULL); |
fb5cbf0bd923
replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents:
813
diff
changeset
|
46 |
fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg); |
5 | 47 |
perror(" failed"); |
48 |
} |
|
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
123
diff
changeset
|
49 |
exit(0); |
5 | 50 |
} |
51 |
wait(0); |
|
52 |
} |