Skip to content

Commit

Permalink
Add -i/--interactive option to tlog-rec-session
Browse files Browse the repository at this point in the history
Shells such as bash/tcsh accept the -i option to start an interactive shell.

Pass the -i argument to the shell when tlog-rec-session is called with
the "-i" argument. This may be useful for applications/programs written
to execute shell programs with -i, such as Cockpit.
  • Loading branch information
justin-stephenson committed Jul 19, 2019
1 parent 3b3cc25 commit d1cad1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions lib/tlog/rec_session_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ tlog_rec_session_conf_get_shell(struct tlog_errs **perrs,
struct json_object *args;
bool login;
bool command;
bool interactive;
bool option;
const char *path;
char *name = NULL;
char *buf = NULL;
Expand Down Expand Up @@ -333,6 +335,10 @@ tlog_rec_session_conf_get_shell(struct tlog_errs **perrs,
command = json_object_object_get_ex(conf, "command", &obj) &&
json_object_get_boolean(obj);

/* Read the interactive flag */
interactive = json_object_object_get_ex(conf, "interactive", &obj) &&
json_object_get_boolean(obj);

/* Read and check the positional arguments */
if (!json_object_object_get_ex(conf, "args", &args)) {
grc = TLOG_RC_FAILURE;
Expand All @@ -344,7 +350,9 @@ tlog_rec_session_conf_get_shell(struct tlog_errs **perrs,
}

/* Create and fill argv list */
argv = calloc(1 + (command ? 1 : 0) + json_object_array_length(args) + 1,
option = interactive || command;

argv = calloc(1 + (option ? 1 : 0) + json_object_array_length(args) + 1,
sizeof(*argv));
if (argv == NULL) {
grc = TLOG_GRC_ERRNO;
Expand All @@ -353,8 +361,8 @@ tlog_rec_session_conf_get_shell(struct tlog_errs **perrs,
argi = 0;
argv[argi++] = name;
name = NULL;
if (command) {
arg = strdup("-c");
if (option) {
arg = strdup(command ? "-c" : "-i");
if (arg == NULL) {
grc = TLOG_GRC_ERRNO;
TLOG_ERRS_RAISECF(grc,
Expand Down
6 changes: 6 additions & 0 deletions m4/tlog/rec_session_conf_schema.m4
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ M4_PARAM(`', `login', `name-',
`This is done by prepending argv[0] of the shell',
`with a dash character.')')m4_dnl
m4_dnl
M4_PARAM(`', `interactive', `name-',
`M4_TYPE_BOOL()', false,
`i', `', `Make the shell an interactive shell',
`If specified, ', `If true ',
`M4_LINES(`tlog-rec-session passes the -i option to the shell.')')m4_dnl
m4_dnl
M4_PARAM(`', `command', `opts',
`M4_TYPE_BOOL()', false,
`c', `', `Execute shell commands',
Expand Down
4 changes: 2 additions & 2 deletions man/tlog-rec-session.8.m4
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ required and should contain shell commands to execute, the following
arguments can specify first the script name (CMD_NAME, i.e. argv[0]) and then
its arguments (CMD_ARG).

If no non-option arguments are encountered, then the shell is started
interactively.
If no non-option arguments are encountered, or the "-i" option is specified
then the shell is started interactively.

If tlog-M4_PROG_NAME() is invoked under a name beginning with a dash (i.e.
argv[0] beginning with '-'), then the executed shell name is also prepended
Expand Down

0 comments on commit d1cad1f

Please sign in to comment.