CMake: bump the minimum required CMake version to 3.5
[project/netifd.git] / utils.c
diff --git a/utils.c b/utils.c
index e01b633c09e0143ebf98dbdb62ef77deecacaf73..8997b4853b615142ee0ae9ff808d153f2ba9d1fd 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -13,7 +13,6 @@
  */
 #include <string.h>
 #include <stdlib.h>
-#include "utils.h"
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
@@ -23,6 +22,8 @@
 #include <libproc.h>
 #endif
 
+#include "utils.h"
+
 void
 __vlist_simple_init(struct vlist_simple_tree *tree, int offset)
 {
@@ -119,7 +120,6 @@ int
 parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask)
 {
        char *astr = alloca(strlen(str) + 1);
-       int ret = 0;
 
        strcpy(astr, str);
        if (!split_netmask(astr, netmask, af == AF_INET6))
@@ -133,23 +133,7 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask)
                        return 0;
        }
 
-       ret = inet_pton(af, astr, addr);
-       if (ret > 0) {
-               if (af == AF_INET) {
-                       struct in_addr *ip4_addr = (struct in_addr *)addr;
-                       uint32_t host_addr = ntohl(ip4_addr->s_addr);
-
-                       if (IN_EXPERIMENTAL(host_addr)) {
-                               return 0;
-                       }
-               }
-               else if (af == AF_INET6) {
-                       if (IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) {
-                               return 0;
-                       }
-               }
-       }
-       return ret;
+       return inet_pton(af, astr, addr);
 }
 
 char *
@@ -193,6 +177,8 @@ crc32_file(FILE *fp)
 
 bool check_pid_path(int pid, const char *exe)
 {
+       const char deleted[] = " (deleted)";
+       const int deleted_len = strlen(deleted);
        int proc_exe_len;
        int exe_len = strlen(exe);
 
@@ -208,10 +194,13 @@ bool check_pid_path(int pid, const char *exe)
        proc_exe_len = readlink(proc_exe, proc_exe_buf, exe_len);
 #endif
 
-       if (proc_exe_len != exe_len)
+       if (proc_exe_len == exe_len)
+               return !memcmp(exe, proc_exe_buf, exe_len);
+       else if (proc_exe_len == exe_len + deleted_len)
+               return !memcmp(exe, proc_exe_buf, exe_len) &&
+                       !memcmp(exe + exe_len, deleted, deleted_len);
+       else
                return false;
-
-       return !memcmp(exe, proc_exe_buf, exe_len);
 }
 
 static const char * const uci_validate_name[__BLOBMSG_TYPE_LAST] = {