Skip to content

Commit 9d1be31

Browse files
ifranzkijschmidb
authored andcommitted
icastats: Ignore unknown user in summary and all report
If icastats is used with option '--summary' and it encounters a statistics shared memory segment for a user that no longer exists, it fails with 'get_stats_sum: : Success'. This is because getpwuid() fails, but does not set errno, so that perror prints 'Success'. Instead of failing, just ignore such shared memory segments for users that do no longer exist. A similar problem exists with option '--all', it stops iterating over the statistics shared memory segments if it finds one for a non existing user. Continue the loop to return statistics for additional users. Also fix a problem when stats_mmap() fails in the loop to close the directory file descriptor before returning NULL. Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1 parent 75153fa commit 9d1be31

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/icastats_shared.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,8 @@ int get_stats_sum(stats_entry_t *sum)
263263
int fd;
264264
stats_entry_t *tmp;
265265

266-
if ((getpwuid(atoi(&direntp->d_name[9]))) == NULL) {
267-
closedir(shmDir);
268-
return 0;
269-
}
266+
if ((getpwuid(atoi(&direntp->d_name[9]))) == NULL)
267+
continue;
270268

271269
if ((fd = shm_open(direntp->d_name, O_RDONLY, 0)) == -1) {
272270
closedir(shmDir);
@@ -324,9 +322,9 @@ char *get_next_usr()
324322
int uid = atoi(&direntp->d_name[9]);
325323
struct passwd *pwd;
326324
if ((pwd = getpwuid(uid)) == NULL)
327-
return NULL;
325+
continue;
328326
if (stats_mmap(uid) == -1)
329-
return NULL;
327+
break;
330328

331329
return pwd->pw_name;
332330
} else {

0 commit comments

Comments
 (0)