aewl

annotate util.c @ 168:9d3c91a30fe3

Added tag 0.6 for changeset c11f86db4550cac5d0a648a3fe4d6d3b9a4fcf7e
author arg@10ksloc.org
date Wed, 02 Aug 2006 16:52:21 +0200
parents c1185dc7a36e
children 41f8ee33771e
rev   line source
garbeam@2 1 /*
garbeam@2 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@2 3 * See LICENSE file for license details.
garbeam@2 4 */
garbeam@76 5 #include "dwm.h"
garbeam@2 6 #include <stdarg.h>
garbeam@2 7 #include <stdio.h>
garbeam@2 8 #include <stdlib.h>
garbeam@5 9 #include <sys/wait.h>
garbeam@5 10 #include <unistd.h>
garbeam@5 11
garbeam@84 12 /* static */
garbeam@2 13
garbeam@3 14 static void
garbeam@3 15 bad_malloc(unsigned int size)
garbeam@3 16 {
arg@138 17 eprint("fatal: could not malloc() %u bytes\n", size);
garbeam@3 18 }
garbeam@3 19
garbeam@84 20 /* extern */
garbeam@76 21
garbeam@3 22 void *
garbeam@3 23 emallocz(unsigned int size)
garbeam@3 24 {
garbeam@3 25 void *res = calloc(1, size);
arg@123 26
garbeam@3 27 if(!res)
garbeam@3 28 bad_malloc(size);
garbeam@3 29 return res;
garbeam@3 30 }
garbeam@3 31
garbeam@3 32 void
garbeam@76 33 eprint(const char *errstr, ...) {
garbeam@76 34 va_list ap;
arg@123 35
garbeam@76 36 va_start(ap, errstr);
garbeam@76 37 vfprintf(stderr, errstr, ap);
garbeam@76 38 va_end(ap);
garbeam@92 39 exit(EXIT_FAILURE);
garbeam@76 40 }
garbeam@76 41
garbeam@76 42 void
garbeam@49 43 spawn(Arg *arg)
garbeam@5 44 {
garbeam@49 45 char **argv = (char **)arg->argv;
arg@123 46
garbeam@14 47 if(!argv || !argv[0])
garbeam@5 48 return;
garbeam@5 49 if(fork() == 0) {
garbeam@5 50 if(fork() == 0) {
garbeam@5 51 if(dpy)
garbeam@5 52 close(ConnectionNumber(dpy));
garbeam@9 53 setsid();
garbeam@14 54 execvp(argv[0], argv);
garbeam@34 55 fprintf(stderr, "dwm: execvp %s", argv[0]);
garbeam@5 56 perror(" failed");
garbeam@5 57 }
arg@138 58 exit(0);
garbeam@5 59 }
garbeam@5 60 wait(0);
garbeam@5 61 }