uxc: make force-delete kill container process
authorDaniel Golle <daniel@makrotopia.org>
Thu, 19 Nov 2020 17:12:54 +0000 (17:12 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 21 Nov 2020 01:13:13 +0000 (01:13 +0000)
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 <daniel@makrotopia.org>
uxc.c

diff --git a/uxc.c b/uxc.c
index 3c6942ab8b63500dc4e6e65e333605f45eae43d2..9e73b0772c38602a408bd1e7120e6e6422943d83 100644 (file)
--- 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: