#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);
}
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,
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_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,
&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
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;
{
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
{
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;
}
#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;
{
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
}
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;
}
#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)