ubus/lua: pass notification name to callback
[project/ubus.git] / examples / server.c
index bbb3347..e0cde0b 100644 (file)
@@ -66,7 +66,10 @@ static void test_hello_reply(struct uloop_timeout *t)
        blobmsg_add_string(&b, "message", req->data);
        ubus_send_reply(ctx, &req->req, b.head);
 
-       pipe(fds);
+       if (pipe(fds) == -1) {
+               fprintf(stderr, "Failed to create pipe\n");
+               return;
+       }
        ubus_request_set_fd(ctx, &req->req, fds[0]);
        ubus_complete_deferred_request(ctx, &req->req, 0);
        req->fd = fds[1];
@@ -90,6 +93,9 @@ static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
                msgstr = blobmsg_data(tb[HELLO_MSG]);
 
        hreq = calloc(1, sizeof(*hreq) + strlen(format) + strlen(obj->name) + strlen(msgstr) + 1);
+       if (!hreq)
+               return UBUS_STATUS_UNKNOWN_ERROR;
+
        sprintf(hreq->data, format, obj->name, msgstr);
        ubus_defer_request(ctx, req, &hreq->req);
        hreq->timeout.cb = test_hello_reply;