summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handler.c1
-rw-r--r--interface-event.c1
-rw-r--r--interface-ip.c1
-rw-r--r--iprule.c1
-rw-r--r--main.c1
-rw-r--r--proto-shell.c1
-rw-r--r--system-linux.c1
-rw-r--r--utils.c27
-rw-r--r--utils.h2
9 files changed, 29 insertions, 7 deletions
diff --git a/handler.c b/handler.c
index 531b509..f4e27e1 100644
--- a/handler.c
+++ b/handler.c
@@ -16,7 +16,6 @@
#include <glob.h>
#include <fcntl.h>
#include <stdio.h>
-#include <unistd.h>
#include "netifd.h"
#include "system.h"
diff --git a/interface-event.c b/interface-event.c
index 707764a..3b0d1fa 100644
--- a/interface-event.c
+++ b/interface-event.c
@@ -14,7 +14,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <libubox/uloop.h>
diff --git a/interface-ip.c b/interface-ip.c
index 2280266..084688c 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
#include <limits.h>
#include <arpa/inet.h>
diff --git a/iprule.c b/iprule.c
index a31db99..4e3dd15 100644
--- a/iprule.c
+++ b/iprule.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
#include <arpa/inet.h>
diff --git a/main.c b/main.c
index c1f55e9..92c6f49 100644
--- a/main.c
+++ b/main.c
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
-#include <unistd.h>
#include <signal.h>
#include <stdarg.h>
#include <syslog.h>
diff --git a/proto-shell.c b/proto-shell.c
index aa638ad..629f43b 100644
--- a/proto-shell.c
+++ b/proto-shell.c
@@ -16,7 +16,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
#include <signal.h>
#include <arpa/inet.h>
diff --git a/system-linux.c b/system-linux.c
index e5364e0..d01d7e3 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -41,7 +41,6 @@
#define RTN_FAILED_POLICY 12
#endif
-#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <glob.h>
diff --git a/utils.c b/utils.c
index 6b53c22..d202505 100644
--- a/utils.c
+++ b/utils.c
@@ -18,6 +18,10 @@
#include <arpa/inet.h>
#include <netinet/in.h>
+#ifdef __APPLE__
+#include <libproc.h>
+#endif
+
void
__vlist_simple_init(struct vlist_simple_tree *tree, int offset)
{
@@ -168,3 +172,26 @@ crc32_file(FILE *fp)
return c ^ 0xFFFFFFFF;
}
+
+bool check_pid_path(int pid, const char *exe)
+{
+ int proc_exe_len;
+ int exe_len = strlen(exe);
+
+#ifdef __APPLE__
+ char proc_exe_buf[PROC_PIDPATHINFO_SIZE];
+
+ proc_exe_len = proc_pidpath(pid, proc_exe_buf, sizeof(proc_exe_buf));
+#else
+ char proc_exe[32];
+ char *proc_exe_buf = alloca(exe_len);
+
+ sprintf(proc_exe, "/proc/%d/exe", pid);
+ proc_exe_len = readlink(proc_exe, proc_exe_buf, exe_len);
+#endif
+
+ if (proc_exe_len != exe_len)
+ return false;
+
+ return !memcmp(exe, proc_exe_buf, exe_len);
+}
diff --git a/utils.h b/utils.h
index 23795e5..b0a7d02 100644
--- a/utils.h
+++ b/utils.h
@@ -14,6 +14,7 @@
#ifndef __NETIFD_UTILS_H
#define __NETIFD_UTILS_H
+#include <unistd.h>
#include <stdio.h>
#include <libubox/list.h>
#include <libubox/avl.h>
@@ -107,6 +108,7 @@ static inline int fls(int x)
unsigned int parse_netmask_string(const char *str, bool v6);
bool split_netmask(char *str, unsigned int *netmask, bool v6);
int parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask);
+bool check_pid_path(int pid, const char *exe);
char * format_macaddr(uint8_t *mac);