[was also: sh(1): POSIX "Command Search and Execution"]
Please note that this is not an "official" proposal. It just a
modification that I implement and could be picked up by others.
In a nutshell, I want to add the possibility to "qualify" an utility
name, with a name composed with components separated by '/' but still
allowing to search this "URI" (qualified name) with PATH---this is not
POSIX compliant.
For example, imagine one has organized all the "The" filesystem
utilities this way:
tfs/create
tfs/ck
tfs/mount
tfs/ctl
In this case, the qualified name is "tfs/create" just like it could be
"DOE/John". It's an URI. The problem is to locate this identified
resource in the PATH.
PATH searching is done in two places: in the shell (I'm only concerned
with bin/sh here) and in the exec[lv]p* family of functions, used by such
utilities as nice, nohup, timeout or xargs.
To quote the exec(3) man page:
---8<---
The functions execlp(), execlpe(), execvp(), and execvpe() will duplicate
the actions of the shell in searching for an executable file if the
specified file name does not contain a slash "/" character. The search
path is the path specified in the environment by the PATH variable. If
this variable isn't specified, _PATH_DEFPATH from <paths.h> is used
instead, its value being: /usr/bin:/bin:/usr/pkg/bin:/usr/local/bin. In
addition, certain errors are treated specially.
--->8---
In order for this to be accomplished, I plan to add a PATH_OPT
environment variable, that will be only a string of ASCII alpha
caracters [A-Za-z], with 'p' reserved for POSIX (having precedence)
and 'q' specifying to allow for such qualified name search. The order
of the flags in the string is not significant.
This adds a:
path_opt = getenv("PATH_OPT");
call and the processing of the flags:
do_qname = (path_opt != NULL
&& strchr(path_opt, 'q') != NULL
&& strchr(path_opt, 'p') == NULL)? 1 : 0;
In order for the test to be very simple and not cost much, a qualified
name is such that the first char is not '/' and that no component has
a terminating '.'. Supposing q is such a tentative pathname (neither
nil nor empty):
q[0] != '/' && strstr(q, "./") == NULL
&& ( (p = strrchr(q, '\0')) && *--p != '/' && *p != '.' )
This does mean that any relative '.' or '..' invalidates the pathname
as an URI.
To use bar/foo relative to current working directory, supposing the
qualified names extension is active, just prepend a "./".
Has anyone comments about such a scheme? The name of the env variable?
The cost in exec*p* functions?
TIA
--
Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.