Bash-4.4 distribution sources and documentation

This commit is contained in:
Chet Ramey 2016-09-15 16:59:08 -04:00
commit a0c0a00fc4
588 changed files with 130746 additions and 80164 deletions

115
findcmd.c
View file

@ -1,6 +1,6 @@
/* findcmd.c -- Functions to search for commands by name. */
/* Copyright (C) 1997-2012 Free Software Foundation, Inc.
/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -44,6 +44,8 @@
#include "hashcmd.h"
#include "findcmd.h" /* matching prototypes and declarations */
#include <glob/strmatch.h>
#if !defined (errno)
extern int errno;
#endif
@ -69,7 +71,7 @@ static char *file_to_lose_on;
/* Non-zero if we should stat every command found in the hash table to
make sure it still exists. */
int check_hashed_filenames;
int check_hashed_filenames = CHECKHASH_DEFAULT;
/* DOT_FOUND_IN_SEARCH becomes non-zero when find_user_command ()
encounters a `.' as the directory pathname while scanning the
@ -77,6 +79,36 @@ int check_hashed_filenames;
containing the file of interest. */
int dot_found_in_search = 0;
/* Set up EXECIGNORE; a blacklist of patterns that executable files should not
match. */
static struct ignorevar execignore =
{
"EXECIGNORE",
NULL,
0,
NULL,
NULL
};
void
setup_exec_ignore (varname)
char *varname;
{
setup_ignore_patterns (&execignore);
}
static int
exec_name_should_ignore (name)
const char *name;
{
struct ign *p;
for (p = execignore.ignores; p && p->val; p++)
if (strmatch (p->val, (char *)name, FNMATCH_EXTFLAG|FNM_CASEFOLD) != FNM_NOMATCH)
return 1;
return 0;
}
/* Return some flags based on information about this file.
The EXISTS bit is non-zero if the file is found.
The EXECABLE bit is non-zero the file is executble.
@ -104,7 +136,7 @@ file_status (name)
file access mechanisms into account. eaccess uses the effective
user and group IDs, not the real ones. We could use sh_eaccess,
but we don't want any special treatment for /dev/fd. */
if (eaccess (name, X_OK) == 0)
if (exec_name_should_ignore (name) == 0 && eaccess (name, X_OK) == 0)
r |= FS_EXECABLE;
if (eaccess (name, R_OK) == 0)
r |= FS_READABLE;
@ -114,7 +146,7 @@ file_status (name)
/* We have to use access(2) to determine access because AFS does not
support Unix file system semantics. This may produce wrong
answers for non-AFS files when ruid != euid. I hate AFS. */
if (access (name, X_OK) == 0)
if (exec_name_should_ignore (name) == 0 && access (name, X_OK) == 0)
r |= FS_EXECABLE;
if (access (name, R_OK) == 0)
r |= FS_READABLE;
@ -131,7 +163,7 @@ file_status (name)
if (current_user.euid == (uid_t)0)
{
r |= FS_READABLE;
if (finfo.st_mode & S_IXUGO)
if (exec_name_should_ignore (name) == 0 && (finfo.st_mode & S_IXUGO))
r |= FS_EXECABLE;
return r;
}
@ -139,7 +171,7 @@ file_status (name)
/* If we are the owner of the file, the owner bits apply. */
if (current_user.euid == finfo.st_uid)
{
if (finfo.st_mode & S_IXUSR)
if (exec_name_should_ignore (name) == 0 && (finfo.st_mode & S_IXUSR))
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRUSR)
r |= FS_READABLE;
@ -148,7 +180,7 @@ file_status (name)
/* If we are in the owning group, the group permissions apply. */
else if (group_member (finfo.st_gid))
{
if (finfo.st_mode & S_IXGRP)
if (exec_name_should_ignore (name) == 0 && (finfo.st_mode & S_IXGRP))
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRGRP)
r |= FS_READABLE;
@ -157,7 +189,7 @@ file_status (name)
/* Else we check whether `others' have permission to execute the file */
else
{
if (finfo.st_mode & S_IXOTH)
if (exec_name_should_ignore (name) == 0 && finfo.st_mode & S_IXOTH)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IROTH)
r |= FS_READABLE;
@ -178,7 +210,7 @@ executable_file (file)
int s;
s = file_status (file);
#if defined EISDIR
#if defined (EISDIR)
if (s & FS_DIRECTORY)
errno = EISDIR; /* let's see if we can improve error messages */
#endif
@ -297,15 +329,17 @@ get_next_path_element (path_list, path_index_pointer)
/* Look for PATHNAME in $PATH. Returns either the hashed command
corresponding to PATHNAME or the first instance of PATHNAME found
in $PATH. If (FLAGS&1) is non-zero, insert the instance of PATHNAME
found in $PATH into the command hash table. Returns a newly-allocated
string. */
in $PATH. If (FLAGS&CMDSRCH_HASH) is non-zero, insert the instance of
PATHNAME found in $PATH into the command hash table. If (FLAGS&CMDSRCH_STDPATH)
is non-zero, we are running in a `command -p' environment and should use
the Posix standard path.
Returns a newly-allocated string. */
char *
search_for_command (pathname, flags)
const char *pathname;
int flags;
{
char *hashed_file, *command;
char *hashed_file, *command, *pathlist;
int temp_path, st;
SHELL_VAR *path;
@ -315,13 +349,11 @@ search_for_command (pathname, flags)
hash table to search for the full pathname. */
path = find_variable_tempenv ("PATH");
temp_path = path && tempvar_p (path);
if (temp_path == 0 && path)
path = (SHELL_VAR *)NULL;
/* Don't waste time trying to find hashed data for a pathname
that is already completely specified or if we're using a command-
specific value for PATH. */
if (path == 0 && absolute_program (pathname) == 0)
if (temp_path == 0 && absolute_program (pathname) == 0)
hashed_file = phash_search (pathname);
/* If a command found in the hash table no longer exists, we need to
@ -347,18 +379,34 @@ search_for_command (pathname, flags)
command = savestring (pathname);
else
{
/* If $PATH is in the temporary environment, we've already retrieved
it, so don't bother trying again. */
if (temp_path)
{
command = find_user_command_in_path (pathname, value_cell (path),
FS_EXEC_PREFERRED|FS_NODIRS);
}
if (flags & CMDSRCH_STDPATH)
pathlist = conf_standard_path ();
else if (temp_path || path)
pathlist = value_cell (path);
else
command = find_user_command (pathname);
if (command && hashing_enabled && temp_path == 0 && (flags & 1))
phash_insert ((char *)pathname, command, dot_found_in_search, 1); /* XXX fix const later */
pathlist = 0;
command = find_user_command_in_path (pathname, pathlist, FS_EXEC_PREFERRED|FS_NODIRS);
if (command && hashing_enabled && temp_path == 0 && (flags & CMDSRCH_HASH))
{
/* If we found the full pathname the same as the command name, the
command probably doesn't exist. Don't put it into the hash
table. */
if (STREQ (command, pathname))
{
st = file_status (command);
if (st & FS_EXECABLE)
phash_insert ((char *)pathname, command, dot_found_in_search, 1);
}
else
phash_insert ((char *)pathname, command, dot_found_in_search, 1);
}
if (flags & CMDSRCH_STDPATH)
free (pathlist);
}
return (command);
}
@ -478,7 +526,7 @@ find_in_path_element (name, path, flags, name_len, dotinfop)
int status;
char *full_path, *xpath;
xpath = (*path == '~') ? bash_tilde_expand (path, 0) : path;
xpath = (posixly_correct == 0 && *path == '~') ? bash_tilde_expand (path, 0) : path;
/* Remember the location of "." in the path, in all its forms
(as long as they begin with a `.', e.g. `./.') */
@ -520,7 +568,7 @@ find_in_path_element (name, path, flags, name_len, dotinfop)
/* The file is not executable, but it does exist. If we prefer
an executable, then remember this one if it is the first one
we have found. */
if ((flags & FS_EXEC_PREFERRED) && file_to_lose_on == 0)
if ((flags & FS_EXEC_PREFERRED) && file_to_lose_on == 0 && exec_name_should_ignore (full_path) == 0)
file_to_lose_on = savestring (full_path);
/* If we want only executable files, or we don't want directories and
@ -621,3 +669,14 @@ find_user_command_in_path (name, path_list, flags)
return (file_to_lose_on);
}
/* External interface to find a command given a $PATH. Separate from
find_user_command_in_path to allow future customization. */
char *
find_in_path (name, path_list, flags)
const char *name;
char *path_list;
int flags;
{
return (find_user_command_in_path (name, path_list, flags));
}