dwm-meillo
annotate util.c @ 159:a5eab6aaf859
reverting to old resize policy
author | arg@10ksloc.org |
---|---|
date | Wed, 02 Aug 2006 10:48:58 +0200 |
parents | 61490330e90a |
children | 21071ae1fe68 |
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 |
garbeam@2 | 7 #include <stdarg.h> |
garbeam@2 | 8 #include <stdio.h> |
garbeam@2 | 9 #include <stdlib.h> |
garbeam@5 | 10 #include <sys/wait.h> |
garbeam@5 | 11 #include <unistd.h> |
garbeam@5 | 12 |
garbeam@84 | 13 /* static */ |
garbeam@2 | 14 |
garbeam@3 | 15 static void |
garbeam@3 | 16 bad_malloc(unsigned int size) |
garbeam@3 | 17 { |
arg@138 | 18 eprint("fatal: could not malloc() %u bytes\n", size); |
garbeam@3 | 19 } |
garbeam@3 | 20 |
garbeam@84 | 21 /* extern */ |
garbeam@76 | 22 |
garbeam@3 | 23 void * |
garbeam@3 | 24 emallocz(unsigned int size) |
garbeam@3 | 25 { |
garbeam@3 | 26 void *res = calloc(1, size); |
arg@123 | 27 |
garbeam@3 | 28 if(!res) |
garbeam@3 | 29 bad_malloc(size); |
garbeam@3 | 30 return res; |
garbeam@3 | 31 } |
garbeam@3 | 32 |
garbeam@3 | 33 void |
garbeam@76 | 34 eprint(const char *errstr, ...) { |
garbeam@76 | 35 va_list ap; |
arg@123 | 36 |
garbeam@76 | 37 va_start(ap, errstr); |
garbeam@76 | 38 vfprintf(stderr, errstr, ap); |
garbeam@76 | 39 va_end(ap); |
garbeam@92 | 40 exit(EXIT_FAILURE); |
garbeam@76 | 41 } |
garbeam@76 | 42 |
garbeam@76 | 43 void |
garbeam@49 | 44 spawn(Arg *arg) |
garbeam@5 | 45 { |
garbeam@49 | 46 char **argv = (char **)arg->argv; |
arg@123 | 47 |
garbeam@14 | 48 if(!argv || !argv[0]) |
garbeam@5 | 49 return; |
garbeam@5 | 50 if(fork() == 0) { |
garbeam@5 | 51 if(fork() == 0) { |
garbeam@5 | 52 if(dpy) |
garbeam@5 | 53 close(ConnectionNumber(dpy)); |
garbeam@9 | 54 setsid(); |
garbeam@14 | 55 execvp(argv[0], argv); |
garbeam@34 | 56 fprintf(stderr, "dwm: execvp %s", argv[0]); |
garbeam@5 | 57 perror(" failed"); |
garbeam@5 | 58 } |
arg@138 | 59 exit(0); |
garbeam@5 | 60 } |
garbeam@5 | 61 wait(0); |
garbeam@5 | 62 } |