1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2021 Felix Fietkau <nbd@nbd.name>
10 #include <libubox/uloop.h>
14 static int usage(const char *progname
)
16 fprintf(stderr
, "Usage: %s [options]\n"
18 " -l <file> Load defaults from <file>\n"
19 " -o only load program/maps without running as daemon\n"
25 int qosify_run_cmd(char *cmd
, bool ignore_error
)
27 char *argv
[] = { "sh", "-c", cmd
, NULL
};
41 if (fds
[1] != STDOUT_FILENO
)
42 dup2(fds
[1], STDOUT_FILENO
);
43 if (fds
[1] != STDERR_FILENO
)
44 dup2(fds
[1], STDERR_FILENO
);
45 if (fds
[1] > STDERR_FILENO
)
47 execv("/bin/sh", argv
);
55 f
= fdopen(fds
[0], "r");
61 while (fgets(buf
, sizeof(buf
), f
) != NULL
) {
67 ULOG_WARN("Command: %s\n", cmd
);
70 ULOG_WARN("%s%s", buf
, strchr(buf
, '\n') ? "" : "\n");
76 while (waitpid(pid
, &status
, 0) < 0)
84 int main(int argc
, char **argv
)
86 const char *load_file
= NULL
;
90 while ((ch
= getopt(argc
, argv
, "fl:o")) != -1) {
101 return usage(argv
[0]);
105 if (qosify_loader_init())
108 if (qosify_map_init())
111 if (qosify_map_load_file(load_file
))
117 ulog_open(ULOG_SYSLOG
, LOG_DAEMON
, "qosify");
120 if (qosify_ubus_init() ||