summaryrefslogtreecommitdiff
path: root/src/rc/rc-applets.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-06-03 11:57:15 +0000
committerRoy Marples <roy@marples.name>2008-06-03 11:57:15 +0000
commit587051ec679229632d107b24f61d01191f58bc73 (patch)
treecb71157669035c5515b96908dccdb8669c705565 /src/rc/rc-applets.c
parentf2ea7ca51443f2fec41a6a3cbcf468fa84be2a90 (diff)
downloadopenrc-587051ec679229632d107b24f61d01191f58bc73.tar.gz
openrc-587051ec679229632d107b24f61d01191f58bc73.tar.bz2
openrc-587051ec679229632d107b24f61d01191f58bc73.tar.xz
Add the ewaitfile function so init scripts can wait until sockts are created, Gentoo #175783.
Diffstat (limited to 'src/rc/rc-applets.c')
-rw-r--r--src/rc/rc-applets.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c
index 60c0c27..1649fb8 100644
--- a/src/rc/rc-applets.c
+++ b/src/rc/rc-applets.c
@@ -51,6 +51,10 @@
#include "einfo.h"
#include "rc-misc.h"
+/* usecs to wait while we poll the file existance */
+#define WAIT_INTERVAL 20000000
+#define ONE_SECOND 690000000
+
/* Applet is first parsed in rc.c - no point in doing it again */
extern const char *applet;
@@ -77,6 +81,8 @@ static int do_e(int argc, char **argv)
char *p;
int level = 0;
const char *fmt = "%s";
+ struct timespec ts;
+ struct timeval stop, now;
/* Punt applet */
argc--;
@@ -97,11 +103,14 @@ static int do_e(int argc, char **argv)
if (strcmp(applet, "eend") == 0 ||
strcmp(applet, "ewend") == 0 ||
strcmp(applet, "veend") == 0 ||
- strcmp(applet, "vweend") == 0)
+ strcmp(applet, "vweend") == 0 ||
+ strcmp(applet, "ewaitfile") == 0)
{
errno = 0;
- retval = (int) strtoimax(argv[0], NULL, 0);
- if (errno != 0)
+ retval = (int)strtoimax(argv[0], &p, 0);
+ if (!p || *p != '\0')
+ errno = EINVAL;
+ if (errno)
retval = EXIT_FAILURE;
else {
argc--;
@@ -124,6 +133,38 @@ static int do_e(int argc, char **argv)
}
}
+ if (strcmp(applet, "ewaitfile") == 0) {
+ if (errno)
+ eerrorx("%s: invalid timeout", applet);
+ if (argc == 0)
+ eerrorx("%s: not enough arguments", applet);
+
+ gettimeofday(&stop, NULL);
+ /* retval stores the timeout */
+ stop.tv_sec += retval;
+ ts.tv_sec = 0;
+ ts.tv_nsec = WAIT_INTERVAL;
+ for (i = 0; i < argc; i++) {
+ ebeginv("Waiting for %s", argv[i]);
+ for (;;){
+ if (exists(argv[i]))
+ break;
+ if (nanosleep(&ts, NULL) == -1)
+ return EXIT_FAILURE;
+ gettimeofday(&now, NULL);
+ if (retval <= 0)
+ continue;
+ if (timercmp(&now, &stop, <))
+ continue;
+ eendv(EXIT_FAILURE,
+ "timed out waiting for %s", argv[i]);
+ return EXIT_FAILURE;
+ }
+ eendv(EXIT_SUCCESS, NULL);
+ }
+ return EXIT_SUCCESS;
+ }
+
if (argc > 0) {
for (i = 0; i < argc; i++)
l += strlen(argv[i]) + 1;