author | arg@mig29 |
Thu, 07 Dec 2006 11:55:04 +0100 | |
changeset 621 | 69fc4b2d4bc9 |
parent 532 | 651f2c868b31 |
child 643 | e90bf387bf6f |
permissions | -rw-r--r-- |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
471
diff
changeset
|
1 |
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
2 | 2 |
* See LICENSE file for license details. |
3 |
*/ |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
4 |
#include "dwm.h" |
2 | 5 |
#include <stdarg.h> |
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
5 | 8 |
#include <sys/wait.h> |
9 |
#include <unistd.h> |
|
10 |
||
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
76
diff
changeset
|
11 |
/* extern */ |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
12 |
|
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
13 |
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
|
14 |
emallocz(unsigned int size) { |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
15 |
void *res = calloc(1, size); |
123 | 16 |
|
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
17 |
if(!res) |
325
58c09c533d3f
removed badmalloc (thx for the pointer to Uriel)
Anselm R. Garbe <arg@10kloc.org>
parents:
317
diff
changeset
|
18 |
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
|
19 |
return res; |
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
20 |
} |
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
21 |
|
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
22 |
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
|
23 |
eprint(const char *errstr, ...) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
24 |
va_list ap; |
123 | 25 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
26 |
va_start(ap, errstr); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
27 |
vfprintf(stderr, errstr, ap); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
28 |
va_end(ap); |
92
4bee0aa5b286
using EXIT_stuff in exit() now
Anselm R. Garbe <garbeam@wmii.de>
parents:
84
diff
changeset
|
29 |
exit(EXIT_FAILURE); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
30 |
} |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
31 |
|
270
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
32 |
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
|
33 |
erealloc(void *ptr, unsigned int size) { |
270
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
34 |
void *res = realloc(ptr, size); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
471
diff
changeset
|
35 |
|
270
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
36 |
if(!res) |
325
58c09c533d3f
removed badmalloc (thx for the pointer to Uriel)
Anselm R. Garbe <arg@10kloc.org>
parents:
317
diff
changeset
|
37 |
eprint("fatal: could not malloc() %u bytes\n", size); |
270
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
38 |
return res; |
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
39 |
} |
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
217
diff
changeset
|
40 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
41 |
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
|
42 |
spawn(Arg *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
|
43 |
static char *shell = NULL; |
123 | 44 |
|
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
|
45 |
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
|
46 |
shell = "/bin/sh"; |
523df4a3c1c4
using execl now, argv changed, using cmd and const char defs directly in the KEYS struct
arg@10ksloc.org
parents:
187
diff
changeset
|
47 |
if(!arg->cmd) |
5 | 48 |
return; |
471 | 49 |
/* The double-fork construct avoids zombie processes and keeps the code |
50 |
* clean from stupid signal handlers. */ |
|
5 | 51 |
if(fork() == 0) { |
52 |
if(fork() == 0) { |
|
53 |
if(dpy) |
|
54 |
close(ConnectionNumber(dpy)); |
|
9
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
6
diff
changeset
|
55 |
setsid(); |
338
06438e022f9a
eliminated sentinel warning
Anselm R. Garbe <arg@10kloc.org>
parents:
325
diff
changeset
|
56 |
execl(shell, shell, "-c", arg->cmd, (char *)NULL); |
217 | 57 |
fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd); |
5 | 58 |
perror(" failed"); |
59 |
} |
|
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
123
diff
changeset
|
60 |
exit(0); |
5 | 61 |
} |
62 |
wait(0); |
|
63 |
} |