diff --git a/doc/html/team.shtml b/doc/html/team.shtml index 9c1d16466856603915a7acb3027b8b5ceb75cbd9..ccc5edc89847fd64f6e152774ad34244d6310318 100644 --- a/doc/html/team.shtml +++ b/doc/html/team.shtml @@ -88,6 +88,7 @@ Lead Slurm developers are: <li>Andriy Grytsenko (Massive Solutions Limited, Ukraine)</li> <li>Michael Gutteridge (Fred Hutchinson Cancer Research Center)</li> <br> +<li>Anders Halager (Aarhus University, Denmark)</li> <li>Chris Harwell (D. E. Shaw Research)</li> <li>Takao Hatazaki (HP)</li> <li>Matthieu Hautreux (CEA, France)</li> @@ -200,6 +201,6 @@ Lead Slurm developers are: <!-- INDIVIDUALS, PLEASE KEEP IN ALPHABETICAL ORDER --> </ul> -<p style="text-align:center;">Last modified 25 April 2014</p> +<p style="text-align:center;">Last modified 30 June 2014</p> <!--#include virtual="footer.txt"--> diff --git a/src/common/uid.c b/src/common/uid.c index 28d73e68d40151eb2ff404104f0fe1ea3ed1bb2e..4e1ed73035d910933722750661d7f1b89a6127b1 100644 --- a/src/common/uid.c +++ b/src/common/uid.c @@ -49,6 +49,14 @@ #include "src/common/xmalloc.h" #include "src/common/xstring.h" +typedef struct { + uid_t uid; + char *username; +} uid_cache_entry_t; + +static uid_cache_entry_t *uid_cache; +static int uid_cache_used = 0; + static int _getpwnam_r (const char *name, struct passwd *pwd, char *buf, size_t bufsiz, struct passwd **result) { @@ -139,6 +147,33 @@ uid_to_string (uid_t uid) return ustring; } + +static int _uid_compare(const void *a, const void *b) +{ + uid_t ua = *(const uid_t *)a; + uid_t ub = *(const uid_t *)b; + return ua - ub; +} + +extern char *uid_to_string_cached(uid_t uid) +{ + uid_cache_entry_t target = {uid, NULL}; + uid_cache_entry_t *entry = bsearch(&target, uid_cache, uid_cache_used, + sizeof(uid_cache_entry_t), + _uid_compare); + if (entry == NULL) { + uid_cache_entry_t new_entry = {uid, uid_to_string(uid)}; + uid_cache_used++; + uid_cache = realloc(uid_cache, + sizeof(uid_cache_entry_t) * uid_cache_used); + uid_cache[uid_cache_used-1] = new_entry; + qsort(uid_cache, uid_cache_used, sizeof(uid_cache_entry_t), + _uid_compare); + return new_entry.username; + } + return entry->username; +} + gid_t gid_from_uid (uid_t uid) { diff --git a/src/common/uid.h b/src/common/uid.h index 6c4e742ea4f922a8bc02bb0290a8c9a3004f3d1c..45c09e8dcd13406449e086acd0049a3334b6fff2 100644 --- a/src/common/uid.h +++ b/src/common/uid.h @@ -84,6 +84,11 @@ int gid_from_string (char *name, gid_t *gidp); */ char *uid_to_string (uid_t uid); +/* + * Translate uid to user name, using a cache. + */ +extern char *uid_to_string_cached(uid_t uid); + /* * Same as uid_to_string, but for group name. * NOTE: xfree the return value diff --git a/src/squeue/print.c b/src/squeue/print.c index 71e25ec6a32291116687bc3471f6601a792b3a18..47bfa700b5278a50108c06ce944da1e4197fe5d8 100644 --- a/src/squeue/print.c +++ b/src/squeue/print.c @@ -544,9 +544,8 @@ int _print_job_user_name(job_info_t * job, int width, bool right, char* suffix) if (job == NULL) /* Print the Header instead */ _print_str("USER", width, right, true); else { - char *uname = uid_to_string((uid_t) job->user_id); + char *uname = uid_to_string_cached((uid_t) job->user_id); _print_str(uname, width, right, true); - xfree(uname); } if (suffix) printf("%s", suffix); @@ -1476,7 +1475,6 @@ int _print_step_user_name(job_step_info_t * step, int width, bool right, else { char *uname = uid_to_string((uid_t) step->user_id); _print_str(uname, width, right, true); - xfree(uname); } if (suffix) printf("%s", suffix); diff --git a/src/squeue/sort.c b/src/squeue/sort.c index 31f511866e31ab7e79b55a753a8d9dd2a84becb1..49eaa225223cc89cb987aa08985c627a20307535 100644 --- a/src/squeue/sort.c +++ b/src/squeue/sort.c @@ -758,11 +758,9 @@ static int _sort_job_by_user_name(void *void1, void *void2) _get_job_info_from_void(&job1, &job2, void1, void2); - name1 = uid_to_string((uid_t) job1->user_id); - name2 = uid_to_string((uid_t) job2->user_id); + name1 = uid_to_string_cached((uid_t) job1->user_id); + name2 = uid_to_string_cached((uid_t) job2->user_id); diff = strcmp(name1, name2); - xfree(name1); - xfree(name2); if (reverse_order) diff = -diff; @@ -979,11 +977,9 @@ static int _sort_step_by_user_name(void *void1, void *void2) _get_step_info_from_void(&step1, &step2, void1, void2); - name1 = uid_to_string((uid_t) step1->user_id); - name2 = uid_to_string((uid_t) step2->user_id); + name1 = uid_to_string_cached((uid_t) step1->user_id); + name2 = uid_to_string_cached((uid_t) step2->user_id); diff = strcmp(name1, name2); - xfree(name1); - xfree(name2); if (reverse_order) diff = -diff;