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.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index f74bd9266..c017a1e38 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -257,9 +257,114 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
257#endif 257#endif
258} 258}
259 259
260/**
261 * Retrieve the status of a process
262 * @param proc process ID
263 * @param type status type
264 * @param code return code/signal number
265 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
266 */
267int
268GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
269 unsigned long *code)
270{
271#ifndef MINGW
272 int status;
273
274 if (proc != waitpid (0, &status, WNOHANG))
275 return GNUNET_SYSERR;
276 if (WIFEXITED (status))
277 {
278 *type = GNUNET_OS_PROCESS_EXITED;
279 *code = WEXITSTATUS (status);
280 }
281 else if (WIFSIGNALED (status))
282 {
283 *type = GNUNET_OS_PROCESS_SIGNALED;
284 *code = WTERMSIG (status);
285 }
286 else if (WIFSTOPPED (status))
287 {
288 *type = GNUNET_OS_PROCESS_SIGNALED;
289 *code = WSTOPSIG (status);
290 }
291 else if (WIFCONTINUED (status))
292 {
293 *type = GNUNET_OS_PROCESS_RUNNING;
294 *code = 0;
295 }
296 else
297 {
298 *type = GNUNET_OS_PROCESS_UNKNOWN;
299 *code = 0;
300 }
301#else
302 HANDLE h;
303 DWORD c;
304
305 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
306 if (INVALID_HANDLE_VALUE == h)
307 {
308 SetErrnoFromWinError (GetLastError ());
309 return GNUNET_SYSERR;
310 }
311
312 c = GetExitCodeProcess (proc, &c);
313 if (STILL_ACTIVE == c)
314 {
315 *type = GNUNET_OS_PROCESS_RUNNING;
316 *code = 0;
317 }
318 else
319 {
320 *type = GNUNET_OS_PROCESS_EXITED;
321 *code = c;
322 }
323
324 CloseHandle (h);
325#endif
326
327 return GNUNET_OK;
328}
329
330/**
331 * Wait for a process
332 * @param proc process ID to wait for
333 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
334 */
335int
336GNUNET_OS_process_wait (pid_t proc)
337{
338#ifndef MINGW
339 if (proc != waitpid (proc, NULL, 0))
340 return GNUNET_SYSERR;
260 341
342 return GNUNET_OK;
343#else
344 HANDLE h;
345 DWORD c;
346 int ret;
261 347
348 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
349 if (INVALID_HANDLE_VALUE == h)
350 {
351 SetErrnoFromWinError (GetLastError ());
352 return GNUNET_SYSERR;
353 }
262 354
355 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
356 {
357 SetErrnoFromWinError (GetLastError ());
358 ret = GNUNET_SYSERR;
359 }
360 else
361 ret = GNUNET_OK;
362
363 CloseHandle (h);
364
365 return ret;
366#endif
367}
263 368
264 369
265/* end of os_priority.c */ 370/* end of os_priority.c */