[PATCH v7 04/14] tests/waitid: Correctly use the long types from the rusage struct

Dmitry V. Levin ldv at altlinux.org
Sun Apr 19 22:04:01 UTC 2020


On Fri, Apr 17, 2020 at 09:47:14AM -0700, Alistair Francis wrote:
> The kernel's rusage struct uses the kernel's __kernel_old_timeval which
> means that even for 32-bit archs with 64-bit time_t (like RV32) the time
> values are 32-bit.
> 
> We can fix this by making sure we don't use libc's rusage struct and
> instead use our own with the kernel's old timeval.
> 
> Signed-off-by: Alistair Francis <alistair.francis at wdc.com>
> ---
>  configure.ac   |  17 --------
>  tests/waitid.c | 108 +++++++++----------------------------------------
>  2 files changed, 18 insertions(+), 107 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 7c4f9292..24a0f2ba 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -625,23 +625,6 @@ AC_CHECK_HEADERS([linux/btrfs.h], [
>  
>  st_CHECK_TYPES
>  
> -AC_CHECK_MEMBERS(m4_normalize([
> -	struct rusage.__ru_maxrss_word,
> -	struct rusage.__ru_ixrss_word,
> -	struct rusage.__ru_idrss_word,
> -	struct rusage.__ru_isrss_word,
> -	struct rusage.__ru_minflt_word,
> -	struct rusage.__ru_majflt_word,
> -	struct rusage.__ru_nswap_word,
> -	struct rusage.__ru_inblock_word,
> -	struct rusage.__ru_oublock_word,
> -	struct rusage.__ru_msgsnd_word,
> -	struct rusage.__ru_msgrcv_word,
> -	struct rusage.__ru_nsignals_word,
> -	struct rusage.__ru_nvcsw_word,
> -	struct rusage.__ru_nivcsw_word
> -]),,, [#include <sys/resource.h>])
> -
>  AC_CHECK_DECLS([sys_errlist])
>  AC_CHECK_DECLS(m4_normalize([
>  	PTRACE_PEEKUSER,
> diff --git a/tests/waitid.c b/tests/waitid.c
> index f6738e18..98fef531 100644
> --- a/tests/waitid.c
> +++ b/tests/waitid.c
> @@ -15,83 +15,11 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <sys/wait.h>
> -#include <sys/resource.h>
>  #include "scno.h"
> -
> -/* Workaround for glibc/kernel interface discrepancy */
> -#ifdef HAVE_STRUCT_RUSAGE___RU_MAXRSS_WORD
> -# define RU_MAXRSS __ru_maxrss_word
> -#else
> -# define RU_MAXRSS ru_maxrss
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_IXRSS_WORD
> -# define RU_IXRSS __ru_ixrss_word
> -#else
> -# define RU_IXRSS ru_ixrss
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_IDRSS_WORD
> -# define RU_IDRSS __ru_idrss_word
> -#else
> -# define RU_IDRSS ru_idrss
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_ISRSS_WORD
> -# define RU_ISRSS __ru_isrss_word
> -#else
> -# define RU_ISRSS ru_isrss
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_MINFLT_WORD
> -# define RU_MINFLT __ru_minflt_word
> -#else
> -# define RU_MINFLT ru_minflt
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_MAJFLT_WORD
> -# define RU_MAJFLT __ru_majflt_word
> -#else
> -# define RU_MAJFLT ru_majflt
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_NSWAP_WORD
> -# define RU_NSWAP __ru_nswap_word
> -#else
> -# define RU_NSWAP ru_nswap
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_INBLOCK_WORD
> -# define RU_INBLOCK __ru_inblock_word
> -#else
> -# define RU_INBLOCK ru_inblock
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_OUBLOCK_WORD
> -# define RU_OUBLOCK __ru_oublock_word
> -#else
> -# define RU_OUBLOCK ru_oublock
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_MSGSND_WORD
> -# define RU_MSGSND __ru_msgsnd_word
> -#else
> -# define RU_MSGSND ru_msgsnd
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_MSGRCV_WORD
> -# define RU_MSGRCV __ru_msgrcv_word
> -#else
> -# define RU_MSGRCV ru_msgrcv
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_NSIGNALS_WORD
> -# define RU_NSIGNALS __ru_nsignals_word
> -#else
> -# define RU_NSIGNALS ru_nsignals
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_NVCSW_WORD
> -# define RU_NVCSW __ru_nvcsw_word
> -#else
> -# define RU_NVCSW ru_nvcsw
> -#endif
> -#ifdef HAVE_STRUCT_RUSAGE___RU_NIVCSW_WORD
> -# define RU_NIVCSW __ru_nivcsw_word
> -#else
> -# define RU_NIVCSW ru_nivcsw
> -#endif
> +#include "kernel_rusage.h"
>  
>  static const char *
> -sprint_rusage(const struct rusage *const ru)
> +sprint_rusage(const kernel_rusage_t *const ru)
>  {
>  	static char buf[1024];
>  	snprintf(buf, sizeof(buf),
> @@ -120,20 +48,20 @@ sprint_rusage(const struct rusage *const ru)
>  		 , (long long) ru->ru_stime.tv_sec
>  		 , zero_extend_signed_to_ull(ru->ru_stime.tv_usec)
>  #if VERBOSE
> -		 , zero_extend_signed_to_ull(ru->RU_MAXRSS)
> -		 , zero_extend_signed_to_ull(ru->RU_IXRSS)
> -		 , zero_extend_signed_to_ull(ru->RU_IDRSS)
> -		 , zero_extend_signed_to_ull(ru->RU_ISRSS)
> -		 , zero_extend_signed_to_ull(ru->RU_MINFLT)
> -		 , zero_extend_signed_to_ull(ru->RU_MAJFLT)
> -		 , zero_extend_signed_to_ull(ru->RU_NSWAP)
> -		 , zero_extend_signed_to_ull(ru->RU_INBLOCK)
> -		 , zero_extend_signed_to_ull(ru->RU_OUBLOCK)
> -		 , zero_extend_signed_to_ull(ru->RU_MSGSND)
> -		 , zero_extend_signed_to_ull(ru->RU_MSGRCV)
> -		 , zero_extend_signed_to_ull(ru->RU_NSIGNALS)
> -		 , zero_extend_signed_to_ull(ru->RU_NVCSW)
> -		 , zero_extend_signed_to_ull(ru->RU_NIVCSW)
> +		 , zero_extend_signed_to_ull(ru->ru_maxrss)
> +		 , zero_extend_signed_to_ull(ru->ru_ixrss)
> +		 , zero_extend_signed_to_ull(ru->ru_idrss)
> +		 , zero_extend_signed_to_ull(ru->ru_isrss)
> +		 , zero_extend_signed_to_ull(ru->ru_minflt)
> +		 , zero_extend_signed_to_ull(ru->ru_majflt)
> +		 , zero_extend_signed_to_ull(ru->ru_nswap)
> +		 , zero_extend_signed_to_ull(ru->ru_inblock)
> +		 , zero_extend_signed_to_ull(ru->ru_oublock)
> +		 , zero_extend_signed_to_ull(ru->ru_msgsnd)
> +		 , zero_extend_signed_to_ull(ru->ru_msgrcv)
> +		 , zero_extend_signed_to_ull(ru->ru_nsignals)
> +		 , zero_extend_signed_to_ull(ru->ru_nvcsw)
> +		 , zero_extend_signed_to_ull(ru->ru_nivcsw)
>  #endif
>  		 );
>  	return buf;
> @@ -200,7 +128,7 @@ do_waitid(const unsigned int idtype,
>  	  const unsigned int id,
>  	  const siginfo_t *const infop,
>  	  const unsigned int options,
> -	  const struct rusage *const rusage)
> +	  const kernel_rusage_t *const rusage)
>  {
>  	sigset_t mask = {};
>  	sigaddset(&mask, SIGCHLD);
> @@ -241,7 +169,7 @@ main(void)
>  
>  	TAIL_ALLOC_OBJECT_CONST_PTR(siginfo_t, sinfo);
>  	memset(sinfo, 0, sizeof(*sinfo));
> -	TAIL_ALLOC_OBJECT_CONST_PTR(struct rusage, rusage);
> +	TAIL_ALLOC_OBJECT_CONST_PTR(kernel_rusage_t, rusage);
>  	if (do_waitid(P_PID, pid, sinfo, WNOHANG|WEXITED|WSTOPPED, rusage))
>  		perror_msg_and_fail("waitid #2");
>  	tprintf("waitid(P_PID, %d, {}, WNOHANG|WEXITED|WSTOPPED, %s) = 0\n",

Applied with almost no changes, thanks.


-- 
ldv


More information about the Strace-devel mailing list