Lines 1-104
Link Here
|
1 |
--- controller/seafile-controller.c.orig 2015-09-21 03:42:11 UTC |
|
|
2 |
+++ controller/seafile-controller.c |
3 |
@@ -17,6 +17,19 @@ |
4 |
#include "log.h" |
5 |
#include "seafile-controller.h" |
6 |
|
7 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
8 |
+#include <sys/sysctl.h> |
9 |
+#include <sys/types.h> |
10 |
+#include <sys/user.h> |
11 |
+#include <limits.h> |
12 |
+ |
13 |
+#ifndef WITH_PROC_FS |
14 |
+#define WITH_PROC_FS g_file_test("/proc/curproc", G_FILE_TEST_EXISTS) |
15 |
+#endif |
16 |
+ |
17 |
+static char *command_name = NULL; |
18 |
+#endif |
19 |
+ |
20 |
#define CHECK_PROCESS_INTERVAL 10 /* every 10 seconds */ |
21 |
|
22 |
SeafileController *ctl; |
23 |
@@ -247,7 +260,20 @@ static void |
24 |
init_seafile_path () |
25 |
{ |
26 |
GError *error = NULL; |
27 |
+#if defined(__linux__) |
28 |
char *executable = g_file_read_link ("/proc/self/exe", &error); |
29 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
30 |
+ /* |
31 |
+ * seafile.sh starts the process using abs path |
32 |
+ */ |
33 |
+ char executable[_POSIX_PATH_MAX]; |
34 |
+ memset(executable, 0, _POSIX_PATH_MAX); |
35 |
+ char * rc = realpath(command_name, executable); |
36 |
+ if (!rc) { |
37 |
+ seaf_warning ("failed to readpath: %s\n", executable); |
38 |
+ return; |
39 |
+ } |
40 |
+#endif |
41 |
char *tmp = NULL; |
42 |
if (error != NULL) { |
43 |
seaf_warning ("failed to readlink: %s\n", error->message); |
44 |
@@ -261,7 +287,9 @@ init_seafile_path () |
45 |
|
46 |
topdir = g_path_get_dirname (installpath); |
47 |
|
48 |
+#if defined(__linux__) |
49 |
g_free (executable); |
50 |
+#endif |
51 |
g_free (tmp); |
52 |
} |
53 |
|
54 |
@@ -402,11 +430,40 @@ need_restart (int which) |
55 |
return FALSE; |
56 |
} else { |
57 |
char buf[256]; |
58 |
+ gboolean with_procfs; |
59 |
+#if defined(__linux__) |
60 |
+ with_procfs = g_file_test("/proc/self", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); |
61 |
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) |
62 |
+ with_procfs = g_file_test("/proc/curproc", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); |
63 |
+#else |
64 |
+ with_procfs = FALSE; |
65 |
+#endif |
66 |
+ if (with_procfs) { |
67 |
snprintf (buf, sizeof(buf), "/proc/%d", pid); |
68 |
if (g_file_test (buf, G_FILE_TEST_IS_DIR)) { |
69 |
return FALSE; |
70 |
} else { |
71 |
return TRUE; |
72 |
+ } |
73 |
+ |
74 |
+ } else { |
75 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
76 |
+#ifdef __OpenBSD__ |
77 |
+ int min[6] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), 1}; |
78 |
+#else |
79 |
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}; |
80 |
+#endif |
81 |
+ size_t len = sizeof(struct kinfo_proc); |
82 |
+ struct kinfo_proc kp; |
83 |
+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0) != -1 && |
84 |
+ len == sizeof(struct kinfo_proc)) { |
85 |
+ return FALSE; |
86 |
+ } else { |
87 |
+ return TRUE; |
88 |
+ } |
89 |
+#else |
90 |
+ return FALSE; |
91 |
+#endif |
92 |
} |
93 |
} |
94 |
} |
95 |
@@ -877,6 +934,9 @@ int main (int argc, char **argv) |
96 |
exit (1); |
97 |
} |
98 |
|
99 |
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
100 |
+ command_name = argv[0]; |
101 |
+#endif |
102 |
char *config_dir = DEFAULT_CONFIG_DIR; |
103 |
char *seafile_dir = NULL; |
104 |
char *logdir = NULL; |