lib/util/sudo_debug.c: add a function for querying if debugging is needed
for a level. Rationale: this way we can avoid computing details for the log which will not happen at all if the computation is slow.
This commit is contained in:

committed by
Todd C. Miller

parent
80fa75f0e8
commit
6710048c8d
@@ -269,7 +269,9 @@ __dso_public int sudo_debug_set_active_instance_v1(int inst);
|
||||
__dso_public void sudo_debug_update_fd_v1(int ofd, int nfd);
|
||||
__dso_public void sudo_debug_vprintf2_v1(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0);
|
||||
__dso_public void sudo_debug_write2_v1(int fd, const char *func, const char *file, int line, const char *str, int len, int errnum);
|
||||
__dso_public bool sudo_debug_needed_v1(int level);
|
||||
|
||||
#define sudo_debug_needed(level) sudo_debug_needed_v1((level)|sudo_debug_subsys)
|
||||
#define sudo_debug_deregister(_a) sudo_debug_deregister_v1((_a))
|
||||
#define sudo_debug_enter(_a, _b, _c, _d) sudo_debug_enter_v1((_a), (_b), (_c), (_d))
|
||||
#define sudo_debug_execve2(_a, _b, _c, _d) sudo_debug_execve2_v1((_a), (_b), (_c), (_d))
|
||||
|
@@ -623,6 +623,41 @@ sudo_debug_write2_v1(int fd, const char *func, const char *file, int lineno,
|
||||
ignore_result(writev(fd, iov, iovcnt));
|
||||
}
|
||||
|
||||
bool
|
||||
sudo_debug_needed_v1(int level)
|
||||
{
|
||||
unsigned int subsys;
|
||||
int pri;
|
||||
struct sudo_debug_instance *instance;
|
||||
struct sudo_debug_output *output;
|
||||
bool result = false;
|
||||
|
||||
if (sudo_debug_active_instance == -1)
|
||||
goto out;
|
||||
|
||||
/* Extract priority and subsystem from level. */
|
||||
pri = SUDO_DEBUG_PRI(level);
|
||||
subsys = (unsigned int)SUDO_DEBUG_SUBSYS(level);
|
||||
|
||||
if (sudo_debug_active_instance > sudo_debug_last_instance)
|
||||
goto out;
|
||||
|
||||
instance = sudo_debug_instances[sudo_debug_active_instance];
|
||||
if (instance == NULL)
|
||||
goto out;
|
||||
|
||||
if (subsys <= instance->max_subsystem) {
|
||||
SLIST_FOREACH(output, &instance->outputs, entries) {
|
||||
if (output->settings[subsys] >= pri) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
sudo_debug_vprintf2_v1(const char *func, const char *file, int lineno, int level,
|
||||
const char *fmt, va_list ap)
|
||||
|
@@ -37,6 +37,7 @@ sudo_debug_set_active_instance_v1
|
||||
sudo_debug_update_fd_v1
|
||||
sudo_debug_vprintf2_v1
|
||||
sudo_debug_write2_v1
|
||||
sudo_debug_needed_v1
|
||||
sudo_digest_alloc_v1
|
||||
sudo_digest_final_v1
|
||||
sudo_digest_free_v1
|
||||
|
Reference in New Issue
Block a user