aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-06-12 00:49:14 +0000
committerChristian Grothoff <christian@grothoff.org>2009-06-12 00:49:14 +0000
commit9014a563e22c07927b8c319d1458d96fe0a35f67 (patch)
tree3dbd114615709ea721bd2500e7c03b13b520b57e /src
parent0bafde3a5b49eb06e01103fa1b0d98ab6c25b84d (diff)
downloadgnunet-9014a563e22c07927b8c319d1458d96fe0a35f67.tar.gz
gnunet-9014a563e22c07927b8c319d1458d96fe0a35f67.zip
fixing pid issues
Diffstat (limited to 'src')
-rw-r--r--src/arm/gnunet-service-arm.c13
-rw-r--r--src/include/gnunet_os_lib.h2
-rw-r--r--src/util/os_priority.c30
3 files changed, 28 insertions, 17 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 9643273cf..3a93c654b 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -529,6 +529,7 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
529 const char *statstr; 529 const char *statstr;
530 int statcode; 530 int statcode;
531 struct stat sbuf; 531 struct stat sbuf;
532 int ret;
532 533
533 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 534 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
534 { 535 {
@@ -556,15 +557,13 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
556 enum GNUNET_OS_ProcessStatusType statusType; 557 enum GNUNET_OS_ProcessStatusType statusType;
557 unsigned long statusCode; 558 unsigned long statusCode;
558 559
559 if (GNUNET_OS_process_status(pos->pid, &statusType, &statusCode) != GNUNET_OK) 560 if (GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->pid, &statusType, &statusCode)))
560 {
561 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "GNUNET_OS_process_status");
562 continue; 561 continue;
563 } 562 if ( (ret == GNUNET_NO) ||
564 563 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
565 if (statusType == GNUNET_OS_PROCESS_STOPPED || statusType == GNUNET_OS_PROCESS_RUNNING) 564 (statusType == GNUNET_OS_PROCESS_RUNNING) )
566 continue; 565 continue;
567 else if (statusType == GNUNET_OS_PROCESS_EXITED) 566 if (statusType == GNUNET_OS_PROCESS_EXITED)
568 { 567 {
569 statstr = _( /* process termination method */ "exit"); 568 statstr = _( /* process termination method */ "exit");
570 statcode = statusCode; 569 statcode = statusCode;
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index 8e48a049c..1d4d47441 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -163,7 +163,7 @@ pid_t GNUNET_OS_start_process_v (const char *filename, char *const argv[]);
163 * @param proc process ID 163 * @param proc process ID
164 * @param type status type 164 * @param type status type
165 * @param code return code/signal number 165 * @param code return code/signal number
166 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 166 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
167 */ 167 */
168int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, 168int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
169 unsigned long *code); 169 unsigned long *code);
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index c017a1e38..0dfc9cafe 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -262,7 +262,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
262 * @param proc process ID 262 * @param proc process ID
263 * @param type status type 263 * @param type status type
264 * @param code return code/signal number 264 * @param code return code/signal number
265 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 265 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
266 */ 266 */
267int 267int
268GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, 268GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
@@ -270,9 +270,22 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
270{ 270{
271#ifndef MINGW 271#ifndef MINGW
272 int status; 272 int status;
273 int ret;
273 274
274 if (proc != waitpid (0, &status, WNOHANG)) 275 ret = waitpid (0, &status, WNOHANG);
275 return GNUNET_SYSERR; 276 if ( (0 == ret) ||
277 ( (-1 == ret) &&
278 (ECHILD == errno) ) )
279 {
280 *type = GNUNET_OS_PROCESS_RUNNING;
281 *code = 0;
282 return GNUNET_NO;
283 }
284 if (proc != ret)
285 {
286 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
287 return GNUNET_SYSERR;
288 }
276 if (WIFEXITED (status)) 289 if (WIFEXITED (status))
277 { 290 {
278 *type = GNUNET_OS_PROCESS_EXITED; 291 *type = GNUNET_OS_PROCESS_EXITED;
@@ -306,6 +319,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
306 if (INVALID_HANDLE_VALUE == h) 319 if (INVALID_HANDLE_VALUE == h)
307 { 320 {
308 SetErrnoFromWinError (GetLastError ()); 321 SetErrnoFromWinError (GetLastError ());
322 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess");
309 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
310 } 324 }
311 325
@@ -314,13 +328,11 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
314 { 328 {
315 *type = GNUNET_OS_PROCESS_RUNNING; 329 *type = GNUNET_OS_PROCESS_RUNNING;
316 *code = 0; 330 *code = 0;
331 CloseHandle (h);
332 return GNUNET_NO;
317 } 333 }
318 else 334 *type = GNUNET_OS_PROCESS_EXITED;
319 { 335 *code = c;
320 *type = GNUNET_OS_PROCESS_EXITED;
321 *code = c;
322 }
323
324 CloseHandle (h); 336 CloseHandle (h);
325#endif 337#endif
326 338