diff --git a/src/cmd/ksh93/include/jobs.h b/src/cmd/ksh93/include/jobs.h index 6de9e2917f4d..9d16be540204 100644 --- a/src/cmd/ksh93/include/jobs.h +++ b/src/cmd/ksh93/include/jobs.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -31,7 +31,10 @@ #ifndef SIGINT # include #endif /* !SIGINT */ -#include +#if !_std_atomic +# include +# define atomic_uint uint32_t +#endif #include "terminal.h" #ifndef SIGCHLD @@ -65,7 +68,7 @@ struct jobs pid_t mypgid; /* process group ID of shell */ pid_t mytgid; /* terminal group ID of shell */ int curjobid; - unsigned int in_critical; /* >0 => in critical region */ + atomic_uint in_critical; /* >0 => in critical region */ int savesig; /* active signal */ int numpost; /* number of posted jobs */ #if SHOPT_BGX @@ -88,6 +91,18 @@ struct jobs extern struct jobs job; +#if _std_atomic +/* locking functions used when C11's atomic_uint is available */ +#define job_lock() (job.in_critical++) +#define job_unlock() \ + do { \ + int _sig; \ + if (job.in_critical == 1 && (_sig = job.savesig)) \ + job_reap(_sig); \ + job.in_critical--; \ + } while(0) +#else +/* fallbacks using the ASO functions provided by libast */ #define job_lock() asoincint(&job.in_critical) #define job_unlock() \ do { \ @@ -96,6 +111,7 @@ extern struct jobs job; job_reap(_sig); \ asodecint(&job.in_critical); \ } while(0) +#endif extern const char e_jobusage[]; extern const char e_done[]; diff --git a/src/lib/libast/comp/eaccess.c b/src/lib/libast/comp/eaccess.c index 3690ed5806f8..8a919c6df4d5 100644 --- a/src/lib/libast/comp/eaccess.c +++ b/src/lib/libast/comp/eaccess.c @@ -18,7 +18,9 @@ * * ***********************************************************************/ /* - * access() EUID/EGID implementation + * AST eaccess() implementation + * Uses POSIX faccessat() for better portability and performance + * Fallbacks include native eaccess(), euidaccess(), EFF_ONLY_OK, and a custom implementation */ #include @@ -26,19 +28,21 @@ #include "FEATURE/eaccess" -#if _lib_eaccess - -NoN(eaccess) - -#else +#if _lib_eaccess && !(_lib_faccessat && defined(AT_EACCESS)) +#undef eaccess +extern int eaccess(const char* path, int flags); +#endif -extern int -eaccess(const char* path, int flags) +int +_ast_eaccess(const char* path, int flags) { -#ifdef EFF_ONLY_OK +#if _lib_faccessat && defined(AT_EACCESS) + return faccessat(AT_FDCWD, path, flags, AT_EACCESS); +#elif _lib_eaccess + return eaccess(path, flags); +#elif defined(EFF_ONLY_OK) return access(path, flags|EFF_ONLY_OK); -#else -#if _lib_euidaccess +#elif _lib_euidaccess return euidaccess(path, flags); #else int mode; @@ -125,7 +129,4 @@ eaccess(const char* path, int flags) errno = EACCES; return -1; #endif -#endif } - -#endif diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index b74a7413330d..10d4ef421d4a 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -10,6 +10,13 @@ std noreturn note{ noreturn ok }end compile{ int main(void) { foo(); } }end +std atomic note{ _Atomic ok }end compile{ + #include + #include + static atomic_uint i = 0; + int main(void) { return i; } +}end + cat{ #if __clang__ #pragma clang diagnostic ignored "-Wmissing-braces" @@ -66,6 +73,9 @@ cat{ #else #define noreturn /* empty */ #endif /* _std_noreturn */ + #if _std_atomic + #include + #endif /* _std_atomic */ }end if tst - note{ + works }end compile{ diff --git a/src/lib/libast/features/eaccess b/src/lib/libast/features/eaccess index bf9710a2e67e..8076a4194951 100644 --- a/src/lib/libast/features/eaccess +++ b/src/lib/libast/features/eaccess @@ -1,4 +1,4 @@ -lib eaccess,euidaccess +lib faccessat,eaccess,euidaccess macro{ #include #include diff --git a/src/lib/libast/features/map.c b/src/lib/libast/features/map.c index 7e3bb62b82f4..03090db4f653 100644 --- a/src/lib/libast/features/map.c +++ b/src/lib/libast/features/map.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2025 Contributors to ksh 93u+m * +* Copyright (c) 2020-2026 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -47,6 +47,10 @@ main(void) /* do the same with sigunblock(), just to be sure (e.g., native QNX sigunblock() is different) */ printf("#undef sigunblock\n"); printf("#define sigunblock _ast_sigunblock\n"); + /* use AST eaccess(3) (which will prefer faccessat over native eaccess) */ + printf("#undef eaccess\n"); + printf("#define eaccess _ast_eaccess\n"); + printf("extern int eaccess(const char*, int);\n"); /* Override the native regex library in favor of libast's regex functions */ printf("#undef regaddclass\n"); printf("#define regaddclass _ast_regaddclass\n");