aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ndb/runproc.c
blob: db344f975e5b8cee147fe46066816256cabeffaa (plain)
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
32
33
34
35
36
37
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include <ndb.h>
#include "dns.h"

Waitmsg*
runprocfd(char *file, char **v, int fd[3])
{
	int pid, i;

	threadwaitchan();
	pid = threadspawn(fd, file, v);
	for(i=0; i<3; i++)
		close(fd[i]);
	if(pid < 0)
		return nil;
	return procwait(pid);
}

Waitmsg*
runproc(char *file, char **v, int devnull)
{
	int fd[3], i;

	if(devnull){
		fd[0] = open("/dev/null", ORDWR);
		fd[1] = dup(1, fd[0]);
		fd[2] = dup(2, fd[0]);
	}else{
		for(i=0; i<3; i++)
			fd[i] = dup(i, -1);
	}
	return runprocfd(file, v, fd);
}