Changeset View
Changeset View
Standalone View
Standalone View
net-mgmt/ccnet/files/patch-lib_utils.c
--- lib/utils.c.orig 2015-01-27 23:13:50.000000000 -0500 | --- lib/utils.c.orig 2015-11-11 09:50:52 UTC | ||||
+++ lib/utils.c 2015-01-27 23:18:04.000000000 -0500 | +++ lib/utils.c | ||||
@@ -43,6 +43,16 @@ | @@ -43,6 +43,16 @@ | ||||
#include <event2/util.h> | #include <event2/util.h> | ||||
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) | +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) | ||||
+#include <netinet/in.h> | +#include <netinet/in.h> | ||||
+#include <stdlib.h> | +#include <stdlib.h> | ||||
+#include <kvm.h> | +#include <kvm.h> | ||||
+#include <paths.h> | +#include <paths.h> | ||||
+#include <sys/param.h> | +#include <sys/param.h> | ||||
+#include <sys/sysctl.h> | +#include <sys/sysctl.h> | ||||
+#include <sys/user.h> | +#include <sys/user.h> | ||||
+#endif | +#endif | ||||
+ | + | ||||
extern int inet_pton(int af, const char *src, void *dst); | extern int inet_pton(int af, const char *src, void *dst); | ||||
@@ -1465,14 +1475,20 @@ | @@ -1469,14 +1479,20 @@ get_argv_utf8 (int *argc) | ||||
} | } | ||||
#endif /* ifdef WIN32 */ | #endif /* ifdef WIN32 */ | ||||
-#ifdef __linux__ | -#ifdef __linux__ | ||||
+ | + | ||||
/* read the link of /proc/123/exe and compare with `process_name' */ | /* read the link of /proc/123/exe and compare with `process_name' */ | ||||
static int | static int | ||||
-find_process_in_dirent(struct dirent *dir, const char *process_name) | -find_process_in_dirent(struct dirent *dir, const char *process_name) | ||||
+find_process_in_dirent_procfs(struct dirent *dir, const char *process_name) | +find_process_in_dirent_procfs(struct dirent *dir, const char *process_name) | ||||
{ | { | ||||
char path[512]; | char path[512]; | ||||
/* fisrst construct a path like /proc/123/exe */ | /* fisrst construct a path like /proc/123/exe */ | ||||
+#if defined(__linux__) | +#if defined(__linux__) | ||||
if (sprintf (path, "/proc/%s/exe", dir->d_name) < 0) { | if (sprintf (path, "/proc/%s/exe", dir->d_name) < 0) { | ||||
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) | +#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) | ||||
+ if (sprintf (path, "/proc/%s/file", dir->d_name) < 0) { | + if (sprintf (path, "/proc/%s/file", dir->d_name) < 0) { | ||||
+#else | +#else | ||||
+ if (1) { | + if (1) { | ||||
+#endif | +#endif | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -1496,7 +1512,8 @@ | @@ -1500,7 +1516,8 @@ find_process_in_dirent(struct dirent *di | ||||
} | } | ||||
/* read the /proc fs to determine whether some process is running */ | /* read the /proc fs to determine whether some process is running */ | ||||
-gboolean process_is_running (const char *process_name) | -gboolean process_is_running (const char *process_name) | ||||
+static gboolean | +static gboolean | ||||
+process_is_running_procfs (const char *process_name) | +process_is_running_procfs (const char *process_name) | ||||
{ | { | ||||
DIR *proc_dir = opendir("/proc"); | DIR *proc_dir = opendir("/proc"); | ||||
if (!proc_dir) { | if (!proc_dir) { | ||||
@@ -1510,7 +1527,7 @@ | @@ -1514,7 +1531,7 @@ gboolean process_is_running (const char | ||||
/* /proc/[1-9][0-9]* */ | /* /proc/[1-9][0-9]* */ | ||||
if (first > '9' || first < '1') | if (first > '9' || first < '1') | ||||
continue; | continue; | ||||
- int pid = find_process_in_dirent(subdir, process_name); | - int pid = find_process_in_dirent(subdir, process_name); | ||||
+ int pid = find_process_in_dirent_procfs(subdir, process_name); | + int pid = find_process_in_dirent_procfs(subdir, process_name); | ||||
if (pid > 0) { | if (pid > 0) { | ||||
closedir(proc_dir); | closedir(proc_dir); | ||||
return TRUE; | return TRUE; | ||||
@@ -1520,6 +1537,18 @@ | @@ -1524,6 +1541,18 @@ gboolean process_is_running (const char | ||||
closedir(proc_dir); | closedir(proc_dir); | ||||
return FALSE; | return FALSE; | ||||
} | } | ||||
+ | + | ||||
+#ifdef __linux__ | +#ifdef __linux__ | ||||
+static int | +static int | ||||
+find_process_in_dirent(struct dirent *dir, const char *process_name) | +find_process_in_dirent(struct dirent *dir, const char *process_name) | ||||
+{ | +{ | ||||
+ return find_process_in_dirent_procfs(dir, process_name); | + return find_process_in_dirent_procfs(dir, process_name); | ||||
+} | +} | ||||
+ | + | ||||
+gboolean | +gboolean | ||||
+process_is_running (const char *process_name) { | +process_is_running (const char *process_name) { | ||||
+ return process_is_running_procfs(process_name); | + return process_is_running_procfs(process_name); | ||||
+} | +} | ||||
#endif | #endif | ||||
#ifdef __APPLE__ | #ifdef __APPLE__ | ||||
@@ -1530,6 +1559,108 @@ | @@ -1534,6 +1563,108 @@ gboolean process_is_running (const char | ||||
} | } | ||||
#endif | #endif | ||||
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) | +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) | ||||
+#if defined(__FreeBSD__) | +#if defined(__FreeBSD__) | ||||
+#define PSKIP(kp) ((kp)->ki_pid == mypid || \ | +#define PSKIP(kp) ((kp)->ki_pid == mypid || \ | ||||
+ (!kthreads && ((kp)->ki_flag & P_KTHREAD) != 0)) | + (!kthreads && ((kp)->ki_flag & P_KTHREAD) != 0)) | ||||
+#define KVM_OPENFILES(exec, coref, buf) \ | +#define KVM_OPENFILES(exec, coref, buf) \ | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |