aewl

annotate util.c @ 75:f08271b7cb20

rearranged several stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 16:30:50 +0200
parents 50450aa24a46
children 4bd49f404f10
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@2 5
garbeam@2 6 #include <stdarg.h>
garbeam@2 7 #include <stdio.h>
garbeam@2 8 #include <stdlib.h>
garbeam@5 9 #include <sys/types.h>
garbeam@5 10 #include <sys/wait.h>
garbeam@5 11 #include <unistd.h>
garbeam@5 12
garbeam@43 13 #include "dwm.h"
garbeam@2 14
garbeam@2 15 void
garbeam@75 16 eprint(const char *errstr, ...) {
garbeam@2 17 va_list ap;
garbeam@2 18 va_start(ap, errstr);
garbeam@2 19 vfprintf(stderr, errstr, ap);
garbeam@2 20 va_end(ap);
garbeam@2 21 exit(1);
garbeam@2 22 }
garbeam@2 23
garbeam@3 24 static void
garbeam@3 25 bad_malloc(unsigned int size)
garbeam@3 26 {
garbeam@3 27 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
garbeam@3 28 (int) size);
garbeam@3 29 exit(1);
garbeam@3 30 }
garbeam@3 31
garbeam@3 32 void *
garbeam@3 33 emallocz(unsigned int size)
garbeam@3 34 {
garbeam@3 35 void *res = calloc(1, size);
garbeam@3 36 if(!res)
garbeam@3 37 bad_malloc(size);
garbeam@3 38 return res;
garbeam@3 39 }
garbeam@3 40
garbeam@3 41 void
garbeam@49 42 spawn(Arg *arg)
garbeam@5 43 {
garbeam@49 44 char **argv = (char **)arg->argv;
garbeam@14 45 if(!argv || !argv[0])
garbeam@5 46 return;
garbeam@5 47 if(fork() == 0) {
garbeam@5 48 if(fork() == 0) {
garbeam@5 49 if(dpy)
garbeam@5 50 close(ConnectionNumber(dpy));
garbeam@9 51 setsid();
garbeam@14 52 execvp(argv[0], argv);
garbeam@34 53 fprintf(stderr, "dwm: execvp %s", argv[0]);
garbeam@5 54 perror(" failed");
garbeam@5 55 }
garbeam@5 56 exit (0);
garbeam@5 57 }
garbeam@5 58 wait(0);
garbeam@5 59 }