Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd0f173e authored by Colin Cross's avatar Colin Cross
Browse files

init: Add wait command and mount wait flag

Change-Id: I6b4c10f8f246095a7fb7342388ec4f6ff97d5733
parent ed8a7d84
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -277,6 +277,7 @@ int do_mount(int nargs, char **args)
    char *options = NULL;
    unsigned flags = 0;
    int n, i;
    int wait = 0;

    for (n = 4; n < nargs; n++) {
        for (i = 0; mount_flags[i].name; i++) {
@@ -286,10 +287,14 @@ int do_mount(int nargs, char **args)
            }
        }

        if (!mount_flags[i].name) {
            if (!strcmp(args[n], "wait"))
                wait = 1;
            /* if our last argument isn't a flag, wolf it up as an option string */
        if (n + 1 == nargs && !mount_flags[i].name)
            else if (n + 1 == nargs)
                options = args[n];
        }
    }

    system = args[1];
    source = args[2];
@@ -303,6 +308,8 @@ int do_mount(int nargs, char **args)

        sprintf(tmp, "/dev/block/mtdblock%d", n);

        if (wait)
            wait_for_file(tmp, COMMAND_RETRY_TIMEOUT);
        if (mount(tmp, target, system, flags, options) < 0) {
            return -1;
        }
@@ -349,6 +356,8 @@ int do_mount(int nargs, char **args)
        ERROR("out of loopback devices");
        return -1;
    } else {
        if (wait)
            wait_for_file(source, COMMAND_RETRY_TIMEOUT);
        if (mount(source, target, system, flags, options) < 0) {
            return -1;
        }
@@ -574,3 +583,11 @@ int do_device(int nargs, char **args) {
                          decode_uid(args[4]), prefix);
    return 0;
}

int do_wait(int nargs, char **args)
{
    if (nargs == 2) {
        return wait_for_file(args[1], COMMAND_RETRY_TIMEOUT);
    }
    return -1;
}
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ int do_chown(int nargs, char **args);
int do_chmod(int nargs, char **args);
int do_loglevel(int nargs, char **args);
int do_device(int nargs, char **args);
int do_wait(int nargs, char **args);
#define __MAKE_KEYWORD_ENUM__
#define KEYWORD(symbol, flags, nargs, func) K_##symbol,
enum {
@@ -69,6 +70,7 @@ enum {
    KEYWORD(symlink,     COMMAND, 1, do_symlink)
    KEYWORD(sysclktz,    COMMAND, 1, do_sysclktz)
    KEYWORD(user,        OPTION,  0, 0)
    KEYWORD(wait,        COMMAND, 1, do_wait)
    KEYWORD(write,       COMMAND, 2, do_write)
    KEYWORD(copy,        COMMAND, 2, do_copy)
    KEYWORD(chown,       COMMAND, 2, do_chown)
+1 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ int lookup_keyword(const char *s)
        break;
    case 'w':
        if (!strcmp(s, "rite")) return K_write;
        if (!strcmp(s, "ait")) return K_wait;
        break;
    }
    return K_UNKNOWN;
+12 −0
Original line number Diff line number Diff line
@@ -378,3 +378,15 @@ void remove_link(const char *oldpath, const char *newpath)
    if (!strcmp(path, oldpath))
        unlink(newpath);
}

int wait_for_file(const char *filename, int timeout)
{
    struct stat info;
    time_t timeout_time = gettime() + timeout;
    int ret = -1;

    while (gettime() < timeout_time && ((ret = stat(filename, &info)) < 0))
        usleep(10000);

    return ret;
}
+1 −0
Original line number Diff line number Diff line
@@ -28,4 +28,5 @@ int mkdir_recursive(const char *pathname, mode_t mode);
void sanitize(char *p);
void make_link(const char *oldpath, const char *newpath);
void remove_link(const char *oldpath, const char *newpath);
int wait_for_file(const char *filename, int timeout);
#endif