\-s, \-\-signal <signal string>
Signal to send to the command when exit it (default: 1, SIGHUP)
+.PP
+\-w, \-\-cwd <path>
+ Working directory to be set for the child program
+
.PP
\-a, \-\-url\-arg
Allow client to send command line arguments in URL (eg:
-s, --signal <signal string>
Signal to send to the command when exit it (default: 1, SIGHUP)
+ -w, --cwd <path>
+ Working directory to be set for the child program
+
-a, --url-arg
Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)
static bool spawn_process(struct pss_tty *pss, uint16_t columns, uint16_t rows) {
pty_process *process = process_init((void *)pss, server->loop, build_args(pss), build_env(pss));
+ if (server->cwd != NULL) process->cwd = strdup(server->cwd);
if (columns > 0) process->columns = columns;
if (rows > 0) process->rows = rows;
if (pty_spawn(process, process_read_cb, process_exit_cb) != 0) {
#endif
if (process->io != NULL) pty_io_free(process->io);
if (process->argv != NULL) free(process->argv);
+ if (process->cwd != NULL) free(process->cwd);
char **p = process->envp;
for (; *p; p++) free(*p);
free(process->envp);
env = prep_env(process->envp);
if (env == NULL) goto cleanup;
- if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, flags, env, NULL, &process->si.StartupInfo, &pi)) {
+ if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, flags, env, process->cwd, &process->si.StartupInfo, &pi)) {
print_error("CreateProcessW");
goto cleanup;
}
return status;
} else if (pid == 0) {
setsid();
+ if (process->cwd != NULL) {
+ if (chdir(process->cwd) == -1) {
+ perror("chdir failed\n");
+ _exit(1);
+ }
+ }
int ret = pty_execvpe(process->argv[0], process->argv, process->envp);
if (ret < 0) {
perror("execvp failed\n");
#endif
char **argv;
char **envp;
+ char *cwd;
uv_loop_t *loop;
uv_async_t async;
{"uid", required_argument, NULL, 'u'},
{"gid", required_argument, NULL, 'g'},
{"signal", required_argument, NULL, 's'},
+ {"cwd", required_argument, NULL, 'w'},
{"index", required_argument, NULL, 'I'},
{"base-path", required_argument, NULL, 'b'},
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, 0, 0}};
-static const char *opt_string = "p:i:c:H:u:g:s:I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh";
+static const char *opt_string = "p:i:c:H:u:g:s:w:I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh";
static void print_help() {
// clang-format off
" -u, --uid User id to run with\n"
" -g, --gid Group id to run with\n"
" -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n"
+ " -w, --cwd Working directory to be set for the child program\n"
" -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n"
" -R, --readonly Do not allow clients to write to the TTY\n"
" -t, --client-option Send option to client (format: key=value), repeat to add more options\n"
if (ts->credential != NULL) free(ts->credential);
if (ts->auth_header != NULL) free(ts->auth_header);
if (ts->index != NULL) free(ts->index);
+ if (ts->cwd != NULL) free(ts->cwd);
free(ts->command);
free(ts->prefs_json);
return -1;
}
} break;
+ case 'w':
+ server->cwd = strdup(optarg);
+ break;
case 'I':
if (!strncmp(optarg, "~/", 2)) {
const char *home = getenv("HOME");
char *command; // full command line
char **argv; // command with arguments
int argc; // command + arguments count
+ char *cwd; // working directory
int sig_code; // close signal
char sig_name[20]; // human readable signal string
bool url_arg; // allow client to send cli arguments in URL