]> git.ipfire.org Git - people/ms/network.git/blame - src/networkd/main.c
networkd: Create a simple daemon class
[people/ms/network.git] / src / networkd / main.c
CommitLineData
050f4ece
MT
1/*#############################################################################
2# #
3# IPFire.org - A linux based firewall #
4# Copyright (C) 2023 IPFire Network Development Team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
26acbb4e
MT
21#include <errno.h>
22#include <stdlib.h>
23
24#include <systemd/sd-daemon.h>
25#include <systemd/sd-event.h>
26
112358f3
MT
27#include "daemon.h"
28
050f4ece 29int main(int argc, char** argv) {
112358f3
MT
30 struct nw_daemon* daemon = NULL;
31 int r;
32
26acbb4e
MT
33 // XXX Drop privileges
34
112358f3
MT
35 // Create the daemon
36 r = nw_daemon_create(&daemon);
37 if (r)
38 goto ERROR;
39
26acbb4e
MT
40 // We are now ready to process any requests
41 sd_notify(0, "READY=1\n" "STATUS=Processing requests...");
42
43 // Run event loop
44 // XXX TODO
45
46 // Let systemd know that we are shutting down
47 sd_notify(0, "STOPPING=1\n" "STATUS=Shutting down...");
48
112358f3 49 goto CLEANUP;
26acbb4e
MT
50
51ERROR:
52 sd_notifyf(0, "ERRNO=%i", errno);
53
112358f3
MT
54CLEANUP:
55 if (daemon)
56 nw_daemon_unref(daemon);
57
26acbb4e 58 return EXIT_FAILURE;
050f4ece 59}