aewl

view util.c @ 331:0ed2de01e9f7

titlebars contain tags in the right now
author Anselm R. Garbe <arg@10kloc.org>
date Tue, 22 Aug 2006 19:55:20 +0200
parents 45af6a8a0cbf
children 06438e022f9a
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 /* extern */
14 void *
15 emallocz(unsigned int size)
16 {
17 void *res = calloc(1, size);
19 if(!res)
20 eprint("fatal: could not malloc() %u bytes\n", size);
21 return res;
22 }
24 void
25 eprint(const char *errstr, ...)
26 {
27 va_list ap;
29 va_start(ap, errstr);
30 vfprintf(stderr, errstr, ap);
31 va_end(ap);
32 exit(EXIT_FAILURE);
33 }
35 void *
36 erealloc(void *ptr, unsigned int size)
37 {
38 void *res = realloc(ptr, size);
39 if(!res)
40 eprint("fatal: could not malloc() %u bytes\n", size);
41 return res;
42 }
44 void
45 spawn(Arg *arg)
46 {
47 static char *shell = NULL;
49 if(!shell && !(shell = getenv("SHELL")))
50 shell = "/bin/sh";
52 if(!arg->cmd)
53 return;
54 if(fork() == 0) {
55 if(fork() == 0) {
56 if(dpy)
57 close(ConnectionNumber(dpy));
58 setsid();
59 execl(shell, shell, "-c", arg->cmd, NULL);
60 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
61 perror(" failed");
62 }
63 exit(0);
64 }
65 wait(0);
66 }