]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/qosctrl.c
BETA 1!
[people/pmueller/ipfire-2.x.git] / src / misc-progs / qosctrl.c
CommitLineData
b684b13b
MT
1/* This file is part of the IPFire Firewall.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <unistd.h>
12#include <sys/types.h>
13#include <fcntl.h>
14#include "setuid.h"
15
16int main(int argc, char *argv[]) {
17
18 int fd = -1;
b684b13b
MT
19
20 if (!(initsetuid()))
21 exit(1);
22
23 if (argc < 2) {
cfd19520 24 fprintf(stderr, "\nNo argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
b684b13b
MT
25 exit(1);
26 }
903310c4 27
905fbf3e
MT
28 if (strcmp(argv[1], "generate") == 0)
29 safe_system("/usr/bin/perl /var/ipfire/qos/bin/makeqosscripts.pl > /var/ipfire/qos/bin/qos.sh");
30
903310c4
MT
31 if ((fd = open("/var/ipfire/qos/bin/qos.sh", O_RDONLY)) != -1) {
32 close(fd);
33 } else {
34 // If there is no qos.sh do nothing.
35 exit(0);
36 }
37
e44b26cf 38 safe_system("chmod 755 /var/ipfire/qos/bin/qos.sh &>/dev/null");
a7fb5630 39 if (strcmp(argv[1], "start") == 0) {
903310c4 40 safe_system("/var/ipfire/qos/bin/qos.sh start");
a7fb5630
MT
41 } else if (strcmp(argv[1], "stop") == 0) {
42 safe_system("/var/ipfire/qos/bin/qos.sh clear");
43 } else if (strcmp(argv[1], "status") == 0) {
44 safe_system("/var/ipfire/qos/bin/qos.sh status");
45 } else if (strcmp(argv[1], "restart") == 0) {
46 safe_system("/var/ipfire/qos/bin/qos.sh restart");
47 } else {
cfd19520 48 fprintf(stderr, "\nBad argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
a7fb5630
MT
49 exit(1);
50 }
b684b13b
MT
51
52 return 0;
53}