| @@ -1,206 +1,208 @@ | | | @@ -1,206 +1,208 @@ |
1 | $NetBSD: patch-bf,v 1.5 2016/12/23 04:11:03 ryoon Exp $ | | 1 | $NetBSD: patch-bf,v 1.6 2017/06/23 18:25:12 kamil Exp $ |
2 | | | 2 | |
3 | --- lib/procMgr/procMgrPosix.c.orig 2016-09-29 10:07:22.000000000 +0000 | | 3 | --- lib/procMgr/procMgrPosix.c.orig 2017-02-11 10:06:31.000000000 +0000 |
4 | +++ lib/procMgr/procMgrPosix.c | | 4 | +++ lib/procMgr/procMgrPosix.c |
5 | @@ -27,7 +27,7 @@ | | 5 | @@ -27,7 +27,7 @@ |
6 | // pull in setresuid()/setresgid() if possible | | 6 | // pull in setresuid()/setresgid() if possible |
7 | #define _GNU_SOURCE | | 7 | #define _GNU_SOURCE |
8 | #include <unistd.h> | | 8 | #include <unistd.h> |
9 | -#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) | | 9 | -#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) |
10 | +#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) && !defined(__NetBSD__) | | 10 | +#if !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) && !defined(__NetBSD__) |
11 | #include <asm/param.h> | | 11 | #include <asm/param.h> |
12 | #endif | | 12 | #endif |
13 | #if !defined(sun) && !defined(__APPLE__) | | 13 | #if !defined(sun) && !defined(__APPLE__) |
14 | @@ -47,13 +47,13 @@ | | 14 | @@ -47,13 +47,15 @@ |
15 | #include <time.h> | | 15 | #include <time.h> |
16 | #include <grp.h> | | 16 | #include <grp.h> |
17 | #include <sys/syscall.h> | | 17 | #include <sys/syscall.h> |
18 | -#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) | | 18 | -#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) |
19 | +#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) || defined(__NetBSD__) | | 19 | +#if defined(linux) || defined(__FreeBSD__) || defined(HAVE_SYS_USER_H) || defined(__NetBSD__) |
20 | // sys/param.h is required on FreeBSD before sys/user.h | | 20 | // sys/param.h is required on FreeBSD before sys/user.h |
21 | # include <sys/param.h> | | 21 | # include <sys/param.h> |
22 | // Pull in PAGE_SIZE/PAGE_SHIFT defines ahead of vm_basic_defs.h | | 22 | // Pull in PAGE_SIZE/PAGE_SHIFT defines ahead of vm_basic_defs.h |
| | | 23 | +#if defined(__FreeBSD__) || defined(__DragonFly__) |
23 | # include <sys/user.h> | | 24 | # include <sys/user.h> |
24 | #endif | | 25 | #endif |
25 | -#if defined (__FreeBSD__) | | 26 | -#if defined (__FreeBSD__) |
| | | 27 | +#endif |
26 | +#if defined (__FreeBSD__) || defined(__NetBSD__) | | 28 | +#if defined (__FreeBSD__) || defined(__NetBSD__) |
27 | #include <kvm.h> | | 29 | #include <kvm.h> |
28 | #include <limits.h> | | 30 | #include <limits.h> |
29 | #include <paths.h> | | 31 | #include <paths.h> |
30 | @@ -136,7 +136,7 @@ Bool ProcMgr_PromoteEffectiveToReal(void | | 32 | @@ -136,7 +138,7 @@ Bool ProcMgr_PromoteEffectiveToReal(void |
31 | #ifdef sun | | 33 | #ifdef sun |
32 | #define BASH_PATH "/usr/bin/bash" | | 34 | #define BASH_PATH "/usr/bin/bash" |
33 | #else | | 35 | #else |
34 | -#define BASH_PATH "/bin/bash" | | 36 | -#define BASH_PATH "/bin/bash" |
35 | +#define BASH_PATH "@PREFIX@/bin/bash" | | 37 | +#define BASH_PATH "@PREFIX@/bin/bash" |
36 | #endif | | 38 | #endif |
37 | | | 39 | |
38 | | | 40 | |
39 | @@ -607,7 +607,7 @@ abort: | | 41 | @@ -607,7 +609,7 @@ abort: |
40 | *---------------------------------------------------------------------- | | 42 | *---------------------------------------------------------------------- |
41 | */ | | 43 | */ |
42 | | | 44 | |
43 | -#if defined(__FreeBSD__) | | 45 | -#if defined(__FreeBSD__) |
44 | +#if defined(__FreeBSD__) || defined(__NetBSD__) | | 46 | +#if defined(__FreeBSD__) || defined(__NetBSD__) |
45 | ProcMgrProcInfoArray * | | 47 | ProcMgrProcInfoArray * |
46 | ProcMgr_ListProcesses(void) | | 48 | ProcMgr_ListProcesses(void) |
47 | { | | 49 | { |
48 | @@ -615,7 +615,11 @@ ProcMgr_ListProcesses(void) | | 50 | @@ -615,7 +617,11 @@ ProcMgr_ListProcesses(void) |
49 | ProcMgrProcInfo procInfo; | | 51 | ProcMgrProcInfo procInfo; |
50 | Bool failed = TRUE; | | 52 | Bool failed = TRUE; |
51 | static kvm_t *kd; | | 53 | static kvm_t *kd; |
52 | +#if defined(__NetBSD__) | | 54 | +#if defined(__NetBSD__) |
53 | + struct kinfo_proc2 *kp; | | 55 | + struct kinfo_proc2 *kp; |
54 | +#else | | 56 | +#else |
55 | struct kinfo_proc *kp; | | 57 | struct kinfo_proc *kp; |
56 | +#endif | | 58 | +#endif |
57 | char errbuf[_POSIX2_LINE_MAX]; | | 59 | char errbuf[_POSIX2_LINE_MAX]; |
58 | int i; | | 60 | int i; |
59 | int nentries=-1; | | 61 | int nentries=-1; |
60 | @@ -638,7 +642,12 @@ ProcMgr_ListProcesses(void) | | 62 | @@ -638,7 +644,12 @@ ProcMgr_ListProcesses(void) |
61 | /* | | 63 | /* |
62 | * Get the list of process info structs | | 64 | * Get the list of process info structs |
63 | */ | | 65 | */ |
64 | +#if defined(__NetBSD__) | | 66 | +#if defined(__NetBSD__) |
65 | + int elemsize = sizeof(struct kinfo_proc2); | | 67 | + int elemsize = sizeof(struct kinfo_proc2); |
66 | + kp = kvm_getproc2(kd, KERN_PROC_ALL, flag, elemsize, &nentries); | | 68 | + kp = kvm_getproc2(kd, KERN_PROC_ALL, flag, elemsize, &nentries); |
67 | +#else | | 69 | +#else |
68 | kp = kvm_getprocs(kd, KERN_PROC_PROC, flag, &nentries); | | 70 | kp = kvm_getprocs(kd, KERN_PROC_PROC, flag, &nentries); |
69 | +#endif | | 71 | +#endif |
70 | if (kp == NULL || nentries <= 0) { | | 72 | if (kp == NULL || nentries <= 0) { |
71 | Warning("%s: failed to get proc infos with error: %s\n", | | 73 | Warning("%s: failed to get proc infos with error: %s\n", |
72 | __FUNCTION__, kvm_geterr(kd)); | | 74 | __FUNCTION__, kvm_geterr(kd)); |
73 | @@ -666,14 +675,26 @@ ProcMgr_ListProcesses(void) | | 75 | @@ -666,14 +677,26 @@ ProcMgr_ListProcesses(void) |
74 | /* | | 76 | /* |
75 | * Store the pid of the process. | | 77 | * Store the pid of the process. |
76 | */ | | 78 | */ |
77 | +#if defined(__NetBSD__) | | 79 | +#if defined(__NetBSD__) |
78 | + procInfo.procId = kp->p_pid; | | 80 | + procInfo.procId = kp->p_pid; |
79 | +#else | | 81 | +#else |
80 | procInfo.procId = kp->ki_pid; | | 82 | procInfo.procId = kp->ki_pid; |
81 | +#endif | | 83 | +#endif |
82 | | | 84 | |
83 | /* | | 85 | /* |
84 | * Store the owner of the process. | | 86 | * Store the owner of the process. |
85 | */ | | 87 | */ |
86 | +#if defined(__NetBSD__) | | 88 | +#if defined(__NetBSD__) |
87 | + pwd = getpwuid(kp->p_uid); | | 89 | + pwd = getpwuid(kp->p_uid); |
88 | +#else | | 90 | +#else |
89 | pwd = getpwuid(kp->ki_uid); | | 91 | pwd = getpwuid(kp->ki_uid); |
90 | +#endif | | 92 | +#endif |
91 | procInfo.procOwner = (NULL == pwd) | | 93 | procInfo.procOwner = (NULL == pwd) |
92 | +#if defined(__NetBSD__) | | 94 | +#if defined(__NetBSD__) |
93 | + ? Str_SafeAsprintf(NULL, "%d", (int) kp->p_uid) | | 95 | + ? Str_SafeAsprintf(NULL, "%d", (int) kp->p_uid) |
94 | +#else | | 96 | +#else |
95 | ? Str_SafeAsprintf(NULL, "%d", (int) kp->ki_uid) | | 97 | ? Str_SafeAsprintf(NULL, "%d", (int) kp->ki_uid) |
96 | +#endif | | 98 | +#endif |
97 | : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT); | | 99 | : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT); |
98 | | | 100 | |
99 | /* | | 101 | /* |
100 | @@ -681,15 +702,24 @@ ProcMgr_ListProcesses(void) | | 102 | @@ -681,15 +704,24 @@ ProcMgr_ListProcesses(void) |
101 | * maximum allowed size, then we can save it right now. Else we shall | | 103 | * maximum allowed size, then we can save it right now. Else we shall |
102 | * need to try and parse it from the entire command line. | | 104 | * need to try and parse it from the entire command line. |
103 | */ | | 105 | */ |
104 | +#if defined(__NetBSD__) | | 106 | +#if defined(__NetBSD__) |
105 | + if (strlen(kp->p_comm) + 1 < sizeof kp->p_comm) { | | 107 | + if (strlen(kp->p_comm) + 1 < sizeof kp->p_comm) { |
106 | + procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); | | 108 | + procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); |
107 | +#else | | 109 | +#else |
108 | if (strlen(kp->ki_comm) + 1 < sizeof kp->ki_comm) { | | 110 | if (strlen(kp->ki_comm) + 1 < sizeof kp->ki_comm) { |
109 | procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); | | 111 | procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); |
110 | +#endif | | 112 | +#endif |
111 | cmdNameLookup = FALSE; | | 113 | cmdNameLookup = FALSE; |
112 | } | | 114 | } |
113 | | | 115 | |
114 | /* | | 116 | /* |
115 | * Store the command line string of the process. | | 117 | * Store the command line string of the process. |
116 | */ | | 118 | */ |
117 | +#if defined(__NetBSD__) | | 119 | +#if defined(__NetBSD__) |
118 | + cmdLineTemp = kvm_getargv2(kd, kp, 0); | | 120 | + cmdLineTemp = kvm_getargv2(kd, kp, 0); |
119 | +#else | | 121 | +#else |
120 | cmdLineTemp = kvm_getargv(kd, kp, 0); | | 122 | cmdLineTemp = kvm_getargv(kd, kp, 0); |
121 | +#endif | | 123 | +#endif |
122 | if (cmdLineTemp != NULL) { | | 124 | if (cmdLineTemp != NULL) { |
123 | /* | | 125 | /* |
124 | * Flatten the argument list to get cmd & all params. | | 126 | * Flatten the argument list to get cmd & all params. |
125 | @@ -745,9 +775,15 @@ ProcMgr_ListProcesses(void) | | 127 | @@ -745,9 +777,15 @@ ProcMgr_ListProcesses(void) |
126 | procInfo.procCmdLine = DynBuf_Detach(&dbuf); | | 128 | procInfo.procCmdLine = DynBuf_Detach(&dbuf); |
127 | DynBuf_Destroy(&dbuf); | | 129 | DynBuf_Destroy(&dbuf); |
128 | } else { | | 130 | } else { |
129 | +#if defined(__NetBSD__) | | 131 | +#if defined(__NetBSD__) |
130 | + procInfo.procCmdLine = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); | | 132 | + procInfo.procCmdLine = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); |
131 | + if (cmdNameLookup) { | | 133 | + if (cmdNameLookup) { |
132 | + procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); | | 134 | + procInfo.procCmdName = Unicode_Alloc(kp->p_comm, STRING_ENCODING_DEFAULT); |
133 | +#else | | 135 | +#else |
134 | procInfo.procCmdLine = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); | | 136 | procInfo.procCmdLine = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); |
135 | if (cmdNameLookup) { | | 137 | if (cmdNameLookup) { |
136 | procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); | | 138 | procInfo.procCmdName = Unicode_Alloc(kp->ki_comm, STRING_ENCODING_DEFAULT); |
137 | +#endif | | 139 | +#endif |
138 | cmdNameLookup = FALSE; | | 140 | cmdNameLookup = FALSE; |
139 | } | | 141 | } |
140 | } | | 142 | } |
141 | @@ -755,7 +791,11 @@ ProcMgr_ListProcesses(void) | | 143 | @@ -755,7 +793,11 @@ ProcMgr_ListProcesses(void) |
142 | /* | | 144 | /* |
143 | * Store the start time of the process | | 145 | * Store the start time of the process |
144 | */ | | 146 | */ |
145 | +#if defined(__NetBSD__) | | 147 | +#if defined(__NetBSD__) |
146 | + procInfo.procStartTime = kp->p_rtime_sec; | | 148 | + procInfo.procStartTime = kp->p_rtime_sec; |
147 | +#else | | 149 | +#else |
148 | procInfo.procStartTime = kp->ki_start.tv_sec; | | 150 | procInfo.procStartTime = kp->ki_start.tv_sec; |
149 | +#endif | | 151 | +#endif |
150 | | | 152 | |
151 | /* | | 153 | /* |
152 | * Store the process info pointer into a list buffer. | | 154 | * Store the process info pointer into a list buffer. |
153 | @@ -785,7 +825,7 @@ abort: | | 155 | @@ -785,7 +827,7 @@ abort: |
154 | | | 156 | |
155 | return procList; | | 157 | return procList; |
156 | } | | 158 | } |
157 | -#endif // defined(__FreeBSD__) | | 159 | -#endif // defined(__FreeBSD__) |
158 | +#endif // defined(__NetBSD__) | | 160 | +#endif // defined(__NetBSD__) |
159 | | | 161 | |
160 | | | 162 | |
161 | #if defined(__APPLE__) | | 163 | #if defined(__APPLE__) |
162 | @@ -2022,7 +2062,7 @@ ProcMgr_Free(ProcMgr_AsyncProc *asyncPro | | 164 | @@ -2022,7 +2064,7 @@ ProcMgr_Free(ProcMgr_AsyncProc *asyncPro |
163 | free(asyncProc); | | 165 | free(asyncProc); |
164 | } | | 166 | } |
165 | | | 167 | |
166 | -#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) | | 168 | -#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) |
167 | +#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) | | 169 | +#if defined(linux) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) |
168 | | | 170 | |
169 | /* | | 171 | /* |
170 | *---------------------------------------------------------------------- | | 172 | *---------------------------------------------------------------------- |
171 | @@ -2104,7 +2144,7 @@ ProcMgr_ImpersonateUserStart(const char | | 173 | @@ -2104,7 +2146,7 @@ ProcMgr_ImpersonateUserStart(const char |
172 | // first change group | | 174 | // first change group |
173 | #if defined(USERWORLD) | | 175 | #if defined(USERWORLD) |
174 | ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); | | 176 | ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); |
175 | -#elif defined(__APPLE__) | | 177 | -#elif defined(__APPLE__) |
176 | +#elif defined(__APPLE__) || defined(__NetBSD__) | | 178 | +#elif defined(__APPLE__) || defined(__NetBSD__) |
177 | ret = setegid(ppw->pw_gid); | | 179 | ret = setegid(ppw->pw_gid); |
178 | #else | | 180 | #else |
179 | ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid); | | 181 | ret = setresgid(ppw->pw_gid, ppw->pw_gid, root_gid); |
180 | @@ -2123,7 +2163,7 @@ ProcMgr_ImpersonateUserStart(const char | | 182 | @@ -2123,7 +2165,7 @@ ProcMgr_ImpersonateUserStart(const char |
181 | // now user | | 183 | // now user |
182 | #if defined(USERWORLD) | | 184 | #if defined(USERWORLD) |
183 | ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); | | 185 | ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); |
184 | -#elif defined(__APPLE__) | | 186 | -#elif defined(__APPLE__) |
185 | +#elif defined(__APPLE__) || defined(__NetBSD__) | | 187 | +#elif defined(__APPLE__) || defined(__NetBSD__) |
186 | ret = seteuid(ppw->pw_uid); | | 188 | ret = seteuid(ppw->pw_uid); |
187 | #else | | 189 | #else |
188 | ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); | | 190 | ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); |
189 | @@ -2185,7 +2225,7 @@ ProcMgr_ImpersonateUserStop(void) | | 191 | @@ -2185,7 +2227,7 @@ ProcMgr_ImpersonateUserStop(void) |
190 | // first change back user | | 192 | // first change back user |
191 | #if defined(USERWORLD) | | 193 | #if defined(USERWORLD) |
192 | ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); | | 194 | ret = Id_SetREUid(ppw->pw_uid, ppw->pw_uid); |
193 | -#elif defined(__APPLE__) | | 195 | -#elif defined(__APPLE__) |
194 | +#elif defined(__APPLE__) || defined(__NetBSD__) | | 196 | +#elif defined(__APPLE__) || defined(__NetBSD__) |
195 | ret = seteuid(ppw->pw_uid); | | 197 | ret = seteuid(ppw->pw_uid); |
196 | #else | | 198 | #else |
197 | ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); | | 199 | ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0); |
198 | @@ -2198,7 +2238,7 @@ ProcMgr_ImpersonateUserStop(void) | | 200 | @@ -2198,7 +2240,7 @@ ProcMgr_ImpersonateUserStop(void) |
199 | // now group | | 201 | // now group |
200 | #if defined(USERWORLD) | | 202 | #if defined(USERWORLD) |
201 | ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); | | 203 | ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid); |
202 | -#elif defined(__APPLE__) | | 204 | -#elif defined(__APPLE__) |
203 | +#elif defined(__APPLE__) || defined(__NetBSD__) | | 205 | +#elif defined(__APPLE__) || defined(__NetBSD__) |
204 | ret = setegid(ppw->pw_gid); | | 206 | ret = setegid(ppw->pw_gid); |
205 | #else | | 207 | #else |
206 | ret = setresgid(ppw->pw_gid, ppw->pw_gid, ppw->pw_gid); | | 208 | ret = setresgid(ppw->pw_gid, ppw->pw_gid, ppw->pw_gid); |