#include <libubox/blobmsg_json.h>
#include <libubox/json_script.h>
#include <libubox/uloop.h>
+#include <libubox/utils.h>
#include <json-c/json.h>
#include <errno.h>
return NULL;
}
-static void mkdir_p(char *dir)
-{
- char *l = strrchr(dir, '/');
-
- if (l) {
- *l = '\0';
- mkdir_p(dir);
- *l = '/';
- mkdir(dir, 0755);
- }
-}
-
static void chgrp_error(const char *group, const char *target, const char *failed)
{
ERROR("cannot set group %s for %s (%s: %d)\n",
char *d = strdup(blobmsg_get_string(tb[0]));
d = dirname(d);
- mkdir_p(d);
+ mkdir_p(d, 0755);
free(d);
if (!strcmp(subsystem, "block"))
argv[i] = NULL;
execvp(argv[0], &argv[0]);
}
- exit(-1);
+ exit(EXIT_FAILURE);
}
static void handle_button_start(struct blob_attr *msg, struct blob_attr *data)
int fw, src, load, len;
static char buf[4096];
- DEBUG(2, "Firmware request for %s/%s\n", dir, file);
+ P_DEBUG(2, "Firmware request for %s/%s\n", dir, file);
if (!file || !dir || !dev) {
ERROR("Request for unknown firmware %s/%s\n", dir, file);
- exit(-1);
+ exit(EXIT_FAILURE);
}
path = alloca(strlen(dir) + strlen(file) + 2);
load = open(loadpath, O_WRONLY);
if (!load) {
ERROR("Failed to open %s: %m\n", loadpath);
- exit(-1);
+ exit(EXIT_FAILURE);
}
if (write(load, "1", 1) == -1) {
ERROR("Failed to write to %s: %m\n", loadpath);
- exit(-1);
+ exit(EXIT_FAILURE);
}
close(load);
fw = open(syspath, O_WRONLY);
if (fw < 0) {
ERROR("Failed to open %s: %m\n", syspath);
- exit(-1);
+ exit(EXIT_FAILURE);
}
len = s.st_size;
ERROR("failed to write to %s: %m\n", loadpath);
close(load);
- DEBUG(2, "Done loading %s\n", path);
+ P_DEBUG(2, "Done loading %s\n", path);
- exit(-1);
+ exit(EXIT_FAILURE);
+}
+
+static void handle_start_console(struct blob_attr *msg, struct blob_attr *data)
+{
+ char *dev = blobmsg_get_string(blobmsg_data(data));
+
+ P_DEBUG(2, "Start console request for %s\n", dev);
+
+ procd_inittab_run("respawn");
+ procd_inittab_run("askfirst");
+
+ P_DEBUG(2, "Done starting console for %s\n", dev);
+
+ exit(EXIT_FAILURE);
}
enum {
HANDLER_EXEC,
HANDLER_BUTTON,
HANDLER_FW,
+ HANDLER_START_CONSOLE,
};
static struct cmd_handler {
.name = "load-firmware",
.handler = handle_firmware,
},
+ [HANDLER_START_CONSOLE] = {
+ .name = "start-console",
+ .handler = handle_start_console,
+ },
};
static void queue_next(void)
uloop_process_add(&queue_proc);
- DEBUG(4, "Launched hotplug exec instance, pid=%d\n", (int) queue_proc.pid);
+ P_DEBUG(4, "Launched hotplug exec instance, pid=%d\n", (int) queue_proc.pid);
}
static void queue_proc_cb(struct uloop_process *c, int ret)
{
- DEBUG(4, "Finished hotplug exec instance, pid=%d\n", (int) c->pid);
+ P_DEBUG(4, "Finished hotplug exec instance, pid=%d\n", (int) c->pid);
if (current) {
current->complete(current->msg, current->data, ret);
int rem, i;
if (debug > 3) {
- DEBUG(4, "Command: %s\n", name);
+ P_DEBUG(4, "Command: %s\n", name);
blobmsg_for_each_attr(cur, data, rem)
- DEBUG(4, " %s\n", (char *) blobmsg_data(cur));
+ P_DEBUG(4, " %s\n", (char *) blobmsg_data(cur));
- DEBUG(4, "Message:\n");
+ P_DEBUG(4, "Message:\n");
blobmsg_for_each_attr(cur, vars, rem)
- DEBUG(4, " %s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
+ P_DEBUG(4, " %s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
}
for (i = 0; i < ARRAY_SIZE(handlers); i++)
return;
str = blobmsg_format_json(data, true);
- DEBUG(3, "%s\n", str);
+ P_DEBUG(3, "%s\n", str);
free(str);
}
rule_file = strdup(rules);
nls.nl_family = AF_NETLINK;
- nls.nl_pid = getpid();
+ nls.nl_pid = 0;
nls.nl_groups = -1;
if ((hotplug_fd.fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT)) == -1) {