X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fos_priority.c;h=52e2f6d0e88d7106c19d03787c246ab554904dcc;hb=ed28dd2141e77aa073d81089cb5a07e0a0fc013c;hp=d3310abb175463c9e58fb3deca0651de37fa90f5;hpb=274f395e7a8174292ded0db094180ad4731d24ff;p=oweals%2Fgnunet.git diff --git a/src/util/os_priority.c b/src/util/os_priority.c index d3310abb1..52e2f6d0e 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2002, 2003, 2004, 2005, 2006, 2011 Christian Grothoff (and other contributing authors) + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2011 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -268,7 +268,10 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) } return 0; #else - LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Sending signal %d to pid: %u via system call\n", + sig, + proc->pid); return PLIBC_KILL (proc->pid, sig); #endif default: @@ -307,7 +310,7 @@ GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc) if (NULL != proc->control_pipe) GNUNET_DISK_file_close (proc->control_pipe); #if defined (WINDOWS) - if (proc->handle != NULL) + if (NULL != proc->handle) CloseHandle (proc->handle); #endif GNUNET_free (proc); @@ -492,6 +495,7 @@ open_dev_null (int target_fd, * (when they are non-NULL). * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) + * @param pipe_stderr pipe to use for stderr for child process (or NULL) * @param lsocks array of listen sockets to dup systemd-style (or NULL); * must be NULL on platforms where dup is not supported * @param filename name of the binary @@ -1061,7 +1065,9 @@ start_process (int pipe_control, if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len))) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno); + "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", + cmd, + errno); GNUNET_free (env_block); GNUNET_free (cmd); free (wpath); @@ -1099,7 +1105,11 @@ start_process (int pipe_control, SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef); if (!bresult) - LOG (GNUNET_ERROR_TYPE_ERROR, "CreateProcess(%s, %s) failed: %lu\n", path, cmd, error_code); + LOG (GNUNET_ERROR_TYPE_ERROR, + "CreateProcess(%s, %s) failed: %lu\n", + path, + cmd, + error_code); GNUNET_free (env_block); GNUNET_free (cmd); @@ -1516,7 +1526,7 @@ GNUNET_OS_start_process_s (int pipe_control, * @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 + * @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, @@ -1531,7 +1541,8 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, ret = waitpid (proc->pid, &status, WNOHANG); if (ret < 0) { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, + "waitpid"); return GNUNET_SYSERR; } if (0 == ret) @@ -1580,7 +1591,8 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, ret = proc->pid; if (h == NULL || ret == 0) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", + LOG (GNUNET_ERROR_TYPE_WARNING, + "Invalid process information {%d, %08X}\n", ret, h); return GNUNET_SYSERR; } @@ -1611,10 +1623,14 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, /** - * Wait for a process + * Wait for a process to terminate. The return code is discarded. + * You must not use #GNUNET_OS_process_status() on the same process + * after calling this function! This function is blocking and should + * thus only be used if the child process is known to have terminated + * or to terminate very soon. * * @param proc pointer to process structure - * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ int GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) @@ -1627,7 +1643,8 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) (EINTR == errno) ) ; if (pid != ret) { - LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, + "waitpid"); return GNUNET_SYSERR; } return GNUNET_OK; @@ -1637,7 +1654,8 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) h = proc->handle; if (NULL == h) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", + LOG (GNUNET_ERROR_TYPE_WARNING, + "Invalid process information {%d, %08X}\n", proc->pid, h); return GNUNET_SYSERR; } @@ -1681,7 +1699,7 @@ struct GNUNET_OS_CommandHandle GNUNET_OS_LineProcessor proc; /** - * Closure for 'proc'. + * Closure for @e proc. */ void *proc_cls; @@ -1693,7 +1711,7 @@ struct GNUNET_OS_CommandHandle /** * Task reading from pipe. */ - GNUNET_SCHEDULER_TaskIdentifier rtask; + struct GNUNET_SCHEDULER_Task *rtask; /** * When to time out. @@ -1719,7 +1737,7 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd) { if (NULL != cmd->proc) { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); + GNUNET_assert (NULL != cmd->rtask); GNUNET_SCHEDULER_cancel (cmd->rtask); } (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); @@ -1744,7 +1762,7 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) char *end; ssize_t ret; - cmd->rtask = GNUNET_SCHEDULER_NO_TASK; + cmd->rtask = NULL; if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) { /* timeout, shutdown, etc. */ @@ -1789,15 +1807,17 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * for each line of the output. * * @param proc function to call for each line of the output - * @param proc_cls closure for proc + * @param proc_cls closure for @a proc * @param timeout when to time out * @param binary command to run * @param ... arguments to command * @return NULL on error */ struct GNUNET_OS_CommandHandle * -GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, - struct GNUNET_TIME_Relative timeout, const char *binary, +GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, + void *proc_cls, + struct GNUNET_TIME_Relative timeout, + const char *binary, ...) { struct GNUNET_OS_CommandHandle *cmd;