Set debug instance for standalone programs.

This commit is contained in:
Todd C. Miller
2014-10-23 09:40:36 -06:00
parent 1ca52382a4
commit fe9e035ccf
4 changed files with 30 additions and 14 deletions

View File

@@ -169,6 +169,8 @@ struct search_node {
static struct search_node_list search_expr = STAILQ_HEAD_INITIALIZER(search_expr); static struct search_node_list search_expr = STAILQ_HEAD_INITIALIZER(search_expr);
static int sudoreplay_debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
static int timing_idx_adj; static int timing_idx_adj;
static double speed_factor = 1.0; static double speed_factor = 1.0;
@@ -236,7 +238,7 @@ main(int argc, char *argv[])
char *cp, *ep, path[PATH_MAX]; char *cp, *ep, path[PATH_MAX];
struct log_info *li; struct log_info *li;
double max_wait = 0; double max_wait = 0;
debug_decl(main, SUDO_DEBUG_MAIN, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(main, SUDO_DEBUG_MAIN, sudoreplay_debug_instance)
#if defined(SUDO_DEVEL) && defined(__OpenBSD__) #if defined(SUDO_DEVEL) && defined(__OpenBSD__)
{ {
@@ -257,6 +259,9 @@ main(int argc, char *argv[])
/* Read sudo.conf. */ /* Read sudo.conf. */
sudo_conf_read(NULL); sudo_conf_read(NULL);
/* Set debug instance to use (if configured). */
sudoreplay_debug_instance = sudo_debug_get_instance(getprogname());
while ((ch = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { while ((ch = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch (ch) { switch (ch) {
case 'd': case 'd':
@@ -385,7 +390,7 @@ replay_session(const double max_wait, const char *decimal)
char buf[LINE_MAX]; char buf[LINE_MAX];
sigaction_t sa; sigaction_t sa;
int idx; int idx;
debug_decl(replay_session, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(replay_session, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
/* Restore tty settings if interupted. */ /* Restore tty settings if interupted. */
fflush(stdout); fflush(stdout);
@@ -553,7 +558,7 @@ replay_session(const double max_wait, const char *decimal)
static int static int
open_io_fd(char *path, int len, struct io_log_file *iol) open_io_fd(char *path, int len, struct io_log_file *iol)
{ {
debug_decl(open_io_fd, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(open_io_fd, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
if (!iol->enabled) if (!iol->enabled)
debug_return_int(0); debug_return_int(0);
@@ -575,7 +580,7 @@ write_output(int fd, int what, void *v)
ssize_t nwritten; ssize_t nwritten;
size_t count, remainder; size_t count, remainder;
unsigned int i; unsigned int i;
debug_decl(write_output, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(write_output, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
nwritten = writev(STDOUT_FILENO, wc->iov, wc->iovcnt); nwritten = writev(STDOUT_FILENO, wc->iov, wc->iovcnt);
switch (nwritten) { switch (nwritten) {
@@ -628,7 +633,7 @@ parse_expr(struct search_node_list *head, char *argv[], bool sub_expr)
bool or = false, not = false; bool or = false, not = false;
struct search_node *sn; struct search_node *sn;
char type, **av; char type, **av;
debug_decl(parse_expr, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(parse_expr, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
for (av = argv; *av != NULL; av++) { for (av = argv; *av != NULL; av++) {
switch (av[0][0]) { switch (av[0][0]) {
@@ -747,7 +752,7 @@ match_expr(struct search_node_list *head, struct log_info *log, bool last_match)
struct search_node *sn; struct search_node *sn;
bool res, matched = last_match; bool res, matched = last_match;
int rc; int rc;
debug_decl(match_expr, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(match_expr, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
STAILQ_FOREACH(sn, head, entries) { STAILQ_FOREACH(sn, head, entries) {
switch (sn->type) { switch (sn->type) {
@@ -808,7 +813,7 @@ parse_logfile(char *logfile)
const char *errstr; const char *errstr;
size_t bufsize = 0, cwdsize = 0, cmdsize = 0; size_t bufsize = 0, cwdsize = 0, cmdsize = 0;
struct log_info *li = NULL; struct log_info *li = NULL;
debug_decl(parse_logfile, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(parse_logfile, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
fp = fopen(logfile, "r"); fp = fopen(logfile, "r");
if (fp == NULL) { if (fp == NULL) {
@@ -940,7 +945,7 @@ list_session(char *logfile, REGEX_T *re, const char *user, const char *tty)
const char *timestr; const char *timestr;
struct log_info *li; struct log_info *li;
int rval = -1; int rval = -1;
debug_decl(list_session, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(list_session, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
if ((li = parse_logfile(logfile)) == NULL) if ((li = parse_logfile(logfile)) == NULL)
goto done; goto done;
@@ -1005,7 +1010,7 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
#else #else
const bool checked_type = false; const bool checked_type = false;
#endif #endif
debug_decl(find_sessions, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(find_sessions, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
d = opendir(dir); d = opendir(dir);
if (d == NULL) if (d == NULL)
@@ -1079,7 +1084,7 @@ list_sessions(int argc, char **argv, const char *pattern, const char *user,
const char *tty) const char *tty)
{ {
REGEX_T rebuf, *re = NULL; REGEX_T rebuf, *re = NULL;
debug_decl(list_sessions, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(list_sessions, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
/* Parse search expression if present */ /* Parse search expression if present */
parse_expr(&search_expr, argv, false); parse_expr(&search_expr, argv, false);
@@ -1110,7 +1115,7 @@ check_input(int fd, int what, void *v)
struct timeval tv, *timeout = NULL; struct timeval tv, *timeout = NULL;
static bool paused = 0; static bool paused = 0;
char ch; char ch;
debug_decl(check_input, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(check_input, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
if (ISSET(what, SUDO_EV_READ)) { if (ISSET(what, SUDO_EV_READ)) {
switch (read(fd, &ch, 1)) { switch (read(fd, &ch, 1)) {
@@ -1174,7 +1179,7 @@ parse_timing(const char *buf, const char *decimal, int *idx, double *seconds,
long l; long l;
double d, fract = 0; double d, fract = 0;
char *cp, *ep; char *cp, *ep;
debug_decl(parse_timing, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(parse_timing, SUDO_DEBUG_UTIL, sudoreplay_debug_instance)
/* Parse index */ /* Parse index */
ul = strtoul(buf, &ep, 10); ul = strtoul(buf, &ep, 10);

View File

@@ -141,6 +141,9 @@ main(int argc, char *argv[])
/* Read sudo.conf. */ /* Read sudo.conf. */
sudo_conf_read(NULL); sudo_conf_read(NULL);
/* Set debug instance to use (if configured). */
sudoers_debug_instance = sudo_debug_get_instance(getprogname());
dflag = 0; dflag = 0;
grfile = pwfile = NULL; grfile = pwfile = NULL;
while ((ch = getopt(argc, argv, "dg:G:h:P:p:tu:U:")) != -1) { while ((ch = getopt(argc, argv, "dg:G:h:P:p:tu:U:")) != -1) {

View File

@@ -172,6 +172,9 @@ main(int argc, char *argv[])
/* Read sudo.conf. */ /* Read sudo.conf. */
sudo_conf_read(NULL); sudo_conf_read(NULL);
/* Set debug instance to use (if configured). */
sudoers_debug_instance = sudo_debug_get_instance(getprogname());
/* /*
* Arg handling. * Arg handling.
*/ */

View File

@@ -51,6 +51,8 @@
__dso_public int main(int argc, char *argv[], char *envp[]); __dso_public int main(int argc, char *argv[], char *envp[]);
int sudo_debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
static int sesh_sudoedit(int argc, char *argv[]); static int sesh_sudoedit(int argc, char *argv[]);
/* /*
@@ -66,7 +68,7 @@ int
main(int argc, char *argv[], char *envp[]) main(int argc, char *argv[], char *envp[])
{ {
int ret; int ret;
debug_decl(main, SUDO_DEBUG_MAIN, sudo_debug_instance, SUDO_DEBUG_INSTANCE_DEFAULT) debug_decl(main, SUDO_DEBUG_MAIN, sudo_debug_instance)
initprogname(argc > 0 ? argv[0] : "sesh"); initprogname(argc > 0 ? argv[0] : "sesh");
@@ -80,6 +82,9 @@ main(int argc, char *argv[], char *envp[])
/* Read sudo.conf. */ /* Read sudo.conf. */
sudo_conf_read(NULL); sudo_conf_read(NULL);
/* Set debug instance to use (if configured). */
sudo_debug_instance = sudo_debug_get_instance(getprogname());
if (strcmp(argv[1], "-e") == 0) { if (strcmp(argv[1], "-e") == 0) {
ret = sesh_sudoedit(argc, argv); ret = sesh_sudoedit(argc, argv);
} else { } else {
@@ -121,7 +126,7 @@ sesh_sudoedit(int argc, char *argv[])
struct stat sb; struct stat sb;
struct timeval times[2]; struct timeval times[2];
char buf[BUFSIZ]; char buf[BUFSIZ];
debug_decl(sesh_sudoedit, SUDO_DEBUG_MAIN) debug_decl(sesh_sudoedit, SUDO_DEBUG_EDIT, sudo_debug_instance)
if (argc < 3) if (argc < 3)
debug_return_int(SESH_ERR_FAILURE); debug_return_int(SESH_ERR_FAILURE);