swrap: Also log the process name
authorAndreas Schneider <asn@samba.org>
Mon, 12 Nov 2018 14:22:35 +0000 (15:22 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 13 Nov 2018 10:59:48 +0000 (11:59 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
ConfigureChecks.cmake
config.h.cmake
src/socket_wrapper.c

index 94fed2288a4ceb9a127c0680df6b2919c950ff6c..6cedb90fcd4f39163a76ca5a6184d4a78471f4ad 100644 (file)
@@ -54,6 +54,13 @@ check_include_file(sys/timerfd.h HAVE_SYS_TIMERFD_H)
 check_include_file(gnu/lib-names.h HAVE_GNU_LIB_NAMES_H)
 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
 
+# SYMBOLS
+set(CMAKE_REQUIRED_FLAGS -D_GNU_SOURCE)
+check_symbol_exists(program_invocation_short_name
+                    "errno.h"
+                    HAVE_PROGRAM_INVOCATION_SHORT_NAME)
+unset(CMAKE_REQUIRED_FLAGS)
+
 # FUNCTIONS
 check_function_exists(strncpy HAVE_STRNCPY)
 check_function_exists(vsnprintf HAVE_VSNPRINTF)
@@ -65,6 +72,8 @@ check_function_exists(bindresvport HAVE_BINDRESVPORT)
 check_function_exists(accept4 HAVE_ACCEPT4)
 check_function_exists(open64 HAVE_OPEN64)
 check_function_exists(fopen64 HAVE_FOPEN64)
+check_function_exists(getprogname HAVE_GETPROGNAME)
+check_function_exists(getexecname HAVE_GETEXECNAME)
 
 check_function_exists(pledge HAVE_PLEDGE)
 
index 5baa789a6fbc21b837b3a648f5f9c4bec980e3f8..0207031c6e53cf8d9dae25f1f47f5484343d535d 100644 (file)
 #cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
 #cmakedefine HAVE_STRUCT_MSGHDR_MSG_CONTROL 1
 
+/**************************** SYMBOLS ****************************/
+
+#cmakedefine HAVE_PROGRAM_INVOCATION_SHORT_NAME 1
+
 /*************************** FUNCTIONS ***************************/
 
 /* Define to 1 if you have the `getaddrinfo' function. */
@@ -42,6 +46,8 @@
 #cmakedefine HAVE_ACCEPT4 1
 #cmakedefine HAVE_OPEN64 1
 #cmakedefine HAVE_FOPEN64 1
+#cmakedefine HAVE_GETPROGNAME 1
+#cmakedefine HAVE_GETEXECNAME 1
 #cmakedefine HAVE_PLEDGE 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
index 165922b79d0be36571cb9a7b9bb08b6986d5bd19..2b77cebf516ff4663aa48469cb5b83af6faf5f61 100644 (file)
@@ -333,6 +333,19 @@ bool socket_wrapper_enabled(void);
 void swrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
 void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 
+#ifndef HAVE_GETPROGNAME
+static const char *getprogname(void)
+{
+#if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME)
+       return program_invocation_short_name;
+#elif defined(HAVE_GETEXECNAME)
+       return getexecname();
+#else
+       return NULL;
+#endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
+}
+#endif /* HAVE_GETPROGNAME */
+
 static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
 # define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
 
@@ -345,6 +358,7 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
        const char *d;
        unsigned int lvl = 0;
        const char *prefix = "SWRAP";
+       const char *progname = getprogname();
 
        d = getenv("SOCKET_WRAPPER_DEBUGLEVEL");
        if (d != NULL) {
@@ -374,9 +388,17 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl,
                        break;
        }
 
+       if (progname == NULL) {
+               progname = "<unknown>";
+       }
+
        fprintf(stderr,
-               "%s(%d) - %s: %s\n",
-               prefix, (int)getpid(), func, buffer);
+               "%s[%s (%u)] - %s: %s\n",
+               prefix,
+               progname,
+               (unsigned int)getpid(),
+               func,
+               buffer);
 }
 
 /*********************************************************