service: optimize relaying stdio output of daemons a bit.
authorYousong Zhou <yszhou4tech@gmail.com>
Sun, 14 Jun 2015 04:14:43 +0000 (12:14 +0800)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 14 Jun 2015 16:28:40 +0000 (18:28 +0200)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
service/instance.c

index 3367885..4ace40b 100644 (file)
@@ -366,6 +366,10 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in)
        char *newline, *str, *arg0, ident[32];
        int len;
 
        char *newline, *str, *arg0, ident[32];
        int len;
 
+       arg0 = basename(blobmsg_data(blobmsg_data(in->command)));
+       snprintf(ident, sizeof(ident), "%s[%d]", arg0, in->proc.pid);
+       ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident);
+
        do {
                str = ustream_get_read_buf(s, NULL);
                if (!str)
        do {
                str = ustream_get_read_buf(s, NULL);
                if (!str)
@@ -376,17 +380,13 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in)
                        break;
 
                *newline = 0;
                        break;
 
                *newline = 0;
-               len = newline + 1 - str;
-
-               arg0 = basename(blobmsg_data(blobmsg_data(in->command)));
-               snprintf(ident, sizeof(ident), "%s[%d]", arg0, in->proc.pid);
-
-               ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident);
                ulog(prio, "%s\n", str);
                ulog(prio, "%s\n", str);
-               ulog_open(ULOG_SYSLOG, LOG_DAEMON, "procd");
 
 
+               len = newline + 1 - str;
                ustream_consume(s, len);
        } while (1);
                ustream_consume(s, len);
        } while (1);
+
+       ulog_open(ULOG_SYSLOG, LOG_DAEMON, "procd");
 }
 
 static void
 }
 
 static void