Commit 31429ebd authored by Shane Snyder's avatar Shane Snyder
Browse files

switch from cuserid to getpwuid for username

parent 5a3d1bdc
...@@ -31,13 +31,6 @@ AC_ARG_ENABLE(ld-preload, ...@@ -31,13 +31,6 @@ AC_ARG_ENABLE(ld-preload,
fi] fi]
,) ,)
AC_ARG_ENABLE(cuserid,
[ --disable-cuserid Disables attempted use of cuserid() at run time],
[if test "x$enableval" = "xno" ; then
AC_DEFINE(__DARSHAN_DISABLE_CUSERID, 1, Define if cuserid() should be disabled)
fi]
,)
AC_ARG_ENABLE(group-readable-logs, AC_ARG_ENABLE(group-readable-logs,
[ --enable-group-readable-logs [ --enable-group-readable-logs
Set log files to be group readable], Set log files to be group readable],
......
...@@ -51,6 +51,9 @@ ...@@ -51,6 +51,9 @@
/* Default runtime compression buffer size */ /* Default runtime compression buffer size */
#define DARSHAN_COMP_BUF_SIZE DARSHAN_MOD_MEM_MAX #define DARSHAN_COMP_BUF_SIZE DARSHAN_MOD_MEM_MAX
/* Maximum length of a username corresponding to a Darshan log */
#define DARSHAN_USERNAME_LEN_MAX 32
/* structure to track registered modules */ /* structure to track registered modules */
struct darshan_core_module struct darshan_core_module
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <pwd.h>
#include <zlib.h> #include <zlib.h>
#include <mpi.h> #include <mpi.h>
#include <assert.h> #include <assert.h>
...@@ -117,7 +118,7 @@ static void darshan_fs_info_from_path( ...@@ -117,7 +118,7 @@ static void darshan_fs_info_from_path(
static int darshan_add_name_record_ref( static int darshan_add_name_record_ref(
struct darshan_core_runtime *core, darshan_record_id rec_id, struct darshan_core_runtime *core, darshan_record_id rec_id,
const char *name, darshan_module_id mod_id); const char *name, darshan_module_id mod_id);
static void darshan_get_user_name( static void darshan_get_username(
char *user); char *user);
static void darshan_get_logfile_name( static void darshan_get_logfile_name(
char* logfile_name, int jobid, struct tm* start_tm); char* logfile_name, int jobid, struct tm* start_tm);
...@@ -785,7 +786,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -785,7 +786,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
int mmap_fd; int mmap_fd;
int mmap_size; int mmap_size;
int sys_page_size; int sys_page_size;
char cuser[L_cuserid] = {0}; char username[DARSHAN_USERNAME_LEN_MAX] = {0};
uint64_t hlevel; uint64_t hlevel;
char hname[HOST_NAME_MAX]; char hname[HOST_NAME_MAX];
uint64_t logmod; uint64_t logmod;
...@@ -807,7 +808,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -807,7 +808,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
else else
mmap_log_path = DARSHAN_DEF_MMAP_LOG_PATH; mmap_log_path = DARSHAN_DEF_MMAP_LOG_PATH;
darshan_get_user_name(cuser); darshan_get_username(username);
/* generate a random number to help differentiate the temporary log */ /* generate a random number to help differentiate the temporary log */
/* NOTE: job id is not sufficient for constructing a unique log file name, /* NOTE: job id is not sufficient for constructing a unique log file name,
...@@ -827,7 +828,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -827,7 +828,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
*/ */
snprintf(core->mmap_log_name, PATH_MAX, snprintf(core->mmap_log_name, PATH_MAX,
"/%s/%s_%s_id%d_mmap-log-%" PRIu64 "-%d.darshan", "/%s/%s_%s_id%d_mmap-log-%" PRIu64 "-%d.darshan",
mmap_log_path, cuser, __progname, jobid, logmod, my_rank); mmap_log_path, username, __progname, jobid, logmod, my_rank);
/* create the temporary mmapped darshan log */ /* create the temporary mmapped darshan log */
mmap_fd = open(core->mmap_log_name, O_CREAT|O_RDWR|O_EXCL , 0644); mmap_fd = open(core->mmap_log_name, O_CREAT|O_RDWR|O_EXCL , 0644);
...@@ -1170,14 +1171,15 @@ static int darshan_add_name_record_ref(struct darshan_core_runtime *core, ...@@ -1170,14 +1171,15 @@ static int darshan_add_name_record_ref(struct darshan_core_runtime *core,
return(1); return(1);
} }
static void darshan_get_user_name(char *cuser) static void darshan_get_username(char *username)
{ {
struct passwd *pwd;
char* logname_string; char* logname_string;
/* get the username for this job. In order we will try each of the /* get the username for this job. In order we will try each of the
* following until one of them succeeds: * following until one of them succeeds:
* *
* - cuserid() * - getpwuid(geteuid())
* - getenv("LOGNAME") * - getenv("LOGNAME")
* - snprintf(..., geteuid()); * - snprintf(..., geteuid());
* *
...@@ -1185,25 +1187,25 @@ static void darshan_get_user_name(char *cuser) ...@@ -1185,25 +1187,25 @@ static void darshan_get_user_name(char *cuser)
* work in statically compiled binaries. * work in statically compiled binaries.
*/ */
#ifndef __DARSHAN_DISABLE_CUSERID pwd = getpwuid(geteuid());
cuserid(cuser); if(pwd)
#endif strncpy(username, pwd->pw_name, (DARSHAN_USERNAME_LEN_MAX-1));
/* if cuserid() didn't work, then check the environment */ /* if getpwuid() didn't work, then check the environment */
if(strcmp(cuser, "") == 0) if(strcmp(username, "") == 0)
{ {
logname_string = getenv("LOGNAME"); logname_string = getenv("LOGNAME");
if(logname_string) if(logname_string)
{ {
strncpy(cuser, logname_string, (L_cuserid-1)); strncpy(username, logname_string, (DARSHAN_USERNAME_LEN_MAX-1));
} }
} }
/* if cuserid() and environment both fail, then fall back to uid */ /* if getpwuid() and environment both fail, then fall back to uid */
if(strcmp(cuser, "") == 0) if(strcmp(username, "") == 0)
{ {
uid_t uid = geteuid(); uid_t uid = geteuid();
snprintf(cuser, L_cuserid, "%u", uid); snprintf(username, DARSHAN_USERNAME_LEN_MAX, "%u", uid);
} }
return; return;
...@@ -1222,7 +1224,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s ...@@ -1222,7 +1224,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
uint64_t hlevel; uint64_t hlevel;
char hname[HOST_NAME_MAX]; char hname[HOST_NAME_MAX];
uint64_t logmod; uint64_t logmod;
char cuser[L_cuserid] = {0}; char username[DARSHAN_USERNAME_LEN_MAX] = {0};
int ret; int ret;
/* first, check if user specifies a complete logpath to use */ /* first, check if user specifies a complete logpath to use */
...@@ -1252,7 +1254,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s ...@@ -1252,7 +1254,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
#endif #endif
} }
darshan_get_user_name(cuser); darshan_get_username(username);
/* generate a random number to help differentiate the log */ /* generate a random number to help differentiate the log */
hlevel=DARSHAN_MPI_CALL(PMPI_Wtime)() * 1000000; hlevel=DARSHAN_MPI_CALL(PMPI_Wtime)() * 1000000;
...@@ -1292,7 +1294,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s ...@@ -1292,7 +1294,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
ret = snprintf(logfile_name, PATH_MAX, ret = snprintf(logfile_name, PATH_MAX,
"%s/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial", "%s/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial",
logpath_override, logpath_override,
cuser, __progname, jobid, username, __progname, jobid,
(start_tm->tm_mon+1), (start_tm->tm_mon+1),
start_tm->tm_mday, start_tm->tm_mday,
(start_tm->tm_hour*60*60 + start_tm->tm_min*60 + start_tm->tm_sec), (start_tm->tm_hour*60*60 + start_tm->tm_min*60 + start_tm->tm_sec),
...@@ -1311,7 +1313,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s ...@@ -1311,7 +1313,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
"%s/%d/%d/%d/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial", "%s/%d/%d/%d/%s_%s_id%d_%d-%d-%d-%" PRIu64 ".darshan_partial",
logpath, (start_tm->tm_year+1900), logpath, (start_tm->tm_year+1900),
(start_tm->tm_mon+1), start_tm->tm_mday, (start_tm->tm_mon+1), start_tm->tm_mday,
cuser, __progname, jobid, username, __progname, jobid,
(start_tm->tm_mon+1), (start_tm->tm_mon+1),
start_tm->tm_mday, start_tm->tm_mday,
(start_tm->tm_hour*60*60 + start_tm->tm_min*60 + start_tm->tm_sec), (start_tm->tm_hour*60*60 + start_tm->tm_min*60 + start_tm->tm_sec),
......
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