I'm intending to fix [bugs:1430]
<https://sourceforge.net/p/oorexx/bugs/1440> with attached patch (which
also fixes the broken no-shell Unix subcommands "command", and "cmd", and
adds subcommand handling for shells "dash", "tcsh", and "zsh").
Before doing so, I'd like to discuss two things:
1. bash shortcut for Linux calling /bin/sh
Our code in SystemCommands.cpp contains a special shortcut just for the
"bash" subcommand handler in a conditional #ifdef LINUX section. This
shortcut calls system(), which in turn calls /bin/*sh* to execute the
command. This makes it impossible e. g. an Ubuntu system, which symlinks
/bin/sh to /bin/dash, to send a subcommand to /bin/bash.
Subcommands other than "bash" are handled separately by fork()-ing and then
execl()-executing the command instead of calling system()).
Does anyone know why we have this shortcut section? Any idea why it could
be required? Are there any known advantages/disadvantages in using
system() instead of fork() / execl()?
The shortcut (only) also does some return code modulo 256 processing, that
I'd like to understand when/how it's required.
2. default shell
Our code currently hard-codes the default shell for AIX to be "ksh", for
SUN to be "sh", and for all other Unix's to be "bash". Shouldn't the
default be "sh" all the time? With "sh" supposedly being symlinked to the
preferred shell for the specific platform?
That could also answer René's request for a new "shell" subcommand handler,
that would select the preferred shell.
Thanks for your thoughts.
Erich
Index: SystemCommands.cpp
===================================================================
--- SystemCommands.cpp (revision 11227)
+++ SystemCommands.cpp (working copy)
@@ -1,7 +1,7 @@
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
-/* Copyright (c) 2005-2014 Rexx Language Association. All rights reserved. */
+/* Copyright (c) 2005-2017 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
@@ -61,21 +61,10 @@
#include <pwd.h>
#include <limits.h>
-#define CMDBUFSIZE 1024 /* Max size of executable cmd */
#define MAX_COMMAND_ARGS 400
-#if defined(AIX)
-#define CMDDEFNAME "/bin/ksh" /* Korn shell is default for AIX */
-#elif defined(OPSYS_SUN) /* path for AIX */
-#define CMDDEFNAME "/bin/sh" /* Bourne Again Shell is default */
-#else /* shell for Linux */
-#define CMDDEFNAME "/bin/bash" /* Bourne Again Shell is default */
-#endif
-
#define UNKNOWN_COMMAND 127 /* unknown command return code */
-#define SYSENV "command" /* Default cmd environment */
-#define SHELL "SHELL" /* UNIX cmd handler env. var. name*/
#define EXPORT_FLAG 1
#define SET_FLAG 2
#define UNSET_FLAG 3
@@ -728,25 +717,46 @@
if (Utilities::strCaselessCompare("sh", envName) == 0)
{
execl("/bin/sh", "sh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
else if (Utilities::strCaselessCompare("ksh", envName) == 0)
{
execl("/bin/ksh", "ksh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
else if (Utilities::strCaselessCompare("bsh", envName) == 0)
{
execl("/bin/bsh", "bsh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
else if (Utilities::strCaselessCompare("csh", envName) == 0)
{
execl("/bin/csh", "csh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
else if (Utilities::strCaselessCompare("bash", envName) == 0)
{
execl("/bin/bash", "bash", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
- else if (Utilities::strCaselessCompare("cmd", envName) == 0)
+ else if (Utilities::strCaselessCompare("dash", envName) == 0)
{
+ execl("/bin/dash", "dash", "-c", cmd, NULL);
+ exit(30); // shell unavailable
+ }
+ else if (Utilities::strCaselessCompare("tcsh", envName) == 0)
+ {
+ execl("/bin/tcsh", "tcsh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
+ }
+ else if (Utilities::strCaselessCompare("zsh", envName) == 0)
+ {
+ execl("/bin/zsh", "zsh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
+ }
+ else if (Utilities::strCaselessCompare("command", envName) == 0 ||
+ Utilities::strCaselessCompare("cmd", envName) == 0)
+ {
char * args[MAX_COMMAND_ARGS+1]; /* Array for argument parsing */
if (!scan_cmd(cmd, args)) /* Parse cmd into arguments */
{
@@ -758,6 +768,7 @@
else
{
execl("/bin/sh", "sh", "-c", cmd, NULL);
+ exit(30); // shell unavailable
}
}
}
@@ -785,6 +796,7 @@
{
// Unix has a whole collection of similar environments, services by a single handler
_instance->addCommandHandler("COMMAND", (REXXPFN)systemCommandHandler);
+ _instance->addCommandHandler("CMD", (REXXPFN)systemCommandHandler);
_instance->addCommandHandler("", (REXXPFN)systemCommandHandler);
_instance->addCommandHandler("SH", (REXXPFN)systemCommandHandler);
_instance->addCommandHandler("KSH", (REXXPFN)systemCommandHandler);
@@ -791,6 +803,9 @@
_instance->addCommandHandler("CSH", (REXXPFN)systemCommandHandler);
_instance->addCommandHandler("BSH", (REXXPFN)systemCommandHandler);
_instance->addCommandHandler("BASH", (REXXPFN)systemCommandHandler);
+ _instance->addCommandHandler("DASH", (REXXPFN)systemCommandHandler);
+ _instance->addCommandHandler("TCSH", (REXXPFN)systemCommandHandler);
+ _instance->addCommandHandler("ZSH", (REXXPFN)systemCommandHandler);
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel