annotate util.c @ 3:faa4cb9d7bd6

add TASKBAR and CLICK_TO_FOCUS
author paulo@localhost
date Thu, 23 Apr 2009 02:43:13 -0700
parents
children
rev   line source
paulo@0 1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
paulo@0 2 * See LICENSE file for license details.
paulo@0 3 */
paulo@0 4 #include "dwm.h"
paulo@0 5 #include <stdarg.h>
paulo@0 6 #include <stdio.h>
paulo@0 7 #include <stdlib.h>
paulo@0 8 #include <sys/wait.h>
paulo@0 9 #include <unistd.h>
paulo@0 10
paulo@0 11 /* extern */
paulo@0 12
paulo@0 13 void *
paulo@0 14 emallocz(unsigned int size) {
paulo@0 15 void *res = calloc(1, size);
paulo@0 16
paulo@0 17 if(!res)
paulo@0 18 eprint("fatal: could not malloc() %u bytes\n", size);
paulo@0 19 return res;
paulo@0 20 }
paulo@0 21
paulo@0 22 void
paulo@0 23 eprint(const char *errstr, ...) {
paulo@0 24 va_list ap;
paulo@0 25
paulo@0 26 va_start(ap, errstr);
paulo@0 27 vfprintf(stderr, errstr, ap);
paulo@0 28 va_end(ap);
paulo@0 29 exit(EXIT_FAILURE);
paulo@0 30 }
paulo@0 31
paulo@0 32 void
paulo@0 33 spawn(Arg *arg) {
paulo@0 34 static char *shell = NULL;
paulo@0 35
paulo@0 36 if(!shell && !(shell = getenv("SHELL")))
paulo@0 37 shell = "/bin/sh";
paulo@0 38 if(!arg->cmd)
paulo@0 39 return;
paulo@0 40 /* The double-fork construct avoids zombie processes and keeps the code
paulo@0 41 * clean from stupid signal handlers. */
paulo@0 42 if(fork() == 0) {
paulo@0 43 if(fork() == 0) {
paulo@0 44 if(dpy)
paulo@0 45 close(ConnectionNumber(dpy));
paulo@0 46 setsid();
paulo@0 47 execl(shell, shell, "-c", arg->cmd, (char *)NULL);
paulo@0 48 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
paulo@0 49 perror(" failed");
paulo@0 50 }
paulo@0 51 exit(0);
paulo@0 52 }
paulo@0 53 wait(0);
paulo@0 54 }