From d9f7669b9e305c6fa55bc4abb4645a66ae512342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D1=80=D0=BE=D0=BC=D0=B5=D0=BD=D0=BE=D0=BA=20=D0=A0?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=BD=20=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 29 May 2024 20:36:20 +0200 Subject: [PATCH] add find work dir in path script --- apps/cli/cli_common.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 94c8e197..58141d1a 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -60,6 +60,7 @@ #include #include #include +#include /* cligen */ #include @@ -810,6 +811,7 @@ cli_start_program(clixon_handle h, char *script_path = NULL; char *runner = NULL; char *buf = NULL; + char *work_dir = NULL, *reserve_path = NULL; struct passwd pw, *pwresult = NULL; size_t bufsize; int s; @@ -839,7 +841,10 @@ cli_start_program(clixon_handle h, if (cvec_len(cvv) == 2){ script_path = cv_string_get(cvec_i(cvv, 1)); } - + if (script_path){ + reserve_path = strdup(script_path); + work_dir = dirname(reserve_path); + } bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); if (bufsize == -1){ bufsize = 16384; @@ -862,7 +867,7 @@ cli_start_program(clixon_handle h, /* main run */ if ((pid = fork()) == 0) { /* child process */ - if (chdir(pw.pw_dir) < 0){ + if ((work_dir ? chdir(work_dir) : chdir(pw.pw_dir)) < 0) { clixon_err(OE_PLUGIN, errno, "chdir"); } execlp(runner, runner, script_path, NULL); @@ -884,6 +889,8 @@ cli_start_program(clixon_handle h, done: if(buf) free(buf); + if(reserve_path) + free(reserve_path); return retval; }