Skip to content

Commit

Permalink
Add build time check and a shim for __rlimit_resource_t
Browse files Browse the repository at this point in the history
Use the __rlimit_resource_t type (which may be an int or an emum)
to clean up enum conversion warnings with icc.

Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Apr 7, 2022
1 parent 7a1b210 commit 96afb8b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
20 changes: 12 additions & 8 deletions Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -872,14 +872,15 @@ types: \
COMPLEX DATTR_T DVD_AUTHINFO DVD_STRUCT FLOAT_DECIMAL32 FLOAT_DECIMAL64 \
FLOAT_DECIMAL128 FLOAT16 FLOAT32 FLOAT64 FLOAT80 FLOAT128 INO64_T \
INT128_T KERNEL_LONG_T KERNEL_ULONG_T LANDLOCK_RULE_TYPE LOFF_T \
MODE_T OFF_T OFF64_T PTHREAD_MUTEXATTR_T CDROM_BLK CDROM_MCN CDROM_MSF \
CDROM_READ_AUDIO CDROM_SUBCHNL CDROM_TI CDROM_TOCENTRY CDROM_TOCHDR \
CDROM_VOLCTRL CONSOLEFONTDESC DM_IOCTL FLOPPY_FDC_STATE FLOPPY_DRIVE_STRUCT \
FLOPPY_STRUCT FSVERITY_DIGEST FSVERITY_ENABLE_ARG FSXATTR_STRUCT IFCONF \
ICMPHDR KBDIACRS KBENTRY KBKEYCODE KBSENTRY LANDLOCK_RULESET_ATTR \
MEDIA_DEVICE_INFO MSGINFO MTRR_GENTRY MTRR_SENTRY OPEN_HOW RTC_PARAM \
RUSAGE_RU_MINFLT RUSAGE_RU_NVCSW SECCOMP_NOTIF_SIZES SERIAL_ICOUNTER \
SERIAL_STRUCT SHMID_DS SHMINFO SND_CTL_CARD_INFO SND_CTL_TLV SOCKADDR_UN \
MODE_T OFF_T OFF64_T PTHREAD_MUTEXATTR_T RLIMIT_RESOURCE_T \
CDROM_BLK CDROM_MCN CDROM_MSF CDROM_READ_AUDIO CDROM_SUBCHNL CDROM_TI \
CDROM_TOCENTRY CDROM_TOCHDR CDROM_VOLCTRL CONSOLEFONTDESC DM_IOCTL \
FLOPPY_FDC_STATE FLOPPY_DRIVE_STRUCT FLOPPY_STRUCT FSVERITY_DIGEST \
FSVERITY_ENABLE_ARG FSXATTR_STRUCT IFCONF ICMPHDR KBDIACRS KBENTRY \
KBKEYCODE KBSENTRY LANDLOCK_RULESET_ATTR MEDIA_DEVICE_INFO MSGINFO \
MTRR_GENTRY MTRR_SENTRY OPEN_HOW RTC_PARAM RUSAGE_RU_MINFLT \
RUSAGE_RU_NVCSW SECCOMP_NOTIF_SIZES SERIAL_ICOUNTER SERIAL_STRUCT \
SHMID_DS SHMINFO SND_CTL_CARD_INFO SND_CTL_TLV SOCKADDR_UN \
TERMIOS UNIMAPDESC USBDEVFS_GETDRIVER USER_DESC VT_CONSIZE VT_MODE \
VT_SIZES VT_STAT V4L2_AUDIO V4L2_AUDIOOUT V4L2_CAPABILITY V4L2_DV_TIMINGS \
V4L2_ENC_IDX V4L2_FRAMEBUFFER V4L2_JPEGCOMPRESSION V4L2_STD_ID V2DI \
Expand Down Expand Up @@ -951,6 +952,9 @@ OFF64_T:
PTHREAD_MUTEXATTR_T:
$(call check,test-pthread-mutexattr_t,HAVE_PTHREAD_MUTEXATTR_T,pthread_mutexattr_t)

RLIMIT_RESOURCE_T:
$(call check,test-rlimit_resource_t,HAVE_RLIMIT_RESOURCE_T,__rlimit_resource_t)

CDROM_BLK:
$(call check,test-cdrom_blk,HAVE_CDROM_BLK,struct cdrom_blk)

Expand Down
2 changes: 1 addition & 1 deletion core-limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
#include "stress-ng.h"

