All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>
Subject: [LTP] [PATCH] lapi/sched: Fix sched_getattr/setattr fallback definitions
Date: Tue,  1 Sep 2026 22:45:12 +0000	[thread overview]
Message-ID: <20260901224512.1180203-1-wakel@google.com> (raw)

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.

Fixes: c48700d8cdbe ("sched_attr: Do not define for glibc >= 2.41")
Signed-off-by: Wake Liu <wakel@google.com>
---
 configure.ac         |  3 +++
 include/lapi/sched.h | 16 ++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 19fc5e1b8..8aa3ff539 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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>])
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 05b322c1c..d835537e7 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -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 {
-- 
2.55.0.966.g6673acef38-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2026-09-01 22:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 22:45 Wake Liu via ltp [this message]
2026-09-01 23:05 ` [LTP] lapi/sched: Fix sched_getattr/setattr fallback definitions linuxtestproject.agent
2026-09-04  8:57 ` [LTP] [PATCH] " Andrea Cervesato via ltp
2026-09-04 10:41 ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260901224512.1180203-1-wakel@google.com \
    --to=ltp@lists.linux.it \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.