summaryrefslogtreecommitdiffstats
path: root/misc-utils/logger.c
diff options
context:
space:
mode:
authorSami Kerola2014-06-23 00:43:09 +0200
committerSami Kerola2014-07-28 22:15:17 +0200
commitc462a8caf2b885df4a8e769d9056d8f63b82f6be (patch)
tree1cd841cf595700dafb267b213e94716ce73895d8 /misc-utils/logger.c
parentlogger: do not rely only getlogin(3) telling who ran the command (diff)
downloadkernel-qcow2-util-linux-c462a8caf2b885df4a8e769d9056d8f63b82f6be.tar.gz
kernel-qcow2-util-linux-c462a8caf2b885df4a8e769d9056d8f63b82f6be.tar.xz
kernel-qcow2-util-linux-c462a8caf2b885df4a8e769d9056d8f63b82f6be.zip
logger: refactor long if clause
When if clause that continues throughout whole function it usually can be shorten to immediate action, e.g., in this case return on the spot not at end of the function. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/logger.c')
-rw-r--r--misc-utils/logger.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 5204cef55..9f9650c31 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -273,24 +273,22 @@ static void mysyslog(int fd, int logflags, int pri, char *tag, char *msg)
char buf[1000], pid[30], *cp, *tp;
time_t now;
- if (fd > -1) {
- if (logflags & LOG_PID)
- snprintf(pid, sizeof(pid), "[%d]", getpid());
- else
- pid[0] = 0;
- if (tag)
- cp = tag;
- else
- cp = xgetlogin();
- time(&now);
- tp = ctime(&now) + 4;
-
- snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
- pri, tp, cp, pid, msg);
-
- if (write_all(fd, buf, strlen(buf) + 1) < 0)
- warn(_("write failed"));
- }
+ if (fd < 0)
+ return;
+ if (logflags & LOG_PID)
+ snprintf(pid, sizeof(pid), "[%d]", getpid());
+ else
+ pid[0] = 0;
+ if (tag)
+ cp = tag;
+ else
+ cp = xgetlogin();
+ time(&now);
+ tp = ctime(&now) + 4;
+ snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
+ pri, tp, cp, pid, msg);
+ if (write_all(fd, buf, strlen(buf) + 1) < 0)
+ warn(_("write failed"));
}
static void __attribute__ ((__noreturn__)) usage(FILE *out)