static const int limits[] = {
static const shim_rlimit_resource_t limits[] = {
#if defined(RLIMIT_AS)
RLIMIT_AS,
#endif
Expand Down
8 changes: 4 additions & 4 deletions stress-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static const stress_rusage_t rusages[] = {
#undef RLIMIT_FSIZE
#endif

static const int rlimits[] = {
static const shim_rlimit_resource_t rlimits[] = {
#if defined(RLIMIT_AS)
RLIMIT_AS,
#endif
Expand Down Expand Up @@ -426,7 +426,7 @@ static int stress_get(const stress_args_t *args)
UNEXPECTED
#endif
/* Invalid getrlimit syscall and ignoring failure */
(void)getrlimit(INT_MAX, &rlim);
(void)getrlimit((shim_rlimit_resource_t)INT_MAX, &rlim);

for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) {
ret = getrlimit(rlimits[i], &rlim);
Expand Down Expand Up @@ -457,9 +457,9 @@ static int stress_get(const stress_args_t *args)
NEED_GLIBC(2,13,0) && \
defined(EOVERFLOW)
/* Invalid prlimit syscall and ignoring failure */
(void)prlimit(mypid, INT_MAX, NULL, &rlim);
(void)prlimit(mypid, (shim_rlimit_resource_t)INT_MAX, NULL, &rlim);
pid = stress_get_unused_pid_racy(false);
(void)prlimit(pid, INT_MAX, NULL, &rlim);
(void)prlimit(pid, (shim_rlimit_resource_t)INT_MAX, NULL, &rlim);

for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) {
struct rlimit rlims[2];
Expand Down
6 changes: 6 additions & 0 deletions stress-ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ typedef long int __kernel_long_t;
typedef unsigned long int __kernel_ulong_t;
#endif

#if defined(HAVE_RLIMIT_RESOURCE_T)
#define shim_rlimit_resource_t __rlimit_resource_t
#else
#define shim_rlimit_resource_t int
#endif

#if defined(__sun__)
#if defined(HAVE_GETDOMAINNAME)
extern int getdomainname(char *name, size_t len);
Expand Down
6 changes: 3 additions & 3 deletions stress-rlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ typedef struct {
#define MAX_RLIMIT_NOFILE (32)

typedef struct {
const int resource; /* rlimit resource ID */
const shim_rlimit_resource_t resource; /* rlimit resource ID */
const struct rlimit new_limit; /* new rlimit setting */
struct rlimit old_limit; /* original old rlimit setting */
int ret; /* saved old rlimit setting return status */
} stress_limits_t;

typedef struct {
const int resource;
const shim_rlimit_resource_t resource;
const char *name;
} stress_resource_id_t;

Expand Down Expand Up @@ -184,7 +184,7 @@ static int stress_rlimit_child(const stress_args_t *args, void *ctxt)
/*
* Exercise illegal bad resource id
*/
ret = getrlimit(~0, &rlim);
ret = getrlimit((shim_rlimit_resource_t)~0, &rlim);
(void)ret;


Expand Down
6 changes: 3 additions & 3 deletions stress-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ UNEXPECTED
#define GIDS_MAX (1024)

typedef struct {
int id;
shim_rlimit_resource_t id;
int ret;
struct rlimit rlim;
} stress_rlimit_info_t;
Expand Down Expand Up @@ -514,8 +514,8 @@ static int stress_set(const stress_args_t *args)
* resource attribute resulting in EINVAL error
*/
(void)memset(&rlim, 0, sizeof(rlim));
if ((getrlimit(INT_MAX, &rlim) < 0) && (errno == EINVAL)) {
(void)setrlimit(INT_MAX, &rlim);
if ((getrlimit((shim_rlimit_resource_t)INT_MAX, &rlim) < 0) && (errno == EINVAL)) {
(void)setrlimit((shim_rlimit_resource_t)INT_MAX, &rlim);
}

for (i = 0; i < SIZEOF_ARRAY(rlimits); i++) {
Expand Down
28 changes: 28 additions & 0 deletions test/test-rlimit_resource_t.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2022 Colin Ian King
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#define _GNU_SOURCE

#include <sys/resource.h>

int main(void)
{
__rlimit_resource_t r = 0;

return (int)r;
}

0 comments on commit 96afb8b

Please sign in to comment.