Skip to content

Commit

Permalink
libast: cleanup: remove obsolete pre-sigaction(2) fallbacks
Browse files Browse the repository at this point in the history
Like the similar operation for ksh in 3e2e519, this cleans up a
bunch of dead code in libast and the associated feature tests. The
feature tests for sigaction(2) and friends are also removed; their
presence is now assumed (POSIX specified them in 1988).

Notable changes:

src/lib/libast/comp/sigunblock.c,
src/lib/libast/features/map.c:
- Always use the AST version of sigunblock(3), never the native
  version (if any), and rename it to _ast_sigunblock via map.c just
  to be sure a native version won't override it. There is no
  guarantee native versions are the same. For instance, on QNX,
  sigunblock() takes a signal mask argument, not a signal number.
  • Loading branch information
McDutchie committed Aug 16, 2024
1 parent 89813dd commit eea842f
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 245 deletions.
2 changes: 1 addition & 1 deletion src/lib/libast/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -4521,7 +4521,7 @@ make install virtual
done

note * section 3 manual pages
loop SECT3MAN LIBAST aso ast cdt chr compat error find fmt fmtls ftwalk getcwd hash iblocks int ip6 magic mem mime modecanon optget path proc re regex setenviron sfio sig spawnveg stk strcopy strdup strelapsed strerror stresc streval strgid strmatch stropt strperm strsignal strsort strtape strton struid swap tab tm tmx tok touch tv
loop SECT3MAN LIBAST aso ast cdt chr compat error find fmt fmtls ftwalk getcwd hash iblocks int ip6 magic mem mime modecanon optget path proc re regex setenviron sfio sig spawnveg stk strcopy strdup strelapsed strerror stresc streval strgid strmatch stropt strperm strsort strtape strton struid swap tab tm tmx tok touch tv
make %{INSTALLROOT}/man/man3/%{SECT3MAN}.3
makp man/%{SECT3MAN}.3
exec - cp -f %{<} %{@}
Expand Down
6 changes: 1 addition & 5 deletions src/lib/libast/comp/sigflag.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -30,7 +30,6 @@ NoN(sigflag)
int
sigflag(int sig, int flags, int set)
{
#if _lib_sigaction
struct sigaction sa;

if (sigaction(sig, NULL, &sa))
Expand All @@ -40,9 +39,6 @@ sigflag(int sig, int flags, int set)
else
sa.sa_flags &= ~flags;
return sigaction(sig, &sa, NULL);
#else
return -1;
#endif
}

#endif
34 changes: 12 additions & 22 deletions src/lib/libast/comp/sigunblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand All @@ -17,24 +17,24 @@
* *
***********************************************************************/

#include <ast.h>

#if _lib_sigunblock

NoN(sigunblock)

#else
/*
* There is no longer a test for a native sigunblock() here because we
* always use the sigprocmask(3) version now. Obsolete functions don't
* necessarily mix with the POSIX interface. Plus, on QNX, sigunblock()
* expects a signal mask argument, not a signal number.
*/

#include <ast.h>
#include <sig.h>

#ifndef SIG_UNBLOCK
#undef _lib_sigprocmask
#endif
/*
* remove s from the set of blocked signals
* s==0 unblocks them all
*/

int
sigunblock(int s)
{
#if _lib_sigprocmask
int op;
sigset_t mask;

Expand All @@ -46,14 +46,4 @@ sigunblock(int s)
}
else op = SIG_SETMASK;
return sigprocmask(op, &mask, NULL);
#else
#if _lib_sigsetmask
return sigsetmask(s ? (sigsetmask(0L) & ~sigmask(s)) : 0L);
#else
NoP(s);
return 0;
#endif
#endif
}

#endif
10 changes: 2 additions & 8 deletions src/lib/libast/features/lib
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ lib mbtowc,mbrtowc,memalign,memdup
lib mkdir,mkfifo,mktemp,mktime
lib mount,opendir,pathconf
lib readlink,remove,rename,rewinddir,rmdir,setlocale
lib setpgrp,setpgrp2,setreuid,setuid,sigaction
lib sigprocmask,sigsetmask,sigunblock,sigvec,socketpair
lib setpgrp,setpgrp2,setreuid,setuid
lib socketpair
lib spawn,spawnve
lib strcoll,strdup,strerror,strcasecmp,strncasecmp,strlcat,strlcpy
lib strmode,strxfrm,strftime,swab,symlink,sysconf,sysinfo
Expand Down Expand Up @@ -376,12 +376,6 @@ std remove note{ stuck with standard remove() }end nostatic{
int main(void) { return unlink("foo"); }
}end

std signal note{ stuck with standard signal }end nolink{
extern void abort(void);
int signal(void) { return 0; }
int main(void) { signal(); abort(); return 0; }
}end

