aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ConfigureChecks.cmake9
-rw-r--r--config.h.cmake6
-rw-r--r--src/socket_wrapper.c26
3 files changed, 39 insertions, 2 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 94fed22..6cedb90 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -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)
diff --git a/config.h.cmake b/config.h.cmake
index 5baa789..0207031 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -31,6 +31,10 @@
#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
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 165922b..2b77ceb 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -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);
}
/*********************************************************