diff --git a/Add-Client-ID-to-debug-messages.patch b/Add-Client-ID-to-debug-messages.patch new file mode 100644 index 0000000..f7150e1 --- /dev/null +++ b/Add-Client-ID-to-debug-messages.patch @@ -0,0 +1,148 @@ +From b617bf0274de43abb2592ba11568f10d3e8535bf Mon Sep 17 00:00:00 2001 +From: Simo Sorce +Date: Thu, 25 May 2017 15:22:37 -0400 +Subject: [PATCH] Add Client ID to debug messages + +This allows to sort out which debug message belongs to which client when +multiple clients are preforming operations at the same time. + +Signed-off-by: Simo Sorce +Reviewed-by: Robbie Harwood + +Resolves: #189 +Merges: #191 +(cherry picked from commit 2f158fe4d39c11589d214d3d602c6d10411052dc) +--- + proxy/src/gp_debug.c | 28 +++++++++++++++++++++++++++- + proxy/src/gp_debug.h | 1 + + proxy/src/gp_proxy.h | 1 + + proxy/src/gp_socket.c | 5 +++++ + proxy/src/gp_workers.c | 6 ++++++ + proxy/src/gssproxy.c | 4 ++++ + 6 files changed, 44 insertions(+), 1 deletion(-) + +diff --git a/proxy/src/gp_debug.c b/proxy/src/gp_debug.c +index 3029574..4a141fc 100644 +--- a/proxy/src/gp_debug.c ++++ b/proxy/src/gp_debug.c +@@ -64,6 +64,32 @@ const char *gp_debug_timestamp(void) + return buffer; + } + ++/* thread local connection/client id */ ++static __thread int cid; ++ ++void gp_debug_set_conn_id(int id) ++{ ++ cid = id; ++} ++ ++static const char*gp_debug_conn_id(void) ++{ ++ static __thread char buffer[18]; ++ static __thread int last_cid = 0; ++ ++ if (cid == 0) { ++ buffer[0] = '\0'; ++ return buffer; ++ } ++ ++ if (last_cid == cid) return buffer; ++ ++ (void)snprintf(buffer, 17, "[CID %d]", cid); ++ buffer[17] = '\0'; ++ last_cid = cid; ++ return buffer; ++} ++ + void gp_debug_printf(const char *format, ...) + { + va_list varargs; +@@ -76,7 +102,7 @@ void gp_debug_time_printf(const char *format, ...) + { + va_list varargs; + +- fprintf(stderr, "%s", gp_debug_timestamp()); ++ fprintf(stderr, "%s%s", gp_debug_conn_id(), gp_debug_timestamp()); + + va_start(varargs, format); + vfprintf(stderr, format, varargs); +diff --git a/proxy/src/gp_debug.h b/proxy/src/gp_debug.h +index d3420b0..1c2f8a3 100644 +--- a/proxy/src/gp_debug.h ++++ b/proxy/src/gp_debug.h +@@ -14,6 +14,7 @@ int gp_debug_args(int level); + void gp_debug_toggle(int); + void gp_debug_printf(const char *format, ...); + void gp_debug_time_printf(const char *format, ...); ++void gp_debug_set_conn_id(int id); + + #define GPDEBUG(...) do { \ + if (gp_debug) { \ +diff --git a/proxy/src/gp_proxy.h b/proxy/src/gp_proxy.h +index 971a7b6..55ab83c 100644 +--- a/proxy/src/gp_proxy.h ++++ b/proxy/src/gp_proxy.h +@@ -113,6 +113,7 @@ void gp_socket_send_data(verto_ctx *vctx, struct gp_conn *conn, + struct gp_creds *gp_conn_get_creds(struct gp_conn *conn); + uid_t gp_conn_get_uid(struct gp_conn *conn); + const char *gp_conn_get_socket(struct gp_conn *conn); ++int gp_conn_get_cid(struct gp_conn *conn); + bool gp_selinux_ctx_equal(SELINUX_CTX ctx1, SELINUX_CTX ctx2); + bool gp_conn_check_selinux(struct gp_conn *conn, SELINUX_CTX ctx); + +diff --git a/proxy/src/gp_socket.c b/proxy/src/gp_socket.c +index e07789c..133db9c 100644 +--- a/proxy/src/gp_socket.c ++++ b/proxy/src/gp_socket.c +@@ -103,6 +103,11 @@ const char *gp_conn_get_socket(struct gp_conn *conn) + return conn->sock_ctx->socket; + } + ++int gp_conn_get_cid(struct gp_conn *conn) ++{ ++ return conn->us.sd; ++} ++ + void gp_conn_free(struct gp_conn *conn) + { + if (!conn) return; +diff --git a/proxy/src/gp_workers.c b/proxy/src/gp_workers.c +index c089b54..d37e57c 100644 +--- a/proxy/src/gp_workers.c ++++ b/proxy/src/gp_workers.c +@@ -357,6 +357,9 @@ static void *gp_worker_main(void *pvt) + + while (!t->pool->shutdown) { + ++ /* initialize debug client id to 0 until work is scheduled */ ++ gp_debug_set_conn_id(0); ++ + /* ======> COND_MUTEX */ + pthread_mutex_lock(&t->cond_mutex); + while (t->query == NULL) { +@@ -374,6 +377,9 @@ static void *gp_worker_main(void *pvt) + /* <====== COND_MUTEX */ + pthread_mutex_unlock(&t->cond_mutex); + ++ /* set client id before hndling requests */ ++ gp_debug_set_conn_id(gp_conn_get_cid(q->conn)); ++ + /* handle the client request */ + gp_handle_query(t->pool, q); + +diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c +index a020218..9ffec5e 100644 +--- a/proxy/src/gssproxy.c ++++ b/proxy/src/gssproxy.c +@@ -159,6 +159,10 @@ int main(int argc, const char *argv[]) + int wait_fd; + int ret; + ++ /* initialize debug client id to 0 in the main thread */ ++ /* we do this early, before any code starts using debug statements */ ++ gp_debug_set_conn_id(0); ++ + struct poptOption long_options[] = { + POPT_AUTOHELP + {"daemon", 'D', POPT_ARG_NONE, &opt_daemon, 0, \ diff --git a/gssproxy.spec b/gssproxy.spec index 5cc27a4..737f4ec 100644 --- a/gssproxy.spec +++ b/gssproxy.spec @@ -1,6 +1,6 @@ Name: gssproxy Version: 0.7.0 -Release: 11%{?dist} +Release: 12%{?dist} Summary: GSSAPI Proxy Group: System Environment/Libraries @@ -24,6 +24,7 @@ Patch6: Fix-segfault-when-no-config-files-are-present.patch Patch7: Include-header-for-writev.patch Patch8: Make-proc-file-failure-loud-but-nonfatal.patch Patch9: Tolerate-NULL-pointers-in-gp_same.patch +Patch10: Add-Client-ID-to-debug-messages.patch ### Dependencies ### Requires: krb5-libs >= 1.12.0 @@ -53,22 +54,13 @@ BuildRequires: libverto-devel BuildRequires: popt-devel BuildRequires: findutils BuildRequires: systemd-units +BuildRequires: git %description A proxy for GSSAPI credential handling %prep -%setup -q -%patch0 -p2 -b .Properly-renew-expired-credentials -%patch1 -p2 -b .Change-impersonator-check-code -%patch2 -p2 -b .Allow-connection-to-self-when-impersonator-set -%patch3 -p2 -b .Remove-gpm_release_ctx-to-fix-double-unlock -%patch4 -p2 -b .Update-systemd-file -%patch5 -p2 -b .Fix-unused-variables -%patch6 -p2 -b .Fix-segfault-when-no-config-files-are-present -%patch7 -p2 -b .Include-header-for-writev -%patch8 -p2 -b .Make-proc-file-failure-loud-but-nonfatal -%patch9 -p2 -b .Tolerate-NULL-pointers-in-gp_same +%autosetup -p2 -S git %build autoreconf -f -i @@ -124,6 +116,10 @@ rm -rf %{buildroot} %systemd_postun_with_restart gssproxy.service %changelog +* Mon Jul 31 2017 Robbie Harwood - 0.7.0-12 +- Add client ID to debug messages +- Move packaging to autosetup + * Wed Jul 26 2017 Fedora Release Engineering - 0.7.0-11 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild