Skip to content

Commit add65e8

Browse files
committed
Delay krb5 tracing setup in daemon mode
This delays the initialization of the krb5 tracing function until after daemonization when not running interactively. Setting it up earlier caused the trace reader thread to be killed during the fork. It also adds an early check to cache the state of the KRB5_TRACE environment variable, ensuring that gssproxy does not override or unset a user-provided trace configuration. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent d0a0660 commit add65e8

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/gp_debug.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99

1010
/* global debug switch */
1111
int gp_debug = 0;
12+
bool gp_env_trace = false;
1213

14+
/* determine if we can set KRB5_TRACE or the user already set it.
15+
* we do not override a user's setting */
16+
void gp_debug_check_env_(void)
17+
{
18+
if (getenv("KRB5_TRACE")) {
19+
gp_env_trace = true;
20+
}
21+
}
1322

1423
void (*gp_debug_setup_k5_trace_fn)(int) = NULL;
1524

@@ -27,24 +36,26 @@ void gp_debug_set_krb5_tracing_fn(void (*fn)(int))
2736
* initial debug level is set via configuration.
2837
* Make sure to immedaiately call it if debug level is
2938
* already above 3 */
30-
if (gp_debug >= 3 && !getenv("KRB5_TRACE")) {
39+
if (gp_debug >= 3 && !gp_env_trace) {
3140
gp_debug_setup_k5_trace_fn(1);
3241
}
3342
}
3443

3544
void gp_debug_toggle(int level)
3645
{
37-
if (level >= 3 && !getenv("KRB5_TRACE")) {
38-
if (gp_debug_setup_k5_trace_fn) {
39-
gp_debug_setup_k5_trace_fn(1);
40-
} else {
41-
setenv("KRB5_TRACE", "/dev/stderr", 1);
42-
}
43-
} else if (level < 3) {
44-
if (gp_debug_setup_k5_trace_fn) {
45-
gp_debug_setup_k5_trace_fn(0);
46-
} else {
47-
unsetenv("KRB5_TRACE");
46+
if (!gp_env_trace) {
47+
if (level >= 3) {
48+
if (gp_debug_setup_k5_trace_fn) {
49+
gp_debug_setup_k5_trace_fn(1);
50+
} else {
51+
setenv("KRB5_TRACE", "/dev/stderr", 1);
52+
}
53+
} else if (level < 3) {
54+
if (gp_debug_setup_k5_trace_fn) {
55+
gp_debug_setup_k5_trace_fn(0);
56+
} else {
57+
unsetenv("KRB5_TRACE");
58+
}
4859
}
4960
}
5061

src/gp_debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
extern int gp_debug;
1414

15+
void gp_debug_check_env_(void);
1516
void gp_debug_toggle(int);
1617
void gp_debug_printf(const char *format, ...);
1718
void gp_debug_time_printf(const char *format, ...);

src/gssproxy.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ int main(int argc, const char *argv[])
8686
goto cleanup;
8787
}
8888

89-
/* set tracing function before handling debug level */
90-
gp_debug_set_krb5_tracing_fn(&gp_krb5_tracing_setup);
89+
gp_debug_check_env_();
9190

9291
if (opt_debug || opt_debug_level > 0) {
9392
if (opt_debug_level == 0) opt_debug_level = 1;
9493
gp_debug_toggle(opt_debug_level);
9594
}
9695

96+
/* if we are in interactive mode set up tracing immediately */
97+
if (opt_interactive) {
98+
gp_debug_set_krb5_tracing_fn(&gp_krb5_tracing_setup);
99+
}
100+
97101
if (opt_extract_ccache) {
98102
ret = extract_ccache(opt_extract_ccache, opt_dest_ccache);
99103
goto cleanup;
@@ -141,6 +145,12 @@ int main(int argc, const char *argv[])
141145

142146
init_server(gpctx->config->daemonize, opt_userproxy, &wait_fd);
143147

148+
if (!opt_interactive) {
149+
/* set tracing function *after* demonizing, or we kill the
150+
* trace reader thread */
151+
gp_debug_set_krb5_tracing_fn(&gp_krb5_tracing_setup);
152+
}
153+
144154
if (!gpctx->userproxymode) {
145155
write_pid();
146156
}

0 commit comments

Comments
 (0)