[LEDE-DEV] [PATCH packages] rpcd-mod-lxc: info: return NOT_FOUND if container doesn't exist

Rafał Miłecki zajec5 at gmail.com
Thu Nov 30 02:04:53 PST 2017


From: Rafał Miłecki <rafal at milecki.pl>

It allow distinction between not existing and stopped container. So far
querying for not existing container was resulting in:
> ubus call lxc info '{ "name": "foo" }'
{
        "name": "foo",
        "state": "STOPPED",
        "ips": [

        ]
}

Now it's an error and it matches lxc-info command line:

> ubus call lxc info '{ "name": "foo" }'
Command failed: Not found

> lxc-info --name foo
foo doesn't exist

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 utils/rpcd-mod-lxc/files/lxc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/utils/rpcd-mod-lxc/files/lxc.c b/utils/rpcd-mod-lxc/files/lxc.c
index 6db1b311..a98fcfc5 100644
--- a/utils/rpcd-mod-lxc/files/lxc.c
+++ b/utils/rpcd-mod-lxc/files/lxc.c
@@ -332,6 +332,11 @@ rpc_lxc_info(struct ubus_context *ctx, struct ubus_object *obj,
 	l = rpc_lxc_init(tb);
 	if (!l)
 		return UBUS_STATUS_INVALID_ARGUMENT;
+
+	if (!l->container->is_running(l->container) &&
+	    !l->container->is_defined(l->container))
+		return UBUS_STATUS_NOT_FOUND;
+
 	blob_buf_init(&buf, 0);
 
 	blobmsg_add_string(&buf, "name", l->container->name);
-- 
2.11.0




More information about the Lede-dev mailing list