Conver sudo_debug_write() to a macro
This commit is contained in:
@@ -202,6 +202,9 @@
|
|||||||
#define sudo_debug_execve(pri, path, argv, envp) \
|
#define sudo_debug_execve(pri, path, argv, envp) \
|
||||||
sudo_debug_execve2((pri)|sudo_debug_subsys, (path), (argv), (envp))
|
sudo_debug_execve2((pri)|sudo_debug_subsys, (path), (argv), (envp))
|
||||||
|
|
||||||
|
#define sudo_debug_write(str, len, errnum) \
|
||||||
|
sudo_debug_write2(NULL, NULL, 0, (str), (len), (errnum))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NULL-terminated string lists of priorities and subsystems.
|
* NULL-terminated string lists of priorities and subsystems.
|
||||||
*/
|
*/
|
||||||
@@ -224,7 +227,6 @@ __dso_public int sudo_debug_init(const char *debugfile, const char *settings);
|
|||||||
__dso_public void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3);
|
__dso_public void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3);
|
||||||
__dso_public void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6);
|
__dso_public void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6);
|
||||||
__dso_public void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0);
|
__dso_public void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0);
|
||||||
__dso_public void sudo_debug_write(const char *str, int len, int errno_val);
|
|
||||||
__dso_public void sudo_debug_write2(const char *func, const char *file, int line, const char *str, int len, int errno_val);
|
__dso_public void sudo_debug_write2(const char *func, const char *file, int line, const char *str, int len, int errno_val);
|
||||||
__dso_public pid_t sudo_debug_fork(void);
|
__dso_public pid_t sudo_debug_fork(void);
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2013 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 2011-2014 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -297,7 +297,7 @@ sudo_debug_exit_ptr(const char *func, const char *file, int line,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
sudo_debug_write_conv(const char *func, const char *file, int lineno,
|
sudo_debug_write_conv(const char *func, const char *file, int lineno,
|
||||||
const char *str, int len, int errno_val)
|
const char *str, int len, int errnum)
|
||||||
{
|
{
|
||||||
/* Remove trailing newlines. */
|
/* Remove trailing newlines. */
|
||||||
while (len > 0 && str[len - 1] == '\n')
|
while (len > 0 && str[len - 1] == '\n')
|
||||||
@@ -305,35 +305,35 @@ sudo_debug_write_conv(const char *func, const char *file, int lineno,
|
|||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (func != NULL && file != NULL) {
|
if (func != NULL && file != NULL) {
|
||||||
if (errno_val) {
|
if (errnum) {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s @ %s() %s:%d",
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s @ %s() %s:%d",
|
||||||
len, str, strerror(errno_val), func, file, lineno);
|
len, str, strerror(errnum), func, file, lineno);
|
||||||
} else {
|
} else {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s @ %s() %s:%d",
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s @ %s() %s:%d",
|
||||||
len, str, func, file, lineno);
|
len, str, func, file, lineno);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (errno_val) {
|
if (errnum) {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s",
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s",
|
||||||
len, str, strerror(errno_val));
|
len, str, strerror(errnum));
|
||||||
} else {
|
} else {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s", len, str);
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s", len, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (errno_val) {
|
} else if (errnum) {
|
||||||
/* Only print error string. */
|
/* Only print error string. */
|
||||||
if (func != NULL && file != NULL) {
|
if (func != NULL && file != NULL) {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%s @ %s() %s:%d",
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%s @ %s() %s:%d",
|
||||||
strerror(errno_val), func, file, lineno);
|
strerror(errnum), func, file, lineno);
|
||||||
} else {
|
} else {
|
||||||
sudo_printf(SUDO_CONV_DEBUG_MSG, "%s", strerror(errno_val));
|
sudo_printf(SUDO_CONV_DEBUG_MSG, "%s", strerror(errnum));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sudo_debug_write_file(const char *func, const char *file, int lineno,
|
sudo_debug_write_file(const char *func, const char *file, int lineno,
|
||||||
const char *str, int len, int errno_val)
|
const char *str, int len, int errnum)
|
||||||
{
|
{
|
||||||
char *timestr, numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
|
char *timestr, numbuf[(((sizeof(int) * 8) + 2) / 3) + 2];
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -356,13 +356,13 @@ sudo_debug_write_file(const char *func, const char *file, int lineno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Append error string if errno is specified. */
|
/* Append error string if errno is specified. */
|
||||||
if (errno_val) {
|
if (errnum) {
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
iov[iovcnt].iov_base = ": ";
|
iov[iovcnt].iov_base = ": ";
|
||||||
iov[iovcnt].iov_len = 2;
|
iov[iovcnt].iov_len = 2;
|
||||||
iovcnt++;
|
iovcnt++;
|
||||||
}
|
}
|
||||||
iov[iovcnt].iov_base = strerror(errno_val);
|
iov[iovcnt].iov_base = strerror(errnum);
|
||||||
iov[iovcnt].iov_len = strlen(iov[iovcnt].iov_base);
|
iov[iovcnt].iov_len = strlen(iov[iovcnt].iov_base);
|
||||||
iovcnt++;
|
iovcnt++;
|
||||||
}
|
}
|
||||||
@@ -410,25 +410,18 @@ sudo_debug_write_file(const char *func, const char *file, int lineno,
|
|||||||
|
|
||||||
void
|
void
|
||||||
sudo_debug_write2(const char *func, const char *file, int lineno,
|
sudo_debug_write2(const char *func, const char *file, int lineno,
|
||||||
const char *str, int len, int errno_val)
|
const char *str, int len, int errnum)
|
||||||
{
|
{
|
||||||
switch (sudo_debug_mode) {
|
switch (sudo_debug_mode) {
|
||||||
case SUDO_DEBUG_MODE_CONV:
|
case SUDO_DEBUG_MODE_CONV:
|
||||||
sudo_debug_write_conv(func, file, lineno, str, len, errno_val);
|
sudo_debug_write_conv(func, file, lineno, str, len, errnum);
|
||||||
break;
|
break;
|
||||||
case SUDO_DEBUG_MODE_FILE:
|
case SUDO_DEBUG_MODE_FILE:
|
||||||
sudo_debug_write_file(func, file, lineno, str, len, errno_val);
|
sudo_debug_write_file(func, file, lineno, str, len, errnum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX - turn into a macro */
|
|
||||||
void
|
|
||||||
sudo_debug_write(const char *str, int len, int errno_val)
|
|
||||||
{
|
|
||||||
sudo_debug_write2(NULL, NULL, 0, str, len, errno_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level,
|
||||||
const char *fmt, va_list ap)
|
const char *fmt, va_list ap)
|
||||||
|
Reference in New Issue
Block a user