*/
static struct GNUNET_SCHEDULER_Task *pch;
+/**
+ * Handle for the #shutdown_pch() Task.
+ */
+static struct GNUNET_SCHEDULER_Task *spch;
+
/**
* This handler is called on shutdown to remove the #pch.
shutdown_pch (void *cls)
{
struct GNUNET_DISK_FileHandle *control_pipe = cls;
-
+
GNUNET_SCHEDULER_cancel (pch);
pch = NULL;
GNUNET_DISK_file_close (control_pipe);
"Closing control pipe\n");
GNUNET_DISK_file_close (control_pipe);
control_pipe = NULL;
+ GNUNET_SCHEDULER_cancel (spch);
+ spch = NULL;
return;
}
pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
control_pipe,
&parent_control_handler,
control_pipe);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
- control_pipe);
+ spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
+ control_pipe);
putenv (GNUNET_OS_CONTROL_PIPE "=");
}
* @param proc process ID
* @param type status type
* @param code return code/signal number
+ * @param options WNOHANG if non-blocking is desired
* @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
*/
-int
-GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
- enum GNUNET_OS_ProcessStatusType *type,
- unsigned long *code)
+static int
+process_status (struct GNUNET_OS_Process *proc,
+ enum GNUNET_OS_ProcessStatusType *type,
+ unsigned long *code,
+ int options)
{
#ifndef MINGW
int status;
int ret;
GNUNET_assert (0 != proc);
- ret = waitpid (proc->pid, &status, WNOHANG);
+ ret = waitpid (proc->pid, &status, options);
if (ret < 0)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
*code = 0;
}
#else
+#ifndef WNOHANG
+#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
+#endif
+
HANDLE h;
DWORD c, error_code, ret;
if (h == NULL)
h = GetCurrentProcess ();
+ if (WNOHANG != options)
+ {
+ if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
+ {
+ SetErrnoFromWinError (GetLastError ());
+ return GNUNET_SYSERR;
+ }
+ }
SetLastError (0);
ret = GetExitCodeProcess (h, &c);
error_code = GetLastError ();
}
+/**
+ * Retrieve the status of a process, waiting on him if dead.
+ * Nonblocking version.
+ *
+ * @param proc process ID
+ * @param type status type
+ * @param code return code/signal number
+ * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
+ enum GNUNET_OS_ProcessStatusType *type,
+ unsigned long *code)
+{
+ return process_status (proc,
+ type,
+ code,
+ WNOHANG);
+}
+
+
+/**
+ * Retrieve the status of a process, waiting on him if dead.
+ * Blocking version.
+ *
+ * @param proc pointer to process structure
+ * @param type status type
+ * @param code return code/signal number
+ * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
+ enum GNUNET_OS_ProcessStatusType *type,
+ unsigned long *code)
+{
+ return process_status (proc,
+ type,
+ code,
+ 0);
+}
+
+
/**
* Wait for a process to terminate. The return code is discarded.
* You must not use #GNUNET_OS_process_status() on the same process
cmd->off -= (end + 1 - cmd->buf);
end = memchr (cmd->buf, '\n', cmd->off);
}
- cmd->rtask
+ cmd->rtask
= GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
(cmd->timeout),
cmd->r,