#include "gnunet_scheduler_lib.h"
#include "disk.h"
+#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+
#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE"
struct GNUNET_OS_Process
int sig;
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' invoked because of %d\n", __FUNCTION__, tc->reason);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__,
+ tc->reason);
#endif
- if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN |
- GNUNET_SCHEDULER_REASON_TIMEOUT |
- GNUNET_SCHEDULER_REASON_PREREQ_DONE))
+ if (tc->reason &
+ (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT |
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
GNUNET_DISK_npipe_close (control_pipe);
}
else
{
- if (GNUNET_DISK_file_read (control_pipe,
- &sig, sizeof (sig)) != sizeof (sig))
+ if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) !=
+ sizeof (sig))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
GNUNET_DISK_npipe_close (control_pipe);
}
else
{
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got control code %d from parent\n", sig);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig);
#endif
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler, control_pipe);
+ control_pipe, &parent_control_handler,
+ control_pipe);
raise (sig);
}
}
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
if ((env_buf == NULL) || (strlen (env_buf) <= 0))
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Not installing a handler because $%s=%s\n"),
- GNUNET_OS_CONTROL_PIPE, env_buf);
+ LOG (GNUNET_ERROR_TYPE_INFO, _("Not installing a handler because $%s=%s\n"),
+ GNUNET_OS_CONTROL_PIPE, env_buf);
return;
}
- control_pipe = GNUNET_DISK_npipe_open (env_buf,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ control_pipe =
+ GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
return;
}
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding parent control handler pipe `%s' to the scheduler\n",
- env_buf);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
#endif
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
&parent_control_handler, control_pipe);
}
{
/* Child process is not controllable via pipe */
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Child process is not controllable, will kill it directly\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Child process is not controllable, will kill it directly\n");
#endif
}
else if (errno == EPIPE)
{
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n");
#endif
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to write into control pipe , errno is %d\n", errno);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to write into control pipe , errno is %d\n", errno);
#if WINDOWS && !defined(__CYGWIN__)
TerminateProcess (proc->handle, 0);
#else
else
{
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote control code into control pipe, now waiting\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wrote control code into control pipe, now waiting\n");
#endif
#if WINDOWS
*/
while (1)
{
- ret = GNUNET_NETWORK_socket_select (rfds, NULL, efds,
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_relative_get_unit (),
- 5000));
-
- if (ret < 1 || GNUNET_NETWORK_fdset_handle_isset (efds,
- proc->control_pipe))
+ ret =
+ GNUNET_NETWORK_socket_select (rfds, NULL, efds,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_relative_get_unit (),
+ 5000));
+
+ if (ret < 1 ||
+ GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe))
{
/* Just to be sure */
PLIBC_KILL (proc->pid, sig);
}
else
{
- if (GNUNET_DISK_file_read (proc->control_pipe, &ret,
- sizeof (ret)) != GNUNET_OK)
+ if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) !=
+ GNUNET_OK)
res = PLIBC_KILL (proc->pid, sig);
/* Child signaled shutdown is in progress */
errno = 0;
if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "nice");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice");
return GNUNET_SYSERR;
}
}
{
if (0 != setpriority (PRIO_PROCESS, pid, rprio))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK, "setpriority");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "setpriority");
return GNUNET_SYSERR;
}
}
#else
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "Priority management not availabe for this platform\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+ "Priority management not availabe for this platform\n");
#endif
#endif
return GNUNET_OK;
int fd_stdin_write;
#if ENABLE_WINDOWS_WORKAROUNDS
- control_pipe = GNUNET_DISK_npipe_create (&childpipename,
- GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ control_pipe =
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
&fd_stdin_write, sizeof (int));
}
-#if HAVE_WORKING_VFORK
- ret = vfork ();
-#else
ret = fork ();
-#endif
if (ret != 0)
{
if (ret == -1)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
#if ENABLE_WINDOWS_WORKAROUNDS
GNUNET_DISK_npipe_close (control_pipe);
#endif
}
else
{
-
-#if HAVE_WORKING_VFORK
- /* let's hope vfork actually works; for some extreme cases (including
- * a testcase) we need 'execvp' to have run before we return, since
- * we may send a signal to the process next and we don't want it
- * to be caught by OUR signal handler (but either by the default
- * handler or the actual handler as installed by the process itself). */
-#else
- /* let's give the child process a chance to run execvp, 1s should
- * be plenty in practice */
- if (pipe_stdout != NULL)
- GNUNET_DISK_pipe_close_end (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
- if (pipe_stdin != NULL)
- GNUNET_DISK_pipe_close_end (pipe_stdin, GNUNET_DISK_PIPE_END_READ);
- sleep (1);
-#endif
gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
gnunet_proc->pid = ret;
#if ENABLE_WINDOWS_WORKAROUNDS
{
GNUNET_break (0 == close (fd_stdout_read));
if (-1 == dup2 (fd_stdout_write, 1))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
GNUNET_break (0 == close (fd_stdout_write));
}
GNUNET_break (0 == close (fd_stdin_write));
if (-1 == dup2 (fd_stdin_read, 0))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
GNUNET_break (0 == close (fd_stdin_read));
}
execvp (filename, argv);
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit (1);
#else
char *arg;
path, NULL))
{
SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
- non_const_filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
return NULL;
start.hStdOutput = stdout_handle;
}
- control_pipe = GNUNET_DISK_npipe_create (&childpipename,
- GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ control_pipe =
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
{
GNUNET_free (cmd);
}
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Opened the parent end of the pipe `%s'\n", childpipename);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
+ childpipename);
#endif
GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
env_block, NULL, &start, &proc))
{
SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
GNUNET_free (env_block);
GNUNET_free (cmd);
return NULL;
* @return process ID of the new process, -1 on error
*/
struct GNUNET_OS_Process *
-GNUNET_OS_start_process_v (const int *lsocks,
- const char *filename, char *const argv[])
+GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
+ char *const argv[])
{
#if ENABLE_WINDOWS_WORKAROUNDS
struct GNUNET_DISK_FileHandle *control_pipe = NULL;
unsigned int ls;
#if ENABLE_WINDOWS_WORKAROUNDS
- control_pipe = GNUNET_DISK_npipe_create (&childpipename,
- GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ control_pipe =
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
return NULL;
#endif
GNUNET_array_append (lscp, ls, k);
GNUNET_array_append (lscp, ls, -1);
}
-#if HAVE_WORKING_VFORK
- ret = vfork ();
-#else
ret = fork ();
-#endif
if (ret != 0)
{
if (ret == -1)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
#if ENABLE_WINDOWS_WORKAROUNDS
GNUNET_DISK_npipe_close (control_pipe);
#endif
}
else
{
-#if HAVE_WORKING_VFORK
- /* let's hope vfork actually works; for some extreme cases (including
- * a testcase) we need 'execvp' to have run before we return, since
- * we may send a signal to the process next and we don't want it
- * to be caught by OUR signal handler (but either by the default
- * handler or the actual handler as installed by the process itself). */
-#else
- /* let's give the child process a chance to run execvp, 1s should
- * be plenty in practice */
- sleep (1);
-#endif
gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
gnunet_proc->pid = ret;
#if ENABLE_WINDOWS_WORKAROUNDS
}
GNUNET_array_grow (lscp, ls, 0);
execvp (filename, argv);
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit (1);
#else
char **arg, **non_const_argv;
path, NULL))
{
SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
- non_const_filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
return NULL;
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
- control_pipe = GNUNET_DISK_npipe_create (&childpipename,
- GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ control_pipe =
+ GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (control_pipe == NULL)
{
GNUNET_free (cmd);
}
#if DEBUG_OS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Opened the parent end of the pipe `%s'\n", childpipename);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n",
+ childpipename);
#endif
GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE);
env_block, NULL, &start, &proc))
{
SetErrnoFromWinError (GetLastError ());
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess");
GNUNET_free (env_block);
GNUNET_free (cmd);
return NULL;
ret = waitpid (proc->pid, &status, WNOHANG);
if (ret < 0)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
if (0 == ret)
}
if (proc->pid != ret)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
if (WIFEXITED (status))
ret = proc->pid;
if (h == NULL || ret == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n", ret, h);
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
+ ret, h);
return GNUNET_SYSERR;
}
if (h == NULL)
if (ret == 0 || error_code != NO_ERROR)
{
SetErrnoFromWinError (error_code);
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
return GNUNET_SYSERR;
}
if (STILL_ACTIVE == c)
h = proc->handle;
if (NULL == h)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n", proc->pid, h);
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
+ proc->pid, h);
return GNUNET_SYSERR;
}
if (h == NULL)
proc (cmd->proc_cls, NULL);
return;
}
- ret = GNUNET_DISK_file_read (cmd->r,
- &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ ret =
+ GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
{
if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
* @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;
struct GNUNET_OS_Process *eip;