/*
* rpcd - UBUS RPC server
*
- * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ * Copyright (C) 2013-2014 Jo-Philipp Wich <jow@openwrt.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include <sys/stat.h>
#include <sys/wait.h>
-#include "exec.h"
+#include <rpcd/exec.h>
static int
rpc_errno_status(void)
}
}
-static const char *
+const char *
rpc_exec_lookup(const char *cmd)
{
struct stat s;
rpc_ustream_to_blobmsg(&c->blob, &c->opipe.stream, "stdout");
rpc_ustream_to_blobmsg(&c->blob, &c->epipe.stream, "stderr");
}
+ }
- if (c->finish_cb)
- rv = c->finish_cb(&c->blob, c->stat, c->priv);
+ if (c->finish_cb)
+ rv = c->finish_cb(&c->blob, c->stat, c->priv);
- if (rv == UBUS_STATUS_OK)
- ubus_send_reply(c->context, &c->request, c->blob.head);
- }
+ if (rv == UBUS_STATUS_OK)
+ ubus_send_reply(c->context, &c->request, c->blob.head);
ubus_complete_deferred_request(c->context, &c->request, rv);
ustream_poll(&c->opipe.stream);
ustream_poll(&c->epipe.stream);
+
+ close(c->opipe.fd.fd);
+ close(c->epipe.fd.fd);
+
+ ustream_poll(&c->opipe.stream);
+ ustream_poll(&c->epipe.stream);
}
static void
switch ((pid = fork()))
{
case -1:
- return rpc_errno_status();
+ goto fail_fork;
case 0:
uloop_done();
uloop_process_add(&c->process);
c->timeout.cb = rpc_exec_timeout_cb;
- uloop_timeout_set(&c->timeout, RPC_EXEC_MAX_RUNTIME);
+ uloop_timeout_set(&c->timeout, rpc_exec_timeout);
if (c->stdin_cb)
{
return UBUS_STATUS_OK;
+fail_fork:
+ close(epipe[0]);
+ close(epipe[1]);
+
fail_epipe:
close(opipe[0]);
close(opipe[1]);
close(ipipe[1]);
fail_ipipe:
+ free(c);
return rpc_errno_status();
}