return conn_first;
}
+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 = 0;
+ fscanf(fp, "%d", &pid);
+ fclose(fp);
+
+ return pid;
+}
+
void ovpnInit(void) {
// Read OpenVPN configuration
char command[STRING_SIZE];
int pid = readPidFile("/var/run/openvpn.pid");
- if (pid == NULL) {
+ if (!pid > 0) {
exit(1);
}
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) {
connection *conn = NULL;
connection *conn_iter;
}
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);
int pid = readPidFile(pidfile);
- if (pid == NULL) {
+ if (!pid > 0) {
exit(1);
}