1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

bump internal libast version; various minor cleanups

These are minor things I accumulated over the last month or so.

Notable changes:

src/lib/libast/features/api,
src/lib/libast/misc/state.c,
src/lib/libast/comp/conf.tab,
src/cmd/ksh93/include/defs.h:
- Bump internal libast version to 20220101L. We've made a few
  additions to the API, at least pathicase (see 71934570, ca3ec200)
  and astconf_long (see c2ac69b2), so this should have been done
  already. This also updates '/opt/ast/bin/getconf _AST_VERSION'.
- Use AST_VERSION instead of outdated _AST_VERSION.
- In state.c, use AST_VERSION instead of hardcoding the version.

src/cmd/ksh93/sh/xec.c:
- Remove 'restorefd' variable, unused as of 42becab6.
- Remove 'cmdrecurse' function and SH_RUNPROG macro; this was once
  used by a few libcmd commands, but ast-open-archive reveals it's
  unused as of ast 1999-12-25.

src/cmd/ksh93/sh/*.c:
- Where available, use e_dot instead of "." for consistency; it is
  defined as an extern so we might as well use it.

src/cmd/ksh93/tests/*.sh:
- When reporting signal names in fails, include the SIG prefix.
- Fix a broken process hang test in subshell.sh.

src/lib/libast/man/sfdisc.3:
- Removed. The interfaces described here never made it out of AT&T;
  they do not exist in any libast version in ast-open-archive.
  Resolves: https://github.com/ksh93/ksh/issues/426
This commit is contained in:
Martijn Dekker 2022-01-14 16:56:41 +00:00
parent 07fc64f52b
commit e569f23ef9
25 changed files with 58 additions and 300 deletions

View file

@ -2344,7 +2344,7 @@ ____
the original trap wasn't executed.
01-11-26 +The value for 0 is now preceded by the base number when
the base was not 10.
01-11-26 +The default has compilation mode has been changes so that
01-11-26 +The default compilation mode has been changed so that
viraw mode will always be on.
01-10-31 --- Release ksh93m ---

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -326,7 +326,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
sh_onoption(SH_MARKDIRS);
{
register char **com;
char *cp=begin, *left=0, *saveout=".";
char *cp=begin, *left=0, *saveout=(char*)e_dot;
int nocase=0,narg,cmd_completion=0;
register int size='x';
while(cp>outbuff && ((size=cp[-1])==' ' || size=='\t'))

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -430,7 +430,7 @@ static History_t* hist_trim(History_t *hp, int n)
*last = '/';
}
else
pathtmp(tmpname,".","hist",NIL(int*));
pathtmp(tmpname,e_dot,"hist",NIL(int*));
if(rename(name,tmpname) < 0)
{
free(tmpname);

View file

@ -29,8 +29,8 @@
#define defs_h_defined
#include <ast.h>
#if !defined(AST_VERSION) || AST_VERSION < 20111111L
#error libast version 20111111 or later is required
#if !defined(AST_VERSION) || AST_VERSION < 20220101
#error libast version 20220101 or later is required
#endif
#if !_lib_fork
#error In 2021, ksh joined the 21st century and started requiring fork(2).

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -469,8 +469,7 @@ extern int sh_waitsafe(void);
extern int sh_exec(const Shnode_t*,int);
/*
* As of 93u+m, direct access to sh is no longer obsolete, and
* shgd ("global data") is no longer a separately allocated struct;
* As of 93u+m, direct access to sh is no longer obsolete;
* sh_getinterp() is here for compatibility with the documented interface.
*/
extern Shell_t sh;
@ -504,6 +503,5 @@ extern Shell_t sh;
#define SH_SIGSET 4
#define SH_EXITSIG 0400 /* signal exit bit */
#define SH_EXITMASK (SH_EXITSIG-1) /* normal exit status bits */
#define SH_RUNPROG -1022 /* needs to be negative and < 256 */
#endif /* !shell_h_defined */

View file

@ -319,7 +319,7 @@ static char *dotpaths_lib(Pathcomp_t *pp, char *path)
if(last)
*last = 0;
else
path = ".";
path = (char*)e_dot;
r = stat(path,&statb);
if(last)
*last = '/';
@ -1671,7 +1671,7 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, register const char *path,int type)
if(*cp==':')
{
if(type!=PATH_FPATH)
first = path_addcomp(first,old,".",type);
first = path_addcomp(first,old,e_dot,type);
while(*++path == ':');
}
else

