This replacement function will be used in tests environment.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
}
if (USER_STRING(pidflag)) {
- if ((pwdent = getpwuid((*pstc)->uid)) != NULL) {
+ if ((pwdent = __getpwuid((*pstc)->uid)) != NULL) {
if (strcmp(pwdent->pw_name, userstr))
/* This PID doesn't belong to user */
return -1;
char format[32];
struct passwd *pwdent;
- if (DISPLAY_USERNAME(pidflag) && ((pwdent = getpwuid(pst->uid)) != NULL)) {
+ if (DISPLAY_USERNAME(pidflag) && ((pwdent = __getpwuid(pst->uid)) != NULL)) {
cprintf_in(IS_STR, " %8s", pwdent->pw_name, 0);
}
else {
#include <time.h>
#include <unistd.h>
#include <dirent.h>
+#include <pwd.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/statvfs.h>
#include <sys/time.h>
+#include <sys/types.h>
#include "systest.h"
return resolved_name;
}
+/*
+ ***************************************************************************
+ * Replacement function for getpwuid() system call. Fill a dummy passwd
+ * structure containing the name of a user.
+ *
+ * IN:
+ * @uid UID of the user
+ *
+ * RETURNS:
+ * Pointer on the passwd structure.
+ ***************************************************************************
+ */
+struct passwd *get_usrname(uid_t uid)
+{
+ static struct passwd pwd_ent;
+ static char pw_name[16];
+
+ pwd_ent.pw_name = pw_name;
+ if (!uid) {
+ strcpy(pwd_ent.pw_name, "root");
+ }
+ else {
+ strcpy(pwd_ent.pw_name, "testusr");
+ }
+
+ return &pwd_ent;
+}
+
#endif /* TEST */
#define __closedir(m) close_list(m)
#define __realpath(m,n) get_realname(m,n)
#define __gettimeofday(m,n) get_day_time(m)
+#define __getpwuid(m) get_usrname(m)
#define ROOTDIR "./tests/root"
#define ROOTFILE "root"
#define __closedir(m) closedir(m)
#define __realpath(m,n) realpath(m,n)
#define __gettimeofday(m,n) gettimeofday(m,n)
+#define __getpwuid(m) getpwuid(m)
#endif
(struct utsname *);
void get_unix_time
(time_t *);
+struct passwd *get_usrname
+ (uid_t);
void next_time_step
(void);
DIR *open_list