1 |
Author: grobian |
2 |
Date: 2011-03-31 14:12:31 +0000 (Thu, 31 Mar 2011) |
3 |
New Revision: 1688 |
4 |
|
5 |
Modified: |
6 |
trunk/baselayout-prefix/src/start-stop-daemon.c |
7 |
Log: |
8 |
applied baselayout-1.12.5-aix.patch |
9 |
|
10 |
W00T, AIX does have /proc filesystem - even with slightly different layout. |
11 |
|
12 |
Modified: trunk/baselayout-prefix/src/start-stop-daemon.c |
13 |
=================================================================== |
14 |
--- trunk/baselayout-prefix/src/start-stop-daemon.c 2011-03-31 14:12:21 UTC (rev 1687) |
15 |
+++ trunk/baselayout-prefix/src/start-stop-daemon.c 2011-03-31 14:12:31 UTC (rev 1688) |
16 |
@@ -56,6 +56,8 @@ |
17 |
# define OSNetBSD |
18 |
#elif defined(__APPLE__) |
19 |
# define OSDarwin |
20 |
+#elif defined(_AIX) |
21 |
+# define OSaix |
22 |
#else |
23 |
# error Unknown architecture - cannot build start-stop-daemon |
24 |
#endif |
25 |
@@ -85,6 +87,10 @@ |
26 |
#include <sys/pstat.h> |
27 |
#endif |
28 |
|
29 |
+#if defined(OSaix) |
30 |
+#include <sys/procfs.h> |
31 |
+#endif |
32 |
+ |
33 |
#include <errno.h> |
34 |
#include <stdio.h> |
35 |
#include <stdlib.h> |
36 |
@@ -178,7 +184,7 @@ |
37 |
static void do_pidfile(const char *name); |
38 |
static void do_stop(int signal_nr, int quietmode, |
39 |
int *n_killed, int *n_notkilled, int retry_nr); |
40 |
-#if defined(OSLinux) || defined(OShpux) |
41 |
+#if defined(OSLinux) || defined(OShpux) || defined(OSaix) |
42 |
static int pid_is_exec(pid_t pid, const struct stat *esb); |
43 |
#endif |
44 |
|
45 |
@@ -755,7 +761,7 @@ |
46 |
static void |
47 |
check(pid_t pid) |
48 |
{ |
49 |
-#if defined(OSLinux) || defined(OShpux) |
50 |
+#if defined(OSLinux) || defined(OShpux) || defined(OSaix) |
51 |
if (execname && !pid_is_exec(pid, &exec_stat)) |
52 |
return; |
53 |
#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin) |
54 |
@@ -791,7 +797,7 @@ |
55 |
/* WTA: this needs to be an autoconf check for /proc/pid existance. |
56 |
*/ |
57 |
|
58 |
-#if defined(OSLinux) || defined (OSsunos) || defined(OSfreebsd) |
59 |
+#if defined(OSLinux) || defined (OSsunos) || defined(OSfreebsd) || defined(OSaix) |
60 |
static void |
61 |
do_procinit(void) |
62 |
{ |
63 |
@@ -1059,7 +1065,59 @@ |
64 |
} |
65 |
#endif /* OShpux */ |
66 |
|
67 |
+#if defined(OSaix) |
68 |
+/* max possible pid (signed long) in theory: |
69 |
+ * 32bit: 2147483647 (10 digits) |
70 |
+ * 64bit: 9223372036854775807 (19 digits) |
71 |
+ */ |
72 |
+static int |
73 |
+pid_is_exec(pid_t pid, const struct stat *esb) |
74 |
+{ |
75 |
+ struct stat sb; |
76 |
+ char buf[40]; |
77 |
|
78 |
+ sprintf(buf, "/proc/%ld/object/a.out", pid); |
79 |
+ if (stat(buf, &sb) != 0) |
80 |
+ return 0; |
81 |
+ return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino); |
82 |
+} |
83 |
+ |
84 |
+ |
85 |
+static int |
86 |
+pid_is_user(pid_t pid, uid_t uid) |
87 |
+{ |
88 |
+ struct stat sb; |
89 |
+ char buf[32]; |
90 |
+ |
91 |
+ sprintf(buf, "/proc/%ld", pid); |
92 |
+ if (stat(buf, &sb) != 0) |
93 |
+ return 0; |
94 |
+ return (sb.st_uid == uid); |
95 |
+} |
96 |
+ |
97 |
+ |
98 |
+static int |
99 |
+pid_is_cmd(pid_t pid, const char *name) |
100 |
+{ |
101 |
+ char buf[40]; |
102 |
+ FILE *f; |
103 |
+ struct psinfo psi; |
104 |
+ int r; |
105 |
+ |
106 |
+ sprintf(buf, "/proc/%ld/psinfo", pid); |
107 |
+ f = fopen(buf, "r"); |
108 |
+ if (!f) |
109 |
+ return 0; |
110 |
+ r = fread(&psi, sizeof(psi), 1, f); |
111 |
+ fclose(f); |
112 |
+ if (r != 1) { |
113 |
+ return 0; |
114 |
+ } |
115 |
+ return strcmp(name, psi.pr_fname) == 0; |
116 |
+} |
117 |
+#endif /* OSaix */ |
118 |
+ |
119 |
+ |
120 |
static void |
121 |
do_findprocs(void) |
122 |
{ |