mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This combines 20 cleanup commits from the dev branch. All changed files: - Clean up pointer defererences to sh. - Remove shp arguments from functions. Other notable changes: src/cmd/ksh93/include/shell.h, src/cmd/ksh93/sh/init.c: - On second thought, get rid of the function version of sh_getinterp() as libshell ABI compatibility is moot. We've already been breaking that by reordering the sh struct, so there is no way it's going to work without recompiling. src/cmd/ksh93/sh/name.c: - De-obfuscate the relationship between nv_scan() and scanfilter(). The former just calls the latter as a static function, there's no need to do that via a function pointer and void* type conversions. src/cmd/ksh93/bltins/typeset.c, src/cmd/ksh93/sh/name.c, src/cmd/ksh93/sh/nvdisc.c: - 'struct adata' and 'struct tdata', defined as local struct types in these files, need to have their first three fields in common, the first being a pointer to sh. This is because scanfilter() in name.c accesses these fields via a type conversion. So the sh field needed to be removed in all three at the same time. TODO: de-obfuscate: good practice definition via a header file. src/cmd/ksh93/sh/path.c: - Naming consistency: reserve the path_ function name prefix for externs and rename statics with that prefix. - The default path was sometimes referred to as the standard path. To use one term, rename std_path to defpath and onstdpath() to ondefpath(). - De-obfuscate SHOPT_PFSH conditional code by only calling pf_execve() (was path_pfexecve()) if that is compiled in. src/cmd/ksh93/include/streval.h, src/cmd/ksh93/sh/streval.c: - Rename extern strval() to arith_strval() for consistency. src/cmd/ksh93/sh/string.c: - Remove outdated/incorrect isxdigit() fallback; '#ifnded isxdigit' is not a correct test as isxdigit() is specified as a function. Plus, it's part of C89/C90 which we now require. (re:ac8991e5) src/cmd/ksh93/sh/suid_exec.c: - Replace an incorrect reference to shgd->current_pid with getpid(); it cannot work as (contrary to its misleading directory placement) suid_exec is an independent libast program with no link to ksh or libshell at all. However, no one noticed because this was in fallback code for ancient systems without setreuid(2). Since that standard function was specified in POSIX Issue 4 Version 2 from 1994, we should remove that fallback code sometime as part of another obsolete code cleanup operation to avoid further bit rot. (re:843b546c) src/cmd/ksh93/bltins/print.c: genformat(): - Remove preformat[] which was always empty and had no effect. src/cmd/ksh93/shell.3: - Minor copy-edit. - Remove documentation for nonexistent sh.infile_name. A search through ast-open-archive[*] reveals this never existed at all. - Document sh.savexit (== $?). src/cmd/ksh93/shell.3, src/cmd/ksh93/include/shell.h, src/cmd/ksh93/sh/init.c: - Remove sh.gd/shgd; this is now unused and was never documented or exposed in the shell.h public interface. - sh_sigcheck() was documented in shell.3 as taking no arguments whereas in the actual code it took a shp argument. I decided to go with the documentation. - That leaves sh_parse() as the only documented function that still takes an shp argument. I'm just going to go ahead and remove it for consistency, reverting sh_parse() to its pre-2003 spec. - Remove undocumented/unused sh_bltin_tree() function which simply returned sh.bltin_tree. - Bump SH_VERSION to 20220106.
240 lines
6 KiB
C
240 lines
6 KiB
C
/***********************************************************************
|
|
* *
|
|
* 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 *
|
|
* and is licensed under the *
|
|
* Eclipse Public License, Version 1.0 *
|
|
* by AT&T Intellectual Property *
|
|
* *
|
|
* A copy of the License is available at *
|
|
* http://www.eclipse.org/org/documents/epl-v10.html *
|
|
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
|
* *
|
|
* Information and Software Systems Research *
|
|
* AT&T Research *
|
|
* Florham Park NJ *
|
|
* *
|
|
* David Korn <dgk@research.att.com> *
|
|
* *
|
|
***********************************************************************/
|
|
/*
|
|
* ulimit [-HSaMctdfkxlqenuPpmrRbiswTv] [limit]
|
|
*
|
|
* David Korn
|
|
* AT&T Labs
|
|
*
|
|
*/
|
|
|
|
#include <ast.h>
|
|
#include <sfio.h>
|
|
#include <error.h>
|
|
#include "defs.h"
|
|
#include "builtins.h"
|
|
#include "name.h"
|
|
#include "ulimit.h"
|
|
#ifndef SH_DICT
|
|
# define SH_DICT "libshell"
|
|
#endif
|
|
|
|
#ifdef _no_ulimit
|
|
int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|
{
|
|
NOT_USED(argc);
|
|
NOT_USED(argv);
|
|
NOT_USED(context);
|
|
errormsg(SH_DICT,ERROR_exit(2),e_nosupport);
|
|
UNREACHABLE();
|
|
}
|
|
#else
|
|
|
|
static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
|
|
{
|
|
register const Limit_t* tp;
|
|
|
|
for (tp = shtab_limits; tp->option; tp++)
|
|
{
|
|
sfprintf(sp, "[%c=%d:%s?The %s", tp->option, tp - shtab_limits + 1, tp->name, tp->description);
|
|
if(tp->type != LIM_COUNT)
|
|
sfprintf(sp, " in %ss", e_units[tp->type]);
|
|
sfprintf(sp, ".]");
|
|
}
|
|
return(1);
|
|
}
|
|
|
|
#define HARD 2
|
|
#define SOFT 4
|
|
|
|
int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|
{
|
|
register char *limit;
|
|
register int mode=0, n;
|
|
register unsigned long hit = 0;
|
|
#ifdef _lib_getrlimit
|
|
struct rlimit rlp;
|
|
#endif /* _lib_getrlimit */
|
|
const Limit_t* tp;
|
|
char* conf;
|
|
int label, unit, nosupport;
|
|
rlim_t i;
|
|
char tmp[41];
|
|
Optdisc_t disc;
|
|
NOT_USED(context);
|
|
memset(&disc, 0, sizeof(disc));
|
|
disc.version = OPT_VERSION;
|
|
disc.infof = infof;
|
|
opt_info.disc = &disc;
|
|
while((n = optget(argv,sh_optulimit))) switch(n)
|
|
{
|
|
case 'H':
|
|
mode |= HARD;
|
|
continue;
|
|
case 'S':
|
|
mode |= SOFT;
|
|
continue;
|
|
case 'a':
|
|
hit = ~0;
|
|
break;
|
|
default:
|
|
if(n < 0)
|
|
hit |= (1L<<(-(n+1)));
|
|
else
|
|
errormsg(SH_DICT,2, e_notimp, opt_info.name);
|
|
break;
|
|
case ':':
|
|
errormsg(SH_DICT,2, "%s", opt_info.arg);
|
|
break;
|
|
case '?':
|
|
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
|
UNREACHABLE();
|
|
}
|
|
opt_info.disc = 0;
|
|
/* default to -f */
|
|
limit = argv[opt_info.index];
|
|
if(hit==0)
|
|
for(n=0; shtab_limits[n].option; n++)
|
|
if(shtab_limits[n].index == RLIMIT_FSIZE)
|
|
{
|
|
hit |= (1L<<n);
|
|
break;
|
|
}
|
|
/* only one option at a time for setting */
|
|
label = (hit&(hit-1));
|
|
if(error_info.errors || (limit && label) || argc>opt_info.index+1)
|
|
{
|
|
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
|
UNREACHABLE();
|
|
}
|
|
if(mode==0)
|
|
mode = (HARD|SOFT);
|
|
for(tp = shtab_limits; tp->option && hit; tp++,hit>>=1)
|
|
{
|
|
if(!(hit&1))
|
|
continue;
|
|
nosupport = (n = tp->index) == RLIMIT_UNKNOWN;
|
|
unit = shtab_units[tp->type];
|
|
if(limit)
|
|
{
|
|
if(sh.subshell && !sh.subshare)
|
|
sh_subfork();
|
|
if(strcmp(limit,e_unlimited)==0)
|
|
i = INFINITY;
|
|
else
|
|
{
|
|
char *last;
|
|
/* an explicit suffix unit overrides the default */
|
|
if((i=strtol(limit,&last,0))!=INFINITY && !*last)
|
|
i *= unit;
|
|
else if((i=strton(limit,&last,NiL,0))==INFINITY || *last)
|
|
{
|
|
if((i=sh_strnum(limit,&last,2))==INFINITY || *last)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
|
UNREACHABLE();
|
|
}
|
|
i *= unit;
|
|
}
|
|
}
|
|
if(nosupport)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_readonly,tp->name);
|
|
UNREACHABLE();
|
|
}
|
|
else
|
|
{
|
|
#ifdef _lib_getrlimit
|
|
if(getrlimit(n,&rlp) <0)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
|
UNREACHABLE();
|
|
}
|
|
if(mode&HARD)
|
|
rlp.rlim_max = i;
|
|
if(mode&SOFT)
|
|
rlp.rlim_cur = i;
|
|
if(setrlimit(n,&rlp) <0)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_overlimit,limit);
|
|
UNREACHABLE();
|
|
}
|
|
#else
|
|
if((i=vlimit(n,i)) < 0)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
|
UNREACHABLE();
|
|
}
|
|
#endif /* _lib_getrlimit */
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(!nosupport)
|
|
{
|
|
#ifdef _lib_getrlimit
|
|
if(getrlimit(n,&rlp) <0)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
|
UNREACHABLE();
|
|
}
|
|
if(mode&HARD)
|
|
i = rlp.rlim_max;
|
|
if(mode&SOFT)
|
|
i = rlp.rlim_cur;
|
|
#else
|
|
# ifdef _lib_ulimit
|
|
n--;
|
|
# endif /* _lib_ulimit */
|
|
i = -1;
|
|
if((i=vlimit(n,i)) < 0)
|
|
{
|
|
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
|
UNREACHABLE();
|
|
}
|
|
#endif /* _lib_getrlimit */
|
|
}
|
|
if(label)
|
|
{
|
|
if(tp->type != LIM_COUNT)
|
|
sfsprintf(tmp,sizeof(tmp),"%s (%ss)", tp->description, e_units[tp->type]);
|
|
else
|
|
sfsprintf(tmp,sizeof(tmp),"%s", tp->name);
|
|
sfprintf(sfstdout,"%-39s (-%c) ",tmp,tp->option);
|
|
}
|
|
if(nosupport)
|
|
{
|
|
if(!tp->conf || !*(conf = astconf(tp->conf, NiL, NiL)))
|
|
conf = (char*)e_nosupport;
|
|
sfputr(sfstdout,conf,'\n');
|
|
}
|
|
else if(i!=INFINITY)
|
|
{
|
|
i += (unit-1);
|
|
sfprintf(sfstdout,"%I*d\n",sizeof(i),i/unit);
|
|
}
|
|
else
|
|
sfputr(sfstdout,e_unlimited,'\n');
|
|
}
|
|
}
|
|
return(0);
|
|
}
|
|
#endif /* _no_ulimit */
|