Changeset View
Changeset View
Standalone View
Standalone View
net-mgmt/seafile/files/patch-lib_utils.c
--- lib/utils.c.orig 2015-01-28 01:03:42.000000000 -0500 | --- lib/utils.c.orig 2015-09-21 03:42:11 UTC | ||||
+++ lib/utils.c 2015-01-28 01:26:32.000000000 -0500 | +++ lib/utils.c | ||||
@@ -56,6 +56,16 @@ | @@ -56,6 +56,16 @@ | ||||
#include <zlib.h> | #include <zlib.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); | ||||
@@ -2097,14 +2107,19 @@ | @@ -2112,14 +2122,19 @@ wchar_from_utf8 (const char *utf8) | ||||
#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) | ||||
{ | { | ||||
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; | ||||
} | } | ||||
@@ -2128,7 +2143,8 @@ | @@ -2143,7 +2158,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) { | ||||
@@ -2153,7 +2169,8 @@ | @@ -2168,7 +2184,8 @@ gboolean process_is_running (const char | ||||
return FALSE; | return FALSE; | ||||
} | } | ||||
-int count_process(const char *process_name) | -int count_process(const char *process_name) | ||||
+static int | +static int | ||||
+count_process_procfs(const char *process_name) | +count_process_procfs(const char *process_name) | ||||
{ | { | ||||
int count = 0; | int count = 0; | ||||
DIR *proc_dir = opendir("/proc"); | DIR *proc_dir = opendir("/proc"); | ||||
@@ -2177,6 +2194,14 @@ | @@ -2192,6 +2209,14 @@ int count_process(const char *process_na | ||||
return count; | return count; | ||||
} | } | ||||
+#ifdef __linux__ | +#ifdef __linux__ | ||||
+gboolean process_is_running(const char *process_name) { | +gboolean process_is_running(const char *process_name) { | ||||
+ return process_is_running_procfs(process_name); | + return process_is_running_procfs(process_name); | ||||
+} | +} | ||||
+ | + | ||||
+int count_process(const char *process_name) { | +int count_process(const char *process_name) { | ||||
+ return count_process_procfs(process_name); | + return count_process_procfs(process_name); | ||||
+} | +} | ||||
#endif | #endif | ||||
#ifdef __APPLE__ | #ifdef __APPLE__ | ||||
@@ -2187,6 +2212,119 @@ | @@ -2202,6 +2227,119 @@ 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 111 Lines • Show Last 20 Lines |