lapi/sched: Fix sched_getattr/setattr fallback definitions
PATCH 1/1 lapi/sched: Fix sched_getattr/setattr fallback definitions
Commit c48700d8cdbe ("sched_attr: Do not define for glibc >= 2.41") guarded the definitions of struct sched_attr, sched_setattr(), and sched_getattr() under "#ifndef SCHED_ATTR_SIZE_VER0" to avoid conflicts when glibc >= 2.41 provides these definitions.
However, SCHED_ATTR_SIZE_VER0 is a standard Linux kernel UAPI macro defined in <linux/sched/types.h>. When headers include the kernel types (such as on Android Bionic, musl, or older glibc with kernel headers), SCHED_ATTR_SIZE_VER0 is defined even though libc does not provide the sched_setattr() or sched_getattr() functions. This causes the fallback syscall wrappers to be omitted, leading to unresolved symbol errors.
Add autotools checks for sched_getattr, sched_setattr, and struct sched_attr. Guard the fallback functions with HAVE_SCHED_GETATTR and HAVE_SCHED_SETATTR, and remove const from sched_setattr's attr parameter to match the kernel and libc signatures.
--- configure.ac | 3 +++ include/lapi/sched.h | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
configure.ac +3 -0
@@ -155,7 +155,9 @@ AC_CHECK_FUNCS_ONCE([ \ rand_r \ recvmmsg \ renameat2 \ + sched_getattr \ sched_getcpu \ + sched_setattr \ sendmmsg \ sethostid \ setns \
@@ -199,6 +201,7 @@ AC_CHECK_DECLS([TCA_PEDIT_PARMS_EX, TCA_PEDIT_KEYS_EX, TCA_PEDIT_KEY_EX, AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>]) AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>]) AC_CHECK_TYPES([struct clone_args],,,[#include <sched.h>]) +AC_CHECK_TYPES([struct sched_attr],,,[#include <sched.h>]) AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error, struct fanotify_event_info_header, struct fanotify_event_info_pidfd, struct fanotify_event_info_range],,,[#include <sys/fanotify.h>])
include/lapi/sched.h +10 -6
@@ -14,8 +14,8 @@#include "config.h" #include "lapi/syscalls.h" -/* sched_attr is not defined in glibc < 2.41 */ #ifndef SCHED_ATTR_SIZE_VER0 +# ifndef HAVE_STRUCT_SCHED_ATTR struct sched_attr { uint32_t size;
@@ -33,20 +33,24 @@ struct sched_attr {uint64_t sched_deadline;uint64_t sched_period; }; +# endif +# define SCHED_ATTR_SIZE_VER0 48/* sizeof first published struct */ +#endif -static inline int sched_setattr (pid_t pid,const struct sched_attr *attr, -unsigned int flags) +#ifndef HAVE_SCHED_SETATTR +static inline int sched_setattr (pid_t pid,struct sched_attr *attr, +unsigned int flags) {return syscall (__NR_sched_setattr, pid, attr, flags); } +#endif +#ifndef HAVE_SCHED_GETATTR static inline int sched_getattr (pid_t pid,struct sched_attr *attr, -unsigned int size,unsigned int flags) +unsigned int size,unsigned int flags) {return syscall (__NR_sched_getattr, pid, attr, size, flags); } - -# define SCHED_ATTR_SIZE_VER0 48/* sizeof first published struct */ #endif struct clone_args_minimal {
Signature · 5 lines
2.55.0.966.g6673acef38-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake,
Quoted 1 line · Wake Liu
lapi/sched: Fix sched_getattr/setattr fallback definitions
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
AppliedMerged, Thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp