Skip to content

Commit

Permalink
DEBUG: propagate debug_backtrace_enabled to child processes
Browse files Browse the repository at this point in the history
Resolves: #7510

Reviewed-by: Justin Stephenson <[email protected]>
Reviewed-by: Sumit Bose <[email protected]>
  • Loading branch information
alexey-tikhonov committed Oct 23, 2024
1 parent 2300abb commit 88b55de
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/oidc_child/oidc_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ static struct devicecode_ctx *get_dc_ctx(TALLOC_CTX *mem_ctx,

struct cli_opts {
const char *opt_logger;
int backtrace;
const char *issuer_url;
const char *client_id;
const char *device_auth_endpoint;
Expand All @@ -274,13 +275,16 @@ static int parse_cli(int argc, const char *argv[], struct cli_opts *opts)
poptContext pc;
int opt;
errno_t ret;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
bool print_usage = true;

struct poptOption long_options[] = {
POPT_AUTOHELP
SSSD_DEBUG_OPTS
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
{"get-device-code", 0, POPT_ARG_NONE, NULL, 'a',
Expand Down Expand Up @@ -398,6 +402,7 @@ static int parse_cli(int argc, const char *argv[], struct cli_opts *opts)
}

opts->opt_logger = opt_logger;
opts->backtrace = backtrace;

if (debug_fd != -1) {
opts->opt_logger = sss_logger_str[FILES_LOGGER];
Expand Down Expand Up @@ -488,6 +493,7 @@ int main(int argc, const char *argv[])
}

DEBUG_INIT(debug_level, opts.opt_logger);
sss_set_debug_backtrace_enable((opts.backtrace == 0) ? false : true);

DEBUG(SSSDBG_TRACE_FUNC, "oidc_child started.\n");

Expand Down
3 changes: 3 additions & 0 deletions src/p11_child/p11_child_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ int main(int argc, const char *argv[])
int opt;
poptContext pc;
int dumpable = 1;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
errno_t ret = 0;
Expand All @@ -173,6 +174,7 @@ int main(int argc, const char *argv[])
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0, _("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
SSSD_LOGGER_OPTS
Expand Down Expand Up @@ -328,6 +330,7 @@ int main(int argc, const char *argv[])
sss_chain_id_set((uint64_t)chain_id);

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

DEBUG(SSSDBG_TRACE_FUNC, "p11_child started.\n");

Expand Down
4 changes: 4 additions & 0 deletions src/passkey_child/passkey_child_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ parse_arguments(TALLOC_CTX *mem_ctx, int argc, const char *argv[],
{
int opt;
int dumpable = 1;
int backtrace = 1;
int debug_fd = -1;
char *user_verification = NULL;
char *public_keys = NULL;
Expand Down Expand Up @@ -163,6 +164,8 @@ parse_arguments(TALLOC_CTX *mem_ctx, int argc, const char *argv[],
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
SSSD_LOGGER_OPTS
Expand Down Expand Up @@ -332,6 +335,7 @@ parse_arguments(TALLOC_CTX *mem_ctx, int argc, const char *argv[],
}

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

ret = EOK;

Expand Down
4 changes: 4 additions & 0 deletions src/providers/ad/ad_gpo_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ main(int argc, const char *argv[])
int opt;
poptContext pc;
int dumpable = 1;
int backtrace = 1;
int debug_fd = -1;
long chain_id = 0;
const char *opt_logger = NULL;
Expand All @@ -678,6 +679,8 @@ main(int argc, const char *argv[])
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
{"chain-id", 0, POPT_ARG_LONG, &chain_id,
Expand Down Expand Up @@ -723,6 +726,7 @@ main(int argc, const char *argv[])
sss_chain_id_set((uint64_t)chain_id);

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

DEBUG(SSSDBG_TRACE_FUNC, "gpo_child started.\n");

Expand Down
4 changes: 4 additions & 0 deletions src/providers/ipa/selinux_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ int main(int argc, const char *argv[])
poptContext pc;
int debug_fd = -1;
int dumpable = 1;
int backtrace = 1;
errno_t ret;
TALLOC_CTX *main_ctx = NULL;
uint8_t *buf = NULL;
Expand All @@ -227,6 +228,8 @@ int main(int argc, const char *argv[])
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
{"chain-id", 0, POPT_ARG_LONG, &chain_id,
Expand Down Expand Up @@ -272,6 +275,7 @@ int main(int argc, const char *argv[])
sss_chain_id_set((uint64_t)chain_id);

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

DEBUG(SSSDBG_TRACE_FUNC, "selinux_child started.\n");
DEBUG(SSSDBG_TRACE_INTERNAL,
Expand Down
4 changes: 4 additions & 0 deletions src/providers/krb5/krb5_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ int main(int argc, const char *argv[])
int opt;
poptContext pc;
int dumpable = 1;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
errno_t ret;
Expand All @@ -4143,6 +4144,8 @@ int main(int argc, const char *argv[])
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
SSSD_LOGGER_OPTS
Expand Down Expand Up @@ -4232,6 +4235,7 @@ int main(int argc, const char *argv[])
sss_chain_id_set((uint64_t)chain_id);

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

DEBUG(SSSDBG_CONF_SETTINGS,
"Starting under uid=%"SPRIuid" (euid=%"SPRIuid") : "
Expand Down
4 changes: 4 additions & 0 deletions src/providers/ldap/ldap_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ int main(int argc, const char *argv[])
int ret;
int opt;
int dumpable = 1;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
poptContext pc;
Expand All @@ -992,6 +993,8 @@ int main(int argc, const char *argv[])
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
_("An open file descriptor for the debug logs"), NULL},
SSSD_LOGGER_OPTS
Expand Down Expand Up @@ -1033,6 +1036,7 @@ int main(int argc, const char *argv[])
}

DEBUG_INIT(debug_level, opt_logger);
sss_set_debug_backtrace_enable((backtrace == 0) ? false : true);

BlockSignals(false, SIGTERM);
CatchSignal(SIGTERM, sig_term_handler);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/cmocka/dummy_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int main(int argc, const char *argv[])
uint8_t buf[IN_BUF_SIZE];
const char *action = NULL;
int dumpable;
int backtrace;
const char *guitar;
const char *drums;
int timestamp_opt;
Expand All @@ -49,8 +50,8 @@ int main(int argc, const char *argv[])
POPT_AUTOHELP
SSSD_DEBUG_OPTS
SSSD_LOGGER_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0, _("Allow core dumps"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0, _("Enable debug backtrace"), NULL },
{"guitar", 0, POPT_ARG_STRING, &guitar, 0, _("Who plays guitar"), NULL },
{"drums", 0, POPT_ARG_STRING, &drums, 0, _("Who plays drums"), NULL },
POPT_TABLEEND
Expand Down
11 changes: 9 additions & 2 deletions src/util/child_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,9 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx,
/* program name, dumpable,
* debug-microseconds, debug-timestamps,
* logger or debug-fd,
* debug-level and NULL
* debug-level, backtrace and NULL
*/
argc = 7;
argc = 8;
}

if (extra_argv) {
Expand Down Expand Up @@ -769,6 +769,13 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx,
goto fail;
}

argv[--argc] = talloc_asprintf(argv, "--backtrace=%d",
sss_get_debug_backtrace_enable() ? 1 : 0);
if (argv[argc] == NULL) {
ret = ENOMEM;
goto fail;
}

if (sss_logger == FILES_LOGGER) {
argv[--argc] = talloc_asprintf(argv, "--debug-fd=%d",
child_debug_fd);
Expand Down

0 comments on commit 88b55de

Please sign in to comment.