@@ -58,6 +58,7 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'},
5858 {"uid" , required_argument , NULL , 'u' },
5959 {"gid" , required_argument , NULL , 'g' },
6060 {"signal" , required_argument , NULL , 's' },
61+ {"cwd" , required_argument , NULL , 'w' },
6162 {"index" , required_argument , NULL , 'I' },
6263 {"base-path" , required_argument , NULL , 'b' },
6364#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
@@ -80,7 +81,7 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'},
8081 {"version" , no_argument , NULL , 'v' },
8182 {"help" , no_argument , NULL , 'h' },
8283 {NULL , 0 , 0 , 0 }};
83- static const char * opt_string = "p:i:c:H:u:g:s:I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh" ;
84+ static const char * opt_string = "p:i:c:H:u:g:s:w: I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh" ;
8485
8586static void print_help () {
8687 // clang-format off
@@ -97,6 +98,7 @@ static void print_help() {
9798 " -u, --uid User id to run with\n"
9899 " -g, --gid Group id to run with\n"
99100 " -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n"
101+ " -w, --cwd Working directory to be set for the child program\n"
100102 " -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n"
101103 " -R, --readonly Do not allow clients to write to the TTY\n"
102104 " -t, --client-option Send option to client (format: key=value), repeat to add more options\n"
@@ -198,6 +200,7 @@ static void server_free(struct server *ts) {
198200 if (ts -> credential != NULL ) free (ts -> credential );
199201 if (ts -> auth_header != NULL ) free (ts -> auth_header );
200202 if (ts -> index != NULL ) free (ts -> index );
203+ if (ts -> cwd != NULL ) free (ts -> cwd );
201204 free (ts -> command );
202205 free (ts -> prefs_json );
203206
@@ -398,6 +401,9 @@ int main(int argc, char **argv) {
398401 return -1 ;
399402 }
400403 } break ;
404+ case 'w' :
405+ server -> cwd = strdup (optarg );
406+ break ;
401407 case 'I' :
402408 if (!strncmp (optarg , "~/" , 2 )) {
403409 const char * home = getenv ("HOME" );
0 commit comments