]> git.sur5r.net Git - i3/i3status/commitdiff
Make wmiistatus run all the time and wait for wmii_path to exist
authorMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 29 Oct 2008 22:26:26 +0000 (23:26 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 29 Oct 2008 22:26:26 +0000 (23:26 +0100)
Instead of exiting as a file inside wmii_path cannot be opened, we wait
until wmii_path is found again (particularly the /rbar part, that is),
re-setup our files and continue as if nothing happened.

This will make wmiistatus survive restarts of wmii and make it wait for
/mnt/wmii to appear when booting up (and wmiistatus gets started before
wmii itself)

config.c
wmiistatus.c

index 1b6fbec1b9aa69c6c450e4d7533c34c31aa8a12a..ff57f66e8bb64f0c2f126c8bec61bd157ada1e18 100644 (file)
--- a/config.c
+++ b/config.c
@@ -109,8 +109,12 @@ int load_configuration(const char *configfile) {
                OPT("wmii_path")
                {
                        char *globbed = glob_path(dest_value);
-                       if ((stat(globbed, &stbuf)) == -1)
-                               die("wmii_path contains an invalid path");
+                       if ((stat(globbed, &stbuf)) == -1) {
+                               fprintf(stderr, "Warning: wmii_path contains an invalid path\n");
+                               free(globbed);
+                               globbed = strdup(dest_value);
+                       }
+                       fprintf(stderr, "gots path: %s\n", globbed);
                        if (globbed[strlen(globbed)-1] != '/')
                                die("wmii_path is not terminated by /");
                        wmii_path = globbed;
@@ -184,7 +188,7 @@ int load_configuration(const char *configfile) {
        fclose(handle);
 
        if (wmii_path == NULL)
-               exit(-4);
+               exit(EXIT_FAILURE);
 
        return result;
 }
index ffa86e34ee8de376713a7a30b7ec788be350fca8..48c504c7219016569e4103266c51f486d3021c28 100644 (file)
@@ -114,6 +114,31 @@ static void create_file(const char *name) {
        (void)close(fd);
 }
 
+static void setup(void) {
+       unsigned int i;
+       struct stat statbuf;
+       char pathbuf[512];
+
+       /* Wait until wmii_path/rbar exists */
+       for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
+
+       cleanup_rbar_dir();
+       if (wlan_interface)
+               create_file(concat(order[ORDER_WLAN],"wlan"));
+       if (eth_interface)
+               create_file(concat(order[ORDER_ETH],"eth"));
+       if (battery_path)
+               create_file(concat(order[ORDER_BATTERY],"battery"));
+       create_file(concat(order[ORDER_LOAD],"load"));
+       if (time_format)
+               create_file(concat(order[ORDER_TIME],"time"));
+       for (i = 0; i < num_run_watches; i += 2) {
+               snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
+               create_file(pathbuf);
+       }
+
+}
+
 /*
  * Writes the given message in the corresponding file in wmii's /rbar directory
  *
@@ -123,8 +148,11 @@ static void write_to_statusbar(const char *name, const char *message) {
        int fd;
 
        (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
-       if ((fd = open(pathbuf, O_RDWR)) == -1)
-               exit(EXIT_FAILURE);
+       if ((fd = open(pathbuf, O_RDWR)) == -1) {
+               /* Try to re-setup stuff and just continue */
+               setup();
+               return;
+       }
        if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))
                exit(EXIT_FAILURE);
        (void)close(fd);
@@ -151,7 +179,8 @@ void die(const char *fmt, ...) {
        (void)vsnprintf(buffer, sizeof(buffer), fmt, ap);
        va_end(ap);
 
-       write_error_to_statusbar(buffer);
+       if (wmii_path != NULL)
+               write_error_to_statusbar(buffer);
        exit(EXIT_FAILURE);
 }
 
@@ -399,21 +428,10 @@ int main(int argc, char *argv[]) {
                if ((char)o == 'c')
                        configfile = optarg;
 
-       load_configuration(configfile);
-       cleanup_rbar_dir();
-       if (wlan_interface)
-               create_file(concat(order[ORDER_WLAN],"wlan"));
-       if (eth_interface)
-               create_file(concat(order[ORDER_ETH],"eth"));
-       if (battery_path)
-               create_file(concat(order[ORDER_BATTERY],"battery"));
-       create_file(concat(order[ORDER_LOAD],"load"));
-       if (time_format)
-               create_file(concat(order[ORDER_TIME],"time"));
-       for (i = 0; i < num_run_watches; i += 2) {
-               snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
-               create_file(pathbuf);
-       }
+       if (load_configuration(configfile) < 0)
+               return EXIT_FAILURE;
+
+       setup();
 
        while (1) {
                for (i = 0; i < num_run_watches; i += 2) {