* Prevent a segmentation fault if $LOGNAME is not set during startup.
This commit is contained in:
parent
4378b09557
commit
f1ee94f927
12
minidlna.c
12
minidlna.c
@ -25,6 +25,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
/* unix sockets */
|
/* unix sockets */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -183,7 +184,16 @@ getfriendlyname(char * buf, int len)
|
|||||||
#ifdef READYNAS
|
#ifdef READYNAS
|
||||||
strncat(buf, "ReadyNAS", len-strlen(buf)-1);
|
strncat(buf, "ReadyNAS", len-strlen(buf)-1);
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user