File: spawn.c

package info (click to toggle)
wmii2 2.5.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 592 kB
  • ctags: 927
  • sloc: ansic: 9,195; makefile: 228; sh: 136
file content (31 lines) | stat: -rw-r--r-- 556 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "wmii.h"

#include <cext.h>

void 
spawn(void *dpy, char *cmd)
{
	/* the questionable double-fork is done to catch all zombies */
	if (fork() == 0) {
		if (fork() == 0) {
			setsid();
			close(ConnectionNumber(dpy));
			execlp("rc", "rc", "-c", cmd, (char *) 0);
			perror("failed");
			exit(1);
		}
		exit(0);
	}
	wait(0);
}