From 7d961f9746eccf7ec6268eb12af31fd1ea2db189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 9 Jun 2021 16:03:19 +0200 Subject: [PATCH] sys/resource.h: add rusage compatibility fields, set to zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit POSIX defines this structure but specifies only two fields (which we already implement). However, both the *BSD and Linux have agreed on some more fields, which are often assumed to be there by applications. The benefice of having compatibility fields is greater as having to patch every other software at HaikuPorts. Change-Id: Ie28ca2e348aa16b4c57eb3498eb62175100d9b9d Reviewed-on: https://review.haiku-os.org/c/haiku/+/4083 Tested-by: Commit checker robot Reviewed-by: Niels Sascha Reedijk Reviewed-by: Jérôme Duval --- headers/posix/sys/resource.h | 16 +++++++++ src/libs/bsd/Jamfile | 3 ++ src/libs/bsd/libbsd_versions | 5 +++ src/libs/bsd/wait.c | 46 +++++++++++++++++++++--- src/system/libroot/libroot_versions | 3 ++ src/system/libroot/posix/sys/getrusage.c | 24 ++++++++++++- 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/libs/bsd/libbsd_versions diff --git a/headers/posix/sys/resource.h b/headers/posix/sys/resource.h index c27cfda0d9..95de2b7ae4 100644 --- a/headers/posix/sys/resource.h +++ b/headers/posix/sys/resource.h @@ -44,6 +44,22 @@ struct rlimit { struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ + + /* unused, only for compatibility with other systems */ + long ru_maxrss; + long ru_ixrss; + long ru_idrss; + long ru_isrss; + long ru_minflt; + long ru_majflt; + long ru_nswap; + long ru_inblock; + long ru_oublock; + long ru_msgsnd; + long ru_msgrcv; + long ru_nsignals; + long ru_nvcsw; + long ru_nivcsw; }; #define RUSAGE_SELF 0 diff --git a/src/libs/bsd/Jamfile b/src/libs/bsd/Jamfile index 3ec438e8c7..0b3c70d046 100644 --- a/src/libs/bsd/Jamfile +++ b/src/libs/bsd/Jamfile @@ -5,6 +5,9 @@ UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ; local architectureObject ; for architectureObject in [ MultiArchSubDirSetup ] { on $(architectureObject) { + SetVersionScript [ MultiArchDefaultGristFiles libbsd.so ] : + libbsd_versions ; + SharedLibrary [ MultiArchDefaultGristFiles libbsd.so ] : daemon.c err.c diff --git a/src/libs/bsd/libbsd_versions b/src/libs/bsd/libbsd_versions new file mode 100644 index 0000000000..dd0872b33b --- /dev/null +++ b/src/libs/bsd/libbsd_versions @@ -0,0 +1,5 @@ +LIBBSD_BASE { +}; + +LIBBSD_1_BETA3 { +} LIBBSD_BASE; diff --git a/src/libs/bsd/wait.c b/src/libs/bsd/wait.c index 57fc328992..15f0181de3 100644 --- a/src/libs/bsd/wait.c +++ b/src/libs/bsd/wait.c @@ -15,16 +15,23 @@ extern pid_t _waitpid(pid_t pid, int* _status, int options, team_usage_info *usage_info); +// prototypes for the compiler +pid_t _wait3_base(int *status, int options, struct rusage *rusage); +pid_t _wait4_base(pid_t pid, int *status, int options, struct rusage *rusage); +pid_t _wait3_current(int *status, int options, struct rusage *rusage); +pid_t _wait4_current(pid_t pid, int *status, int options, + struct rusage *rusage); + pid_t -wait3(int *status, int options, struct rusage *rusage) +_wait3_base(int *status, int options, struct rusage *rusage) { - return wait4(-1, status, options, rusage); + return _wait4_base(-1, status, options, rusage); } pid_t -wait4(pid_t pid, int *status, int options, struct rusage *rusage) +_wait4_base(pid_t pid, int *status, int options, struct rusage *rusage) { team_usage_info info; pid_t waitPid = _waitpid(pid, status, options, @@ -34,9 +41,38 @@ wait4(pid_t pid, int *status, int options, struct rusage *rusage) rusage->ru_utime.tv_usec = info.user_time % 1000000; rusage->ru_stime.tv_sec = info.kernel_time / 1000000; - rusage->ru_stime.tv_usec = info.kernel_time % 1000000; + rusage->ru_stime.tv_usec = info.kernel_time % 1000000; } - + return waitPid; } + +pid_t +_wait3_current(int *status, int options, struct rusage *rusage) +{ + return _wait4_current(-1, status, options, rusage); +} + + +pid_t +_wait4_current(pid_t pid, int *status, int options, struct rusage *rusage) +{ + pid_t waitPid = _wait4_base(pid, status, options, rusage); + if (waitPid != -1 && rusage != NULL) { + memset(&rusage->ru_maxrss, 0, sizeof(struct rusage) - + offsetof(struct rusage, ru_maxrss)); + } + + return waitPid; +} + + +#define DEFINE_LIBBSD_SYMBOL_VERSION(function, symbol, version) \ + B_DEFINE_SYMBOL_VERSION(function, symbol "LIBBSD_" version) + +DEFINE_LIBBSD_SYMBOL_VERSION("_wait3_base", "wait3@", "BASE"); +DEFINE_LIBBSD_SYMBOL_VERSION("_wait4_base", "wait4@", "BASE"); +DEFINE_LIBBSD_SYMBOL_VERSION("_wait3_current", "wait3@@", "1_BETA3"); +DEFINE_LIBBSD_SYMBOL_VERSION("_wait4_current", "wait4@@", "1_BETA3"); + diff --git a/src/system/libroot/libroot_versions b/src/system/libroot/libroot_versions index 4d8340247e..4478f27143 100644 --- a/src/system/libroot/libroot_versions +++ b/src/system/libroot/libroot_versions @@ -9,3 +9,6 @@ LIBROOT_1_ALPHA4 { LIBROOT_1_ALPHA5 { } LIBROOT_1_ALPHA4; + +LIBROOT_1_BETA3 { +} LIBROOT_1_ALPHA5; diff --git a/src/system/libroot/posix/sys/getrusage.c b/src/system/libroot/posix/sys/getrusage.c index df56ece99a..1d8b4e0d51 100644 --- a/src/system/libroot/posix/sys/getrusage.c +++ b/src/system/libroot/posix/sys/getrusage.c @@ -9,10 +9,16 @@ #include #include +#include + + +// prototypes for the compiler +int _getrusage_base(int who, struct rusage *rusage); +int _getrusage_current(int who, struct rusage *rusage); int -getrusage(int who, struct rusage *rusage) +_getrusage_base(int who, struct rusage *rusage) { team_usage_info info; @@ -30,3 +36,19 @@ getrusage(int who, struct rusage *rusage) return 0; } + +int +_getrusage_current(int who, struct rusage *rusage) +{ + int err = _getrusage_base(who, rusage); + if (err != -1) { + memset(&rusage->ru_maxrss, 0, sizeof(struct rusage) - + offsetof(struct rusage, ru_maxrss)); + } + return err; +} + + +DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("_getrusage_base", "getrusage@", "BASE"); +DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("_getrusage_current", "getrusage@@", + "1_BETA3");