View file

@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
@ -71,7 +71,6 @@ static void coproc_init(int pipes[]);
static void *timeout;
static char nlock;
static char pipejob;
static int restorefd;
struct funenv
{
@ -1325,7 +1324,7 @@ int sh_exec(register const Shnode_t *t, int flags)
if(!sh.pwd)
path_pwd();
if(sh.pwd)
stat(".",&statb);
stat(e_dot,&statb);
sfsync(NULL);
share = sfset(sfstdin,SF_SHARE,0);
sh_onstate(SH_STOPOK);
@ -1371,7 +1370,7 @@ int sh_exec(register const Shnode_t *t, int flags)
bp->data = (void*)save_data;
if(sh.exitval && errno==EINTR && sh.lastsig)
sh.exitval = SH_EXITSIG|sh.lastsig;
else if(!nv_isattr(np,BLT_EXIT) && sh.exitval!=SH_RUNPROG)
else if(!nv_isattr(np,BLT_EXIT))
sh.exitval &= SH_EXITMASK;
}
else
@ -1410,7 +1409,7 @@ int sh_exec(register const Shnode_t *t, int flags)
if(sh.pwd)
{
struct stat stata;
stat(".",&stata);
stat(e_dot,&stata);
/* restore directory changed */
if(statb.st_ino!=stata.st_ino || statb.st_dev!=stata.st_dev)
chdir(sh.pwd);
@ -1614,7 +1613,6 @@ int sh_exec(register const Shnode_t *t, int flags)
}
#endif /* SHOPT_BGX */
nv_getval(RANDNOD);
restorefd = sh.topfd;
if(type&FCOOP)
{
pipes[2] = 0;
@ -3409,20 +3407,6 @@ int sh_fun(Namval_t *np, Namval_t *nq, char *argv[])
return(sh.exitval);
}
/*
* This dummy routine is called by built-ins that do recursion
* on the file system (chmod, chgrp, chown). It causes
* the shell to invoke the non-builtin version in this case
*/
int cmdrecurse(int argc, char* argv[], int ac, char* av[])
{
NOT_USED(argc);
NOT_USED(argv[0]);
NOT_USED(ac);
NOT_USED(av[0]);
return(SH_RUNPROG);
}
/*
* set up pipe for cooperating process
*/

View file

