aewl

annotate util.c @ 357:27082985e51e

removed a bunch of lines, made mode symbols configurable
author Anselm R. Garbe <arg@10kloc.org>
date Fri, 25 Aug 2006 15:12:32 +0200
parents 58c09c533d3f
children 44a55e6e46bf
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 /* extern */
garbeam@76 13
garbeam@3 14 void *
garbeam@3 15 emallocz(unsigned int size)
garbeam@3 16 {
garbeam@3 17 void *res = calloc(1, size);
arg@123 18
garbeam@3 19 if(!res)
arg@325 20 eprint("fatal: could not malloc() %u bytes\n", size);
garbeam@3 21 return res;
garbeam@3 22 }
garbeam@3 23
garbeam@3 24 void
arg@187 25 eprint(const char *errstr, ...)
arg@187 26 {
garbeam@76 27 va_list ap;
arg@123 28
garbeam@76 29 va_start(ap, errstr);
garbeam@76 30 vfprintf(stderr, errstr, ap);
garbeam@76 31 va_end(ap);
garbeam@92 32 exit(EXIT_FAILURE);
garbeam@76 33 }
garbeam@76 34
arg@270 35 void *
arg@270 36 erealloc(void *ptr, unsigned int size)
arg@270 37 {
arg@270 38 void *res = realloc(ptr, size);
arg@270 39 if(!res)
arg@325 40 eprint("fatal: could not malloc() %u bytes\n", size);
arg@270 41 return res;
arg@270 42 }
arg@270 43
garbeam@76 44 void
garbeam@49 45 spawn(Arg *arg)
garbeam@5 46 {
arg@189 47 static char *shell = NULL;
arg@123 48
arg@189 49 if(!shell && !(shell = getenv("SHELL")))
arg@189 50 shell = "/bin/sh";
arg@189 51
arg@189 52 if(!arg->cmd)
garbeam@5 53 return;
garbeam@5 54 if(fork() == 0) {
garbeam@5 55 if(fork() == 0) {
garbeam@5 56 if(dpy)
garbeam@5 57 close(ConnectionNumber(dpy));
garbeam@9 58 setsid();
arg@338 59 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
arg@217 60 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
garbeam@5 61 perror(" failed");
garbeam@5 62 }
arg@138 63 exit(0);
garbeam@5 64 }
garbeam@5 65 wait(0);
garbeam@5 66 }