dwm-meillo

view util.c @ 268:a47b3b0d7bf4

applied Sanders LD and resize patches
author Anselm R.Garbe <arg@10ksloc.org>
date Mon, 14 Aug 2006 08:43:19 +0200
parents 523df4a3c1c4
children dacd3f3c5823
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 bad_malloc(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 bad_malloc(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 spawn(Arg *arg)
45 {
46 static char *shell = NULL;
48 if(!shell && !(shell = getenv("SHELL")))
49 shell = "/bin/sh";
51 if(!arg->cmd)
52 return;
53 if(fork() == 0) {
54 if(fork() == 0) {
55 if(dpy)
56 close(ConnectionNumber(dpy));
57 setsid();
58 execl(shell, shell, "-c", arg->cmd, NULL);
59 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
60 perror(" failed");
61 }
62 exit(0);
63 }
64 wait(0);
65 }