@ -693,7 +693,7 @@ got=$(set +x; { "$SHELL" -c '
echo baz # 7
'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Redirection in DEBUG trap corrupts the trap' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# The DEBUG trap crashed when re-trapping inside a subshell
exp=$'trap -- \': main\' EXIT\ntrap -- \': main\' ERR\ntrap -- \': main\' KEYBD\ntrap -- \': main\' DEBUG'
@ -707,7 +707,7 @@ got=$(set +x; { "$SHELL" -c '
done
'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Pseudosignal trap failed when re-trapping in subshell' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# Field splitting broke upon evaluating an unquoted expansion in a DEBUG trap
exp=$'a\nb\nc'
@ -720,7 +720,7 @@ got=$(set +x; { "$SHELL" -c '
printf "%s\n" "$@"
'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Field splitting broke after executing DEBUG trap' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# The DEBUG trap had side effects on the exit status
trap ':' DEBUG

View file

@ -1162,7 +1162,7 @@ then got=$( { "$SHELL" -c '
done
'; } 2>&1)
((!(e = $?))) || err_exit 'crash with alarm and IFS' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
fi
# ======

View file

@ -1340,7 +1340,7 @@ cat >$tmp/crash_rhbz1117404.ksh <<-'EOF'
EOF
got=$( { "$SHELL" "$tmp/crash_rhbz1117404.ksh"; } 2>&1)
((!(e = $?))) || err_exit 'crash while handling function-local trap' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# ======
exit $((Errors<125?Errors:125))

View file

@ -714,7 +714,7 @@ got=$(command -x cat <(command -x echo foo) 2>&1) || err_exit "process substitut
exit
' empty_redir_crash_test "$tmp"
((!(e = $?))) || err_exit 'crash on null-command redirection with DEBUG trap' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# ======
# stdout was misdirected if an EXIT/ERR trap handler was defined in a -c script

View file

@ -477,7 +477,7 @@ e=$?
trap - TERM INT
[[ $sleep_pid ]] && kill $sleep_pid
((!e)) && [[ $(<$ofile) == ok ]] || err_exit "PATH containing .paths directory:" \
"got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$(<$ofile)")"
"got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$(<$ofile)")"
# ======
# Check that 'command -p' and 'command -p -v' do not use the hash table (a.k.a. tracked aliases).
@ -560,7 +560,7 @@ trap - TERM INT
if [[ ${ kill -l "$e"; } == KILL ]]
then warning "'command -x' test killed, probably due to lack of memory; skipping test"
else if let "e > 0"
then err_exit "'command -x' test yielded exit status $e$( let "e>128" && print -n / && kill -l "$e")"
then err_exit "'command -x' test yielded exit status $e$( let "e>128" && print -n /SIG && kill -l "$e")"
fi
if [[ ! -s $ofile ]]
then err_exit "'command -x' test failed to produce output"
@ -698,7 +698,7 @@ e=$?
trap - TERM INT
[[ $sleep_pid ]] && kill $sleep_pid
((e == 127)) || err_exit "Long nonexistent command name:" \
"got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$(<$ofile)")"
"got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$(<$ofile)")"
# ======
# A function autoload recursion loop used to crash
@ -716,7 +716,7 @@ $SHELL: function, built-in or type definition for self2 not found in $tmp/fun.$$
$SHELL: function, built-in or type definition for self not found in $tmp/fun.$$/self"
got=$({ FPATH=$tmp/fun.$$ "$SHELL" -c self; } 2>&1)
(((e = $?) == 126)) || err_exit 'Function autoload recursion loop:' \
"got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got")"
"got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got")"
# ======
# If a shared-state ${ command substitution; } changed the value of $PATH, the variable

View file

@ -496,7 +496,7 @@ got=$(export sig; "$SHELL" -c '
trap - "$sig"
' 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit "failed to handle SIG$sig from subshell" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
got=$(export sig; "$SHELL" -c '
function tryTrap
@ -508,7 +508,7 @@ got=$(export sig; "$SHELL" -c '
trap - "$sig"
' 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit "failed to handle SIG$sig from ksh function" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# ======
# ksh-style functions didn't handle signals other than SIGINT and SIGQUIT (rhbz#1454804)
@ -526,7 +526,7 @@ got=$(export exp; "$SHELL" -c '
' 2>&1)
got=${got% } # rm final space
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit "ksh function ignores global signal traps" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# ======
# Signal incorrectly issued when function returns with status > 256 and EXIT trap is active

View file

@ -551,11 +551,16 @@ $SHELL <<- \EOF
print -u2 done
}
out=$(eval "foo | cat" 2>&1)
(( ${#out} == 96011 )) || err_exit "\${#out} is ${#out} should be 96011"
print "${#out}" >out
EOF
} & pid=$!
$SHELL -c "{ sleep .4 && kill $pid ;}" 2> /dev/null
(( $? == 0 )) && err_exit 'process has hung'
(sleep 4; kill -s KILL "$pid" 2>/dev/null) & # another bg job to kill frozen test job
{ wait "$pid"; } 2>/dev/null # get job's exit status, suppressing signal messages
if ((!(e = $?)))
then [[ $(<out) == '96011' ]] || err_exit "\${#out} is $(printf %q "$(<out)"), should be 96011"
else err_exit "process has hung (got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
fi
kill "$!" 2>/dev/null # kill sleep process
{
x=$( $SHELL <<- \EOF
@ -848,7 +853,7 @@ test_pid=$!
(sleep 10; kill -s KILL "$test_pid" 2>/dev/null) & # another bg job to kill frozen test job
sleep_pid=$!
{ wait "$test_pid"; } 2>/dev/null # get job's exit status, suppressing signal messages
((!(e = $?))) || err_exit "backtick comsub crash/freeze (got status $e$( ((e>128)) && print -n / && kill -l "$e"))"
((!(e = $?))) || err_exit "backtick comsub crash/freeze (got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
kill "$sleep_pid" 2>/dev/null
# ======
@ -858,7 +863,7 @@ test_pid=$!
(sleep 2; kill -s KILL "$test_pid" 2>/dev/null) &
sleep_pid=$!
{ wait "$test_pid"; } 2>/dev/null
((!(e = $?))) || err_exit "backtick comsub hang (got status $e$( ((e>128)) && print -n / && kill -l "$e"))"
((!(e = $?))) || err_exit "backtick comsub hang (got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
kill "$sleep_pid" 2>/dev/null
# Backtick command substitution with pipe hangs when filling out pipe buffer (rhbz#1138751)
@ -867,7 +872,7 @@ test_pid=$!
(sleep 2; kill -s KILL "$test_pid" 2>/dev/null) &
sleep_pid=$!
{ wait "$test_pid"; } 2>/dev/null
((!(e = $?))) || err_exit "backtick comsub with pipe hangs (got status $e$( ((e>128)) && print -n / && kill -l "$e"))"
((!(e = $?))) || err_exit "backtick comsub with pipe hangs (got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
kill "$sleep_pid" 2>/dev/null
# ======
@ -924,7 +929,7 @@ cat >$tmp/crash_rhbz1117404.ksh <<-'EOF'
EOF
got=$( { "$SHELL" "$tmp/crash_rhbz1117404.ksh"; } 2>&1)
((!(e = $?))) || err_exit 'crash while handling subshell trap' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
# ======
# Segmentation fault when using cd in a subshell, when current directory cannot be determined
@ -941,14 +946,14 @@ got=$(set +x; { "$SHELL" -c '(subshfn() { bad; }; cd ..; echo "subPWD: $PWD"); t
exp="PWD=$PWD"
got=$(set +x; { "$SHELL" -c '(cd /; (cd /)); print -r -- "PWD=$PWD"'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'failed to restore nonexistent PWD on exiting a virtual subshell' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
mkdir "$tmp/recreated"
cd "$tmp/recreated"
tmp=$tmp "$SHELL" -c 'cd /; rmdir "$tmp/recreated"; mkdir "$tmp/recreated"'
exp="PWD=$PWD"
got=$(set +x; { "$SHELL" -c '(cd /); print -r -- "PWD=$PWD"'; } 2>&1)
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'failed to restore re-created PWD on exiting a virtual subshell' \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
cd "$tmp"
# ======

View file

@ -113,7 +113,7 @@ HOME=$saveHOME
if builtin .sh.tilde 2>/dev/null
then got=$(.sh.tilde & wait "$!" 2>&1)
((!(e = $?))) || err_exit ".sh.tilde builtin crashes the shell" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
fi
# ... and replaced by a proper use of discipline functions that allows customising tilde expansion.
@ -164,7 +164,7 @@ do (
if ((!(e = $?)))
then read Errors <$tmp/Errors
else err_exit ".sh.tilde.$disc discipline function crashes the shell" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$(<crashmsg)"))"
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$(<crashmsg)"))"
fi
done

View file

@ -1052,7 +1052,7 @@ $SHELL -c '
exit $((errors + 1)) # a possible erroneous asynchronous fork would cause exit status 0
' unset_test "$@"
(((e = $?) == 1)) || err_exit "Failure in unsetting one or more special variables" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ... unset in virtual subshell inside of nested function
$SHELL -c '
@ -1082,7 +1082,7 @@ $SHELL -c '
exit $((errors + 1)) # a possible erroneous asynchronous fork would cause exit status 0
' unset_subsh_fun_test "$@"
(((e = $?) == 1)) || err_exit "Unset of special variable(s) in a virtual subshell within a nested function fails" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ... readonly in subshell
$SHELL -c '
@ -1106,7 +1106,7 @@ $SHELL -c '
exit $((errors + 1)) # a possible erroneous asynchronous fork would cause exit status 0
' readonly_test "$@"
(((e = $?) == 1)) || err_exit "Failure in making one or more special variables readonly in a subshell" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ... subshell leak test
$SHELL -c '
@ -1123,7 +1123,7 @@ $SHELL -c '
exit $((errors + 1))
' subshell_leak_test "$@"
(((e = $?) == 1)) || err_exit "One or more special variables leak out of a subshell" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ... upper/lowercase test
$SHELL -c '
@ -1159,7 +1159,7 @@ $SHELL -c '
exit $((errors + 1))
' changecase_test "$@"
(((e = $?) == 1)) || err_exit "typeset -l/-u doesn't work on special variables" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ... unset followed by launching a forked subshell
$SHELL -c '
@ -1176,7 +1176,7 @@ $SHELL -c '
exit $?
' unset_to_fork_test "$@"
(((e = $?) == 1)) || err_exit "Failure in unsetting one or more special variables followed by launching forked subshell" \
"(exit status $e$( ((e>128)) && print -n / && kill -l "$e"))"
"(exit status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ======
# ${.sh.pid} should be the forked subshell's PID