std strcoll note{ standard strcoll works }end execute{
#include <string.h>
#define S "hello world"
Expand Down
9 changes: 4 additions & 5 deletions src/lib/libast/features/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ main(void)
printf("#define glob _ast_glob\n");
printf("#undef globfree\n");
printf("#define globfree _ast_globfree\n");
#if _map_libc || (!_std_signal && (_lib_sigaction && defined(SA_NOCLDSTOP) || _lib_sigvec && defined(SV_INTERRUPT)))
/* use the libast signal() function (aka sigaction) when applicable */
/* always rename AST signal(3) to _ast_signal; this avoids breakage when using ASan */
printf("#undef signal\n");
printf("#define signal _ast_signal\n");
#endif
/* 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");
#if _map_libc
printf("#undef memdup\n");
printf("#define memdup _ast_memdup\n");
Expand Down Expand Up @@ -263,8 +264,6 @@ main(void)
printf("#define setenviron _ast_setenviron\n");
printf("#undef sigcritical\n");
printf("#define sigcritical _ast_sigcritical\n");
printf("#undef sigunblock\n");
printf("#define sigunblock _ast_sigunblock\n");
printf("#undef stracmp\n");
printf("#define stracmp _ast_stracmp\n");
printf("#undef strcopy\n");
Expand Down
53 changes: 0 additions & 53 deletions src/lib/libast/man/strsignal.3

This file was deleted.

7 changes: 0 additions & 7 deletions src/lib/libast/misc/procclose.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,7 @@ procclose(Proc_t* p)
signal(SIGINT, p->sigint);
if (p->sigquit != SIG_IGN)
signal(SIGQUIT, p->sigquit);
#if _lib_sigprocmask
sigprocmask(SIG_SETMASK, &p->mask, NULL);
#elif _lib_sigsetmask
sigsetmask(p->mask);
#else
if (p->sigchld != SIG_DFL)
signal(SIGCHLD, p->sigchld);
#endif
}
status = status == -1 ?
EXIT_QUIT :
Expand Down
9 changes: 1 addition & 8 deletions src/lib/libast/misc/proclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,12 @@
#include <sig.h>
#include <wait.h>

#if _lib_sigprocmask
typedef sigset_t Sig_mask_t;
#else
typedef unsigned long Sig_mask_t;
#endif

struct Mods_s;

#define _PROC_PRIVATE_ \
struct Mod_s* mods; /* process modification state */ \
long flags; /* original PROC_* flags */ \
Sig_mask_t mask; /* original blocked sig mask */ \
Sig_handler_t sigchld; /* PROC_FOREGROUND SIG_DFL */ \
sigset_t mask; /* original blocked sig mask */ \
Sig_handler_t sigint; /* PROC_FOREGROUND SIG_IGN */ \
Sig_handler_t sigquit; /* PROC_FOREGROUND SIG_IGN */

Expand Down
32 changes: 1 addition & 31 deletions src/lib/libast/misc/procopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
#if !_pipe_rw && !_lib_socketpair
int poi[2];
#endif /* !_pipe_rw && !_lib_socketpair */
#if _lib_sigprocmask || _lib_sigsetmask
Sig_mask_t mask;
#endif /* _lib_sigprocmask || _lib_sigsetmask */
sigset_t mask;
#if _use_spawnveg
int newenv = 0;
#endif /* _use_spawnveg */
Expand Down Expand Up @@ -498,16 +496,9 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
signalled = 1;
proc->sigint = signal(SIGINT, SIG_IGN);
proc->sigquit = signal(SIGQUIT, SIG_IGN);
#if _lib_sigprocmask
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &proc->mask);
#elif _lib_sigsetmask
mask = sigmask(SIGCHLD);
proc->mask = sigblock(mask);
#else
proc->sigchld = signal(SIGCHLD, SIG_DFL);
#endif /* _lib_sigprocmask */
}
if ((flags & PROC_ORPHAN) && pipe(pop))
goto bad;
Expand All @@ -526,14 +517,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
proc->sigquit = SIG_DFL;
signal(SIGQUIT, proc->sigquit);
}
#if _lib_sigprocmask
sigprocmask(SIG_SETMASK, &proc->mask, NULL);
#elif _lib_sigsetmask
sigsetmask(proc->mask);
#else
if (proc->sigchld != SIG_IGN)
signal(SIGCHLD, SIG_DFL);
#endif /* _lib_sigprocmask */
}
else if (proc->pid == -1)
goto bad;
Expand Down Expand Up @@ -760,16 +744,9 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
signalled = 1;
proc->sigint = signal(SIGINT, SIG_IGN);
proc->sigquit = signal(SIGQUIT, SIG_IGN);
#if _lib_sigprocmask
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &proc->mask);
#elif _lib_sigsetmask
mask = sigmask(SIGCHLD);
proc->mask = sigblock(mask);
#else
proc->sigchld = signal(SIGCHLD, SIG_DFL);
#endif /* _lib_sigprocmask */
}
}
else if (modv)
Expand Down Expand Up @@ -843,14 +820,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
signal(SIGINT, proc->sigint);
if (proc->sigquit != SIG_IGN)
signal(SIGQUIT, proc->sigquit);
#if _lib_sigprocmask
sigprocmask(SIG_SETMASK, &proc->mask, NULL);
#elif _lib_sigsetmask
sigsetmask(proc->mask);
#else
if (proc->sigchld != SIG_DFL)
signal(SIGCHLD, proc->sigchld);
#endif /* _lib_sigprocmask */
}
if ((flags & PROC_CLEANUP) && modv)
for (i = 0; n = modv[i]; i++)
Expand Down
Loading

0 comments on commit eea842f

Please sign in to comment.