aewl

view util.c @ 322:f435016410a0

slight change of my config.h
author Anselm R. Garbe <arg@10kloc.org>
date Tue, 22 Aug 2006 09:57:32 +0200
parents dacd3f3c5823
children 58c09c533d3f
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5 #include "dwm.h"
6 #include <stdarg.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
12 /* static */
14 static void
15 badmalloc(unsigned int size)
16 {
17 eprint("fatal: could not malloc() %u bytes\n", size);
18 }
20 /* extern */
22 void *
23 emallocz(unsigned int size)
24 {
25 void *res = calloc(1, size);
27 if(!res)
28 badmalloc(size);
29 return res;
30 }
32 void
33 eprint(const char *errstr, ...)
34 {
35 va_list ap;
37 va_start(ap, errstr);
38 vfprintf(stderr, errstr, ap);
39 va_end(ap);
40 exit(EXIT_FAILURE);
41 }
43 void *
44 erealloc(void *ptr, unsigned int size)
45 {
46 void *res = realloc(ptr, size);
47 if(!res)
48 badmalloc(size);
49 return res;
50 }
52 void
53 spawn(Arg *arg)
54 {
55 static char *shell = NULL;
57 if(!shell && !(shell = getenv("SHELL")))
58 shell = "/bin/sh";
60 if(!arg->cmd)
61 return;
62 if(fork() == 0) {
63 if(fork() == 0) {
64 if(dpy)
65 close(ConnectionNumber(dpy));
66 setsid();
67 execl(shell, shell, "-c", arg->cmd, NULL);
68 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
69 perror(" failed");
70 }
71 exit(0);
72 }
73 wait(0);
74 }