From 33fb34f3c864161fb24de77b72e157327e1e620c Mon Sep 17 00:00:00 2001 From: zhongtao Date: Thu, 15 Dec 2022 15:55:34 +0800 Subject: [PATCH 63/65] When run options rm is set, delete the stoped container's fifo directory. Signed-off-by: zhongtao --- src/cmd/isula/base/run.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cmd/isula/base/run.c b/src/cmd/isula/base/run.c index 73486c95..24863120 100644 --- a/src/cmd/isula/base/run.c +++ b/src/cmd/isula/base/run.c @@ -42,6 +42,29 @@ struct client_arguments g_cmd_run_args = { .pull = "missing" }; +/* + * --rm option will result in no time to delete the directory created by the client, resulting in residue. + * This function is used to delete the client's fifo file and home directory. + */ +static void delete_client_fifo_and_home_dir(const char *rundir, const char *name, + struct command_fifo_config *console_fifos) +{ + char client_fifo_home_dir[PATH_MAX] = { 0 }; + int nret = 0; + + nret = snprintf(client_fifo_home_dir, sizeof(client_fifo_home_dir), "%s/%s/", rundir, name); + if (nret < 0 || (size_t)nret >= sizeof(client_fifo_home_dir)) { + ERROR("Client fifo home path:%s/%s/ is too long.", rundir, name); + return; + } + + delete_command_fifo(console_fifos); + + if (util_recursive_rmdir(client_fifo_home_dir, 0)) { + WARN("Failed to delete client fifo home path:%s", client_fifo_home_dir); + } +} + static int local_cmd_start(const struct client_arguments *args) { int ret = 0; @@ -66,6 +89,10 @@ static int local_cmd_start(const struct client_arguments *args) client_wait_fifo_exit(args); free_out: + if (args->custom_conf.auto_remove && !args->detach) { + delete_client_fifo_and_home_dir(CLIENT_RUNDIR, args->name, console_fifos); + console_fifos = NULL; + } client_restore_console(reset_tty, &oldtios, console_fifos); return ret; } -- 2.25.1