Fixed sizeof() issue and minor cleanup
This commit is contained in:
parent
401aac51fb
commit
3764ec0e1e
|
@ -33,22 +33,23 @@
|
||||||
const char *
|
const char *
|
||||||
getexecname(void)
|
getexecname(void)
|
||||||
{
|
{
|
||||||
static char execname[PATH_MAX + 1];
|
static char execname[PATH_MAX + 1] = "";
|
||||||
/* Must be MT-safe */
|
|
||||||
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
char *ptr = NULL;
|
||||||
|
ssize_t rc;
|
||||||
|
|
||||||
pthread_mutex_lock(&mtx);
|
pthread_mutex_lock(&mtx);
|
||||||
|
|
||||||
if (strlen(execname) == 0) {
|
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) {
|
if (rc == -1) {
|
||||||
execname[0] = '\0';
|
execname[0] = '\0';
|
||||||
pthread_mutex_unlock(&mtx);
|
} else {
|
||||||
return NULL;
|
|
||||||
} else
|
|
||||||
execname[rc] = '\0';
|
execname[rc] = '\0';
|
||||||
|
ptr = execname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mtx);
|
|
||||||
|
|
||||||
return execname;
|
pthread_mutex_unlock(&mtx);
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue