summaryrefslogtreecommitdiffstats
path: root/src/unitd/unitd.c
blob: be7899a562f65c443239d257c18f345501af9073 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
 *
 * Based on "procd" by:
 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "unitd.h"

#include <sys/types.h>
#include <sys/prctl.h>

#include <errno.h>
#include <unistd.h>


unsigned int debug = 4;


int main()
{
	static char unitd[] = "unitd";

	if (getpid() != 1) {
		fprintf(stderr, "error: must run as PID 1\n");
		return 1;
	}

	program_invocation_short_name = unitd;
	prctl(PR_SET_NAME, unitd);

	ulog_open(ULOG_KMSG, LOG_DAEMON, "unitd");

	setsid();
	uloop_init();
	unitd_signal();
	unitd_state_next();
	uloop_run();
	uloop_done();

	return 0;
}