dwm-meillo

annotate util.c @ 285:e864d658eb02

added missing arrange
author Anselm R.Garbe <arg@10ksloc.org>
date Mon, 14 Aug 2006 17:14:22 +0200
parents 7b63c375d28c
children 45af6a8a0cbf
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
arg@187 33 eprint(const char *errstr, ...)
arg@187 34 {
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
arg@270 43 void *
arg@270 44 erealloc(void *ptr, unsigned int size)
arg@270 45 {
arg@270 46 void *res = realloc(ptr, size);
arg@270 47 if(!res)
arg@270 48 bad_malloc(size);
arg@270 49 return res;
arg@270 50 }
arg@270 51
garbeam@76 52 void
garbeam@49 53 spawn(Arg *arg)
garbeam@5 54 {
arg@189 55 static char *shell = NULL;
arg@123 56
arg@189 57 if(!shell && !(shell = getenv("SHELL")))
arg@189 58 shell = "/bin/sh";
arg@189 59
arg@189 60 if(!arg->cmd)
garbeam@5 61 return;
garbeam@5 62 if(fork() == 0) {
garbeam@5 63 if(fork() == 0) {
garbeam@5 64 if(dpy)
garbeam@5 65 close(ConnectionNumber(dpy));
garbeam@9 66 setsid();
arg@189 67 execl(shell, shell, "-c", arg->cmd, NULL);
arg@217 68 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
garbeam@5 69 perror(" failed");
garbeam@5 70 }
arg@138 71 exit(0);
garbeam@5 72 }
garbeam@5 73 wait(0);
garbeam@5 74 }