static int sudo_debug_settings[NUM_SUBSYSTEMS];
static int sudo_debug_fd = -1;
static int sudo_debug_mode;
+static char sudo_debug_pidstr[(((sizeof(int) * 8) + 2) / 3) + 3];
+static size_t sudo_debug_pidlen;
extern sudo_conv_t sudo_conv;
}
efree(buf);
+ (void)snprintf(sudo_debug_pidstr, sizeof(sudo_debug_pidstr), "[%d] ",
+ (int)getpid());
+ sudo_debug_pidlen = strlen(sudo_debug_pidstr);
+
return 1;
}
+pid_t
+sudo_debug_fork(void)
+{
+ pid_t pid;
+
+ if ((pid = fork()) == 0) {
+ (void)snprintf(sudo_debug_pidstr, sizeof(sudo_debug_pidstr), "[%d] ",
+ (int)getpid());
+ sudo_debug_pidlen = strlen(sudo_debug_pidstr);
+ }
+
+ return pid;
+}
+
void
sudo_debug_enter(const char *func, const char *file, int line,
int subsys)
int iovcnt = 4;
bool need_newline = false;
- /* Prepend program name with trailing space. */
+ /* Prepend program name and pid with a trailing space. */
iov[1].iov_base = (char *)getprogname();
iov[1].iov_len = strlen(iov[1].iov_base);
- iov[2].iov_base = " ";
- iov[2].iov_len = 1;
+ iov[2].iov_base = sudo_debug_pidstr;
+ iov[2].iov_len = sudo_debug_pidlen;
/* Add string along with newline if it doesn't have one. */
iov[3].iov_base = (char *)str;
void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *format, ...) __printflike(5, 6);
void sudo_debug_write(const char *str, int len, int errno_val);
void sudo_debug_write2(const char *func, const char *file, int line, const char *str, int len, int errno_val);
+pid_t sudo_debug_fork(void);
#endif /* _SUDO_DEBUG_H */
debug_return;
/* Fork and return, child will daemonize. */
- switch (pid = fork()) {
+ switch (pid = sudo_debug_fork()) {
case -1:
/* Error. */
error(1, _("unable to fork"));
_exit(1);
}
- switch (pid = fork()) {
+ switch (pid = sudo_debug_fork()) {
case -1:
/* Error. */
mysyslog(LOG_ERR, _("unable to fork: %m"));
pid_t pid, rv;
debug_decl(run_command, SUDO_DEBUG_UTIL)
- switch (pid = fork()) {
+ switch (pid = sudo_debug_fork()) {
case -1:
error(1, _("unable to execute %s"), path);
break; /* NOTREACHED */
sa.sa_handler = handler;
sigaction(SIGCONT, &sa, NULL);
- child = fork();
+ child = sudo_debug_fork();
switch (child) {
case -1:
error(1, _("unable to fork"));
/* If running in background mode, fork and exit. */
if (ISSET(details->flags, CD_BACKGROUND)) {
- switch (fork()) {
+ switch (sudo_debug_fork()) {
case -1:
cstat->type = CMD_ERRNO;
cstat->val = errno;
}
}
- child = fork();
+ child = sudo_debug_fork();
switch (child) {
case -1:
error(1, _("unable to fork"));
/* Start command and wait for it to stop or exit */
if (pipe(errpipe) == -1)
error(1, _("unable to create pipe"));
- child = fork();
+ child = sudo_debug_fork();
if (child == -1) {
warning(_("unable to fork"));
goto bad;