From 3764ec0e1ee9a28591b7d42fce14645bf2769a3a Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 14 Jan 2009 12:03:03 -0800 Subject: [PATCH] Fixed sizeof() issue and minor cleanup --- lib/libspl/getexecname.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/libspl/getexecname.c b/lib/libspl/getexecname.c index f240193117..43bf39ae33 100644 --- a/lib/libspl/getexecname.c +++ b/lib/libspl/getexecname.c @@ -33,22 +33,23 @@ const char * getexecname(void) { - static char execname[PATH_MAX + 1]; - /* Must be MT-safe */ + static char execname[PATH_MAX + 1] = ""; static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; + char *ptr = NULL; + ssize_t rc; pthread_mutex_lock(&mtx); if (strlen(execname) == 0) { - ssize_t rc = readlink("/proc/self/exe", execname, sizeof(execname - 1)); + rc = readlink("/proc/self/exe", execname, sizeof(execname) - 1); if (rc == -1) { execname[0] = '\0'; - pthread_mutex_unlock(&mtx); - return NULL; - } else + } else { execname[rc] = '\0'; + ptr = execname; + } } - pthread_mutex_unlock(&mtx); - return execname; + pthread_mutex_unlock(&mtx); + return ptr; }