allow configuration of Shell in lcdexec.conf;
fall back to $SHELL if not set, and to /bin/sh if $SHELL is not set
This commit is contained in:
@@ -11,6 +11,7 @@ v.0.5dev (ongoing development)
|
||||
* ged rid of global variables buffer & tmp in lcdproc client
|
||||
+ add init-script templates for LSB 3.x conforming systems
|
||||
* fix cellwidth & hbar in iMon driver
|
||||
* try harder to find a shell in lcdexec
|
||||
|
||||
v.0.5.1
|
||||
+ config file support in lcdproc client (Andrew Foss)
|
||||
|
||||
@@ -46,7 +46,7 @@ char * help_text =
|
||||
" -s <0|1> Report to syslog (1) or stderr (0, default)\n"
|
||||
" -h Show this help\n";
|
||||
|
||||
char * progname = "lcdexec";
|
||||
char *progname = "lcdexec";
|
||||
|
||||
/* Variables set by config */
|
||||
#define UNSET_INT -1
|
||||
@@ -58,6 +58,7 @@ int foreground_mode = UNSET_INT;
|
||||
static int report_level = UNSET_INT;
|
||||
static int report_dest = UNSET_INT;
|
||||
char *displayname = NULL;
|
||||
char *default_shell = NULL;
|
||||
|
||||
MenuEntry *main_menu;
|
||||
|
||||
@@ -206,6 +207,21 @@ int process_configfile(char *configfile)
|
||||
if ((tmp = config_get_string(progname, "DisplayName", 0, NULL)) != NULL)
|
||||
displayname = strdup(tmp);
|
||||
|
||||
/* try to find a shell that understands the -c COMMAND syntax */
|
||||
if ((tmp = config_get_string(progname, "Shell", 0, NULL)) != NULL)
|
||||
default_shell = strdup(tmp);
|
||||
else {
|
||||
/* 1st fallback: SHELL environment variable */
|
||||
report(RPT_WARNING, "Shell not set in configuration, falling back to variable SHELL");
|
||||
default_shell = getenv("SHELL");
|
||||
|
||||
/* 2nd fallback: /bin/sh */
|
||||
if (default_shell == NULL) {
|
||||
report(RPT_WARNING, "variable SHELL not set, falling back to /bin/sh");
|
||||
default_shell = "/bin/sh";
|
||||
}
|
||||
}
|
||||
|
||||
main_menu = menu_read(NULL, "MainMenu");
|
||||
#if defined(DEBUG)
|
||||
menu_dump(main_menu);
|
||||
@@ -316,16 +332,11 @@ int exec_command(MenuEntry *cmd)
|
||||
|
||||
report(RPT_NOTICE, "Executing: %s", command);
|
||||
|
||||
argv[0] = getenv("SHELL");
|
||||
argv[0] = default_shell;
|
||||
argv[1] = "-c";
|
||||
argv[2] = command;
|
||||
argv[3] = NULL;
|
||||
|
||||
if (!argv[0]) {
|
||||
report(RPT_ERR, "SHELL environment variable not set.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
/* We're the child. Execute the command. */
|
||||
|
||||
@@ -17,6 +17,10 @@ ReportToSyslog=false
|
||||
# run in foreground [default: false; legal: true, false]
|
||||
Foreground=false
|
||||
|
||||
# shell to use for executing programsi
|
||||
# [default: $SHELL or /bin/sh; legal: any shell that understands: -c COMMAND]
|
||||
#Shell=/bin/sh
|
||||
|
||||
# display name for the main menu [default: lcdexec HOST]
|
||||
#DisplayName=lcdexec
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ typedef struct menu_entry {
|
||||
} MenuEntry;
|
||||
|
||||
|
||||
MenuEntry *menu_read(MenuEntry *parent, const char *ame);
|
||||
MenuEntry *menu_read(MenuEntry *parent, const char *name);
|
||||
int menu_sock_send(MenuEntry *me, MenuEntry *parent, int sock);
|
||||
MenuEntry *menu_find_by_id(MenuEntry *me, int id);
|
||||
const char *menu_command(MenuEntry *me);
|
||||
|
||||
+8
-1
@@ -87,8 +87,15 @@ If not given, the default is FALSE for daemon mode.
|
||||
.TP 8
|
||||
.B DisplayName=\fIDisplay\fP
|
||||
Set the display name for the main menu.
|
||||
If not given it defaults to \fBlcdexec\fI \fIHOST\fP, where \fIHOST\fP
|
||||
If not given it defaults to \fBlcdexec\fP \fIHOST\fP, where \fIHOST\fP
|
||||
is the hostname of the system \fIlcdexec\fP is running on.
|
||||
.TP 8
|
||||
.B Shell=\fI/path/to/shell\fP
|
||||
Set the shell to use when executing programs.
|
||||
If not given, \fBlcdexec\fP tries to read the environment variable \fISHELL\fP.
|
||||
If that fails, it defaults to \fB/bin/sh\fP.
|
||||
Please note that the shell given here must understand the option \fB-c\fP
|
||||
followed by the command line to execute.
|
||||
.PP
|
||||
|
||||
The \fB[MainMenu]\fP section and the sections it refers to define the menu hierarchy
|
||||
|
||||
Reference in New Issue
Block a user