Newer
Older
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* SPDX-License-Identifier: GPL-2.0 */
/*
* main.c - qosmngr's boilerplate and entry point
*
* Copyright (C) 2019 iopsys Software Solutions AB. All rights reserved.
*
* Author: Oskar Viljasaar <oskar.viljasaar@iopsys.eu>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <libubus.h>
#include "qosmngr.h"
#include "version.h"
const char *ubus_socket;
struct ubus_context *ctx = NULL;
/* install a signal handler */
int set_sighandler(int sig, void (*handler)(int))
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = handler;
if (sigaction(sig, &sa, NULL) < 0) {
fprintf(stderr, "Error sigaction %d\n", sig);
return -1;
}
return 0;
}
static int qosmngr_exit()
{
ubus_free(ctx);
uloop_done();
exit(EXIT_SUCCESS);
}
static void qosmngr_sighandler(int sig)
{
switch (sig) {
case SIGTERM:
case SIGINT:
qosmngr_exit();
break;
default:
break;
}
}
void qosmngr_version()
{
fprintf(stderr, "version : %s.%s\n", qosmngr_base_version, qosmngr_xtra_version);
}
int main(int argc, char **argv)
{
int ret;
int ch;
while ((ch = getopt(argc, argv, "vs:e:")) != -1) {
switch (ch) {
case 'v':
qosmngr_version();
exit(0);
case 's':
ubus_socket = optarg;
break;
default:
break;
}
}
argc -= optind;
argv += optind;
uloop_init();
ctx = ubus_connect(ubus_socket);
if (!ctx) {
fprintf(stderr, "Failed to connect to ubus\n");
return -1;
}
ubus_add_uloop(ctx);
ret = qosmngr_publish_object(ctx);
if (ret)
goto out;
set_sighandler(SIGPIPE, SIG_DFL);
set_sighandler(SIGINT, qosmngr_sighandler);
set_sighandler(SIGTERM, qosmngr_sighandler);
/* Main loop of qosmngr */
uloop_run();
out:
ubus_free(ctx);
uloop_done();
return 0;
}