aboutsummaryrefslogtreecommitdiff
path: root/initd/runsvc.c
blob: 338a7de2a6817d47df378899ffda7f8724679b1b (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
/* SPDX-License-Identifier: ISC */
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#include "init.h"

pid_t runsvc(service_t *svc)
{
	char *argv[4], *envp[1];
	pid_t pid;

	argv[0] = (char *)RUNSVCBIN;
	argv[1] = (char *)SVCDIR;
	argv[2] = svc->fname;
	argv[3] = NULL;

	envp[0] = NULL;

	pid = fork();

	if (pid == -1)
		perror("fork");

	if (pid == 0) {
		sigreset();
		execve(argv[0], argv, envp);
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}

	return pid;
}