Speed up --start-daemon option
authorGeoff Levand <geoff@infradead.org>
Sat, 31 Mar 2012 00:20:48 +0000 (17:20 -0700)
committerGeoff Levand <geoff@infradead.org>
Sat, 31 Mar 2012 01:10:10 +0000 (18:10 -0700)
Signed-off-by: Geoff Levand <geoff@infradead.org>
ui/ncurses/nc-cui.c
ui/twin/pbt-client.c

index 7db482b0cfe040e646d9047198ddc0c3a7b8b1df..b9d8d79048639300b6d4d7667983be7b463627ed 100644 (file)
@@ -556,10 +556,10 @@ struct cui *cui_init(void* platform_info,
 
        /* Loop here for scripts that just started the server. */
 
-start_deamon:
-       for (i = 10; i; i--) {
+retry_start:
+       for (i = start_deamon ? 2 : 10; i; i--) {
                client = discover_client_init(&cui_client_ops, cui);
-               if (client)
+               if (client || !i)
                        break;
                pb_log("%s: waiting for server %d\n", __func__, i);
                sleep(1);
@@ -573,7 +573,7 @@ start_deamon:
                result = pb_start_daemon();
 
                if (!result)
-                       goto start_deamon;
+                       goto retry_start;
 
                pb_log("%s: discover_client_init failed.\n", __func__);
                fprintf(stderr, "%s: error: discover_client_init failed.\n",
index 8d7991a415d9370e42205d83fc328a7b0b50d6ee..bcd17c9153f60e590d8cbccffbbdeda490a39118 100644 (file)
@@ -289,12 +289,12 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
                goto fail_scr_init;
 
        /* Loop here for scripts that just started the server. */
-if (1) {
-start_deamon:
-       for (i = 10; i; i--) {
+
+retry_start:
+       for (i = start_deamon ? 2 : 10; i; i--) {
                pbt_client->discover_client
                        = discover_client_init(&pbt_client_ops, pbt_client);
-               if (pbt_client->discover_client)
+               if (pbt_client->discover_client || !i)
                        break;
                pb_log("%s: waiting for server %d\n", __func__, i);
                sleep(1);
@@ -308,7 +308,7 @@ start_deamon:
                result = pb_start_daemon();
 
                if (!result)
-                       goto start_deamon;
+                       goto retry_start;
 
                pb_log("%s: discover_client_init failed.\n", __func__);
                fprintf(stderr, "%s: error: discover_client_init failed.\n",
@@ -330,7 +330,7 @@ start_deamon:
        waiter_register(discover_client_get_fd(pbt_client->discover_client),
                WAIT_IN, (waiter_cb)discover_client_process,
                pbt_client->discover_client);
-}
+
        return pbt_client;
 
 fail_client_init: