Give up on implementing proglist portably in sh and do it in C. Fixes issue #42.

This commit is contained in:
Kris Maglione 2010-05-30 15:18:15 -04:00
parent 7ae818a3e9
commit a7705355e8
5 changed files with 111 additions and 9 deletions

View File

@ -58,10 +58,7 @@ fn wi_fn-p {
} }
fn wi_proglist { fn wi_proglist {
# XXX: maxdepth is not POSIX compliant. ifs=: { wmiir proglist -- `{echo -n $*} | sort | uniq }
ifs=: { find -L `{echo -n $*} -type f -a -maxdepth 1 \
'(' -perm -0100 -o -perm -0010 -o -perm -0001 ')' >[2]/dev/null \
| sed 's,.*/,,' | sort | uniq}
} }
fn wi_actions { fn wi_actions {

View File

@ -135,9 +135,7 @@ wi_fnmenu() {
} }
wi_proglist() { wi_proglist() {
ls -lL $(echo $* | sed 'y/:/ /') 2>/dev/null \ wmiir proglist -- $(echo $* | sed 'y/:/ /') | sort | uniq
| awk '$1 ~ /^[^d].*x/ { print $NF }' \
| sort | uniq
} }
wi_actions() { wi_actions() {

View File

@ -3,6 +3,7 @@
*/ */
#define IXP_NO_P9_ #define IXP_NO_P9_
#define IXP_P9_STRUCTS #define IXP_P9_STRUCTS
#include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/signal.h> #include <sys/signal.h>
@ -328,15 +329,44 @@ xnamespace(int argc, char *argv[]) {
return 0; return 0;
} }
static int
xproglist(int argc, char *argv[]) {
DIR *d;
struct dirent *de;
char *dir;
quotefmtinstall();
ARGBEGIN{
default:
usage();
}ARGEND;
while((dir = ARGF()))
if((d = opendir(dir))) {
while((de = readdir(d)))
if(access(de->d_name, X_OK))
print("%q\n", de->d_name);
closedir(d);
}
return 0; /* NOTREACHED */
}
static int static int
xsetsid(int argc, char *argv[]) { xsetsid(int argc, char *argv[]) {
char *av0; char *av0;
bool dofork;
av0 = nil; av0 = nil;
dofork = false;
ARGBEGIN{ ARGBEGIN{
case '0': case '0':
av0 = EARGF(usage()); av0 = EARGF(usage());
break; break;
case 'f':
dofork = true;
break;
default: default:
usage(); usage();
}ARGEND; }ARGEND;
@ -346,6 +376,13 @@ xsetsid(int argc, char *argv[]) {
return 1; return 1;
setsid(); setsid();
if(dofork)
switch(fork()) {
case 0: break;
case -1: fatal("can't fork: %r\n");
default: return 0;
}
execvp(av0, argv); execvp(av0, argv);
fatal("setsid: can't exec: %r"); fatal("setsid: can't exec: %r");
return 1; /* NOTREACHED */ return 1; /* NOTREACHED */
@ -368,6 +405,7 @@ struct exectab {
}, utiltab[] = { }, utiltab[] = {
{"namespace", xnamespace}, {"namespace", xnamespace},
{"ns", xnamespace}, {"ns", xnamespace},
{"proglist", xproglist},
{"setsid", xsetsid}, {"setsid", xsetsid},
{0, } {0, }
}; };

View File

@ -25,6 +25,9 @@ configuration scripts.
The address at which to connect to \fBwmii\fR. The address at which to connect to \fBwmii\fR.
.SH COMMANDS .SH COMMANDS
.P
The following commands deal with 9P filesystems.
.TP .TP
create \fI<file>\fR create \fI<file>\fR
Creates a new file or directory in the filesystem. Permissions and Creates a new file or directory in the filesystem. Permissions and
@ -57,7 +60,7 @@ Synonyms: \fBcat\fR
remove \fI<path>\fR remove \fI<path>\fR
Removes \fI<path>\fR from the filesystem. Removes \fI<path>\fR from the filesystem.
Synonyms: rm Synonyms: \fBrm\fR
.TP .TP
write \fI<file>\fR write \fI<file>\fR
Writes the contents of the standard input to \fI<file>\fR. Writes the contents of the standard input to \fI<file>\fR.
@ -66,6 +69,48 @@ xwrite \fI<file>\fR \fI<data>\fR ...
Writes each argument after \fI<file>\fR to the latter. Writes each argument after \fI<file>\fR to the latter.
.P
Additionally, wmiir provides the following utility commands relevant
to scripting wmii:
.TP
namespace
.RS
Prints the current wmii namespace directory, usually
equivalent to /tmp/ns.\fB$USER\fR.\fB${DISPLAY\fR%.0\fB}\fR, but possibly
different depending on the value of \fB$NAMESPACE\fR and
\fB$WMII_NAMESPACE\fR.
.RE
.RS
Synonyms: \fBns\fR
.RE
.TP
setsid \fI[\-0 \fI<argv0>\fR]\fR \fI[\-f]\fR \fI<command>\fR
.RS
Executes the given command after setting the session id (see
setsid(2)). If \fI\-0\fR is given, the command is run with the
given value as argv\fI[0]\fR. For instance, to run sh as a login
shell, one might run
.RE
.nf
wmiir setsid -0 -sh sh
.fi
.RS
If \fI\-f\fR is given, wmiir will fork into the background before
executing the command.
.RE
.TP
proglist \fI[\-\-]\fR \fI<directory>\fR ...
.RS
Lists all executable commands in the given directories.
.RE
.SH ENVIRONMENT .SH ENVIRONMENT
.TP .TP
\fB$WMII_ADDRESS\fR \fB$WMII_ADDRESS\fR

View File

@ -28,6 +28,8 @@ configuration scripts.
: :
= COMMANDS = = COMMANDS =
The following commands deal with 9P filesystems.
: create <file> : create <file>
Creates a new file or directory in the filesystem. Permissions and Creates a new file or directory in the filesystem. Permissions and
file type are inferred by `wmii`. The contents of the standard input file type are inferred by `wmii`. The contents of the standard input
@ -53,13 +55,35 @@ configuration scripts.
: remove <path> : remove <path>
Removes <path> from the filesystem. Removes <path> from the filesystem.
Synonyms: rm Synonyms: `rm`
: write <file> : write <file>
Writes the contents of the standard input to <file>. Writes the contents of the standard input to <file>.
: xwrite <file> <data> ... : xwrite <file> <data> ...
Writes each argument after <file> to the latter. Writes each argument after <file> to the latter.
: :
Additionally, wmiir provides the following utility commands relevant
to scripting wmii:
: namespace
Prints the current wmii namespace directory, usually
equivalent to /tmp/ns.$USER.${DISPLAY%.0}, but possibly
different depending on the value of $NAMESPACE and
$WMII_NAMESPACE.
Synonyms: `ns`
: setsid [-0 <argv0>] [-f] <command>
Executes the given command after setting the session id (see
setsid(2)). If _-0_ is given, the command is run with the
given value as argv[0]. For instance, to run sh as a login
shell, one might run
``` wmiir setsid -0 -sh sh
If _-f_ is given, wmiir will fork into the background before
executing the command.
: proglist [--] <directory> ...
Lists all executable commands in the given directories.
= ENVIRONMENT = = ENVIRONMENT =
: $WMII_ADDRESS : $WMII_ADDRESS