mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
openvpnctrl: Support killing only the roadwarrior server.
This commit is contained in:
@@ -368,12 +368,16 @@ void setFirewallRules(void) {
|
|||||||
void stopDaemon(void) {
|
void stopDaemon(void) {
|
||||||
char command[STRING_SIZE];
|
char command[STRING_SIZE];
|
||||||
|
|
||||||
snprintf(command, STRING_SIZE - 1, "/bin/killall openvpn");
|
int pid = readPidFile("/var/run/openvpn.pid");
|
||||||
executeCommand(command);
|
if (pid == NULL) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Killing PID %d.\n", pid);
|
||||||
|
kill(pid, SIGTERM);
|
||||||
|
|
||||||
snprintf(command, STRING_SIZE - 1, "/bin/rm -f /var/run/openvpn.pid");
|
snprintf(command, STRING_SIZE - 1, "/bin/rm -f /var/run/openvpn.pid");
|
||||||
executeCommand(command);
|
executeCommand(command);
|
||||||
snprintf(command, STRING_SIZE-1, "/sbin/modprobe -r tun");
|
|
||||||
executeCommand(command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDaemon(void) {
|
void startDaemon(void) {
|
||||||
@@ -429,6 +433,20 @@ void startNet2Net(char *name) {
|
|||||||
executeCommand(command);
|
executeCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int readPidFile(const char *pidfile) {
|
||||||
|
FILE *fp = fopen(pidfile, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
fprintf(stderr, "PID file not found: '%s'\n", pidfile);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pid = NULL;
|
||||||
|
fscanf(fp, "%d", &pid);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
void killNet2Net(char *name) {
|
void killNet2Net(char *name) {
|
||||||
connection *conn = NULL;
|
connection *conn = NULL;
|
||||||
connection *conn_iter;
|
connection *conn_iter;
|
||||||
@@ -451,17 +469,11 @@ void killNet2Net(char *name) {
|
|||||||
char pidfile[STRING_SIZE];
|
char pidfile[STRING_SIZE];
|
||||||
snprintf(&pidfile, STRING_SIZE - 1, "/var/run/%sn2n.pid", conn->name);
|
snprintf(&pidfile, STRING_SIZE - 1, "/var/run/%sn2n.pid", conn->name);
|
||||||
|
|
||||||
FILE *fp = fopen(pidfile, "r");
|
int pid = readPidFile(pidfile);
|
||||||
if (fp == NULL) {
|
if (pid == NULL) {
|
||||||
fprintf(stderr, "Could not determine PID for connection '%s'.\n", conn->name);
|
|
||||||
fprintf(stderr, "PID file not found: '%s'\n", pidfile);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pid;
|
|
||||||
fscanf(fp, "%d", &pid);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fprintf(stderr, "Killing PID %d.\n", pid);
|
fprintf(stderr, "Killing PID %d.\n", pid);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user