]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/qosctrl.c
qosctrl: Cleanup code by replacing hardcoded paths
[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
9a09d94e
MT
16#define QOS_SH "/var/ipfire/qos/bin/qos.sh"
17
b684b13b
MT
18int main(int argc, char *argv[]) {
19
af95dec5
CS
20 int fd = -1;
21
22 if (!(initsetuid()))
23 exit(1);
24
25 if (argc < 2) {
26 fprintf(stderr, "\nNo argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
27 exit(1);
28 }
29
30 if (strcmp(argv[1], "generate") == 0) {
9a09d94e 31 safe_system("/usr/bin/perl /var/ipfire/qos/bin/makeqosscripts.pl > " QOS_SH);
af95dec5
CS
32 }
33
9a09d94e 34 if ((fd = open(QOS_SH, O_RDONLY)) != -1) {
af95dec5
CS
35 close(fd);
36 } else {
37 // If there is no qos.sh do nothing.
38 exit(0);
39 }
40
9a09d94e 41 safe_system("chmod 755 " QOS_SH " &>/dev/null");
af95dec5 42 if (strcmp(argv[1], "start") == 0) {
9a09d94e 43 safe_system(QOS_SH " start");
af95dec5 44 } else if (strcmp(argv[1], "stop") == 0) {
9a09d94e 45 safe_system(QOS_SH " clear");
af95dec5 46 } else if (strcmp(argv[1], "status") == 0) {
9a09d94e 47 safe_system(QOS_SH " status");
af95dec5 48 } else if (strcmp(argv[1], "restart") == 0) {
9a09d94e 49 safe_system(QOS_SH " restart");
af95dec5
CS
50 } else {
51 if (strcmp(argv[1], "generate") == 0) {exit(0);}
52 fprintf(stderr, "\nBad argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
53 exit(1);
54 }
55
56 return 0;
b684b13b 57}