Elimate calls to fatal() in the logging code.

This commit is contained in:
Todd C. Miller
2014-04-10 16:03:01 -06:00
parent db831ace32
commit a48c00dc31

View File

@@ -64,7 +64,7 @@
static void do_syslog(int, char *); static void do_syslog(int, char *);
static void do_logfile(char *); static void do_logfile(char *);
static void send_mail(const char *fmt, ...); static bool send_mail(const char *fmt, ...);
static int should_mail(int); static int should_mail(int);
static void mysyslog(int, const char *, ...); static void mysyslog(int, const char *, ...);
static char *new_logline(const char *, int); static char *new_logline(const char *, int);
@@ -256,6 +256,8 @@ log_denial(int status, bool inform_user)
message = _("command not allowed"); message = _("command not allowed");
logline = new_logline(message, 0); logline = new_logline(message, 0);
if (logline == NULL)
debug_return;
/* Become root if we are not already. */ /* Become root if we are not already. */
set_perms(PERM_ROOT|PERM_NOEXIT); set_perms(PERM_ROOT|PERM_NOEXIT);
@@ -543,7 +545,7 @@ log_fatal(int flags, const char *fmt, ...)
/* /*
* Send a message to MAILTO user * Send a message to MAILTO user
*/ */
static void static bool
send_mail(const char *fmt, ...) send_mail(const char *fmt, ...)
{ {
FILE *mail; FILE *mail;
@@ -566,19 +568,20 @@ send_mail(const char *fmt, ...)
#endif /* NO_ROOT_MAILER */ #endif /* NO_ROOT_MAILER */
debug_decl(send_mail, SUDO_DEBUG_LOGGING) debug_decl(send_mail, SUDO_DEBUG_LOGGING)
/* Just return if mailer is disabled. */ /* If mailer is disabled just return. */
if (!def_mailerpath || !def_mailto) if (!def_mailerpath || !def_mailto)
debug_return; debug_return_bool(true);
/* Make sure the mailer exists and is a regular file. */ /* Make sure the mailer exists and is a regular file. */
if (stat(def_mailerpath, &sb) != 0 || !S_ISREG(sb.st_mode)) if (stat(def_mailerpath, &sb) != 0 || !S_ISREG(sb.st_mode))
debug_return; debug_return_int(false);
/* Fork and return, child will daemonize. */ /* Fork and return, child will daemonize. */
switch (pid = sudo_debug_fork()) { switch (pid = sudo_debug_fork()) {
case -1: case -1:
/* Error. */ /* Error. */
fatal(U_("unable to fork")); warning(U_("unable to fork"));
debug_return_int(false);
break; break;
case 0: case 0:
/* Child. */ /* Child. */
@@ -602,7 +605,7 @@ send_mail(const char *fmt, ...)
do { do {
rv = waitpid(pid, &status, 0); rv = waitpid(pid, &status, 0);
} while (rv == -1 && errno == EINTR); } while (rv == -1 && errno == EINTR);
return; /* not debug */ return true; /* not debug */
} }
/* Daemonize - disassociate from session/tty. */ /* Daemonize - disassociate from session/tty. */
@@ -911,5 +914,6 @@ new_logline(const char *message, int serrno)
debug_return_str(line); debug_return_str(line);
toobig: toobig:
fatalx(U_("internal error: insufficient space for log line")); warningx(U_("internal error, %s overflow"), __func__);
debug_return_str(NULL);
} }