array.c | 1 - arrayfunc.c | 8 +- bashline.c | 42 +++++------ braces.c | 13 ++-- builtins.h | 1 + builtins/cd.def | 14 ++-- builtins/command.def | 5 +- builtins/common.c | 2 +- builtins/common.h | 2 +- builtins/declare.def | 5 +- builtins/enable.def | 6 +- builtins/evalfile.c | 2 +- builtins/fc.def | 8 +- builtins/gen-helpfiles.c | 2 +- builtins/help.def | 3 +- builtins/history.def | 2 +- builtins/mapfile.def | 3 +- builtins/mkbuiltins.c | 28 ++++++- builtins/psize.sh | 24 +----- builtins/set.def | 2 +- builtins/setattr.def | 5 +- builtins/shopt.def | 6 +- builtins/test.def | 6 ++ builtins/ulimit.def | 4 + config-top.h | 12 +-- config.h.in | 3 +- configure.ac | 11 ++- doc/Makefile.in | 12 +-- doc/bash.1 | 72 +++++++++++++++--- doc/bashbug.1 | 5 +- doc/bashref.texi | 17 ++++- doc/builtins.1 | 5 +- doc/rbash.1 | 4 +- error.c | 7 +- eval.c | 3 +- examples/loadables/finfo.c | 15 ++-- examples/loadables/head.c | 2 - examples/loadables/id.c | 2 - examples/loadables/mkdir.c | 3 +- examples/loadables/print.c | 2 +- examples/loadables/tee.c | 2 - examples/loadables/uname.c | 2 +- execute_cmd.c | 37 ++++++--- execute_cmd.h | 5 ++ expr.c | 17 +++-- externs.h | 5 +- general.c | 5 +- jobs.c | 22 ++---- lib/glob/glob.c | 13 ++-- lib/glob/gmisc.c | 4 +- lib/glob/smatch.c | 1 - lib/malloc/stats.c | 2 +- lib/malloc/trace.c | 2 +- lib/sh/casemod.c | 2 +- lib/sh/eaccess.c | 8 +- lib/sh/fnxform.c | 2 + lib/sh/mailstat.c | 2 +- lib/sh/tmpfile.c | 184 +++++++-------------------------------------- locale.c | 15 ++-- make_cmd.c | 85 +++++++++++++++++++++ parse.y | 36 ++++----- pathexp.c | 5 +- pcomplete.c | 3 +- redir.c | 27 ++++--- shell.c | 14 +++- subst.c | 122 ++++++++++++++++-------------- support/bashbug.sh | 45 +++-------- support/fixlinks | 35 +++------ support/man2html.c | 38 ++++------ support/mkclone | 39 ++++------ support/rlvers.sh | 24 +++--- trap.c | 4 +- variables.c | 21 ++---- variables.h | 4 +- xmalloc.c | 2 +- 75 files changed, 612 insertions(+), 591 deletions(-) diff --git a/array.c b/array.c index 6a6db77..4a930d0 100644 --- a/array.c +++ b/array.c @@ -391,7 +391,6 @@ array_remove_quoted_nulls(array) ARRAY *array; { ARRAY_ELEMENT *a; - char *t; if (array == 0 || array_head(array) == 0 || array_empty(array)) return (ARRAY *)NULL; diff --git a/arrayfunc.c b/arrayfunc.c index 47c595e..819a624 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -258,9 +258,6 @@ bind_assoc_variable (entry, name, key, value, flags) char *value; int flags; { - SHELL_VAR *dentry; - char *newval; - if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry)) { if (readonly_p (entry)) @@ -280,7 +277,7 @@ assign_array_element (name, value, flags) { char *sub, *vname; int sublen; - SHELL_VAR *entry, *nv; + SHELL_VAR *entry; vname = array_variable_name (name, &sub, &sublen); @@ -450,7 +447,6 @@ expand_compound_array_assignment (var, value, flags) int flags; { WORD_LIST *list, *nlist; - WORD_LIST *hd, *tl, *t, *n; char *val; int ni; @@ -1036,7 +1032,7 @@ array_value_internal (s, quoted, flags, rtype, indp) arrayind_t *indp; { int len; - arrayind_t ind; + arrayind_t ind = 0; char *akey; char *retval, *t, *temp; WORD_LIST *l; diff --git a/bashline.c b/bashline.c index 0275844..bbcd9d1 100644 --- a/bashline.c +++ b/bashline.c @@ -174,11 +174,13 @@ static char *quote_word_break_chars __P((char *)); static void set_filename_bstab __P((const char *)); static char *bash_quote_filename __P((char *, int, char *)); +#if 0 #ifdef _MINIX static void putx __P((int)); #else static int putx __P((int)); #endif +#endif static int bash_execute_unix_command __P((int, int)); static void init_unix_command_map __P((void)); static int isolate_sequence __P((char *, int, int, int *)); @@ -936,7 +938,7 @@ operate_and_get_next (count, c) command being entered (if no explicit argument is given), otherwise on a command from the history file. */ -#define VI_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-vi}}\"" +#define VI_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-vitmp}}\"" #define EMACS_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-emacs}}\"" #define POSIX_VI_EDIT_COMMAND "fc -e vi" @@ -1056,7 +1058,7 @@ bash_forward_shellword (count, key) int count, key; { size_t slen; - int sindex, c, p; + int c, p; DECLARE_MBSTATE; if (count < 0) @@ -1165,7 +1167,7 @@ bash_backward_shellword (count, key) int count, key; { size_t slen; - int sindex, c, p; + int c, p; DECLARE_MBSTATE; if (count < 0) @@ -1420,7 +1422,7 @@ attempt_shell_completion (text, start, end) const char *text; int start, end; { - int in_command_position, ti, saveti, qc, dflags; + int in_command_position, ti, qc = 0, dflags; char **matches, *command_separator_chars; #if defined (PROGRAMMABLE_COMPLETION) int have_progcomps, was_assignment; @@ -1442,7 +1444,6 @@ attempt_shell_completion (text, start, end) appears after a character that separates commands. It cannot be a command word if we aren't at the top-level prompt. */ ti = start - 1; - saveti = qc = -1; while ((ti > -1) && (whitespace (rl_line_buffer[ti]))) ti--; @@ -1453,7 +1454,6 @@ attempt_shell_completion (text, start, end) if (ti >= 0 && (rl_line_buffer[ti] == '"' || rl_line_buffer[ti] == '\'')) { qc = rl_line_buffer[ti]; - saveti = ti--; while (ti > -1 && (whitespace (rl_line_buffer[ti]))) ti--; } @@ -1511,7 +1511,7 @@ attempt_shell_completion (text, start, end) if (matches == 0 && (in_command_position == 0 || text[0] == '\0') && current_prompt_string == ps1_prompt) { - int s, e, s1, e1, os, foundcs; + int s, e, s1, e1 = 0, os, foundcs; char *n; /* XXX - don't free the members */ @@ -1803,7 +1803,7 @@ command_word_completion_function (hint_text, state) static char *dequoted_hint = (char *)NULL; static char *directory_part = (char *)NULL; static char **glob_matches = (char **)NULL; - static int path_index, hint_len, dequoted_len, istate, igncase; + static int path_index, hint_len, istate, igncase; static int mapping_over, local_index, searching_path, hint_is_dir; static int old_glob_ignore_case, globpat; static SHELL_VAR **varlist = (SHELL_VAR **)NULL; @@ -1881,7 +1881,7 @@ command_word_completion_function (hint_text, state) free (hint); hint = dequoted_hint; } - dequoted_len = hint_len = strlen (hint); + hint_len = strlen (hint); if (filename_hint) free (filename_hint); @@ -1909,12 +1909,11 @@ command_word_completion_function (hint_text, state) } dequoted_hint = hint = savestring (hint_text); - dequoted_len = hint_len = strlen (hint); + hint_len = strlen (hint); if (rl_completion_found_quote && rl_completion_quote_character == 0) { dequoted_hint = bash_dequote_filename (hint, 0); - dequoted_len = strlen (dequoted_hint); } path = get_string_value ("PATH"); @@ -2304,7 +2303,6 @@ variable_completion_function (text, state) static char **varlist = (char **)NULL; static int varlist_index; static char *varname = (char *)NULL; - static int namelen; static int first_char, first_char_loc; if (!state) @@ -2323,7 +2321,6 @@ variable_completion_function (text, state) varname = savestring (text + first_char_loc); - namelen = strlen (varname); if (varlist) strvec_dispose (varlist); @@ -2411,7 +2408,7 @@ bash_servicename_completion_function (text, state) #else static char *sname = (char *)NULL; static struct servent *srvent; - static int snamelen, firstc; + static int snamelen; char *value; char **alist, *aentry; int afound; @@ -2419,7 +2416,6 @@ bash_servicename_completion_function (text, state) if (state == 0) { FREE (sname); - firstc = *text; sname = savestring (text); snamelen = strlen (sname); @@ -2792,7 +2788,7 @@ _ignore_completion_names (names, name_func) { char **newnames; int idx, nidx; - char **oldnames; + char **oldnames = 0; int oidx; /* If there is only one completion, see if it is acceptable. If it is @@ -3138,7 +3134,6 @@ bash_filename_stat_hook (dirname) int should_expand_dirname, return_value; int global_nounset; WORD_LIST *wl; - struct stat sb; local_dirname = *dirname; should_expand_dirname = return_value = 0; @@ -3216,10 +3211,8 @@ bash_directory_completion_hook (dirname) char **dirname; { char *local_dirname, *new_dirname, *t; - int return_value, should_expand_dirname, nextch, closer, changed; - size_t local_dirlen; + int return_value, should_expand_dirname, nextch, closer; WORD_LIST *wl; - struct stat sb; return_value = should_expand_dirname = nextch = closer = 0; local_dirname = *dirname; @@ -3870,7 +3863,7 @@ bash_dequote_filename (text, quote_char) *r++ = *p; /* Backslashes are preserved within double quotes unless the character is one that is defined to be escaped */ - else if (quoted == '"' && ((sh_syntaxtab[p[1]] & CBSDQUOTE) == 0)) + else if (quoted == '"' && ((sh_syntaxtab[(unsigned char) p[1]] & CBSDQUOTE) == 0)) *r++ = *p; *r++ = *++p; @@ -3943,7 +3936,7 @@ set_filename_bstab (string) memset (filename_bstab, 0, sizeof (filename_bstab)); for (s = string; s && *s; s++) - filename_bstab[*s] = 1; + filename_bstab[(unsigned char) *s] = 1; } /* Quote a filename using double quotes, single quotes, or backslashes @@ -4051,6 +4044,7 @@ bash_quote_filename (s, rtype, qcp) /* Support for binding readline key sequences to Unix commands. */ static Keymap cmd_xmap; +#if 0 #ifdef _MINIX static void #else @@ -4065,15 +4059,13 @@ putx(c) return x; #endif } +#endif static int bash_execute_unix_command (count, key) int count; /* ignored */ int key; { - Keymap ckmap; /* current keymap */ - Keymap xkmap; /* unix command executing keymap */ - rl_command_func_t *func; int type; register int i, r; intmax_t mi; diff --git a/braces.c b/braces.c index 7f31dd5..b445a96 100644 --- a/braces.c +++ b/braces.c @@ -383,7 +383,7 @@ mkseq (start, end, incr, type, width) int type, width; { intmax_t n, prevn; - int i, j, nelem; + int i, nelem; char **result, *t; if (incr == 0) @@ -445,9 +445,10 @@ mkseq (start, end, incr, type, width) result[i++] = t = itos (n); else if (type == ST_ZINT) { - int len, arg; + int arg; arg = n; - len = asprintf (&t, "%0*d", width, arg); + if (asprintf (&t, "%0*d", width, arg) < 0) + t = 0; result[i++] = t; } else @@ -494,9 +495,9 @@ expand_seqterm (text, tlen) size_t tlen; { char *t, *lhs, *rhs; - int i, lhs_t, rhs_t, lhs_l, rhs_l, width; + int lhs_t, rhs_t, lhs_l, rhs_l, width; intmax_t lhs_v, rhs_v, incr; - intmax_t tl, tr; + intmax_t tl, tr = 0; char **result, *ep, *oep; t = strstr (text, BRACE_SEQ_SPECIFIER); @@ -743,6 +744,7 @@ comsub: return (c); } +#if 0 /* Return 1 if ARR has any non-empty-string members. Used to short-circuit in array_concat() below. */ static int @@ -756,6 +758,7 @@ degenerate_array (arr) return 0; return 1; } +#endif /* Return a new array of strings which is the result of appending each string in ARR2 to each string in ARR1. The resultant array is diff --git a/builtins.h b/builtins.h index 0cfea18..c5874e4 100644 --- a/builtins.h +++ b/builtins.h @@ -42,6 +42,7 @@ #define ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */ #define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */ #define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */ +#define REQUIRES_BUILTIN 0x80 /* This builtin requires other files. */ #define BASE_INDENT 4 diff --git a/builtins/cd.def b/builtins/cd.def index 421e819..4da456f 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -63,7 +63,9 @@ static int setpwd __P((char *)); static char *resetpwd __P((char *)); static int change_to_directory __P((char *, int, int)); +#if defined (O_XATTR) static int cdxattr __P((char *, char **)); +#endif static void resetxattr __P((void)); /* Change this to 1 to get cd spelling correction by default. */ @@ -188,12 +190,12 @@ resetpwd (caller) return (tdir); } +#if defined (O_XATTR) static int cdxattr (dir, ndirp) char *dir; /* don't assume we can always free DIR */ char **ndirp; /* return new constructed directory name */ { -#if defined (O_XATTR) int apfd, fd, r, e; char buf[11+40+40]; /* construct new `fake' path for pwd */ @@ -228,10 +230,8 @@ cdxattr (dir, ndirp) xattrfd = fd; return r; -#else - return -1; -#endif } +#endif /* Clean up the O_XATTR baggage. Currently only closes xattrfd */ static void @@ -546,8 +546,8 @@ change_to_directory (newdir, nolinks, xattr) char *newdir; int nolinks, xattr; { - char *t, *tdir, *ndir; - int err, canon_failed, r, ndlen, dlen; + char *t, *tdir; + int err, canon_failed, r, ndlen; tdir = (char *)NULL; @@ -566,7 +566,6 @@ change_to_directory (newdir, nolinks, xattr) : sh_canonpath (t, PATH_CHECKDOTDOT|PATH_CHECKEXISTS); ndlen = strlen (newdir); - dlen = strlen (t); /* Use the canonicalized version of NEWDIR, or, if canonicalization failed, use the non-canonical form. */ @@ -598,6 +597,7 @@ change_to_directory (newdir, nolinks, xattr) #if defined (O_XATTR) if (xattrflag) { + char *ndir; r = cdxattr (nolinks ? newdir : tdir, &ndir); if (r >= 0) { diff --git a/builtins/command.def b/builtins/command.def index dcb510d..aec82cd 100644 --- a/builtins/command.def +++ b/builtins/command.def @@ -62,7 +62,9 @@ extern size_t confstr __P((int, char *, size_t)); extern int subshell_environment; +#if 0 static void restore_path __P((char *)); +#endif /* Run the commands mentioned in LIST without paying attention to shell functions. */ @@ -71,7 +73,6 @@ command_builtin (list) WORD_LIST *list; { int result, verbose, use_standard_path, opt; - char *old_path, *standard_path; COMMAND *command; verbose = use_standard_path = 0; @@ -145,6 +146,7 @@ command_builtin (list) return (result); } +#if 0 /* Restore the value of the $PATH variable after replacing it when executing `command -p'. */ static void @@ -161,3 +163,4 @@ restore_path (var) stupidly_hack_special_variables ("PATH"); } +#endif diff --git a/builtins/common.c b/builtins/common.c index b100ebe..c616b17 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -823,7 +823,7 @@ display_signal_list (list, forcecols) DISABLED_OKAY means find it even if the builtin is disabled. */ struct builtin * builtin_address_internal (name, disabled_okay) - char *name; + const char *name; int disabled_okay; { int hi, lo, mid, j; diff --git a/builtins/common.h b/builtins/common.h index ed85230..9886c34 100644 --- a/builtins/common.h +++ b/builtins/common.h @@ -130,7 +130,7 @@ extern int display_signal_list __P((WORD_LIST *, int)); /* It's OK to declare a function as returning a Function * without providing a definition of what a `Function' is. */ -extern struct builtin *builtin_address_internal __P((char *, int)); +extern struct builtin *builtin_address_internal __P((const char *, int)); extern sh_builtin_func_t *find_shell_builtin __P((char *)); extern sh_builtin_func_t *builtin_address __P((char *)); extern sh_builtin_func_t *find_special_builtin __P((char *)); diff --git a/builtins/declare.def b/builtins/declare.def index f4819b4..2ee526b 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -290,7 +290,7 @@ declare_internal (list, local_var) int offset, aflags, wflags, created_var, namelen; #if defined (ARRAY_VARS) int making_array_special, compound_array_assign, simple_array_assign; - int var_exists, array_exists, creating_array, array_subscript_assignment; + int array_exists, creating_array, array_subscript_assignment; #endif name = savestring (list->word->word); @@ -359,7 +359,7 @@ declare_internal (list, local_var) restart_new_var_name: #if defined (ARRAY_VARS) - var_exists = array_exists = creating_array = 0; + array_exists = creating_array = 0; compound_array_assign = simple_array_assign = 0; array_subscript_assignment = 0; subscript_start = (char *)NULL; @@ -645,7 +645,6 @@ restart_new_var_name: var = mkglobal ? find_global_variable (name) : find_variable (name); #if defined (ARRAY_VARS) - var_exists = var != 0; array_exists = var && (array_p (var) || assoc_p (var)); creating_array = flags_on & (att_array|att_assoc); #endif diff --git a/builtins/enable.def b/builtins/enable.def index 39c3669..dfba615 100644 --- a/builtins/enable.def +++ b/builtins/enable.def @@ -111,7 +111,7 @@ enable_builtin (list) int result, flags; int opt, filter; #if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM) - char *filename; + char *filename = NULL; #endif result = EXECUTION_SUCCESS; @@ -322,7 +322,7 @@ dyn_load_builtin (list, flags, filename) #if defined (_AIX) handle = dlopen (load_path, RTLD_NOW|RTLD_GLOBAL); #else - handle = dlopen (load_path, RTLD_LAZY); + handle = dlopen (load_path, RTLD_NOW); #endif /* !_AIX */ free (load_path); } @@ -334,7 +334,7 @@ dyn_load_builtin (list, flags, filename) #if defined (_AIX) handle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL); #else - handle = dlopen (filename, RTLD_LAZY); + handle = dlopen (filename, RTLD_NOW); #endif /* !_AIX */ if (handle == 0) diff --git a/builtins/evalfile.c b/builtins/evalfile.c index 316b794..5b7b31e 100644 --- a/builtins/evalfile.c +++ b/builtins/evalfile.c @@ -92,7 +92,7 @@ _evalfile (filename, flags) size_t file_size; sh_vmsg_func_t *errfunc; #if defined (ARRAY_VARS) - SHELL_VAR *funcname_v, *nfv, *bash_source_v, *bash_lineno_v; + SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v; ARRAY *funcname_a, *bash_source_a, *bash_lineno_a; struct func_array_state *fa; # if defined (DEBUGGER) diff --git a/builtins/fc.def b/builtins/fc.def index fe16471..b81b86e 100644 --- a/builtins/fc.def +++ b/builtins/fc.def @@ -33,7 +33,7 @@ string. Options: -e ENAME select which editor to use. Default is FCEDIT, then EDITOR, - then vi + then vitmp -l list lines instead of editing -n omit line numbers when listing -r reverse the order of the lines (newest listed first) @@ -111,7 +111,7 @@ extern FILE *sh_mktmpfp __P((char *, int, char **)); -e ENAME selects which editor to use. Default is FCEDIT, then EDITOR, then the editor which corresponds to the current readline editing - mode, then vi. + mode, then vitmp. -l means list lines instead of editing. -n means no line numbers listed. @@ -165,7 +165,7 @@ set_verbose_flag () } /* String to execute on a file that we want to edit. */ -#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}" +#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vitmp}}" #if defined (STRICT_POSIX) # define POSIX_FC_EDIT_COMMAND "${FCEDIT:-ed}" #else @@ -391,7 +391,7 @@ fc_builtin (list) else { numbering = 0; - stream = sh_mktmpfp ("bash-fc", MT_USERANDOM|MT_USETMPDIR, &fn); + stream = sh_mktmpfp ("bash-fc", MT_USETMPDIR, &fn); if (stream == 0) { builtin_error (_("%s: cannot open temp file: %s"), fn ? fn : "", strerror (errno)); diff --git a/builtins/gen-helpfiles.c b/builtins/gen-helpfiles.c index fac34ed..40b2367 100644 --- a/builtins/gen-helpfiles.c +++ b/builtins/gen-helpfiles.c @@ -153,7 +153,7 @@ int write_helpfiles (builtins) struct builtin *builtins; { - char *helpfile, *bname, *fname; + char *helpfile, *fname; FILE *helpfp; int i, hdlen; struct builtin b; diff --git a/builtins/help.def b/builtins/help.def index 95a1a36..507b672 100644 --- a/builtins/help.def +++ b/builtins/help.def @@ -421,7 +421,6 @@ wdispcolumn (i, buf, bufsize, width, height) char *helpdoc; wchar_t *wcstr; size_t slen, n; - int wclen; /* first column */ helpdoc = _(shell_builtins[i].short_doc); @@ -518,7 +517,7 @@ wdispcolumn (i, buf, bufsize, width, height) static void show_builtin_command_help () { - int i, j; + int i; int height, width; char *t, blurb[128]; diff --git a/builtins/history.def b/builtins/history.def index 48b59ae..41c50b8 100644 --- a/builtins/history.def +++ b/builtins/history.def @@ -105,7 +105,7 @@ history_builtin (list) WORD_LIST *list; { int flags, opt, result, old_history_lines, obase; - char *filename, *delete_arg; + char *filename, *delete_arg = 0; intmax_t delete_offset; flags = 0; diff --git a/builtins/mapfile.def b/builtins/mapfile.def index 0d64f61..d5c6b5d 100644 --- a/builtins/mapfile.def +++ b/builtins/mapfile.def @@ -244,12 +244,11 @@ int mapfile_builtin (list) WORD_LIST *list; { - int opt, code, fd, clear_array, flags; + int opt, code, fd, flags; intmax_t intval; long lines, origin, nskip, callback_quantum; char *array_name, *callback; - clear_array = 1; fd = 0; lines = origin = nskip = 0; flags = MAPF_CLEARARRAY; diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c index 4f51201..e3605c6 100644 --- a/builtins/mkbuiltins.c +++ b/builtins/mkbuiltins.c @@ -69,10 +69,15 @@ extern char *strcpy (); #define whitespace(c) (((c) == ' ') || ((c) == '\t')) /* Flag values that builtins can have. */ +/* These flags are for the C code generator, + the C which is produced (./builtin.c) + includes the flags definitions found + in ../builtins.h */ #define BUILTIN_FLAG_SPECIAL 0x01 #define BUILTIN_FLAG_ASSIGNMENT 0x02 #define BUILTIN_FLAG_LOCALVAR 0x04 #define BUILTIN_FLAG_POSIX_BUILTIN 0x08 +#define BUILTIN_FLAG_REQUIRES 0x10 #define BASE_INDENT 4 @@ -173,11 +178,22 @@ char *posix_builtins[] = (char *)NULL }; +/* The builtin commands that cause requirements on other files. */ +static char *requires_builtins[] = +{ + ".", "command", "exec", "source", +#if defined (apollo) + "inlib", +#endif + (char *)NULL +}; + /* Forward declarations. */ static int is_special_builtin (); static int is_assignment_builtin (); static int is_localvar_builtin (); static int is_posix_builtin (); +static int is_requires_builtin (); #if !defined (HAVE_RENAME) static int rename (); @@ -831,6 +847,8 @@ builtin_handler (self, defs, arg) new->flags |= BUILTIN_FLAG_LOCALVAR; if (is_posix_builtin (name)) new->flags |= BUILTIN_FLAG_POSIX_BUILTIN; + if (is_requires_builtin (name)) + new->flags |= BUILTIN_FLAG_REQUIRES; array_add ((char *)new, defs->builtins); building_builtin = 1; @@ -1250,12 +1268,13 @@ write_builtins (defs, structfile, externfile) else fprintf (structfile, "(sh_builtin_func_t *)0x0, "); - fprintf (structfile, "%s%s%s%s%s, %s_doc,\n", + fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n", "BUILTIN_ENABLED | STATIC_BUILTIN", (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "", (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "", (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "", (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "", + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "", document_name (builtin)); /* Don't translate short document summaries that are identical @@ -1645,6 +1664,13 @@ is_posix_builtin (name) return (_find_in_table (name, posix_builtins)); } +static int +is_requires_builtin (name) + char *name; +{ + return (_find_in_table (name, requires_builtins)); +} + #if !defined (HAVE_RENAME) static int rename (from, to) diff --git a/builtins/psize.sh b/builtins/psize.sh index 29bc115..815d197 100644 --- a/builtins/psize.sh +++ b/builtins/psize.sh @@ -3,19 +3,10 @@ # psize.sh -- determine this system's pipe size, and write a define to # pipesize.h so ulimit.c can use it. -: ${TMPDIR:=/tmp} -# try to use mktemp(1) if the system supports it -{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null -used_mktemp=true +TMPFILE="`mktemp -t pipsize.XXXXXXXXXX`" || exit 1 -if [ -z "$TMPFILE" ]; then - TMPNAME=pipsize.$$ - TMPFILE=$TMPDIR/$TMPNAME - used_mktemp=false -fi - -trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15 -trap 'rm -f "$TMPFILE"' 0 +trap 'rm -f -- "$TMPFILE"; exit 1' 1 2 3 6 15 +trap 'rm -f -- "$TMPFILE"' 0 echo "/*" echo " * pipesize.h" @@ -25,15 +16,6 @@ echo " * Do not edit!" echo " */" echo "" -# -# Try to avoid tempfile races. We can't really check for the file's -# existence before we run psize.aux, because `test -e' is not portable, -# `test -h' (test for symlinks) is not portable, and `test -f' only -# checks for regular files. If we used mktemp(1), we're ahead of the -# game. -# -$used_mktemp || rm -f "$TMPFILE" - ./psize.aux 2>"$TMPFILE" | sleep 3 if [ -s "$TMPFILE" ]; then diff --git a/builtins/set.def b/builtins/set.def index 8122361..5dee21a 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -847,7 +847,7 @@ unset_builtin (list) while (list) { SHELL_VAR *var; - int tem; + int tem = 0; #if defined (ARRAY_VARS) char *t; #endif diff --git a/builtins/setattr.def b/builtins/setattr.def index 8f29e11..22d091e 100644 --- a/builtins/setattr.def +++ b/builtins/setattr.def @@ -539,7 +539,7 @@ set_var_attribute (name, attribute, undo) int attribute, undo; { SHELL_VAR *var, *tv, *v, *refvar; - char *tvalue, *refname; + char *tvalue; if (undo) var = find_variable (name); @@ -611,4 +611,7 @@ set_var_attribute (name, attribute, undo) if (var && (exported_p (var) || (attribute & att_exported))) array_needs_making++; /* XXX */ + + if (var) + stupidly_hack_special_variables (name); } diff --git a/builtins/shopt.def b/builtins/shopt.def index 2febb7e..ec2fdec 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -104,6 +104,7 @@ extern int dircomplete_spelling, dircomplete_expand; extern int complete_fullquote; extern int enable_hostname_completion __P((int)); +static int shopt_enable_hostname_completion __P((char *, int)); #endif #if defined (PROGRAMMABLE_COMPLETION) @@ -121,7 +122,6 @@ extern int debugging_mode; static void shopt_error __P((char *)); static int set_shellopts_after_change __P((char *, int)); -static int shopt_enable_hostname_completion __P((char *, int)); static int set_compatibility_level __P((char *, int)); #if defined (RESTRICTED_SHELL) @@ -576,6 +576,7 @@ shopt_set_debug_mode (option_name, mode) return (0); } +#if defined (READLINE) static int shopt_enable_hostname_completion (option_name, mode) char *option_name; @@ -583,6 +584,7 @@ shopt_enable_hostname_completion (option_name, mode) { return (enable_hostname_completion (mode)); } +#endif static int set_compatibility_level (option_name, mode) @@ -745,7 +747,7 @@ set_bashopts () { char *value; char tflag[N_SHOPT_OPTIONS]; - int vsize, i, vptr, *ip, exported; + int vsize, i, vptr, exported; SHELL_VAR *v; for (vsize = i = 0; shopt_vars[i].name; i++) diff --git a/builtins/test.def b/builtins/test.def index d6c89bf..02eb66d 100644 --- a/builtins/test.def +++ b/builtins/test.def @@ -64,6 +64,9 @@ File operators: FILE1 -ef FILE2 True if file1 is a hard link to file2. +All file operators except -h and -L are acting on the target of a symbolic +link, not on the symlink itself, if FILE is a symbolic link. + String operators: -z STRING True if string is empty. @@ -97,6 +100,9 @@ Arithmetic binary operators return true if ARG1 is equal, not-equal, less-than, less-than-or-equal, greater-than, or greater-than-or-equal than ARG2. +See the bash manual page bash(1) for the handling of parameters (i.e. +missing parameters). + Exit Status: Returns success if EXPR evaluates to true; fails if EXPR evaluates to false or an invalid argument is given. diff --git a/builtins/ulimit.def b/builtins/ulimit.def index 62def4f..bd3ecd5 100644 --- a/builtins/ulimit.def +++ b/builtins/ulimit.def @@ -215,7 +215,9 @@ static int set_limit __P((int, RLIMTYPE, int)); static void printone __P((int, RLIMTYPE, int)); static void print_all_limits __P((int)); +#ifdef NOTYET static int set_all_limits __P((int, RLIMTYPE)); +#endif static int filesize __P((RLIMTYPE *)); static int pipesize __P((RLIMTYPE *)); @@ -755,6 +757,7 @@ printone (limind, curlim, pdesc) print_rlimtype ((curlim / factor), 1); } +#ifdef NOTYET /* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which causes all limits to be set as high as possible depending on mode (like csh `unlimit'). Returns -1 if NEWLIM is invalid, 0 if all limits @@ -794,5 +797,6 @@ set_all_limits (mode, newlim) } return retval; } +#endif #endif /* !_MINIX */ diff --git a/config-top.h b/config-top.h index d89682e..51af983 100644 --- a/config-top.h +++ b/config-top.h @@ -63,14 +63,14 @@ /* The default value of the PATH variable. */ #ifndef DEFAULT_PATH_VALUE #define DEFAULT_PATH_VALUE \ - "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:." + "/bin:/usr/bin:/usr/local/bin" #endif /* The value for PATH when invoking `command -p'. This is only used when the Posix.2 confstr () function, or CS_PATH define are not present. */ #ifndef STANDARD_UTILS_PATH #define STANDARD_UTILS_PATH \ - "/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc" + "/bin:/usr/bin:/sbin:/usr/sbin" #endif /* Default primary and secondary prompt strings. */ @@ -94,13 +94,13 @@ /* Define this to make non-interactive shells begun with argv[0][0] == '-' run the startup files when not in posix mode. */ -/* #define NON_INTERACTIVE_LOGIN_SHELLS */ +#define NON_INTERACTIVE_LOGIN_SHELLS /* Define this if you want bash to try to check whether it's being run by sshd and source the .bashrc if so (like the rshd behavior). This checks for the presence of SSH_CLIENT or SSH2_CLIENT in the initial environment, which can be fooled under certain not-uncommon circumstances. */ -/* #define SSH_SOURCE_BASHRC */ +#define SSH_SOURCE_BASHRC /* Define if you want the case-capitalizing operators (~[~]) and the `capcase' variable attribute (declare -c). */ @@ -130,7 +130,7 @@ /* Define to 0 if you want the checkwinsize option off by default, 1 if you want it on. */ -#define CHECKWINSIZE_DEFAULT 0 +#define CHECKWINSIZE_DEFAULT 1 /* Define to 1 if you want to optimize for sequential array assignment when using indexed arrays, 0 if you want bash-4.2 behavior, which favors @@ -143,7 +143,7 @@ /* Define to 1 if you want the shell to exit if it is running setuid and its attempt to drop privilege using setuid(getuid()) fails with errno == EAGAIN */ -/* #define EXIT_ON_SETUID_FAILURE 1 */ +#define EXIT_ON_SETUID_FAILURE 1 /* Define to 1 if you want the shell to re-check $PATH if a hashed filename no longer exists. This behavior is the default in Posix mode. */ diff --git a/config.h.in b/config.h.in index a5ad9e7..1259b29 100644 --- a/config.h.in +++ b/config.h.in @@ -244,7 +244,7 @@ /* System paths */ -#define DEFAULT_MAIL_DIRECTORY "/usr/spool/mail" +#define DEFAULT_MAIL_DIRECTORY "/var/mail" /* Characteristics of the system's header files and libraries that affect the compilation environment. */ @@ -449,6 +449,7 @@ #undef SYS_TIME_H_DEFINES_STRUCT_TIMESPEC #undef PTHREAD_H_DEFINES_STRUCT_TIMESPEC +#undef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC #undef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC #undef HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC #undef HAVE_STRUCT_STAT_ST_ATIMENSEC diff --git a/configure.ac b/configure.ac index ce4e9b6..7e7d034 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ AC_REVISION([for Bash 4.4, version 4.082])dnl define(bashvers, 4.4) define(relstatus, release) -AC_INIT([bash], bashvers-relstatus, [bug-bash@gnu.org]) +AC_INIT([bash4], bashvers-relstatus, [bug-bash@gnu.org]) dnl make sure we are using a recent autoconf version AC_PREREQ(2.61) @@ -361,7 +361,7 @@ fi HELPDIR= HELPDIRDEFINE= HELPINSTALL= HELPFILES_TARGET= if test "$opt_separate_help" != no; then if test "$opt_separate_help" = "yes" ; then - HELPDIR='${datadir}/bash' + HELPDIR='${datadir}/AC_PACKAGE_NAME' else HELPDIR=$opt_separate_help fi @@ -464,7 +464,7 @@ CFLAGS=${CFLAGS-"$AUTO_CFLAGS"} # turn off paren warnings in gcc if test "$GCC" = yes # && test -n "$DEBUG" then - CFLAGS="$CFLAGS -Wno-parentheses -Wno-format-security" + CFLAGS="$CFLAGS -Wno-parentheses" fi dnl handle options that alter how bash is compiled and linked @@ -1092,9 +1092,8 @@ solaris2.10*) LOCAL_CFLAGS=-DSOLARIS ;; solaris2*) LOCAL_CFLAGS=-DSOLARIS ;; lynxos*) LOCAL_CFLAGS=-DRECYCLES_PIDS ;; linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading - case "`uname -r`" in - 2.[[456789]]*|[[34]]*) AC_DEFINE(PGRP_PIPE) ;; - esac ;; + LOCAL_CFLAGS=-DRECYCLES_PIDS + AC_DEFINE(PGRP_PIPE) ;; *qnx6*) LOCAL_CFLAGS="-Dqnx -Dqnx6" LOCAL_LIBS="-lncurses" ;; *qnx*) LOCAL_CFLAGS="-Dqnx -F -3s" LOCAL_LDFLAGS="-3s" LOCAL_LIBS="-lunix -lncurses" ;; powerux*) LOCAL_LIBS="-lgen" ;; diff --git a/doc/Makefile.in b/doc/Makefile.in index 5f0756c..854f988 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -74,7 +74,6 @@ TEXI2DVI = ${SUPPORT_SRCDIR}/texi2dvi TEXI2HTML = ${SUPPORT_SRCDIR}/texi2html MAN2HTML = ${BUILD_DIR}/support/man2html HTMLPOST = ${srcdir}/htmlpost.sh -INFOPOST = ${srcdir}/infopost.sh QUIETPS = #set this to -q to shut up dvips PAPERSIZE = letter # change to a4 for A4-size paper PSDPI = 600 # could be 300 if you like @@ -188,8 +187,8 @@ bashref.pdf: $(BASHREF_FILES) $(HSUSER) $(RLUSER) bashref.html: $(BASHREF_FILES) $(HSUSER) $(RLUSER) $(MAKEINFO) --html --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi -bash.info: bashref.info - ${SHELL} ${INFOPOST} < $(srcdir)/bashref.info > $@ ; \ +bash.info: $(BASHREF_FILES) $(HSUSER) $(RLUSER) + $(MAKEINFO) --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi -o $@ bash.txt: bash.1 bash.ps: bash.1 @@ -249,12 +248,13 @@ installdirs: install: info installdirs -$(INSTALL_DATA) $(srcdir)/bash.1 $(DESTDIR)$(man1dir)/bash${man1ext} + -$(INSTALL_DATA) $(srcdir)/rbash.1 $(DESTDIR)$(man1dir)/rbash${man1ext} -$(INSTALL_DATA) $(srcdir)/bashbug.1 $(DESTDIR)$(man1dir)/bashbug${man1ext} -$(INSTALL_DATA) $(OTHER_DOCS) $(DESTDIR)$(docdir) # uncomment the next lines to install the builtins man page -# sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1 -# -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext} -# -$(RM) $${TMPDIR:-/var/tmp}/builtins.1 + sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1 + -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext} + -$(RM) $${TMPDIR:-/var/tmp}/builtins.1 -if test -f bash.info; then d=.; else d=$(srcdir); fi; \ $(INSTALL_DATA) $$d/bash.info $(DESTDIR)$(infodir)/bash.info # run install-info if it is present to update the info directory diff --git a/doc/bash.1 b/doc/bash.1 index 9a7a384..477cf4a 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -8,6 +8,22 @@ .\" Last Change: Fri Aug 26 09:45:10 EDT 2016 .\" .\" bash_builtins, strip all but Built-Ins section +.de zZ +.. +.de zY +.. +.\" +.\" File Name macro. This used to be `.PN', for Path Name, +.\" but Sun doesn't seem to like that very much. +.\" +.de FN +\fI\|\\$1\|\fP +.. +.\" Number register zZ is defined in bash-builtins(7) +.\" Number register zY is defined in rbash(1) +.\" This man-page is included in them +.if !rzZ .nr zZ 0 \" avoid a warning about an undefined register +.if !rzY .nr zY 0 \" avoid a warning about an undefined register .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY .TH BASH 1 "2016 August 26" "GNU Bash 4.4" @@ -36,13 +52,6 @@ .el \\*(]X\h|\\n()Iu+\\n()Ru\c .}f .. -.\" -.\" File Name macro. This used to be `.PN', for Path Name, -.\" but Sun doesn't seem to like that very much. -.\" -.de FN -\fI\|\\$1\|\fP -.. .SH NAME bash \- GNU Bourne-Again SHell .SH SYNOPSIS @@ -121,6 +130,18 @@ processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell. .TP +.B \-v +Print shell input lines as they are read. +.TP +.B \-x +After expanding each \fIsimple command\fP, +\fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or +arithmetic \fBfor\fP command, display the expanded value of +.SM +.BR PS4 , +followed by the command and its expanded arguments +or associated word list. +.TP .B \-D A list of all double-quoted strings preceded by \fB$\fP is printed on the standard output. @@ -238,6 +259,14 @@ The shell becomes restricted (see .B "RESTRICTED SHELL" below). .TP +.B \-\-rpm\-requires +Produce the list of files that are required for the +shell script to run. This implies '-n' and is subject +to the same limitations as compile time error checking; +command substitutions, conditional expressions, and +.B eval +builtin are not parsed so some dependencies may be missed. +.TP .B \-\-verbose Equivalent to \fB\-v\fP. .TP @@ -711,6 +740,11 @@ as primaries. .if n .sp 1 When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort lexicographically using the current locale. +.PP +See the description of the +.B test +builtin command (section SHELL BUILTIN COMMANDS below) +for the handling of parameters (i.e. missing parameters). .if t .sp 0.5 .if n .sp 1 When the \fB==\fP and \fB!=\fP operators are used, the string to the @@ -2045,7 +2079,9 @@ A filename whose suffix matches one of the entries in is excluded from the list of matched filenames. A sample value is .if t \f(CW".o:~"\fP. -.if n ".o:~". +.if n ".o:~" +(Quoting is needed when assigning a value to this variable, +which contains tildes). .TP .B FUNCNEST If set to a numeric value greater than 0, defines a maximum function @@ -2326,8 +2362,8 @@ and is set by the administrator who installs .BR bash . A common value is .na -.if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP. -.if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. +.if t \f(CW/usr/local/bin:\:/usr/local/sbin:\:/usr/bin:\:/usr/sbin:\:/bin:\:/sbin\fP. +.if n ``/usr/local/bin:\:/usr/local/sbin:\:/usr/bin:\:/usr/sbin:\:/bin:\:/sbin''. .ad .TP .B POSIXLY_CORRECT @@ -3285,6 +3321,9 @@ and the substitution of the result. The format for arithmetic expansion is: \fB$((\fP\fIexpression\fP\fB))\fP .RE .PP +The old format \fB$[\fP\fIexpression\fP\fB]\fP is deprecated and will +be removed in upcoming versions of bash. +.PP The .I expression is treated as if it were within double quotes, but a double quote @@ -3762,6 +3801,15 @@ the corresponding UDP socket. .PD .RE .PP +.BR NOTE : +this Bash build does +.B not +support +.B /dev/tcp/\fIhost\fP/\fIport\fP +and +.B /dev/udp/\fIhost\fP/\fIport\fP +redirections. +.PP A failure to open or create a file causes the redirection to fail. .PP Redirections using file descriptors greater than 9 should be used with @@ -8128,7 +8176,7 @@ if .SM .B FCEDIT is not set. If neither variable is set, -.FN vi +.FN vitmp is used. When editing is complete, the edited commands are echoed and executed. .sp 1 @@ -10118,7 +10166,7 @@ being inverted using These are the same conditions obeyed by the \fBerrexit\fP (\fB\-e\fP) option. .if t .sp 0.5 .if n .sp 1 -Signals ignored upon entry to the shell cannot be trapped or reset. +Signals ignored upon entry to the shell cannot be trapped, reset, or listed. Trapped signals that are not being ignored are reset to their original values in a subshell or subshell environment when one is created. The return status is false if any diff --git a/doc/bashbug.1 b/doc/bashbug.1 index 61d9122..e04938e 100644 --- a/doc/bashbug.1 +++ b/doc/bashbug.1 @@ -43,9 +43,8 @@ Specifies the preferred editor. If .B EDITOR is not set, .B bashbug -attempts to locate a number of alternative editors, including -.BR emacs , -and defaults to \fBvi\fP. +defaults to an instance of +.BR vi . .TP .B HOME Directory in which the failed bug report is saved if the mail fails. diff --git a/doc/bashref.texi b/doc/bashref.texi index c0f4a2f..6d120dc 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -2625,6 +2625,10 @@ is an integer port number or service name, Bash attempts to open the corresponding UDP socket. @end table +NOTE: this @code{Bash} build does not support +@file{/dev/tcp/@var{host}/@var{port}} and @file{/dev/udp/@var{host}/@var{port}} +redirections. + A failure to open or create a file causes the redirection to fail. Redirections using file descriptors greater than 9 should be used with @@ -3771,7 +3775,7 @@ status is being inverted using @code{!}. These are the same conditions obeyed by the @code{errexit} (@option{-e}) option. -Signals ignored upon entry to the shell cannot be trapped or reset. +Signals ignored upon entry to the shell cannot be trapped, reset, or listed. Trapped signals that are not being ignored are reset to their original values in a subshell or subshell environment when one is created. @@ -6243,6 +6247,13 @@ standard. @xref{Bash POSIX Mode}, for a description of the Bash @item --restricted Make the shell a restricted shell (@pxref{The Restricted Shell}). +@item --rpm-requires +Produce the list of files that are required for the +shell script to run. This implies '-n' and is subject +to the same limitations as compile time error checking; +command substitutions, conditional expressions, and @code{eval} +builtin are not parsed so some dependencies may be missed. + @item --verbose Equivalent to @option{-v}. Print shell input lines as they're read. @@ -6639,6 +6650,10 @@ The @code{test} command uses ASCII ordering. Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself. +See the description of the @code{test} builtin command (section +@pxref{Bash Builtins} below) for the handling of parameters +(i.e. missing parameters). + @table @code @item -a @var{file} True if @var{file} exists. diff --git a/doc/builtins.1 b/doc/builtins.1 index 829a49c..3ca6ad3 100644 --- a/doc/builtins.1 +++ b/doc/builtins.1 @@ -16,9 +16,10 @@ export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, -ulimit, umask, unalias, unset, wait \- bash built-in commands, see \fBbash\fR(1) +ulimit, umask, unalias, unset, wait \- bash built-in commands .SH BASH BUILTIN COMMANDS .nr zZ 1 .so bash.1 .SH SEE ALSO -bash(1), sh(1) +.BR bash (1), +.BR sh (1) diff --git a/doc/rbash.1 b/doc/rbash.1 index 56e38fd..5e21d57 100644 --- a/doc/rbash.1 +++ b/doc/rbash.1 @@ -1,8 +1,8 @@ .TH RBASH 1 "2004 Apr 20" "GNU Bash-4.0" .SH NAME -rbash \- restricted bash, see \fBbash\fR(1) +rbash \- restricted bash .SH RESTRICTED SHELL .nr zY 1 .so bash.1 .SH SEE ALSO -bash(1) +.BR bash (1) diff --git a/error.c b/error.c index b05c39e..46f7994 100644 --- a/error.c +++ b/error.c @@ -146,7 +146,6 @@ programming_error (format, va_alist) #endif { va_list args; - char *h; #if defined (JOB_CONTROL) give_terminal_to (shell_pgrp, 0); @@ -161,7 +160,7 @@ programming_error (format, va_alist) #if defined (HISTORY) if (remember_on_history) { - h = last_history_line (); + char *h = last_history_line (); fprintf (stderr, _("last command: %s\n"), h ? h : "(null)"); } #endif @@ -362,7 +361,7 @@ parser_error (lineno, format, va_alist) exit_shell (last_command_exit_value = 2); } -#ifdef DEBUG +#if 0 /* This assumes ASCII and is suitable only for debugging */ char * strescape (str) @@ -431,7 +430,7 @@ trace (format, va_alist) static FILE *tracefp = (FILE *)NULL; if (tracefp == NULL) - tracefp = fopen("/tmp/bash-trace.log", "a+"); + tracefp = fopen("/var/run/bash-trace.log", "a+"); if (tracefp == NULL) tracefp = stderr; diff --git a/eval.c b/eval.c index db863e7..918b27d 100644 --- a/eval.c +++ b/eval.c @@ -55,6 +55,7 @@ extern int last_command_exit_value, stdin_redir; extern int need_here_doc; extern int current_command_number, current_command_line_count, line_number; extern int expand_aliases; +extern int rpm_requires; extern char *ps0_prompt; #if defined (HAVE_POSIX_SIGNALS) @@ -148,7 +149,7 @@ reader_loop () if (read_command () == 0) { - if (interactive_shell == 0 && read_but_dont_execute) + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires)) { last_command_exit_value = EXECUTION_SUCCESS; dispose_command (global_command); diff --git a/examples/loadables/finfo.c b/examples/loadables/finfo.c index 00833f6..06c26f2 100644 --- a/examples/loadables/finfo.c +++ b/examples/loadables/finfo.c @@ -27,6 +27,7 @@ # include #endif +#include #include #include "posixstat.h" #include @@ -102,7 +103,7 @@ int argc; char **argv; { register int i; - int mode, flags, opt; + int flags, opt; sh_optind = 0; /* XXX */ prog = base_pathname(argv[0]); @@ -283,7 +284,7 @@ struct stat *st; #endif printf("Device (major/minor): %d (%d/%d)\n", d, ma, mi); - printf("Inode: %d\n", (int) st->st_ino); + printf("Inode: %llu\n", (unsigned long long) st->st_ino); printf("Mode: (%o) ", (int) st->st_mode); printmode((int) st->st_mode); printf("Link count: %d\n", (int) st->st_nlink); @@ -334,13 +335,14 @@ int flags; else printf("%ld\n", st->st_ctime); } else if (flags & OPT_DEV) - printf("%d\n", st->st_dev); + printf("%llu\n", (unsigned long long) st->st_dev); else if (flags & OPT_INO) - printf("%d\n", st->st_ino); + printf("%llu\n", (unsigned long long) st->st_ino); else if (flags & OPT_FID) - printf("%d:%ld\n", st->st_dev, st->st_ino); + printf("%llu:%llu\n", (unsigned long long) st->st_dev, + (unsigned long long) st->st_ino); else if (flags & OPT_NLINK) - printf("%d\n", st->st_nlink); + printf("%llu\n", (unsigned long long) st->st_nlink); else if (flags & OPT_LNKNAM) { #ifdef S_ISLNK b = xmalloc(4096); @@ -390,7 +392,6 @@ finfo_builtin(list) { int c, r; char **v; - WORD_LIST *l; v = make_builtin_argv (list, &c); r = finfo_main (c, v); diff --git a/examples/loadables/head.c b/examples/loadables/head.c index 748bb83..144f66b 100644 --- a/examples/loadables/head.c +++ b/examples/loadables/head.c @@ -99,8 +99,6 @@ head_builtin (list) WORD_LIST *l; FILE *fp; - char *t; - munge_list (list); /* change -num into -n num */ reset_internal_getopt (); diff --git a/examples/loadables/id.c b/examples/loadables/id.c index 8773349..5cc2770 100644 --- a/examples/loadables/id.c +++ b/examples/loadables/id.c @@ -64,8 +64,6 @@ static int id_flags; static uid_t ruid, euid; static gid_t rgid, egid; -static char *id_user; - static int inituser (); static int id_pruser (); diff --git a/examples/loadables/mkdir.c b/examples/loadables/mkdir.c index 39ae07f..df5ffeb 100644 --- a/examples/loadables/mkdir.c +++ b/examples/loadables/mkdir.c @@ -136,7 +136,6 @@ make_path (path, nmode, parent_mode) char *path; int nmode, parent_mode; { - int oumask; struct stat sb; char *p, *npath; @@ -157,7 +156,7 @@ make_path (path, nmode, parent_mode) return 0; } - oumask = umask (0); + umask (0); npath = savestring (path); /* So we can write to it. */ /* Check whether or not we need to do anything with intermediate dirs. */ diff --git a/examples/loadables/print.c b/examples/loadables/print.c index e17597b..8b42912 100644 --- a/examples/loadables/print.c +++ b/examples/loadables/print.c @@ -77,7 +77,7 @@ print_builtin (list) { int c, r, nflag, raw, ofd, sflag; intmax_t lfd; - char **v, *pfmt, *arg; + char *pfmt; WORD_LIST *l; nflag = raw = sflag = 0; diff --git a/examples/loadables/tee.c b/examples/loadables/tee.c index 9462cda..d3489c6 100644 --- a/examples/loadables/tee.c +++ b/examples/loadables/tee.c @@ -69,8 +69,6 @@ tee_builtin (list) FLIST *fl; char *buf, *bp; - char *t; - reset_internal_getopt (); append = nointr = 0; tee_flist = (FLIST *)NULL; diff --git a/examples/loadables/uname.c b/examples/loadables/uname.c index 339ec3d..67c7f23 100644 --- a/examples/loadables/uname.c +++ b/examples/loadables/uname.c @@ -67,7 +67,7 @@ int uname_builtin (list) WORD_LIST *list; { - int opt, r; + int opt; struct utsname uninfo; uname_flags = 0; diff --git a/execute_cmd.c b/execute_cmd.c index 76a8076..fd97199 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -529,6 +529,8 @@ async_redirect_stdin () #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0) +extern int rpm_requires; + /* Execute the command passed in COMMAND, perhaps doing it asynchronously. COMMAND is exactly what read_command () places into GLOBAL_COMMAND. ASYNCHROUNOUS, if non-zero, says to do this command in the background. @@ -552,16 +554,23 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, int exec_result, user_subshell, invert, ignore_return, was_error_trap; REDIRECT *my_undo_list, *exec_undo_list; char *tcmd; - volatile int last_pid; volatile int save_line_number; #if defined (PROCESS_SUBSTITUTION) volatile int ofifo, nfifo, osize, saved_fifo; - volatile char *ofifo_list; + volatile char *ofifo_list = 0; #endif if (breaking || continuing) return (last_command_exit_value); - if (command == 0 || read_but_dont_execute) + if (command == 0 || (read_but_dont_execute && !rpm_requires)) + return (EXECUTION_SUCCESS); + + if (rpm_requires && command->type == cm_function_def) + return last_command_exit_value = + execute_intern_function (command->value.Function_def->name, + command->value.Function_def); + + if (read_but_dont_execute) return (EXECUTION_SUCCESS); QUIT; @@ -795,7 +804,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, #if defined (RECYCLES_PIDS) last_made_pid = NO_PID; #endif - last_pid = last_made_pid; was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0; if (ignore_return && command->value.Simple) @@ -1090,6 +1098,8 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, # endif set_pipestatus_from_exit (exec_result); break; + default: + break; } #endif @@ -1673,6 +1683,7 @@ typedef struct cplist } cplist_t; +#if MULTIPLE_COPROCS static struct cpelement *cpe_alloc __P((struct coproc *)); static void cpe_dispose __P((struct cpelement *)); static struct cpelement *cpl_add __P((struct coproc *)); @@ -1682,13 +1693,16 @@ static void cpl_flush __P((void)); static void cpl_closeall __P((void)); static struct cpelement *cpl_search __P((pid_t)); static struct cpelement *cpl_searchbyname __P((const char *)); +#if 0 static void cpl_prune __P((void)); - +#endif static void coproc_free __P((struct coproc *)); +#endif /* Will go away when there is fully-implemented support for multiple coprocs. */ Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0, 0, 0, 0 }; +#if MULTIPLE_COPROCS cplist_t coproc_list = {0, 0, 0}; /* Functions to manage the list of coprocs */ @@ -1879,6 +1893,7 @@ cpl_searchbyname (name) return cp; return (struct cpelement *)NULL; } +#endif #if 0 static void @@ -1964,12 +1979,14 @@ coproc_alloc (name, pid) return (cp); } +#if MULTIPLE_COPROCS static void coproc_free (cp) struct coproc *cp; { free (cp); } +#endif void coproc_dispose (cp) @@ -3003,7 +3020,7 @@ execute_arith_for_command (arith_for_command) #endif #if defined (SELECT_COMMAND) -static int LINES, COLS, tabsize; +static int COLS, tabsize; #define RP_SPACE ") " #define RP_SPACE_LEN 2 @@ -4439,7 +4456,7 @@ execute_builtin (builtin, words, flags, subshell) WORD_LIST *words; int flags, subshell; { - int result, eval_unwind, ignexit_flag, old_e_flag; + int result, eval_unwind, ignexit_flag; int isbltinenv; char *error_trap; @@ -4561,8 +4578,6 @@ static void maybe_restore_getopt_state (gs) sh_getopt_state_t *gs; { - SHELL_VAR *v; - /* If we have a local copy of OPTIND and it's at the right (current) context, then we restore getopt's internal state. If not, we just let it go. We know there is a local OPTIND if gs->gs_flags & 1. @@ -5265,7 +5280,9 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out, } else { +#if defined (RESTRICTED_SHELL) parent_return: +#endif QUIT; /* Make sure that the pipes are closed in the parent. */ @@ -5622,7 +5639,7 @@ execute_intern_function (name, funcdef) if (check_identifier (name, posixly_correct) == 0) { - if (posixly_correct && interactive_shell == 0) + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0) { last_command_exit_value = EX_BADUSAGE; jump_to_top_level (ERREXIT); diff --git a/execute_cmd.h b/execute_cmd.h index 62bec82..439f91a 100644 --- a/execute_cmd.h +++ b/execute_cmd.h @@ -22,6 +22,8 @@ #define _EXECUTE_CMD_H_ #include "stdc.h" +#include "variables.h" +#include "command.h" #if defined (ARRAY_VARS) struct func_array_state @@ -35,6 +37,9 @@ struct func_array_state }; #endif +/* Variables delared in execute_cmd.c, used by many other files */ +extern int executing_command_builtin; + extern struct fd_bitmap *new_fd_bitmap __P((int)); extern void dispose_fd_bitmap __P((struct fd_bitmap *)); extern void close_fd_bitmap __P((struct fd_bitmap *)); diff --git a/expr.c b/expr.c index 172964a..f57cada 100644 --- a/expr.c +++ b/expr.c @@ -178,8 +178,10 @@ static int _is_arithop __P((int)); static void readtok __P((void)); /* lexical analyzer */ static void init_lvalue __P((struct lvalue *)); +#if 0 static struct lvalue *alloc_lvalue __P((void)); static void free_lvalue __P((struct lvalue *)); +#endif static intmax_t expr_streval __P((char *, int, struct lvalue *)); static intmax_t strlong __P((char *)); @@ -207,7 +209,7 @@ static intmax_t exp5 __P((void)); static intmax_t exp4 __P((void)); static intmax_t expshift __P((void)); static intmax_t exp3 __P((void)); -static intmax_t exp2 __P((void)); +static intmax_t bash_exp2 __P((void)); static intmax_t exppower __P((void)); static intmax_t exp1 __P((void)); static intmax_t exp0 __P((void)); @@ -809,14 +811,14 @@ exp3 () { register intmax_t val1, val2; - val1 = exp2 (); + val1 = bash_exp2 (); while ((curtok == PLUS) || (curtok == MINUS)) { int op = curtok; readtok (); - val2 = exp2 (); + val2 = bash_exp2 (); if (op == PLUS) val1 += val2; @@ -828,7 +830,7 @@ exp3 () } static intmax_t -exp2 () +bash_exp2 () { register intmax_t val1, val2; #if defined (HAVE_IMAXDIV) @@ -908,7 +910,7 @@ ipow (base, exp) static intmax_t exppower () { - register intmax_t val1, val2, c; + register intmax_t val1, val2; val1 = exp1 (); while (curtok == POWER) @@ -1067,6 +1069,7 @@ init_lvalue (lv) lv->tokval = lv->ind = -1; } +#if 0 static struct lvalue * alloc_lvalue () { @@ -1076,13 +1079,16 @@ alloc_lvalue () init_lvalue (lv); return (lv); } +#endif +#if 0 static void free_lvalue (lv) struct lvalue *lv; { free (lv); /* should be inlined */ } +#endif static intmax_t expr_streval (tok, e, lvalue) @@ -1235,7 +1241,6 @@ readtok () register char *cp, *xp; register unsigned char c, c1; register int e; - struct lvalue lval; /* Skip leading whitespace. */ cp = tp; diff --git a/externs.h b/externs.h index fa0603d..3a995e3 100644 --- a/externs.h +++ b/externs.h @@ -462,9 +462,10 @@ extern void print_timeval (); /* declarations for functions defined in lib/sh/tmpfile.c */ #define MT_USETMPDIR 0x0001 #define MT_READWRITE 0x0002 -#define MT_USERANDOM 0x0004 -extern char *sh_mktmpname __P((char *, int)); +#if !defined(HAVE_DEV_FD) +extern char *sh_mktmpname_unsafe __P((char *, int)); +#endif extern int sh_mktmpfd __P((char *, int, char **)); /* extern FILE *sh_mktmpfp __P((char *, int, char **)); */ diff --git a/general.c b/general.c index 2d327ad..11f6961 100644 --- a/general.c +++ b/general.c @@ -1087,7 +1087,10 @@ bash_tilde_expand (s, assign_p) const char *s; int assign_p; { - int old_immed, old_term, r; +#if 0 + int old_immed, old_term; +#endif + int r; char *ret; #if 0 diff --git a/jobs.c b/jobs.c index 5ee21e1..9d04438 100644 --- a/jobs.c +++ b/jobs.c @@ -765,7 +765,7 @@ bgp_resize () else nsize = bgpids.nalloc; - while (nsize < js.c_childmax) + while (nsize < (ps_index_t)js.c_childmax) nsize *= 2; if (bgpids.nalloc < js.c_childmax) @@ -785,8 +785,6 @@ bgp_resize () static ps_index_t bgp_getindex () { - ps_index_t psi; - if (bgpids.nalloc < js.c_childmax || bgpids.head >= bgpids.nalloc) bgp_resize (); @@ -2423,11 +2421,11 @@ wait_for_single_pid (pid, flags) void wait_for_background_pids () { - register int i, r, waited_for; + register int i, r; sigset_t set, oset; pid_t pid; - for (waited_for = 0;;) + for (;;) { BLOCK_CHILD (set, oset); @@ -2462,8 +2460,6 @@ wait_for_background_pids () if (errno == ECHILD) mark_all_jobs_as_dead (); } - else - waited_for++; } /* POSIX.2 says the shell can discard the statuses of all completed jobs if @@ -3010,8 +3006,7 @@ wait_for_job (job) int wait_for_any_job () { - pid_t pid; - int i, r, waited_for; + int i, r; sigset_t set, oset; if (jobs_list_frozen) @@ -3038,7 +3033,7 @@ return_job: /* At this point, we have no dead jobs in the jobs table. Wait until we get one, even if it takes multiple pids exiting. */ - for (waited_for = 0;;) + for (;;) { /* Make sure there is a background job to wait for */ BLOCK_CHILD (set, oset); @@ -3462,16 +3457,15 @@ static sighandler sigchld_handler (sig) int sig; { - int n, oerrno; + int oerrno; oerrno = errno; REINSTALL_SIGCHLD_HANDLER; sigchld++; - n = 0; if (queue_sigchld == 0) - n = waitchld (-1, 0); + waitchld (-1, 0); errno = oerrno; - SIGRETURN (n); + SIGRETURN (0); } /* waitchld() reaps dead or stopped children. It's called by wait_for and diff --git a/lib/glob/glob.c b/lib/glob/glob.c index 7f6eafe..a23fc7d 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -182,9 +182,8 @@ extglob_skipname (pat, dname, flags) int flags; { char *pp, *pe, *t, *se; - int n, r, negate; + int n, r = 0; - negate = *pat == '!'; pp = pat + 2; se = pp + strlen (pp) - 1; /* end of string */ pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */ @@ -291,9 +290,8 @@ wextglob_skipname (pat, dname, flags) { #if EXTENDED_GLOB wchar_t *pp, *pe, *t, n, *se; - int r, negate; + int r; - negate = *pat == L'!'; pp = pat + 2; se = pp + wcslen (pp) - 1; /*(*/ pe = glob_patscan_wc (pp, se, 0); @@ -335,7 +333,7 @@ mbskipname (pat, dname, flags) char *pat, *dname; int flags; { - int ret, ext; + int ret = 0, ext; wchar_t *pat_wc, *dn_wc; size_t pat_n, dn_n; @@ -353,7 +351,6 @@ mbskipname (pat, dname, flags) if (pat_n != (size_t)-1) dn_n = xdupmbstowcs (&dn_wc, NULL, dname); - ret = 0; if (pat_n != (size_t)-1 && dn_n !=(size_t)-1) ret = ext ? wextglob_skipname (pat_wc, dn_wc, flags) : wchkname (pat_wc, dn_wc); else @@ -493,7 +490,7 @@ finddirs (pat, sdir, flags, ep, np) struct globval **ep; int *np; { - char **r, *n; + char **r; int ndirs; struct globval *ret, *e, *g; @@ -743,6 +740,8 @@ glob_vector (pat, dir, flags) continue; /* If we're only interested in directories, don't bother with files */ + isdir = 0; + subdir = 0; if (flags & (GX_MATCHDIRS|GX_ALLDIRS)) { pflags = (flags & GX_ALLDIRS) ? MP_RMDOT : 0; diff --git a/lib/glob/gmisc.c b/lib/glob/gmisc.c index 31906a4..3c74999 100644 --- a/lib/glob/gmisc.c +++ b/lib/glob/gmisc.c @@ -91,7 +91,7 @@ wmatchlen (wpat, wmax) size_t wmax; { wchar_t wc; - int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; + int matlen, bracklen, in_cclass, in_collsym, in_equiv; if (*wpat == 0) return (0); @@ -276,7 +276,7 @@ umatchlen (pat, max) size_t max; { char c; - int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; + int matlen, bracklen, in_cclass, in_collsym, in_equiv; if (*pat == 0) return (0); diff --git a/lib/glob/smatch.c b/lib/glob/smatch.c index edc5b95..b01057c 100644 --- a/lib/glob/smatch.c +++ b/lib/glob/smatch.c @@ -388,7 +388,6 @@ xstrmatch (pattern, string, flags) int ret; size_t n; wchar_t *wpattern, *wstring; - size_t plen, slen, mplen, mslen; if (mbsmbchar (string) == 0 && mbsmbchar (pattern) == 0) return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); diff --git a/lib/malloc/stats.c b/lib/malloc/stats.c index ae555a1..6fd993a 100644 --- a/lib/malloc/stats.c +++ b/lib/malloc/stats.c @@ -134,7 +134,7 @@ fprint_malloc_stats (s, fp) _print_malloc_stats (s, fp); } -#define TRACEROOT "/var/tmp/maltrace/stats." +#define TRACEROOT "/var/run/maltrace/stats." void trace_malloc_stats (s, fn) diff --git a/lib/malloc/trace.c b/lib/malloc/trace.c index 95898b7..0d70f7c 100644 --- a/lib/malloc/trace.c +++ b/lib/malloc/trace.c @@ -108,7 +108,7 @@ malloc_trace_bin (n) #endif } -#define TRACEROOT "/var/tmp/maltrace/trace." +#define TRACEROOT "/var/run/maltrace/trace." void malloc_set_tracefn (s, fn) diff --git a/lib/sh/casemod.c b/lib/sh/casemod.c index f68303b..1a73ea1 100644 --- a/lib/sh/casemod.c +++ b/lib/sh/casemod.c @@ -106,7 +106,7 @@ sh_modcase (string, pat, flags) int flags; { int start, next, end, retind; - int inword, c, nc, nop, match, usewords; + int inword, nc, nop, match, usewords; char *ret, *s; wchar_t wc; int mb_cur_max; diff --git a/lib/sh/eaccess.c b/lib/sh/eaccess.c index 8fd8a43..80ad762 100644 --- a/lib/sh/eaccess.c +++ b/lib/sh/eaccess.c @@ -54,7 +54,9 @@ extern int errno; static int path_is_devfd __P((const char *)); static int sh_stataccess __P((const char *, int)); -#if HAVE_DECL_SETREGID +#if HAVE_DECL_SETREGID && \ + !(defined (HAVE_FACCESSAT) && defined (AT_EACCESS)) && \ + !defined (HAVE_EACCESS) && !defined (EFF_ONLY_OK) static int sh_euidaccess __P((const char *, int)); #endif @@ -167,7 +169,9 @@ sh_stataccess (path, mode) return (-1); } -#if HAVE_DECL_SETREGID +#if HAVE_DECL_SETREGID && \ + !(defined (HAVE_FACCESSAT) && defined (AT_EACCESS)) && \ + !defined (HAVE_EACCESS) && !defined (EFF_ONLY_OK) /* Version to call when uid != euid or gid != egid. We temporarily swap the effective and real uid and gid as appropriate. */ static int diff --git a/lib/sh/fnxform.c b/lib/sh/fnxform.c index d7e1b5a..ca63228 100644 --- a/lib/sh/fnxform.c +++ b/lib/sh/fnxform.c @@ -40,6 +40,7 @@ extern const char *locale_charset __P((void)); extern char *get_locale_var __P((char *)); #endif +#ifdef MACOSX #if defined (HAVE_ICONV) static iconv_t conv_fromfs = (iconv_t)-1; static iconv_t conv_tofs = (iconv_t)-1; @@ -93,6 +94,7 @@ init_fromfs () cur = curencoding (); conv_fromfs = iconv_open (cur, "UTF-8-MAC"); } +#endif char * fnx_tofs (string, len) diff --git a/lib/sh/mailstat.c b/lib/sh/mailstat.c index 79b431a..bd5c25f 100644 --- a/lib/sh/mailstat.c +++ b/lib/sh/mailstat.c @@ -60,7 +60,7 @@ mailstat(path, st) struct stat st_ret, st_tmp; DIR *dd; struct dirent *fn; - char dir[PATH_MAX * 2], file[PATH_MAX * 2]; + char dir[PATH_MAX * 2], file[PATH_MAX * 2 + 1]; int i, l; time_t atime, mtime; diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index e41e45b..5ae884b 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -22,10 +22,6 @@ #include -#include -#include -#include -#include #if defined (HAVE_UNISTD_H) # include @@ -34,149 +30,44 @@ #include #include -#include +#include #include -#ifndef errno -extern int errno; -#endif - -#define BASEOPENFLAGS (O_CREAT | O_TRUNC | O_EXCL | O_BINARY) - -#define DEFAULT_TMPDIR "." /* bogus default, should be changed */ -#define DEFAULT_NAMEROOT "shtmp" - -/* Use ANSI-C rand() interface if random(3) is not available */ -#if !HAVE_RANDOM -#define random() rand() -#endif - -extern pid_t dollar_dollar_pid; - -static char *get_sys_tmpdir __P((void)); -static char *get_tmpdir __P((int)); - -static char *sys_tmpdir = (char *)NULL; -static int ntmpfiles; -static int tmpnamelen = -1; -static unsigned long filenum = 1L; - -static char * -get_sys_tmpdir () -{ - if (sys_tmpdir) - return sys_tmpdir; - -#ifdef P_tmpdir - sys_tmpdir = P_tmpdir; - if (file_iswdir (sys_tmpdir)) - return sys_tmpdir; -#endif - - sys_tmpdir = "/tmp"; - if (file_iswdir (sys_tmpdir)) - return sys_tmpdir; - - sys_tmpdir = "/var/tmp"; - if (file_iswdir (sys_tmpdir)) - return sys_tmpdir; - - sys_tmpdir = "/usr/tmp"; - if (file_iswdir (sys_tmpdir)) - return sys_tmpdir; - - sys_tmpdir = DEFAULT_TMPDIR; - - return sys_tmpdir; -} +#define DEFAULT_TMPDIR P_tmpdir +#define DEFAULT_NAMEROOT "bash" static char * get_tmpdir (flags) int flags; { - char *tdir; - - tdir = (flags & MT_USETMPDIR) ? get_string_value ("TMPDIR") : (char *)NULL; - if (tdir && (file_iswdir (tdir) == 0 || strlen (tdir) > PATH_MAX)) - tdir = 0; - - if (tdir == 0) - tdir = get_sys_tmpdir (); - -#if defined (HAVE_PATHCONF) && defined (_PC_NAME_MAX) - if (tmpnamelen == -1) - tmpnamelen = pathconf (tdir, _PC_NAME_MAX); -#else - tmpnamelen = 0; -#endif - - return tdir; -} - -static void -sh_seedrand () -{ -#if HAVE_RANDOM - int d; - static int seeded = 0; - if (seeded == 0) - { - struct timeval tv; - - gettimeofday (&tv, NULL); - srandom (tv.tv_sec ^ tv.tv_usec ^ (getpid () << 16) ^ (uintptr_t)&d); - seeded = 1; - } -#endif + if (flags & MT_USETMPDIR) + return get_string_value ("TMPDIR") ?: DEFAULT_TMPDIR; + return DEFAULT_TMPDIR; } +#if !defined(HAVE_DEV_FD) +/* This is renamed to *_unsafe to trap and review possible additional + * references when applying the patch to future versions of bash. */ char * -sh_mktmpname (nameroot, flags) +sh_mktmpname_unsafe (nameroot, flags) char *nameroot; int flags; { - char *filename, *tdir, *lroot; - struct stat sb; - int r, tdlen; - static int seeded = 0; - - filename = (char *)xmalloc (PATH_MAX + 1); - tdir = get_tmpdir (flags); - tdlen = strlen (tdir); - - lroot = nameroot ? nameroot : DEFAULT_NAMEROOT; + char *filename; -#ifdef USE_MKTEMP - sprintf (filename, "%s/%s.XXXXXX", tdir, lroot); - if (mktemp (filename) == 0) + if (asprintf (&filename, "%s/%s.XXXXXX", get_tmpdir (flags), + nameroot ?: DEFAULT_NAMEROOT) < 0) + return NULL; + if (!mktemp (filename) || !*filename) { free (filename); filename = NULL; } -#else /* !USE_MKTEMP */ - sh_seedrand (); - while (1) - { - filenum = (filenum << 1) ^ - (unsigned long) time ((time_t *)0) ^ - (unsigned long) dollar_dollar_pid ^ - (unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++); - sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum); - if (tmpnamelen > 0 && tmpnamelen < 32) - filename[tdlen + 1 + tmpnamelen] = '\0'; -# ifdef HAVE_LSTAT - r = lstat (filename, &sb); -# else - r = stat (filename, &sb); -# endif - if (r < 0 && errno == ENOENT) - break; - } -#endif /* !USE_MKTEMP */ return filename; } +#endif /* !defined(HAVE_DEV_FD) */ int sh_mktmpfd (nameroot, flags, namep) @@ -184,48 +75,25 @@ sh_mktmpfd (nameroot, flags, namep) int flags; char **namep; { - char *filename, *tdir, *lroot; - int fd, tdlen; - - filename = (char *)xmalloc (PATH_MAX + 1); - tdir = get_tmpdir (flags); - tdlen = strlen (tdir); - - lroot = nameroot ? nameroot : DEFAULT_NAMEROOT; - -#ifdef USE_MKSTEMP - sprintf (filename, "%s/%s.XXXXXX", tdir, lroot); - fd = mkstemp (filename); - if (fd < 0 || namep == 0) + char *filename; + int fd = -1; + + if (namep) + *namep = NULL; + if (asprintf (&filename, "%s/%s.XXXXXX", get_tmpdir (flags), + nameroot ?: DEFAULT_NAMEROOT) < 0) + return -1; + if ((fd = mkstemp (filename)) < 0) { free (filename); filename = NULL; } if (namep) *namep = filename; - return fd; -#else /* !USE_MKSTEMP */ - sh_seedrand (); - do - { - filenum = (filenum << 1) ^ - (unsigned long) time ((time_t *)0) ^ - (unsigned long) dollar_dollar_pid ^ - (unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++); - sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum); - if (tmpnamelen > 0 && tmpnamelen < 32) - filename[tdlen + 1 + tmpnamelen] = '\0'; - fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600); - } - while (fd < 0 && errno == EEXIST); - - if (namep) - *namep = filename; else free (filename); return fd; -#endif /* !USE_MKSTEMP */ } FILE * @@ -239,7 +107,7 @@ sh_mktmpfp (nameroot, flags, namep) fd = sh_mktmpfd (nameroot, flags, namep); if (fd < 0) - return ((FILE *)NULL); + return NULL; fp = fdopen (fd, (flags & MT_READWRITE) ? "w+" : "w"); if (fp == 0) close (fd); diff --git a/locale.c b/locale.c index a199cdf..09acf71 100644 --- a/locale.c +++ b/locale.c @@ -68,7 +68,9 @@ static char *lang; static int reset_locale_vars __P((void)); static void locale_setblanks __P((void)); +#if 0 static int locale_isutf8 __P((char *)); +#endif /* Set the value of default_locale and make the current locale the system default locale. This should be called very early in main(). */ @@ -327,7 +329,6 @@ get_locale_var (var) static int reset_locale_vars () { - char *t; #if defined (HAVE_SETLOCALE) if (lang == 0 || *lang == '\0') maybe_make_export_env (); /* trust that this will change environment for setlocale */ @@ -335,19 +336,19 @@ reset_locale_vars () return 0; # if defined (LC_CTYPE) - t = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE")); + setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE")); # endif # if defined (LC_COLLATE) - t = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE")); + setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE")); # endif # if defined (LC_MESSAGES) - t = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES")); + setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES")); # endif # if defined (LC_NUMERIC) - t = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC")); + setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC")); # endif # if defined (LC_TIME) - t = setlocale (LC_TIME, get_locale_var ("LC_TIME")); + setlocale (LC_TIME, get_locale_var ("LC_TIME")); # endif locale_setblanks (); @@ -547,6 +548,7 @@ locale_setblanks () } } +#if 0 static int locale_isutf8 (lspec) char *lspec; @@ -561,3 +563,4 @@ locale_isutf8 (lspec) return (strstr (lspec, "UTF-8") || strstr (lspec, "utf8")); #endif } +#endif diff --git a/make_cmd.c b/make_cmd.c index b42e9ff..8c02dfa 100644 --- a/make_cmd.c +++ b/make_cmd.c @@ -42,11 +42,15 @@ #include "flags.h" #include "make_cmd.h" #include "dispose_cmd.h" +#include "execute_cmd.h" #include "variables.h" #include "subst.h" #include "input.h" #include "ocache.h" #include "externs.h" +#include "builtins.h" + +#include "builtins/common.h" #if defined (JOB_CONTROL) #include "jobs.h" @@ -57,9 +61,13 @@ extern int line_number, current_command_line_count, parser_state; extern int last_command_exit_value; extern int shell_initialized; +extern int rpm_requires; int here_doc_first_line = 0; +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + /* Object caching */ sh_obj_cache_t wdcache = {0, 0, 0}; sh_obj_cache_t wlcache = {0, 0, 0}; @@ -772,6 +780,27 @@ make_redirection (source, instruction, dest_and_filename, flags) return (temp); } +static void +output_requirement (deptype, filename) +const char *deptype; +char *filename; +{ + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/'))) + return; + + /* + if the executable is called via variable substitution we can + not dermine what it is at compile time. + + if the executable consists only of characters not in the + alphabet we do not consider it a dependency just an artifact + of shell parsing (ex "exec < ${infile}"). + */ + + if (strpbrk(filename, alphabet_set)) + printf ("%s(%s)\n", deptype, filename); +} + COMMAND * make_function_def (name, command, lineno, lstart) WORD_DESC *name; @@ -810,6 +839,24 @@ make_function_def (name, command, lineno, lstart) temp->source_file = temp->source_file ? savestring (temp->source_file) : 0; + if (rpm_requires) { + /* Each function is possibly required, which is, er, provided. + * I need to know function names in order to implement strong + * self-requires elimination in /usr/lib/rpm/shell.req. Just about + * the only way to achieve this without breaking "--rpm-requires" + * compatibility is to spit them here as they go. + * + * Also note that another "function" output in clean_simple_command() + * is not much useful since it only means that a function is defined + * in the very same file before being used (shell have seen it while + * parsing the script). My point is that it makes no sense to resolve + * function requirements -- functions are simply "provided" by its nature. + * + * -- at@altlinux + */ + output_requirement ("function", name->word); + } + return (make_command (cm_function_def, (SIMPLE_COM *)temp)); } @@ -857,6 +904,44 @@ clean_simple_command (command) } parser_state &= ~PST_REDIRLIST; + + if (rpm_requires && command->value.Simple->words) + { + WORD_LIST *words = command->value.Simple->words; + const char *cmd = words->word->word; + + /* skip LC_* assignments */ + while (words->next && assignment (cmd, 0)) + { + if (strncmp (cmd, "LC_", 3) != 0) + break; + words = words->next; + cmd = words->word->word; + } + + if (!assignment (cmd, 0)) + { + struct builtin *b = builtin_address_internal (cmd, 0); + if (b) + { + /* exec-like builtin with an argument */ + if ((b->flags & REQUIRES_BUILTIN) && words->next) + { + words = words->next; + cmd = words->word->word; + output_requirement ("executable", cmd); + } + } + else + { + if (find_function (cmd) || find_function_def (cmd)) + output_requirement ("function", cmd); + else + output_requirement ("executable", cmd); + } + } + } /* rpm_requires */ + return (command); } diff --git a/parse.y b/parse.y index f415d2e..c254862 100644 --- a/parse.y +++ b/parse.y @@ -201,7 +201,9 @@ static int token_is_assignment __P((char *, int)); static int token_is_ident __P((char *, int)); #endif static int read_token_word __P((int)); +#if 0 static void discard_parser_constructs __P((int)); +#endif static char *error_token_from_token __P((int)); static char *error_token_from_text __P((void)); @@ -1453,6 +1455,7 @@ yy_readline_get () old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler); } + sh_unset_nodelay_mode (fileno (rl_instream)); /* just in case */ current_readline_line = readline (current_readline_prompt ? current_readline_prompt : ""); @@ -2065,7 +2068,6 @@ read_secondary_line (remove_quoted_newline) int remove_quoted_newline; { char *ret; - int n, c; prompt_string_pointer = &ps2_prompt; if (SHOULD_PROMPT()) @@ -3705,7 +3707,7 @@ parse_comsub (qc, open, close, lenp, flags) int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind; int nestlen, ttranslen, start_lineno; char *ret, *nestret, *ttrans, *heredelim; - int retind, retsize, rflags, hdlen; + int retind, retsize, rflags, hdlen = 0; /* Posix interp 217 says arithmetic expressions have precedence, so assume $(( introduces arithmetic expansion and parse accordingly. */ @@ -3737,7 +3739,6 @@ parse_comsub (qc, open, close, lenp, flags) while (count) { -comsub_readchar: ch = shell_getc (qc != '\'' && (tflags & (LEX_INCOMMENT|LEX_PASSNEXT)) == 0); if (ch == EOF) @@ -4010,11 +4011,13 @@ eof_error: tflags |= LEX_RESWDOK; lex_rwlen = 0; } - else + else if (shellmeta (ch) == 0) { tflags &= ~LEX_RESWDOK; /*itrace("parse_comsub:%d: found `%.4s', lex_reswdok -> 0", line_number, ret+retind-4);*/ } + else /* can't be in a reserved word any more */ + lex_rwlen = 0; } else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0))) ; /* don't modify LEX_RESWDOK if we're starting a comment */ @@ -4214,11 +4217,10 @@ xparse_dolparen (base, string, indp, flags) { sh_parser_state_t ps; sh_input_line_state_t ls; - int orig_ind, nc, sflags, orig_eof_token; - char *ret, *s, *ep, *ostring; + int nc, sflags, orig_eof_token; + char *ret, *ep, *ostring; /*yydebug = 1;*/ - orig_ind = *indp; ostring = string; /*itrace("xparse_dolparen: size = %d shell_input_line = `%s'", shell_input_line_size, shell_input_line);*/ @@ -4294,7 +4296,7 @@ static int parse_dparen (c) int c; { - int cmdtyp, sline; + int cmdtyp; char *wval; WORD_DESC *wd; @@ -4318,8 +4320,6 @@ parse_dparen (c) #if defined (DPAREN_ARITHMETIC) if (reserved_word_acceptable (last_read_token)) { - sline = line_number; - cmdtyp = parse_arith_cmd (&wval, 0); if (cmdtyp == 1) /* arithmetic command */ { @@ -4355,11 +4355,10 @@ parse_arith_cmd (ep, adddq) char **ep; int adddq; { - int exp_lineno, rval, c; + int rval, c; char *ttok, *tokstr; int ttoklen; - exp_lineno = line_number; ttok = parse_matched_pair (0, '(', ')', &ttoklen, 0); rval = 1; if (ttok == &matched_pair_error) @@ -5461,7 +5460,10 @@ decode_prompt_string (string) #if defined (PROMPT_STRING_DECODE) size_t result_size; int result_index; - int c, n, i; + int c, n; +#if defined (READLINE) + int i; +#endif char *temp, *t_host, octal_string[4]; struct tm *tm; time_t the_time; @@ -5557,6 +5559,8 @@ decode_prompt_string (string) n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm); else if (c == 'A') n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm); + else + n = 0; if (n == 0) timebuf[0] = '\0'; @@ -6033,6 +6037,7 @@ report_syntax_error (message) last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE; } +#if 0 /* ??? Needed function. ??? We have to be able to discard the constructs created during parsing. In the case of error, we want to return allocated objects to the memory pool. In the case of no error, we want @@ -6043,6 +6048,7 @@ discard_parser_constructs (error_p) int error_p; { } +#endif /************************************************ * * @@ -6302,8 +6308,6 @@ sh_parser_state_t * save_parser_state (ps) sh_parser_state_t *ps; { - int i; - if (ps == 0) ps = (sh_parser_state_t *)xmalloc (sizeof (sh_parser_state_t)); if (ps == 0) @@ -6362,8 +6366,6 @@ void restore_parser_state (ps) sh_parser_state_t *ps; { - int i; - if (ps == 0) return; diff --git a/pathexp.c b/pathexp.c index 21fc148..67125c5 100644 --- a/pathexp.c +++ b/pathexp.c @@ -183,7 +183,7 @@ quote_string_for_globbing (pathname, qflags) { char *temp; register int i, j; - int brack, cclass, collsym, equiv, c, last_was_backslash; + int cclass, collsym, equiv, c, last_was_backslash; int savei, savej; temp = (char *)xmalloc (2 * strlen (pathname) + 1); @@ -194,7 +194,7 @@ quote_string_for_globbing (pathname, qflags) return temp; } - brack = cclass = collsym = equiv = last_was_backslash = 0; + cclass = collsym = equiv = last_was_backslash = 0; for (i = j = 0; pathname[i]; i++) { /* Fix for CTLESC at the end of the string? */ @@ -225,7 +225,6 @@ quote_string_for_globbing (pathname, qflags) } else if ((qflags & QGLOB_REGEXP) && (i == 0 || pathname[i-1] != CTLESC) && pathname[i] == '[') /*]*/ { - brack = 1; temp[j++] = pathname[i++]; /* open bracket */ savej = j; savei = i; diff --git a/pcomplete.c b/pcomplete.c index ac0903a..5d1e360 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -728,7 +728,6 @@ pcomp_filename_completion_function (text, state) int state; { static char *dfn; /* dequoted filename */ - int qc; int iscompgen, iscompleting; if (state == 0) @@ -1614,7 +1613,7 @@ programmable_completions (cmd, word, start, end, foundp) const char *word; int start, end, *foundp; { - COMPSPEC *cs, *lastcs; + COMPSPEC *lastcs; STRINGLIST *ret; char **rmatches, *t; int found, retry, count; diff --git a/redir.c b/redir.c index 1858b0b..6a2eaa8 100644 --- a/redir.c +++ b/redir.c @@ -74,7 +74,9 @@ static int add_undo_redirect __P((int, enum r_instruction, int)); static int add_undo_close_redirect __P((int)); static int expandable_redirection_filename __P((REDIRECT *)); static int stdin_redirection __P((enum r_instruction, int)); +#if 0 static int undoablefd __P((int)); +#endif static int do_redirection_internal __P((REDIRECT *, int)); static int write_here_document __P((int, WORD_DESC *)); @@ -157,7 +159,6 @@ redirection_error (temp, error) #endif else if (expandable_redirection_filename (temp)) { -expandable_filename: oflags = temp->redirectee.filename->flags; if (posixly_correct && interactive_shell == 0) temp->redirectee.filename->flags |= W_NOGLOB; @@ -460,7 +461,7 @@ here_document_to_fd (redirectee, ri) char *filename; int r, fd, fd2; - fd = sh_mktmpfd ("sh-thd", MT_USERANDOM|MT_USETMPDIR, &filename); + fd = sh_mktmpfd ("sh-thd", MT_USETMPDIR, &filename); /* If we failed for some reason other than the file existing, abort */ if (fd < 0) @@ -697,6 +698,7 @@ redir_open (filename, flags, mode, ri) return fd; } +#if 0 static int undoablefd (fd) int fd; @@ -708,6 +710,7 @@ undoablefd (fd) return 0; return 1; } +#endif /* Do the specific redirection requested. Returns errno or one of the special redirection errors (*_REDIRECT) in case of error, 0 on success. @@ -722,11 +725,11 @@ do_redirection_internal (redirect, flags) int flags; { WORD_DESC *redirectee; - int redir_fd, fd, redirector, r, oflags; + int redir_fd, fd, redirector, r; intmax_t lfd; char *redirectee_word; enum r_instruction ri; - REDIRECT *new_redirect; + REDIRECT *new_redirect = 0; REDIRECTEE sd; redirectee = redirect->redirectee.filename; @@ -775,6 +778,8 @@ do_redirection_internal (redirect, flags) case r_move_output_word: new_redirect = make_redirection (sd, r_move_output, rd, 0); break; + default: + break; } } else if (ri == r_duplicating_output_word && (redirect->rflags & REDIR_VARASSIGN) == 0 && redirector == 1) @@ -833,12 +838,15 @@ do_redirection_internal (redirect, flags) case r_output_force: if (posixly_correct && interactive_shell == 0) { - oflags = redirectee->flags; + int oflags = redirectee->flags; redirectee->flags |= W_NOGLOB; + redirectee_word = redirection_expand (redirectee); + redirectee->flags = oflags; + } + else + { + redirectee_word = redirection_expand (redirectee); } - redirectee_word = redirection_expand (redirectee); - if (posixly_correct && interactive_shell == 0) - redirectee->flags = oflags; if (redirectee_word == 0) return (AMBIGUOUS_REDIRECT); @@ -1169,6 +1177,7 @@ do_redirection_internal (redirect, flags) case r_duplicating_input_word: case r_duplicating_output_word: + default: break; } return (0); @@ -1328,9 +1337,9 @@ stdin_redirection (ri, redirector) case r_append_err_and_out: case r_output_force: case r_duplicating_output_word: + default: return (0); } - return (0); } /* Return non-zero if any of the redirections in REDIRS alter the standard diff --git a/shell.c b/shell.c index 45b77f9..04c8786 100644 --- a/shell.c +++ b/shell.c @@ -201,6 +201,9 @@ int have_devfd = 0; /* The name of the .(shell)rc file. */ static char *bashrc_file = DEFAULT_BASHRC; +/* Non-zero if we are finding the scripts requirements. */ +int rpm_requires; + /* Non-zero means to act more like the Bourne shell on startup. */ static int act_like_sh; @@ -264,6 +267,7 @@ static const struct { { "protected", Int, &protected_mode, (char **)0x0 }, #endif { "rcfile", Charp, (int *)0x0, &bashrc_file }, + { "rpm-requires", Int, &rpm_requires, (char **)0x0 }, #if defined (RESTRICTED_SHELL) { "restricted", Int, &restricted, (char **)0x0 }, #endif @@ -500,6 +504,12 @@ main (argc, argv, env) if (dump_translatable_strings) read_but_dont_execute = 1; + if (rpm_requires) + { + read_but_dont_execute = 1; + initialize_shell_builtins (); + } + if (running_setuid && privileged_mode == 0) disable_priv_mode (); @@ -1699,7 +1709,7 @@ set_shell_name (argv0) login_shell = 1; } - if (shell_name[0] == 's' && shell_name[1] == 'h' && shell_name[2] == '\0') + if (shell_name[0] == 's' && shell_name[1] == 'h' && (shell_name[2] == '\0' || (shell_name[2] == '4' && shell_name[3] == '\0'))) act_like_sh++; if (shell_name[0] == 's' && shell_name[1] == 'u' && shell_name[2] == '\0') su_shell++; @@ -1791,7 +1801,9 @@ static void shell_initialize () { char hostname[256]; +#if defined (RESTRICTED_SHELL) int should_be_restricted; +#endif /* Line buffer output for stderr and stdout. */ if (shell_initialized == 0) diff --git a/subst.c b/subst.c index fc00cab..7fc5620 100644 --- a/subst.c +++ b/subst.c @@ -234,9 +234,11 @@ static int expand_no_split_dollar_star = 0; without any leading variable assignments. */ static WORD_LIST *garglist = (WORD_LIST *)NULL; +#ifdef INCLUDE_UNUSED static char *quoted_substring __P((char *, int, int)); static int quoted_strlen __P((char *)); static char *quoted_strchr __P((char *, int, int)); +#endif static char *expand_string_if_necessary __P((char *, int, EXPFUNC *)); static inline char *expand_string_to_string_internal __P((char *, int, EXPFUNC *)); @@ -246,13 +248,17 @@ static WORD_LIST *expand_string_leave_quoted __P((char *, int)); static WORD_LIST *expand_string_for_rhs __P((char *, int, int *, int *)); static WORD_LIST *list_quote_escapes __P((WORD_LIST *)); +#ifdef INCLUDE_UNUSED static WORD_LIST *list_dequote_escapes __P((WORD_LIST *)); +#endif static char *make_quoted_char __P((int)); static WORD_LIST *quote_list __P((WORD_LIST *)); +#ifdef INCLUDE_UNUSED static int unquoted_substring __P((char *, char *)); static int unquoted_member __P((int, char *)); +#endif #if defined (ARRAY_VARS) static SHELL_VAR *do_compound_assignment __P((char *, char *, int)); @@ -271,7 +277,9 @@ static int skip_matched_pair __P((const char *, int, int, int, int)); static char *pos_params __P((char *, int, int, int)); +#if 0 static unsigned char *mb_getcharlens __P((char *, int)); +#endif static char *remove_upattern __P((char *, char *, int)); #if defined (HANDLE_MULTIBYTE) @@ -286,7 +294,9 @@ static int match_wpattern __P((wchar_t *, char **, size_t, wchar_t *, int, char static int match_pattern __P((char *, char *, int, char **, char **)); static int getpatspec __P((int, char *)); static char *getpattern __P((char *, int, int)); +#if 0 static char *variable_remove_pattern __P((char *, char *, int, int)); +#endif static char *list_remove_pattern __P((WORD_LIST *, char *, int, int, int)); static char *parameter_list_remove_pattern __P((int, char *, int, int)); #ifdef ARRAY_VARS @@ -334,13 +344,14 @@ static int get_var_and_type __P((char *, char *, arrayind_t, int, int, SHELL_VAR static char *mb_substring __P((char *, int, int)); static char *parameter_brace_substring __P((char *, char *, int, char *, int, int)); +#if 0 static int shouldexp_replacement __P((char *)); +#endif static char *pos_params_pat_subst __P((char *, char *, char *, int)); static char *parameter_brace_patsub __P((char *, char *, int, char *, int, int, int)); -static char *pos_params_casemod __P((char *, char *, int, int)); static char *parameter_brace_casemod __P((char *, char *, int, int, char *, int, int)); static WORD_DESC *parameter_brace_expand __P((char *, int *, int, int, int *, int *)); @@ -589,7 +600,6 @@ quoted_strlen (s) return i; } -#endif /* Find the first occurrence of character C in string S, obeying shell quoting rules. If (FLAGS & ST_BACKSL) is non-zero, backslash-escaped @@ -618,7 +628,6 @@ quoted_strchr (s, c, flags) return ((char *)NULL); } -#if defined (INCLUDE_UNUSED) /* Return 1 if CHARACTER appears in an unquoted portion of STRING. Return 0 otherwise. CHARACTER must be a single-byte character. */ static int @@ -1005,7 +1014,6 @@ skip_double_quoted (string, slen, sind, flags) int flags; { int c, i; - char *ret; int pass_next, backquote, si; DECLARE_MBSTATE; @@ -1042,9 +1050,9 @@ skip_double_quoted (string, slen, sind, flags) { si = i + 2; if (string[i + 1] == LPAREN) - ret = extract_command_subst (string, &si, SX_NOALLOC|(flags&SX_COMPLETE)); + extract_command_subst (string, &si, SX_NOALLOC|(flags&SX_COMPLETE)); else - ret = extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, SX_NOALLOC); + extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, SX_NOALLOC); /* These can consume the entire string if they are unterminated */ CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1134,7 +1142,6 @@ string_extract_verbatim (string, slen, sindex, charlist, flags) { register int i; #if defined (HANDLE_MULTIBYTE) - size_t clen; wchar_t *wcharlist; #endif int c; @@ -1155,7 +1162,6 @@ string_extract_verbatim (string, slen, sindex, charlist, flags) slen = (MB_CUR_MAX > 1) ? strlen (string + *sindex) + *sindex : 1; #endif #if defined (HANDLE_MULTIBYTE) - clen = strlen (charlist); wcharlist = 0; #endif while (c = string[i]) @@ -1315,7 +1321,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) { int i, c, si; size_t slen; - char *t, *result; + char *result; int pass_character, nesting_level, in_comment; int len_closer, len_opener, len_alt_opener; DECLARE_MBSTATE; @@ -1382,7 +1388,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if ((flags & SX_COMMAND) && string[i] == '$' && string[i+1] == LPAREN) { si = i + 2; - t = extract_command_subst (string, &si, flags|SX_NOALLOC); + extract_command_subst (string, &si, flags|SX_NOALLOC); i = si + 1; continue; } @@ -1391,7 +1397,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (STREQN (string + i, opener, len_opener)) { si = i + len_opener; - t = extract_delimited_string (string, &si, opener, alt_opener, closer, flags|SX_NOALLOC); + extract_delimited_string (string, &si, opener, alt_opener, closer, flags|SX_NOALLOC); i = si + 1; continue; } @@ -1400,7 +1406,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (len_alt_opener && STREQN (string + i, alt_opener, len_alt_opener)) { si = i + len_alt_opener; - t = extract_delimited_string (string, &si, alt_opener, alt_opener, closer, flags|SX_NOALLOC); + extract_delimited_string (string, &si, alt_opener, alt_opener, closer, flags|SX_NOALLOC); i = si + 1; continue; } @@ -1419,7 +1425,7 @@ extract_delimited_string (string, sindex, opener, alt_opener, closer, flags) if (c == '`') { si = i + 1; - t = string_extract (string, &si, "`", flags|SX_NOALLOC); + string_extract (string, &si, "`", flags|SX_NOALLOC); i = si + 1; continue; } @@ -1482,7 +1488,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) register int i, c; size_t slen; int pass_character, nesting_level, si, dolbrace_state; - char *result, *t; + char *result; DECLARE_MBSTATE; pass_character = 0; @@ -1536,7 +1542,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) if (c == '`') { si = i + 1; - t = string_extract (string, &si, "`", flags|SX_NOALLOC); + string_extract (string, &si, "`", flags|SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1549,7 +1555,7 @@ extract_dollar_brace_string (string, sindex, quoted, flags) if (string[i] == '$' && string[i+1] == LPAREN) { si = i + 2; - t = extract_command_subst (string, &si, flags|SX_NOALLOC); + extract_command_subst (string, &si, flags|SX_NOALLOC); i = si + 1; continue; } @@ -1691,7 +1697,7 @@ skip_matched_pair (string, start, open, close, flags) { int i, pass_next, backq, si, c, count, oldjmp; size_t slen; - char *temp, *ss; + char *ss; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -1758,9 +1764,9 @@ skip_matched_pair (string, start, open, close, flags) CQ_RETURN(si); if (string[i+1] == LPAREN) - temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ + extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ else - temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); + extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); CHECK_STRING_OVERRUN (i, si, slen, c); @@ -1804,7 +1810,7 @@ skip_to_delim (string, start, delims, flags) int invert, skipquote, skipcmd, noprocsub, completeflag; int arithexp, skipcol; size_t slen; - char *temp, open[3]; + char open[3]; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -1887,7 +1893,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); - temp = extract_delimited_string (string, &si, "(", "(", ")", SX_NOALLOC); /* ) */ + extract_delimited_string (string, &si, "(", "(", ")", SX_NOALLOC); /* ) */ i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ break; @@ -1901,9 +1907,9 @@ skip_to_delim (string, start, delims, flags) CQ_RETURN(si); if (string[i+1] == LPAREN) - temp = extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ + extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ else - temp = extract_dollar_brace_string (string, &si, 0, SX_NOALLOC); + extract_dollar_brace_string (string, &si, 0, SX_NOALLOC); i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ break; @@ -1917,7 +1923,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); #if 1 - temp = extract_delimited_string (string, &si, (c == '<') ? "<(" : ">(", "(", ")", SX_COMMAND|SX_NOALLOC); /* )) */ + extract_delimited_string (string, &si, (c == '<') ? "<(" : ">(", "(", ")", SX_COMMAND|SX_NOALLOC); /* )) */ #else temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si, 0); free (temp); /* XXX - not using SX_NOALLOC here yet */ @@ -1939,7 +1945,7 @@ skip_to_delim (string, start, delims, flags) open[0] = c; open[1] = LPAREN; open[2] = '\0'; - temp = extract_delimited_string (string, &si, open, "(", ")", SX_NOALLOC); /* ) */ + extract_delimited_string (string, &si, open, "(", ")", SX_NOALLOC); /* ) */ i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ @@ -1954,7 +1960,7 @@ skip_to_delim (string, start, delims, flags) if (string[si] == '\0') CQ_RETURN(si); - temp = extract_delimited_string (string, &si, "[", "[", "]", SX_NOALLOC); /* ] */ + extract_delimited_string (string, &si, "[", "[", "]", SX_NOALLOC); /* ] */ i = si; if (string[i] == '\0') /* don't increment i past EOS in loop */ @@ -1983,10 +1989,9 @@ skip_to_histexp (string, start, delims, flags) char *delims; int flags; { - int i, pass_next, backq, dquote, si, c, oldjmp; + int i, pass_next, backq, dquote, c, oldjmp; int histexp_comsub, histexp_backq, old_dquote; size_t slen; - char *temp, open[3]; DECLARE_MBSTATE; slen = strlen (string + start) + start; @@ -3910,7 +3915,7 @@ char * dequote_escapes (string) char *string; { - register char *s, *t, *s1; + register char *s, *t; size_t slen; char *result, *send; int quote_spaces; @@ -3945,6 +3950,7 @@ dequote_escapes (string) return result; } +#ifdef INCLUDE_UNUSED static WORD_LIST * list_dequote_escapes (list) WORD_LIST *list; @@ -3960,6 +3966,7 @@ list_dequote_escapes (list) } return list; } +#endif /* Return a new string with the quoted representation of character C. This turns "" into QUOTED_NULL, so the W_HASQUOTEDNULL flag needs to be @@ -4467,7 +4474,6 @@ match_upattern (string, pat, mtype, sp, ep) size_t len; register char *p, *p1, *npat; char *end; - int n1; /* If the pattern doesn't match anywhere in the string, go ahead and short-circuit right away. A minor optimization, saves a bunch of @@ -4768,7 +4774,6 @@ match_pattern (string, pat, mtype, sp, ep) size_t n; wchar_t *wstring, *wpat; char **indices; - size_t slen, plen, mslen, mplen; #endif if (string == 0 || pat == 0 || *pat == 0) @@ -4966,7 +4971,7 @@ parameter_brace_remove_pattern (varname, value, ind, patstr, rtype, quoted, flag char *patstr; int rtype, quoted, flags; { - int vtype, patspec, starsub; + int vtype, patspec; char *temp1, *val, *pattern; SHELL_VAR *v; @@ -4979,7 +4984,6 @@ parameter_brace_remove_pattern (varname, value, ind, patstr, rtype, quoted, flag if (vtype == -1) return ((char *)NULL); - starsub = vtype & VT_STARSUB; vtype &= ~VT_STARSUB; patspec = getpatspec (rtype, patstr); @@ -5521,13 +5525,24 @@ static char * make_named_pipe () { char *tname; + int retries; - tname = sh_mktmpname ("sh-np", MT_USERANDOM|MT_USETMPDIR); - if (mkfifo (tname, 0600) < 0) + retries = 0x1000; + do { - free (tname); - return ((char *)NULL); - } + tname = sh_mktmpname_unsafe ("sh-np", MT_USETMPDIR); + if (!tname) + { + free (tname); + return ((char *)NULL); + } + if (mkfifo (tname, 0600) == 0) break; + if (errno != EEXIST || !--retries) + { + free (tname); + return ((char *)NULL); + } + } while(1); add_fifo_list (tname); return (tname); @@ -5935,7 +5950,7 @@ read_comsub (fd, quoted, rflag) int fd, quoted; int *rflag; { - char *istring, buf[128], *bufp, *s; + char *istring, buf[128], *bufp = 0, *s; int istring_index, istring_size, c, tflag, skip_ctlesc, skip_ctlnul; ssize_t bufn; int nullbyte; @@ -6051,7 +6066,7 @@ command_substitute (string, quoted) char *string; int quoted; { - pid_t pid, old_pid, old_pipeline_pgrp, old_async_pid; + pid_t pid, old_pid = 0, old_pipeline_pgrp, old_async_pid; char *istring, *s; int result, fildes[2], function_value, pflags, rc, tflag; WORD_DESC *ret; @@ -6649,7 +6664,7 @@ parameter_brace_expand_indir (name, var_is_special, quoted, quoted_dollar_atp, c int var_is_special, quoted; int *quoted_dollar_atp, *contains_dollar_at; { - char *temp, *t; + char *t; WORD_DESC *w; SHELL_VAR *v; @@ -6894,7 +6909,7 @@ static intmax_t parameter_brace_expand_length (name) char *name; { - char *t, *newname; + char *t = 0, *newname; intmax_t number, arg_index; WORD_LIST *list; #if defined (ARRAY_VARS) @@ -7018,8 +7033,8 @@ verify_substring_values (v, value, substr, vtype, e1p, e2p) arrayind_t len; int expok; #if defined (ARRAY_VARS) - ARRAY *a; - HASH_TABLE *h; + ARRAY *a = 0; + HASH_TABLE *h = 0; #endif /* duplicate behavior of strchr(3) */ @@ -7151,7 +7166,6 @@ get_var_and_type (varname, value, ind, quoted, flags, varp, valp) { int vtype, want_indir; char *temp, *vname; - WORD_DESC *wd; SHELL_VAR *v; arrayind_t lind; @@ -7931,13 +7945,12 @@ parameter_brace_expand (string, indexp, quoted, pflags, quoted_dollar_atp, conta { int check_nullness, var_is_set, var_is_null, var_is_special; int want_substring, want_indir, want_patsub, want_casemod; - char *name, *value, *temp, *temp1; + char *name, *value = 0, *temp = 0, *temp1 = 0; WORD_DESC *tdesc, *ret; - int t_index, sindex, c, tflag, modspec, all_element_arrayref; + int t_index, sindex, c, tflag, modspec = 0, all_element_arrayref; intmax_t number; arrayind_t ind; - temp = temp1 = value = (char *)NULL; var_is_set = var_is_null = var_is_special = check_nullness = 0; want_substring = want_indir = want_patsub = want_casemod = 0; @@ -10467,7 +10480,6 @@ shell_expand_word_list (tlist, eflags) { WORD_LIST *expanded, *orig_list, *new_list, *next, *temp_list, *wcmd; int expanded_something, has_dollar_at; - char *temp_string; /* We do tilde expansion all the time. This is what 1003.2 says. */ new_list = (WORD_LIST *)NULL; @@ -10477,8 +10489,6 @@ shell_expand_word_list (tlist, eflags) for (orig_list = tlist; tlist; tlist = next) { - temp_string = tlist->word->word; - next = tlist->next; #if defined (ARRAY_VARS) @@ -10491,7 +10501,8 @@ shell_expand_word_list (tlist, eflags) if ((tlist->word->flags & (W_COMPASSIGN|W_ASSIGNARG)) == (W_COMPASSIGN|W_ASSIGNARG)) { int t; - char opts[16], opti; + unsigned char opti; + char opts[16]; opti = 0; if (tlist->word->flags & (W_ASSIGNASSOC|W_ASSNGLOBAL|W_ASSIGNARRAY)) @@ -10538,7 +10549,7 @@ shell_expand_word_list (tlist, eflags) case 'l': case 'u': case 'c': - omap[l->word->word[oind]] = 1; + omap[(unsigned char) l->word->word[oind]] = 1; if (opti == 0) opts[opti++] = '-'; break; @@ -10673,11 +10684,12 @@ expand_word_list_internal (list, eflags) tint = do_word_assignment (temp_list->word, 0); this_command_name = savecmd; /* Variable assignment errors in non-interactive shells - running in Posix.2 mode cause the shell to exit. */ + running in Posix.2 mode cause the shell to exit, unless + they are being run by the `command' builtin. */ if (tint == 0) { last_command_exit_value = EXECUTION_FAILURE; - if (interactive_shell == 0 && posixly_correct) + if (interactive_shell == 0 && posixly_correct && executing_command_builtin == 0) exp_jump_to_top_level (FORCE_EOF); else exp_jump_to_top_level (DISCARD); diff --git a/support/bashbug.sh b/support/bashbug.sh index 29ce134..2c34cfe 100644 --- a/support/bashbug.sh +++ b/support/bashbug.sh @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/bin/sh4 - # # bashbug - create a bug report and mail it to the bug address # @@ -38,18 +38,14 @@ MACHTYPE="!MACHTYPE!" PATH=/bin:/usr/bin:/usr/local/bin:$PATH export PATH -# Check if TMPDIR is set, default to /tmp -: ${TMPDIR:=/tmp} - -#Securely create a temporary directory for the temporary files -TEMPDIR=$TMPDIR/bbug.$$ -(umask 077 && mkdir $TEMPDIR) || { - echo "$0: could not create temporary directory" >&2 +TEMPFILE1="`mktemp -t bashbug.XXXXXXXXXX`" || exit 1 +TEMPFILE2="`mktemp -t bashbug.XXXXXXXXXX`" || { + rm -f "$TEMPFILE1" exit 1 } -TEMPFILE1=$TEMPDIR/bbug1 -TEMPFILE2=$TEMPDIR/bbug2 +trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' HUP INT PIPE TERM +trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"' EXIT USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]" VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}" @@ -120,24 +116,8 @@ esac BUGADDR="${1-$BUGBASH}" if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then - if [ -x /usr/bin/editor ]; then - DEFEDITOR=editor - elif [ -x /usr/local/bin/ce ]; then - DEFEDITOR=ce - elif [ -x /usr/local/bin/emacs ]; then - DEFEDITOR=emacs - elif [ -x /usr/contrib/bin/emacs ]; then - DEFEDITOR=emacs - elif [ -x /usr/bin/emacs ]; then - DEFEDITOR=emacs - elif [ -x /usr/bin/xemacs ]; then - DEFEDITOR=xemacs - elif [ -x /usr/contrib/bin/jove ]; then - DEFEDITOR=jove - elif [ -x /usr/local/bin/jove ]; then - DEFEDITOR=jove - elif [ -x /usr/bin/vi ]; then - DEFEDITOR=vi + if [ -x /bin/vitmp ]; then + DEFEDITOR=vitmp else echo "$0: No default editor found: attempting to use vi" >&2 DEFEDITOR=vi @@ -149,9 +129,6 @@ fi : ${USER=${LOGNAME-`whoami`}} -trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15 -trap 'rm -rf "$TEMPDIR"' 0 - UN= if (uname) >/dev/null 2>&1; then UN=`uname -a` @@ -202,7 +179,8 @@ EOF cp "$TEMPFILE1" "$TEMPFILE2" chmod u+w "$TEMPFILE1" -trap '' 2 # ignore interrupts while in editor +# ignore interrupts while in editor +trap '' INT edstat=1 while [ $edstat -ne 0 ]; do @@ -249,7 +227,8 @@ while [ $edstat -ne 0 ]; do done -trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT +# restore trap on SIGINT +trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' INT if cmp -s "$TEMPFILE1" "$TEMPFILE2" then diff --git a/support/fixlinks b/support/fixlinks index 73b0fa3..16b56ab 100755 --- a/support/fixlinks +++ b/support/fixlinks @@ -22,7 +22,7 @@ SRCDIR=. while [ $# -gt 0 ]; do case "$1" in - -s) shift; SRCDIR=$1 ;; + -s) shift; SRCDIR="$1" ;; -u) unfix=yes ;; -h) hardlinks=yes ;; -*) echo "$0: $1: bad option" 1>&2 @@ -33,15 +33,15 @@ while [ $# -gt 0 ]; do shift done -if [ ! -d $SRCDIR/builtins ]; then +if [ ! -d "$SRCDIR/builtins" ]; then echo "$0: must be run with valid -s argument or from source directory" 1>&2 exit 1 fi if [ $# -eq 0 ]; then - linkfile=$SRCDIR/support/SYMLINKS + linkfile="$SRCDIR/support/SYMLINKS" else - linkfile=$1 + linkfile="$1" fi if [ ! -f "$linkfile" ]; then @@ -49,25 +49,12 @@ if [ ! -f "$linkfile" ]; then exit 1 fi -rm_ltmp=false -LINKTEMP=`mktemp -t linktmp.XXXXXXXX 2>/dev/null` -if [ -z "$LINKTEMP" ]; then - : ${TMPDIR:=/tmp} - LINKTEMP=${TMPDIR}/linktmp.$$ - rm_ltmp=true -fi - -$rm_ltmp && rm -f ${LINKTEMP} -# if the user specified hard links, then do that. otherwise, try to use -# symlinks if they're present +# if the user specified hard links, then do that. otherwise, use symlinks. if [ -n "$hardlinks" ]; then LN=ln -elif (ln -s /dev/null ${LINKTEMP}) >/dev/null 2>&1; then - LN="ln -s" else - LN=ln + LN="ln -s" fi -rm -f ${LINKTEMP} while read name target do @@ -75,15 +62,15 @@ do \#*) continue;; esac - rm -f $name + rm -f "$name" case "$unfix" in yes) dirname=`expr "$name" ':' '^\(.*\)/[^/]*'` [ -z "$dirname" ] && dirname=. - cp $dirname/$target $name - echo $target copied to $name ;; - *) $LN $target $name ; echo "$name -> $target" ;; + cp "$dirname/$target" "$name" + echo "$target copied to $name" ;; + *) $LN "$target" "$name" ; echo "$name -> $target" ;; esac -done < $linkfile +done < "$linkfile" exit 0 diff --git a/support/man2html.c b/support/man2html.c index 6ba5061..e87e9fa 100644 --- a/support/man2html.c +++ b/support/man2html.c @@ -101,8 +101,6 @@ #define EXIT_USAGE 2 #endif -static char location_base[NULL_TERMINATED(MED_STR_MAX)] = ""; - static char th_page_and_sec[128] = { '\0' }; static char th_datestr[128] = { '\0' }; static char th_version[128] = { '\0' }; @@ -144,6 +142,7 @@ strerror(int e) } #endif /* !HAVE_STRERROR */ +#if 0 static char * strgrow(char *old, int len) { @@ -155,6 +154,7 @@ strgrow(char *old, int len) } return new; } +#endif static char * stralloc(int len) @@ -182,6 +182,7 @@ xmalloc (size_t size) return ret; } +#if 0 /* * Some systems don't have strdup so lets use our own - which can also * check for out of memory. @@ -194,6 +195,7 @@ strduplicate(char *from) strcpy(new, from); return new; } +#endif /* Assumes space for n plus a null */ static char * @@ -206,6 +208,7 @@ strmaxcpy(char *to, char *from, int n) return to; } +#if 0 static char * strmaxcat(char *to, char *from, int n) { @@ -220,6 +223,7 @@ strmaxcat(char *to, char *from, int n) } return to; } +#endif /* Assumes space for limit plus a null */ static char * @@ -232,6 +236,7 @@ strlimitcpy(char *to, char *from, int n, int limit) return to; } +#if 0 /* * takes string and escapes all metacharacters. should be used before * including string in system() or similar call. @@ -261,6 +266,7 @@ escape_input(char *str) new[j] = '\0'; return new; } +#endif static void usage(void) @@ -293,10 +299,12 @@ struct INTDEF { static char NEWLINE[2] = "\n"; static char idxlabel[6] = "ixAAA"; -#define INDEXFILE "/tmp/manindex.list" +#ifdef MAKEINDEX +#define INDEXFILE "manindex.list" static char *fname; static FILE *idxfile; +#endif static STRDEF *chardef, *strdef, *defdef; static INTDEF *intdef; @@ -425,7 +433,6 @@ static STRDEF standardchar[] = { /* default: print code */ -static char eqndelimopen = 0, eqndelimclose = 0; static char escapesym = '\\', nobreaksym = '\'', controlsym = '.', fieldsym = 0, padsym = 0; static char *buffer = NULL; @@ -505,7 +512,6 @@ static char * read_man_page(char *filename) { char *man_buf = NULL; - int i; FILE *man_stream = NULL; struct stat stbuf; int buf_size; @@ -933,7 +939,6 @@ change_to_size(int nr) return sizebuf; } -static int asint = 0; static int intresult = 0; #define SKIPEOL while (*c && *c++!='\n') @@ -1435,12 +1440,12 @@ static char itemreset[20] = "\\fR\\s0"; static char * scan_table(char *c) { - char *t, *h, *g; + char *h, *g; int center = 0, expand = 0, box = 0, border = 0, linesize = 1; int i, j, maxcol = 0, finished = 0; int oldfont, oldsize, oldfillout; char itemsep = '\t'; - TABLEROW *layout = NULL, *currow, *ftable; + TABLEROW *layout = NULL, *currow; TABLEITEM *curfield; while (*c++ != '\n'); @@ -1770,7 +1775,7 @@ scan_table(char *c) static char * scan_expression(char *c, int *result) { - int value = 0, value2, j = 0, sign = 1, opex = 0; + int value = 0, value2, sign = 1, opex = 0; char oper = 'c'; if (*c == '!') { @@ -2239,7 +2244,6 @@ scan_request(char *c) case V('d', 'i'): { STRDEF *de; - int oldcurpos = curpos; c = c + j; i = V(c[0], c[1]); @@ -2536,7 +2540,6 @@ scan_request(char *c) break; case V('s', 'o'): { - FILE *f; struct stat stbuf; int l = 0; char *buf; @@ -3744,11 +3747,6 @@ scan_request(char *c) return c; } -static void -flush(void) -{ -} - static int contained_tab = 0; static int mandoc_line = 0; /* Signals whether to look for embedded * mandoc commands. */ @@ -3760,7 +3758,6 @@ scan_troff(char *c, int san, char **result) char *h; char intbuff[NULL_TERMINATED(MED_STR_MAX)]; int ibp = 0; - int i; char *exbuffer; int exbuffpos, exbuffmax, exscaninbuff, exnewline_for_fun; int usenbsp = 0; @@ -3819,8 +3816,6 @@ scan_troff(char *c, int san, char **result) if (san && h[-1] == '\n') h--; } else { - int mx; - if (h[-1] == '\n' && still_dd && isalnum(*h)) { /* * sometimes a .HP request is not followed by @@ -3989,11 +3984,10 @@ scan_troff_mandoc(char *c, int san, char **result) int main(int argc, char **argv) { - FILE *f; char *t; - int l, i; + int i; char *buf; - char *h, *fullname; + char *h; STRDEF *stdf; t = NULL; diff --git a/support/mkclone b/support/mkclone index 1840b03..df7fb8c 100755 --- a/support/mkclone +++ b/support/mkclone @@ -27,12 +27,12 @@ USAGE="usage: $prog [-m manifest] [-s srcdir] [-v] [-d] [-h] target" while getopts dhm:s:v opt do case "$opt" in - m) MANIFEST=$OPTARG ;; - s) SRCDIR=$OPTARG ;; + m) MANIFEST="$OPTARG" ;; + s) SRCDIR="$OPTARG" ;; v) verbose=y ;; d) ECHO=echo debug=y ;; h) hardlinks=y ;; - ?) echo $USAGE >&2 + ?) echo "$USAGE" >&2 exit 2;; esac done @@ -44,37 +44,24 @@ done shift $(( $OPTIND - 1 )) if [ $# -lt 1 ]; then - echo $USAGE >&2 + echo "$USAGE" >&2 exit 2 fi -if [ ! -f $MANIFEST ]; then +if [ ! -f "$MANIFEST" ]; then echo "$prog: $MANIFEST: no such file or directory" >&2 echo "$prog: must be run with valid -s argument or from source directory" >&2 exit 1 fi -rm_ltmp=false -LINKTEMP=`mktemp -t linktmp.XXXXXXXX 2>/dev/null` -if [ -z "$LINKTEMP" ]; then - : ${TMPDIR:=/tmp} - LINKTEMP=${TMPDIR}/linktmp.$$ - rm_ltmp=true -fi - -$rm_ltmp && rm -f ${LINKTEMP} -# if the user specified hard links, then do that. otherwise, try to use -# symlinks if they're present +# if the user specified hard links, then do that. otherwise, use symlinks. if [ -n "$hardlinks" ]; then LN=ln -elif (ln -s /dev/null ${LINKTEMP}) >/dev/null 2>&1; then - LN="ln -s" else - LN=ln + LN="ln -s" fi -rm -f ${LINKTEMP} -TARGET=$1 +TARGET="$1" if [ ! -d "$TARGET" ]; then mkdir "$TARGET" @@ -94,7 +81,7 @@ do case "$type" in d) [ -n "$verbose" ] && echo mkdir $fname - $ECHO mkdir $fname ;; # already in $TARGET + $ECHO mkdir "$fname" ;; # already in $TARGET f) fn=${fname##*/} case "$fname" in */*) dn=${fname%/*} ;; @@ -103,11 +90,11 @@ do if [ -n "$verbose" ] || [ -n "$debug" ]; then echo "( cd $dn && $LN $SRCDIR/$fname $fn )" fi - [ -z "$debug" ] && ( cd $dn && $LN $SRCDIR/$fname $fn ) + [ -z "$debug" ] && ( cd "$dn" && $LN "$SRCDIR/$fname" "$fn" ) ;; *) echo "${prog}: ${fname}: unknown file type $type" 1>&2 ;; esac -done < $MANIFEST +done < "$MANIFEST" # special SPECIAL="parser-built y.tab.c y.tab.h" @@ -115,8 +102,8 @@ SPECIAL="parser-built y.tab.c y.tab.h" rm -f $SPECIAL for sf in $SPECIAL do - [ -n "$verbose" ] && echo cp -p $SRCDIR/$sf $TARGET - $ECHO cp -p $SRCDIR/$sf $TARGET + [ -n "$verbose" ] && echo cp -p "$SRCDIR/$sf" "$TARGET" + $ECHO "cp -p $SRCDIR/$sf $TARGET" done exit 0 diff --git a/support/rlvers.sh b/support/rlvers.sh index 64cadc7..09657f5 100755 --- a/support/rlvers.sh +++ b/support/rlvers.sh @@ -22,9 +22,6 @@ PROGNAME=`basename $0` -: ${TMPDIR:=/tmp} -TDIR=$TMPDIR/rlvers - # defaults CC=cc RL_LIBDIR=/usr/local/lib @@ -47,11 +44,11 @@ done # if someone happened to install examples/rlversion, use it (it's not # installed by default) -if test -f ${RL_LIBDIR}/rlversion ; then +if test -f "${RL_LIBDIR}/rlversion" ; then if [ -n "$verbose" ]; then echo "${PROGNAME}: using installed rlversion from ${RL_LIBDIR}/rlversion" fi - v=`${RL_LIBDIR}/rlversion 2>/dev/null` + v="`${RL_LIBDIR}/rlversion 2>/dev/null`" case "$v" in unknown | "") echo 0 ;; *) echo "$v" ;; @@ -64,17 +61,14 @@ if [ -n "$verbose" ]; then echo "${PROGNAME}: attempting program compilation" fi -# make $TDIR mode 0700 -mkdir $TDIR || { - echo "${PROGNAME}: ${TDIR}: file exists" >&2 +TDIR="mktemp -td rlvers.XXXXXXXXXX" || { echo 0 exit 1 } -chmod 700 $TDIR -trap 'rm -f $TDIR/rlvers $TDIR/rlvers.? ; rmdir $TDIR' 0 1 2 3 6 15 +trap 'rm -f "$TDIR"/rlvers "$TDIR"/rlvers.? ; rmdir "$TDIR'" EXIT HUP INT TERM -cat > $TDIR/rlvers.c << EOF +cat > "$TDIR"/rlvers.c << EOF #include extern char *rl_library_version; @@ -87,15 +81,15 @@ EOF opwd=`pwd` -cd $TDIR || { +cd "$TDIR" || { echo "${PROGNAME}: cannot cd to $TDIR" >&2 echo 0 exit 1 } -if eval ${CC} -L${RL_LIBDIR} -I${RL_INCDIR} -o $TDIR/rlvers $TDIR/rlvers.c -lreadline ${TERMCAP_LIB}; +if eval ${CC} -L${RL_LIBDIR} -I${RL_INCDIR} -o "$TDIR"/rlvers "$TDIR"/rlvers.c -lreadline ${TERMCAP_LIB}; then - v=`$TDIR/rlvers` + v=`"$TDIR"/rlvers` else if [ -n "$verbose" ] ; then echo "${PROGNAME}: compilation failed: status $?" @@ -109,5 +103,5 @@ unknown | "") echo 0 ;; *) echo "$v" ;; esac -cd $opwd +cd "$opwd" exit 0 diff --git a/trap.c b/trap.c index eb8ecf3..134f21a 100644 --- a/trap.c +++ b/trap.c @@ -940,8 +940,8 @@ _run_trap_internal (sig, tag) char *tag; { char *trap_command, *old_trap; - int trap_exit_value, *token_state; - volatile int save_return_catch_flag, function_code, top_level_code, old_int; + int trap_exit_value; + volatile int save_return_catch_flag, function_code, old_int; int flags; procenv_t save_return_catch; WORD_LIST *save_subst_varlist; diff --git a/variables.c b/variables.c index be2446e..0d00ad0 100644 --- a/variables.c +++ b/variables.c @@ -667,13 +667,11 @@ initialize_shell_variables (env, privmode) static void set_machine_vars () { - SHELL_VAR *temp_var; - - temp_var = set_if_not ("HOSTTYPE", HOSTTYPE); - temp_var = set_if_not ("OSTYPE", OSTYPE); - temp_var = set_if_not ("MACHTYPE", MACHTYPE); + set_if_not ("HOSTTYPE", HOSTTYPE); + set_if_not ("OSTYPE", OSTYPE); + set_if_not ("MACHTYPE", MACHTYPE); - temp_var = set_if_not ("HOSTNAME", current_host_name); + set_if_not ("HOSTNAME", current_host_name); } /* Set $HOME to the information in the password file if we didn't get @@ -1904,7 +1902,7 @@ find_variable_nameref (v) SHELL_VAR *v; { int level, flags; - char *newname, *t; + char *newname; SHELL_VAR *orig, *oldv; level = 0; @@ -1995,7 +1993,6 @@ find_nameref_at_context (v, vc) VAR_CONTEXT *vc; { SHELL_VAR *nv, *nv2; - VAR_CONTEXT *nvc; char *newname; int level; @@ -2832,7 +2829,6 @@ bind_variable (name, value, flags) { SHELL_VAR *v, *nv; VAR_CONTEXT *vc, *nvc; - int level; if (shell_variables == 0) create_variable_tables (); @@ -2910,10 +2906,6 @@ bind_global_variable (name, value, flags) char *value; int flags; { - SHELL_VAR *v, *nv; - VAR_CONTEXT *vc, *nvc; - int level; - if (shell_variables == 0) create_variable_tables (); @@ -5547,13 +5539,12 @@ ARRAY * save_pipestatus_array () { SHELL_VAR *v; - ARRAY *a, *a2; + ARRAY *a2; v = find_variable ("PIPESTATUS"); if (v == 0 || array_p (v) == 0 || array_cell (v) == 0) return ((ARRAY *)NULL); - a = array_cell (v); a2 = array_copy (array_cell (v)); return a2; diff --git a/variables.h b/variables.h index 25c9ae0..be3aebc 100644 --- a/variables.h +++ b/variables.h @@ -95,8 +95,8 @@ typedef struct variable { typedef struct _vlist { SHELL_VAR **list; - int list_size; /* allocated size */ - int list_len; /* current number of entries */ + size_t list_size; /* allocated size */ + size_t list_len; /* current number of entries */ } VARLIST; /* The various attributes that a given variable can have. */ diff --git a/xmalloc.c b/xmalloc.c index b32c068..b8000ea 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -49,11 +49,11 @@ #if defined (HAVE_SBRK) && !HAVE_DECL_SBRK extern char *sbrk(); -#endif static PTR_T lbreak; static int brkfound; static size_t allocated; +#endif /* **************************************************************** */ /* */