aboutsummaryrefslogtreecommitdiff
path: root/src/util/os_priority.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r--src/util/os_priority.c204
1 files changed, 103 insertions, 101 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 4c77704bf..cb04428d3 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -141,23 +141,23 @@ GNUNET_OS_start_process (const char *filename, ...)
141 if (ret != 0) 141 if (ret != 0)
142 { 142 {
143 if (ret == -1) 143 if (ret == -1)
144 { 144 {
145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
146 } 146 }
147 else 147 else
148 { 148 {
149#if HAVE_WORKING_VFORK 149#if HAVE_WORKING_VFORK
150 /* let's hope vfork actually works; for some extreme cases (including 150 /* let's hope vfork actually works; for some extreme cases (including
151 a testcase) we need 'execvp' to have run before we return, since 151 a testcase) we need 'execvp' to have run before we return, since
152 we may send a signal to the process next and we don't want it 152 we may send a signal to the process next and we don't want it
153 to be caught by OUR signal handler (but either by the default 153 to be caught by OUR signal handler (but either by the default
154 handler or the actual handler as installed by the process itself). */ 154 handler or the actual handler as installed by the process itself). */
155#else 155#else
156 /* let's give the child process a chance to run execvp, 1s should 156 /* let's give the child process a chance to run execvp, 1s should
157 be plenty in practice */ 157 be plenty in practice */
158 sleep (1); 158 sleep (1);
159#endif 159#endif
160 } 160 }
161 return ret; 161 return ret;
162 } 162 }
163 argc = 0; 163 argc = 0;
@@ -184,29 +184,30 @@ GNUNET_OS_start_process (const char *filename, ...)
184 cmdlen = 0; 184 cmdlen = 0;
185 va_start (ap, filename); 185 va_start (ap, filename);
186 while (NULL != (arg = va_arg (ap, char *))) 186 while (NULL != (arg = va_arg (ap, char *)))
187 cmdlen = cmdlen + strlen (arg) + 3; 187 cmdlen = cmdlen + strlen (arg) + 3;
188 va_end (ap); 188 va_end (ap);
189 189
190 cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); 190 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
191 va_start (ap, filename); 191 va_start (ap, filename);
192 while (NULL != (arg = va_arg (ap, char *))) 192 while (NULL != (arg = va_arg (ap, char *)))
193 idx += sprintf (idx, "\"%s\" ", arg); 193 idx += sprintf (idx, "\"%s\" ", arg);
194 va_end (ap); 194 va_end (ap);
195 195
196 memset (&start, 0, sizeof(start)); 196 memset (&start, 0, sizeof (start));
197 start.cb = sizeof(start); 197 start.cb = sizeof (start);
198 198
199 if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, 199 if (!CreateProcess
200 NULL, &start, &proc)) 200 (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
201 { 201 &proc))
202 SetErrnoFromWinError (GetLastError ()); 202 {
203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 203 SetErrnoFromWinError (GetLastError ());
204 return -1; 204 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
205 } 205 return -1;
206 }
206 CloseHandle (proc.hProcess); 207 CloseHandle (proc.hProcess);
207 CloseHandle (proc.hThread); 208 CloseHandle (proc.hThread);
208 209
209 GNUNET_free(cmd); 210 GNUNET_free (cmd);
210 211
211 return proc.dwProcessId; 212 return proc.dwProcessId;
212#endif 213#endif
@@ -236,23 +237,23 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
236 if (ret != 0) 237 if (ret != 0)
237 { 238 {
238 if (ret == -1) 239 if (ret == -1)
239 { 240 {
240 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 241 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
241 } 242 }
242 else 243 else
243 { 244 {
244#if HAVE_WORKING_VFORK 245#if HAVE_WORKING_VFORK
245 /* let's hope vfork actually works; for some extreme cases (including 246 /* let's hope vfork actually works; for some extreme cases (including
246 a testcase) we need 'execvp' to have run before we return, since 247 a testcase) we need 'execvp' to have run before we return, since
247 we may send a signal to the process next and we don't want it 248 we may send a signal to the process next and we don't want it
248 to be caught by OUR signal handler (but either by the default 249 to be caught by OUR signal handler (but either by the default
249 handler or the actual handler as installed by the process itself). */ 250 handler or the actual handler as installed by the process itself). */
250#else 251#else
251 /* let's give the child process a chance to run execvp, 1s should 252 /* let's give the child process a chance to run execvp, 1s should
252 be plenty in practice */ 253 be plenty in practice */
253 sleep (1); 254 sleep (1);
254#endif 255#endif
255 } 256 }
256 return ret; 257 return ret;
257 } 258 }
258 execvp (filename, argv); 259 execvp (filename, argv);
@@ -268,33 +269,34 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
268 cmdlen = 0; 269 cmdlen = 0;
269 arg = argv; 270 arg = argv;
270 while (*arg) 271 while (*arg)
271 { 272 {
272 cmdlen = cmdlen + strlen (*arg) + 3; 273 cmdlen = cmdlen + strlen (*arg) + 3;
273 arg++; 274 arg++;
274 } 275 }
275 276
276 cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); 277 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
277 arg = argv; 278 arg = argv;
278 while (*arg) 279 while (*arg)
279 { 280 {
280 idx += sprintf (idx, "\"%s\" ", *arg); 281 idx += sprintf (idx, "\"%s\" ", *arg);
281 arg++; 282 arg++;
282 } 283 }
283 284
284 memset (&start, 0, sizeof(start)); 285 memset (&start, 0, sizeof (start));
285 start.cb = sizeof(start); 286 start.cb = sizeof (start);
286 287
287 if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, 288 if (!CreateProcess
288 NULL, &start, &proc)) 289 (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
289 { 290 &proc))
290 SetErrnoFromWinError (GetLastError ()); 291 {
291 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 292 SetErrnoFromWinError (GetLastError ());
292 return -1; 293 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
293 } 294 return -1;
295 }
294 CloseHandle (proc.hProcess); 296 CloseHandle (proc.hProcess);
295 CloseHandle (proc.hThread); 297 CloseHandle (proc.hThread);
296 298
297 GNUNET_free(cmd); 299 GNUNET_free (cmd);
298 300
299 return proc.dwProcessId; 301 return proc.dwProcessId;
300#endif 302#endif
@@ -309,7 +311,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
309 */ 311 */
310int 312int
311GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, 313GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
312 unsigned long *code) 314 unsigned long *code)
313{ 315{
314#ifndef MINGW 316#ifndef MINGW
315 int status; 317 int status;
@@ -317,7 +319,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
317 319
318 GNUNET_assert (0 != proc); 320 GNUNET_assert (0 != proc);
319 ret = waitpid (proc, &status, WNOHANG); 321 ret = waitpid (proc, &status, WNOHANG);
320 if (0 == ret) 322 if (0 == ret)
321 { 323 {
322 *type = GNUNET_OS_PROCESS_RUNNING; 324 *type = GNUNET_OS_PROCESS_RUNNING;
323 *code = 0; 325 *code = 0;
@@ -329,50 +331,50 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
329 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
330 } 332 }
331 if (WIFEXITED (status)) 333 if (WIFEXITED (status))
332 { 334 {
333 *type = GNUNET_OS_PROCESS_EXITED; 335 *type = GNUNET_OS_PROCESS_EXITED;
334 *code = WEXITSTATUS (status); 336 *code = WEXITSTATUS (status);
335 } 337 }
336 else if (WIFSIGNALED (status)) 338 else if (WIFSIGNALED (status))
337 { 339 {
338 *type = GNUNET_OS_PROCESS_SIGNALED; 340 *type = GNUNET_OS_PROCESS_SIGNALED;
339 *code = WTERMSIG (status); 341 *code = WTERMSIG (status);
340 } 342 }
341 else if (WIFSTOPPED (status)) 343 else if (WIFSTOPPED (status))
342 { 344 {
343 *type = GNUNET_OS_PROCESS_SIGNALED; 345 *type = GNUNET_OS_PROCESS_SIGNALED;
344 *code = WSTOPSIG (status); 346 *code = WSTOPSIG (status);
345 } 347 }
346 else if (WIFCONTINUED (status)) 348 else if (WIFCONTINUED (status))
347 { 349 {
348 *type = GNUNET_OS_PROCESS_RUNNING; 350 *type = GNUNET_OS_PROCESS_RUNNING;
349 *code = 0; 351 *code = 0;
350 } 352 }
351 else 353 else
352 { 354 {
353 *type = GNUNET_OS_PROCESS_UNKNOWN; 355 *type = GNUNET_OS_PROCESS_UNKNOWN;
354 *code = 0; 356 *code = 0;
355 } 357 }
356#else 358#else
357 HANDLE h; 359 HANDLE h;
358 DWORD c; 360 DWORD c;
359 361
360 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); 362 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
361 if (INVALID_HANDLE_VALUE == h) 363 if (INVALID_HANDLE_VALUE == h)
362 { 364 {
363 SetErrnoFromWinError (GetLastError ()); 365 SetErrnoFromWinError (GetLastError ());
364 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess"); 366 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess");
365 return GNUNET_SYSERR; 367 return GNUNET_SYSERR;
366 } 368 }
367 369
368 c = GetExitCodeProcess (proc, &c); 370 c = GetExitCodeProcess (proc, &c);
369 if (STILL_ACTIVE == c) 371 if (STILL_ACTIVE == c)
370 { 372 {
371 *type = GNUNET_OS_PROCESS_RUNNING; 373 *type = GNUNET_OS_PROCESS_RUNNING;
372 *code = 0; 374 *code = 0;
373 CloseHandle (h); 375 CloseHandle (h);
374 return GNUNET_NO; 376 return GNUNET_NO;
375 } 377 }
376 *type = GNUNET_OS_PROCESS_EXITED; 378 *type = GNUNET_OS_PROCESS_EXITED;
377 *code = c; 379 *code = c;
378 CloseHandle (h); 380 CloseHandle (h);
@@ -401,16 +403,16 @@ GNUNET_OS_process_wait (pid_t proc)
401 403
402 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); 404 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
403 if (INVALID_HANDLE_VALUE == h) 405 if (INVALID_HANDLE_VALUE == h)
404 { 406 {
405 SetErrnoFromWinError (GetLastError ()); 407 SetErrnoFromWinError (GetLastError ());
406 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
407 } 409 }
408 410
409 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) 411 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
410 { 412 {
411 SetErrnoFromWinError (GetLastError ()); 413 SetErrnoFromWinError (GetLastError ());
412 ret = GNUNET_SYSERR; 414 ret = GNUNET_SYSERR;
413 } 415 }
414 else 416 else
415 ret = GNUNET_OK; 417 ret = GNUNET_OK;
416 418