From: Daniel Golle Date: Thu, 19 Nov 2020 17:12:54 +0000 (+0000) Subject: uxc: make force-delete kill container process X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=04a2eddcb1a33fee865b8f09100567bd54d36be7;p=project%2Fprocd.git uxc: make force-delete kill container process Don't allow to delete running containers unless '--force' is specified. If '--force' is specified, send KILL signal to container process before deleting it. Signed-off-by: Daniel Golle --- diff --git a/uxc.c b/uxc.c index 3c6942a..9e73b07 100644 --- a/uxc.c +++ b/uxc.c @@ -636,7 +636,7 @@ static int uxc_boot(void) return ret; } -static int uxc_delete(char *name) +static int uxc_delete(char *name, bool force) { struct blob_attr *cur, *tb[__CONF_MAX]; int rem, ret = 0; @@ -663,6 +663,18 @@ static int uxc_delete(char *name) if (!found) return ENOENT; + if (s && s->running) { + if (force) { + ret = uxc_kill(name, SIGKILL)); + if (ret) + goto errout; + + } else { + ret = EWOULDBLOCK; + goto errout; + } + } + if (stat(fname, &sb) == -1) { ret=ENOENT; goto errout; @@ -823,7 +835,7 @@ int main(int argc, char **argv) if (optind != argc - 2) goto usage_out; - ret = uxc_delete(argv[optind + 1]); + ret = uxc_delete(argv[optind + 1], force); break; case CMD_CREATE: