]> granicus.if.org Git - sysstat/commitdiff
pidstat: Add a replacement function for fork()
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 4 Apr 2020 07:53:23 +0000 (09:53 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 4 Apr 2020 07:53:23 +0000 (09:53 +0200)
The replacement function will be used in a non regression test.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
pidstat.c
systest.c
systest.h

index 33a5fe67a5e2673d92a0ca12db773979512fd363..46b8771a365ad1288444a0a610a7dc7ff41ccb19 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -2473,7 +2473,7 @@ pid_t exec_pgm(int argc, char **argv)
        char *args[argc + 1];
        int i;
 
-       child = fork();
+       child = __fork();
 
        switch(child) {
 
index d43d03c488aaf02a22bd4b21a2804c83cf95fbcc..4cbf25f7719185325e2235e999deb723d45da5ba 100644 (file)
--- a/systest.c
+++ b/systest.c
@@ -337,5 +337,19 @@ struct passwd *get_usrname(uid_t uid)
        return &pwd_ent;
 }
 
+/*
+ ***************************************************************************
+ * Replacement function for fork() system call. Don't fork really but return
+ * a known PID number.
+ *
+ * RETURNS:
+ * Known PID number.
+ ***************************************************************************
+ */
+pid_t get_known_pid(void)
+{
+       return 8741;
+}
+
 #endif /* TEST */
 
index e8aba2ba93b9b8d8c6e6319772d7f434848d22d5..ff74ee073b872e001df402252de5b90cf2cbe5f6 100644 (file)
--- a/systest.h
+++ b/systest.h
@@ -29,6 +29,7 @@
 #define __realpath(m,n)                get_realname(m,n)
 #define __gettimeofday(m,n)    get_day_time(m)
 #define __getpwuid(m)          get_usrname(m)
+#define __fork(m)              get_known_pid(m)
 
 #define ROOTDIR                "./tests/root"
 #define ROOTFILE       "root"
 #define __realpath(m,n)                realpath(m,n)
 #define __gettimeofday(m,n)    gettimeofday(m,n)
 #define __getpwuid(m)          getpwuid(m)
+#define __fork(m)              fork(m)
 
 #endif
 
-
 /*
  ***************************************************************************
  * Functions prototypes
@@ -71,6 +72,8 @@ char *get_env_value
        (const char *);
 int get_fs_stat
        (char *, struct statvfs *);
+pid_t get_known_pid
+       (void);
 char *get_realname
        (char *, char *);
 void get_uname