diff --git a/src/cmd/ksh93/features/externs b/src/cmd/ksh93/features/externs index 7e2183bd1011..2e927ac03fd9 100644 --- a/src/cmd/ksh93/features/externs +++ b/src/cmd/ksh93/features/externs @@ -1,7 +1,6 @@ hdr nc mem exception.name,_exception.name math.h -lib setreuid,setregid,nice,fork -lib pathnative,pathposix +lib setreuid,setregid lib memcntl sys/mman.h # for main.c fixargs(): diff --git a/src/cmd/ksh93/include/defs.h b/src/cmd/ksh93/include/defs.h index 1846d6d34b3b..ca20ab43ff08 100644 --- a/src/cmd/ksh93/include/defs.h +++ b/src/cmd/ksh93/include/defs.h @@ -34,11 +34,8 @@ #endif #include -#if !defined(AST_VERSION) || AST_VERSION < 20220801 -#error libast version 20220801 or later is required -#endif -#if !_lib_fork -#error In 2021, ksh joined the 21st century and started requiring fork(2). +#if !defined(AST_VERSION) || AST_VERSION < 20240811 +#error libast version 20240811 or later is required #endif #include diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 7897263d47f8..78f6abb35f2a 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1017,17 +1017,14 @@ static char* get_version(Namval_t* np, Namfun_t *fp) static Sfdouble_t nget_version(Namval_t* np, Namfun_t *fp) { - const char *cp = e_version + strlen(e_version)-10; + const char *cp = e_version + sizeof e_version - 15; /* version date */ int c; Sflong_t t = 0; NOT_USED(np); NOT_USED(fp); while (c = *cp++) - if (c >= '0' && c <= '9') - { - t *= 10; - t += c - '0'; - } + if (isdigit(c)) + t = 10 * t + c - '0'; return (Sfdouble_t)t; } @@ -1260,13 +1257,11 @@ int sh_type(const char *path) */ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) { - size_t n; int type = 0; static char *login_files[2]; sh_onstate(SH_INIT); - n = strlen(e_version); - if(e_version[n-1]=='$' && e_version[n-2]==' ') - e_version[n-2]=0; + /* truncate final " $\0\n" from e_version for ${.sh.version} output (it's there for what(1) or ident(1)) */ + e_version[sizeof e_version - 5] = '\0'; memcpy(sh_lexstates,sh_lexrstates,ST_NONE*sizeof(char*)); sh.current_pid = sh.pid = getpid(); sh.current_ppid = sh.ppid = getppid(); @@ -1327,6 +1322,7 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) */ char *cp=nv_getval(L_ARGNOD); char buff[PATH_MAX+1]; + size_t n; sh.shpath = 0; if((n = pathprog(NULL, buff, sizeof(buff))) > 0 && n <= sizeof(buff)) sh.shpath = sh_strdup(buff); @@ -1390,9 +1386,8 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) name = sh.st.dolv[0]; if(name[1]==':' && (name[2]=='/' || name[2]=='\\')) { -#if _lib_pathposix char* p; - + size_t n; if((n = pathposix(name, NULL, 0)) > 0) { p = (char*)sh_malloc(++n); @@ -1400,7 +1395,6 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) name = p; } else -#endif { name[1] = name[0]; name[0] = name[2] = '/'; diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 55e5576f3033..b50a983568aa 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -1822,9 +1822,7 @@ void nv_putval(Namval_t *np, const char *string, int flags) { void *tofree=0; int offset = 0; -#if _lib_pathnative char buff[PATH_MAX]; -#endif /* _lib_pathnative */ if(flags&NV_INTEGER) { if((flags&NV_DOUBLE)==NV_DOUBLE) @@ -1852,7 +1850,6 @@ void nv_putval(Namval_t *np, const char *string, int flags) } if(nv_isattr(np, NV_HOST|NV_INTEGER)==NV_HOST && sp) { -#if _lib_pathnative /* * return the host file name given the UNIX name */ @@ -1864,9 +1861,6 @@ void nv_putval(Namval_t *np, const char *string, int flags) *buff += 'a'-'A'; } sp = buff; -#else - ; -#endif /* _lib_pathnative */ } else if((nv_isattr(np, NV_RJUST|NV_ZFILL|NV_LJUST)) && sp) { diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 2f6a066bcba9..67710c961aeb 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -49,9 +49,6 @@ #define _use_ntfork_tcpgrp 1 #endif -#if _lib_nice - extern int nice(int); -#endif /* _lib_nice */ #if SHOPT_SPAWN static pid_t sh_ntfork(const Shnode_t*,char*[],int*,int); #endif /* SHOPT_SPAWN */ @@ -1535,10 +1532,8 @@ int sh_exec(const Shnode_t *t, int flags) } sh_offstate(SH_INTERACTIVE); /* pipe in or out */ -#if _lib_nice if((type&FAMP) && sh_isoption(SH_BGNICE)) nice(4); -#endif /* _lib_nice */ #if !SHOPT_DEVFD if(sh.fifo && (type&(FPIN|FPOU))) { diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index 859f8931a0a8..1e83aa72d4d2 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -1734,5 +1734,12 @@ EOF wait "$parallel_1" || err_exit 'setting TMOUT in a virtual subshell removes its special meaning' wait "$parallel_2" || err_exit "TMOUT applies to 'read' from a non-terminal" +# ====== +# TODO: fix to support > 4 year digits well before the year 10,000 :) +got=$((.sh.version)) +exp='^[[:digit:]]{8}$' +[[ $got =~ $exp ]] || err_exit '$((.sh.version)) does not yield YYYYMMDD digits' \ + "(expected match of ERE $exp, got '$got')" + # ====== exit $((Errors<125?Errors:125))