Lines 1-17
Link Here
|
1 |
--- controller/seafile-controller.c.orig 2014-08-05 01:28:35.000000000 -0400 |
1 |
--- controller/seafile-controller.c.orig 2014-08-05 01:28:35.000000000 -0400 |
2 |
+++ controller/seafile-controller.c 2014-08-30 09:11:34.868400091 -0400 |
2 |
+++ controller/seafile-controller.c 2014-11-11 19:29:27.352982983 -0500 |
3 |
@@ -18,6 +18,10 @@ |
3 |
@@ -18,6 +18,13 @@ |
4 |
#include "log.h" |
4 |
#include "log.h" |
5 |
#include "seafile-controller.h" |
5 |
#include "seafile-controller.h" |
6 |
|
6 |
|
7 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
7 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
8 |
+#include <sys/sysctl.h> |
8 |
+#include <sys/sysctl.h> |
|
|
9 |
+#include <sys/types.h> |
10 |
+#include <sys/user.h> |
11 |
+#include <limits.h> |
9 |
+#endif |
12 |
+#endif |
10 |
+ |
13 |
+ |
11 |
#define CHECK_PROCESS_INTERVAL 10 /* every 10 seconds */ |
14 |
#define CHECK_PROCESS_INTERVAL 10 /* every 10 seconds */ |
12 |
|
15 |
|
13 |
SeafileController *ctl; |
16 |
SeafileController *ctl; |
14 |
@@ -273,7 +277,11 @@ |
17 |
@@ -273,7 +280,19 @@ |
15 |
init_seafile_path () |
18 |
init_seafile_path () |
16 |
{ |
19 |
{ |
17 |
GError *error = NULL; |
20 |
GError *error = NULL; |
Lines 18-25
Link Here
|
18 |
+#if defined(__linux__) |
21 |
+#if defined(__linux__) |
19 |
char *executable = g_file_read_link ("/proc/self/exe", &error); |
22 |
char *executable = g_file_read_link ("/proc/self/exe", &error); |
20 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
23 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
21 |
+ char *executable = g_file_read_link ("/proc/curproc/file", &error); |
24 |
+ char executable[_POSIX_PATH_MAX]; |
|
|
25 |
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, 0}; |
26 |
+ size_t len = _POSIX_PATH_MAX ; |
27 |
+ mib[3] = (int)getpid(); |
28 |
+ memset(executable, _POSIX_PATH_MAX, 0); |
29 |
+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), executable, &len, NULL, 0) == -1) { |
30 |
+ seaf_warning ("Error: failed to get process entry\n"); |
31 |
+ return; |
32 |
+ } |
22 |
+#endif |
33 |
+#endif |
23 |
char *tmp = NULL; |
34 |
char *tmp = NULL; |
24 |
if (error != NULL) { |
35 |
if (error != NULL) { |
25 |
seaf_warning ("failed to readlink: %s\n", error->message); |
36 |
seaf_warning ("failed to readlink: %s\n", error->message); |
|
|
37 |
@@ -287,7 +306,9 @@ |
38 |
|
39 |
topdir = g_path_get_dirname (installpath); |
40 |
|
41 |
+#if defined(__linux__) |
42 |
g_free (executable); |
43 |
+#endif |
44 |
g_free (tmp); |
45 |
} |
46 |
|
47 |
@@ -426,6 +447,7 @@ |
48 |
seaf_warning ("failed to read pidfile %s: %s\n", ctl->pidfile[which], strerror(errno)); |
49 |
return FALSE; |
50 |
} else { |
51 |
+#ifdef __linux__ |
52 |
char buf[256]; |
53 |
snprintf (buf, sizeof(buf), "/proc/%d", pid); |
54 |
if (g_file_test (buf, G_FILE_TEST_IS_DIR)) { |
55 |
@@ -433,7 +455,22 @@ |
56 |
} else { |
57 |
return TRUE; |
58 |
} |
59 |
- } |
60 |
+#endif |
61 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
62 |
+#ifdef __OpenBSD__ |
63 |
+ int min[6] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), 1}; |
64 |
+#else |
65 |
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}; |
66 |
+#endif |
67 |
+ size_t len = sizeof(struct kinfo_proc); |
68 |
+ struct kinfo_proc kp; |
69 |
+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0) == -1) { |
70 |
+ return FALSE; |
71 |
+ } else { |
72 |
+ return TRUE; |
73 |
+ } |
74 |
+ } |
75 |
+#endif |
76 |
} |
77 |
|
78 |
static gboolean |