1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 1N/A#
endif /* SHOPT_PFSH */ 1N/A /* Solaris implements realpath(3C) using the resolvepath(2) */ 1N/A /* system call so we can save us to call access(2) first */ 1N/A /* we can exec the command directly instead of via pfexec(1) if */ 1N/A /* there is a matching entry without attributes in exec_attr(4) */ 1N/A * used with command -x to run the command in multiple passes 1N/A * spawn is non-zero when invoked via spawn 1N/A * the exitval is set to the maximum for each execution 1N/A /* leave at least two for last */ 1N/A * make sure PWD is set up correctly 1N/A * Return the present working directory 1N/A * Invokes getcwd() if flag==0 and if necessary 1N/A * Sets the PWD variable to this value 1N/A /* try from lowest to highest */ 1N/A if(
flag)
/* skip next case when non-zero flag */ 1N/A * delete current Pathcomp_t structure 1N/A#
endif /* SHOPT_DYNAMIC */ 1N/A * returns library variable from .paths 1N/A * The value might be returned on the stack overwriting path 1N/A * check for duplicate directories on PATH 1N/A * write the next path to search on the current stack 1N/A * if last is given, all paths that come before <last> are skipped 1N/A * the next pathcomp is returned. 1N/A if(!
pp)
/* this should not happen */ 1N/A * returns that pathlist to search 1N/A * open file corresponding to name using path give by <pp> 1N/A * open file corresponding to name using path give by <pp> 1N/A * given a pathname return the base name 1N/A if ((*
name++ ==
'/') && *
name)
/* don't trim trailing / */ 1N/A * load functions from file <fno> 1N/A * do a path search and track alias if requested 1N/A * if flag is 0, or if name not found, then try autoloading function 1N/A * if flag==2 or 3, returns 1 if name found on FPATH 1N/A * if flag==3 no tracked alias will be set 1N/A * returns 1, if function was autoloaded. 1N/A * If oldpp is not NULL, it will contain a pointer to the path component 1N/A * where it was found. 1N/A * do a path search and find the full pathname of file name 1N/A * this detects the 2007-05-11 builtin context change and also 1N/A * the 2008-03-30 opt_info.num change that hit libcmd::b_head 1N/A#
endif /* SHOPT_DYNAMIC */ 1N/A * returns 0 if path can execute 1N/A * sets exec_err if file is found but can't be executable 1N/A /* check for .exe or .bat suffix */ 1N/A * Return path relative to present working directory 1N/A /* can't relpath when shp->pwd not set */ 1N/A /* name containing / not allowed for restricted shell */ 1N/A /* find first path that has a library component */ 1N/A /* leave room for inserting _= pathname in environment */ 1N/A /* save original pathname */ 1N/A /* check for symlink and use symlink name */ 1N/A * The following code because execv(foo,) and execv(./foo,) 1N/A * may not yield the same results 1N/A#
endif /* SHELLMAGIC */ 1N/A#
endif /* SHELLMAGIC */ 1N/A * On apollo's execve will fail with eacces when 1N/A * file has execute but not read permissions. So, 1N/A * for now we will pretend that EACCES and ENOEXEC 1N/A * mean the same thing. 1N/A /* some systems return EPERM if setuid bit is on */ 1N/A#
endif /* ENAMETOOLONG */ 1N/A * File is executable but not machine code. 1N/A * Assume file is a Shell script and execute it. 1N/A /* clean up any cooperating processes */ 1N/A /* move <n> if n=0,1,2 */ 1N/A /* create a suid open file with owner equal effective uid */ 1N/A /* make sure that file has right owner */ 1N/A * The following code is just for compatibility 1N/A#
endif /* SHOPT_ACCT */ 1N/A /* save name of calling command */ 1N/A /* close history file if name has changed */ 1N/A static char *
SHACCT;
/* set to value of SHACCT environment variable */ 1N/A static shaccton;
/* non-zero causes accounting record to be written */ 1N/A * initialize accounting, i.e., see if SHACCT variable set 1N/A * suspend accounting until turned on by sh_accbegin() 1N/A * begin an accounting record by recording start time 1N/A * terminate an accounting record and append to accounting file 1N/A * Produce a pseudo-floating point representation 1N/A * with 3 bits base-8 exponent, 13 bits fraction. 1N/A#
endif /* SHOPT_ACCT */ 1N/A * add a pathcomponent to the path search list and eliminate duplicates 1N/A * and non-existing absolute paths. 1N/A * This function checks for the .paths file in directory in <pp> 1N/A * it assumes that the directory is on the stack at <offset> 1N/A if(m==0 || m==
6 &&
memcmp((
void*)
sp,(
void*)
"FPATH=",
6)==0)
1N/A else if(m==
12 &&
memcmp((
void*)
sp,(
void*)
"BUILTIN_LIB=",
12)==0)
1N/A * duplicate the path give by <first> by incremented reference counts 1N/A * called whenever the directory is changed 1N/A /* delete .paths component */ 1N/A /* try to insert .paths component */ 1N/A * get discipline for tracked alias 1N/A * set tracked alias node <np> to value <pp>