summaryrefslogtreecommitdiffstats
path: root/misc-utils/logger.c
diff options
context:
space:
mode:
authorSami Kerola2015-03-15 13:54:48 +0100
committerKarel Zak2015-03-16 11:45:38 +0100
commitd5f930614b12c38aeb8cf6f41384e2f5f9f90e9e (patch)
tree83b148a5a508a72ce019e9db47968d63ea7c2c47 /misc-utils/logger.c
parentlogger: tidy few indentation issues (diff)
downloadkernel-qcow2-util-linux-d5f930614b12c38aeb8cf6f41384e2f5f9f90e9e.tar.gz
kernel-qcow2-util-linux-d5f930614b12c38aeb8cf6f41384e2f5f9f90e9e.tar.xz
kernel-qcow2-util-linux-d5f930614b12c38aeb8cf6f41384e2f5f9f90e9e.zip
logger: check xgethostname() return value
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/logger.c')
-rw-r--r--misc-utils/logger.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index fccd39cd1..5af24469d 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -343,9 +343,10 @@ static void write_output(const struct logger_ctl *ctl, const char *const msg)
fprintf(stderr, "%s\n", buf);
}
+#define NILVALUE "-"
static void syslog_rfc3164_header(struct logger_ctl *const ctl)
{
- char pid[30], *hostname, *dot;
+ char pid[30], *hostname;
*pid = '\0';
if (ctl->fd < 0)
@@ -353,10 +354,12 @@ static void syslog_rfc3164_header(struct logger_ctl *const ctl)
if (ctl->pid)
snprintf(pid, sizeof(pid), "[%d]", ctl->pid);
- hostname = xgethostname();
- dot = strchr(hostname, '.');
- if (dot)
- *dot = '\0';
+ if ((hostname = xgethostname())) {
+ char *dot = strchr(hostname, '.');
+ if (dot)
+ *dot = '\0';
+ } else
+ hostname = xstrdup(NILVALUE);
xasprintf(&ctl->hdr, "<%d>%.15s %s %.200s%s: ",
ctl->pri, rfc3164_current_time(), hostname, ctl->tag, pid);
@@ -384,7 +387,6 @@ static void syslog_rfc3164_header(struct logger_ctl *const ctl)
* specified RFC5424. The rest of the field mappings should be
* pretty clear from RFC5424. -- Rainer Gerhards, 2015-03-10
*/
-#define NILVALUE "-"
static void syslog_rfc5424_header(struct logger_ctl *const ctl)
{
char *time;
@@ -417,7 +419,8 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl)
time = xstrdup(NILVALUE);
if (ctl->rfc5424_host) {
- hostname = xgethostname();
+ if (!(hostname = xgethostname()))
+ hostname = xstrdup(NILVALUE);
/* Arbitrary looking 'if (var < strlen()) checks originate from
* RFC 5424 - 6 Syslog Message Format definition. */
if (255 < strlen(hostname))