]> xenbits.xensource.com Git - unikraft/libs/newlib.git/commitdiff
syslog.c: Fix checkpatch warnings
authorCostin Lupu <costin.lupu@cs.pub.ro>
Wed, 14 Aug 2019 18:57:05 +0000 (21:57 +0300)
committerFelipe Huici <felipe.huici@neclab.eu>
Thu, 15 Aug 2019 08:34:29 +0000 (10:34 +0200)
Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
musl-imported/src/syslog.c

index 54a03e91a79e4ffb913ab88864c4fecda9ed3841..179224165be12bcb163b8ea0f25bb718245a7844 100644 (file)
@@ -74,19 +74,21 @@ static int log_facility = LOG_USER;
 
 void openlog(const char *ident, int opt, int facility)
 {
-    LOCK(lock);
-
-    if (ident) {
-        size_t n = strnlen(ident, sizeof log_ident - 1);
-        memcpy(log_ident, ident, n);
-        log_ident[n] = 0;
-    } else {
-        log_ident[0] = 0;
-    }
-    log_opt = opt;
-    log_facility = facility;
-
-    UNLOCK(lock);
+       LOCK(lock);
+
+       if (ident) {
+               size_t n;
+
+               n = strnlen(ident, sizeof(log_ident) - 1);
+               memcpy(log_ident, ident, n);
+               log_ident[n] = 0;
+       } else {
+               log_ident[0] = 0;
+       }
+       log_opt = opt;
+       log_facility = facility;
+
+       UNLOCK(lock);
 }
 
 void closelog(void)
@@ -95,36 +97,41 @@ void closelog(void)
 
 void syslog(int priority, const char *message, ...)
 {
-    LOCK(lock);
-
-    va_list ap;
-    va_start(ap, message);
-
-    char timebuf[16];
-    time_t now;
-    struct tm tm;
-    char buf[256];
-    int pid;
-    int l, l2;
-
-    if (!(priority & LOG_FACMASK)) priority |= log_facility;
-
-    now = time(NULL);
-    gmtime_r(&now, &tm);
-    strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
-
-    pid = (log_opt & LOG_PID) ? getpid() : 0;
-    l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
-        priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
-    l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
-    if (l2 >= 0) {
-        if (l2 >= sizeof buf - l) l = sizeof buf - 1;
-        else l += l2;
-        if (buf[l-1] != '\n') buf[l++] = '\n';
-        fwrite(buf, 1, l, LOG_PRI(priority) >= LOG_ERR ? stderr : stdout);            
-    }
-
-    va_end(ap);
-
-    UNLOCK(lock);
+       va_list ap;
+       char timebuf[16];
+       time_t now;
+       struct tm tm;
+       char buf[256];
+       int pid;
+       int l, l2;
+
+       LOCK(lock);
+
+       va_start(ap, message);
+
+       if (!(priority & LOG_FACMASK))
+               priority |= log_facility;
+
+       now = time(NULL);
+       gmtime_r(&now, &tm);
+       strftime(timebuf, sizeof(timebuf), "%b %e %T", &tm);
+
+       pid = (log_opt & LOG_PID) ? getpid() : 0;
+       l = snprintf(buf, sizeof(buf), "<%d>%s %s%s%.0d%s: ", priority, timebuf,
+                       log_ident, "[" + !pid, pid, "]" + !pid);
+       l2 = vsnprintf(buf + l, sizeof(buf) - l, message, ap);
+       if (l2 >= 0) {
+               if (l2 >= (int) sizeof(buf) - l)
+                       l = sizeof(buf) - 1;
+               else
+                       l += l2;
+               if (buf[l - 1] != '\n')
+                       buf[l++] = '\n';
+               fwrite(buf, 1, l,
+                       LOG_PRI(priority) >= LOG_ERR ? stderr : stdout);
+       }
+
+       va_end(ap);
+
+       UNLOCK(lock);
 }