summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-04-16 09:50:18 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-04-16 09:50:18 +0200
commite53d75aedebbeb6ec739a575c23bcde1c899a82a (patch)
treeddb5c6a1d5498774aa7bbe436e1c0d1733dea8f5
parente26d734dd6d3f5a142b8cfd2d6e912a04cfdb6b6 (diff)
downloadnlplug-e53d75aedebbeb6ec739a575c23bcde1c899a82a.tar.bz2
nlplug-e53d75aedebbeb6ec739a575c23bcde1c899a82a.tar.xz
nlsockd: add support for single run (-s)
Add suport for running the helper exactly once. This is useful when you wait for a specific block device to show up, for example from initramfs script that looks for the device specified as root=... boot option.
-rw-r--r--nlsockd.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/nlsockd.c b/nlsockd.c
index 481eebd..e4a04ce 100644
--- a/nlsockd.c
+++ b/nlsockd.c
@@ -102,7 +102,7 @@ init_netlink_socket(void)
void
usage(void)
{
- errx(1, "usage: %s runpath [...]\n", argv0);
+ errx(1, "usage: %s [-s] runpath [...]\n", argv0);
}
@@ -110,12 +110,19 @@ int
main(int argc, char *argv[])
{
struct pollfd fds;
+ int single_run = 0;
ARGBEGIN {
+ case 's':
+ single_run = 1;
+ break;
default:
usage();
} ARGEND;
+ if (argv[0] == NULL)
+ usage();
+
fds.events = POLLIN;
fds.fd = init_netlink_socket();
@@ -123,9 +130,14 @@ main(int argc, char *argv[])
while (poll(&fds, 1, -1) > -1) {
if (fds.revents & POLLIN) {
- int status;
+ int status, r;
pid_t childpid = spawn_handler(fds.fd, argv);
- waitpid(childpid, &status, 0);
+ r = waitpid(childpid, &status, 0);
+ if(r == -1) {
+ warn("waitpid(%d)", childpid);
+ } else if (single_run && WIFEXITED(status)) {
+ return WEXITSTATUS(status);
+ }
}
}