* Prevent a segmentation fault if $LOGNAME is not set during startup.

This commit is contained in:
Justin Maggard 2009-07-09 22:59:13 +00:00
parent 4378b09557
commit f1ee94f927

View File

@ -25,6 +25,7 @@
#include <sys/param.h>
#include <errno.h>
#include <pthread.h>
#include <pwd.h>
/* unix sockets */
#include "config.h"
@ -183,7 +184,16 @@ getfriendlyname(char * buf, int len)
#ifdef READYNAS
strncat(buf, "ReadyNAS", len-strlen(buf)-1);
#else
strncat(buf, getenv("LOGNAME"), len-strlen(buf)-1);
char * logname;
logname = getenv("LOGNAME");
if( !logname )
{
struct passwd * pwent;
pwent = getpwuid(getuid());
if( pwent )
logname = pwent->pw_name;
}
strncat(buf, logname?logname:"Unknown", len-strlen(buf)-1);
#endif
}