dwm-meillo
annotate util.c @ 64:46d44d185464
removed a bottleneck
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 13:27:01 +0200 |
parents | 466591c2f967 |
children | 50450aa24a46 |
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@33 | 16 error(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@3 | 42 swap(void **p1, void **p2) |
garbeam@3 | 43 { |
garbeam@3 | 44 void *tmp = *p1; |
garbeam@3 | 45 *p1 = *p2; |
garbeam@3 | 46 *p2 = tmp; |
garbeam@3 | 47 } |
garbeam@5 | 48 |
garbeam@5 | 49 void |
garbeam@49 | 50 spawn(Arg *arg) |
garbeam@5 | 51 { |
garbeam@49 | 52 char **argv = (char **)arg->argv; |
garbeam@14 | 53 if(!argv || !argv[0]) |
garbeam@5 | 54 return; |
garbeam@5 | 55 if(fork() == 0) { |
garbeam@5 | 56 if(fork() == 0) { |
garbeam@5 | 57 if(dpy) |
garbeam@5 | 58 close(ConnectionNumber(dpy)); |
garbeam@9 | 59 setsid(); |
garbeam@14 | 60 execvp(argv[0], argv); |
garbeam@34 | 61 fprintf(stderr, "dwm: execvp %s", argv[0]); |
garbeam@5 | 62 perror(" failed"); |
garbeam@5 | 63 } |
garbeam@5 | 64 exit (0); |
garbeam@5 | 65 } |
garbeam@5 | 66 wait(0); |
garbeam@5 | 67 } |