Commit 7a01614c authored by Philip Carns's avatar Philip Carns

add getenv(LOGNAME) fallback for finding user name


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@545 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 2b2d1afa
......@@ -437,12 +437,34 @@ void darshan_shutdown(int timing_flag)
start_time_tmp += final_job->log_job.start_time;
my_tm = localtime(&start_time_tmp);
/* note: getpwuid() causes link errors for static binaries */
/* get the username for this job. In order we will try each of the
* following until one of them succeeds:
*
* - cuserid()
* - getenv("LOGNAME")
* - snprintf(..., geteuid());
*
* Note that we do not use getpwuid() because it generally will not
* work in statically compiled binaries.
*/
cuserid(cuser);
/* if cuserid() didn't work, then check the environment */
if (strcmp(cuser, "") == 0)
{
char* logname_string;
logname_string = getenv("LOGNAME");
if(logname_string)
{
strncpy(cuser, logname_string, (L_cuserid-1));
}
}
/* if cuserid() and environment both fail, then fall back to uid */
if (strcmp(cuser, "") == 0)
{
/* if node config is wrong, cuserid can return an empty string
this is backup in case that happens. */
uid_t uid = geteuid();
snprintf(cuser, sizeof(cuser), "%u", uid);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment