summaryrefslogtreecommitdiffstats
path: root/term-utils/wall.c
diff options
context:
space:
mode:
authorSami Kerola2013-02-16 19:08:40 +0100
committerKarel Zak2013-03-04 12:28:32 +0100
commit2281e1eda38344ebb1ac1f5189c04b6b3f1843f2 (patch)
treeddb017b5b40a44b92a92ff0f0c9e83d5b377b1fe /term-utils/wall.c
parentreadprofile: fix --reest (--reset) typo (diff)
downloadkernel-qcow2-util-linux-2281e1eda38344ebb1ac1f5189c04b6b3f1843f2.tar.gz
kernel-qcow2-util-linux-2281e1eda38344ebb1ac1f5189c04b6b3f1843f2.tar.xz
kernel-qcow2-util-linux-2281e1eda38344ebb1ac1f5189c04b6b3f1843f2.zip
wall: use xgethostname()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/wall.c')
-rw-r--r--term-utils/wall.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/term-utils/wall.c b/term-utils/wall.c
index e370807c8..c2ac7ad12 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -182,10 +182,9 @@ makemsg(char *fname, size_t *mbufsize, int print_banner)
struct stat sbuf;
time_t now;
FILE *fp;
- char *p, *whom, *where, *hostname, *lbuf, *tmpname, *mbuf;
+ char *p, *whom, *where, *lbuf, *tmpname, *mbuf;
long line_max;
- hostname = xmalloc(sysconf(_SC_HOST_NAME_MAX) + 1);
line_max = sysconf(_SC_LINE_MAX);
lbuf = xmalloc(line_max);
@@ -195,6 +194,7 @@ makemsg(char *fname, size_t *mbufsize, int print_banner)
free(tmpname);
if (print_banner == TRUE) {
+ char *hostname = xgethostname();
if (!(whom = getlogin()) || !*whom)
whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
if (!whom) {
@@ -206,7 +206,6 @@ makemsg(char *fname, size_t *mbufsize, int print_banner)
where = "somewhere";
warn(_("cannot get tty name"));
}
- gethostname(hostname, sizeof(hostname));
time(&now);
lt = localtime(&now);
@@ -222,6 +221,7 @@ makemsg(char *fname, size_t *mbufsize, int print_banner)
fprintf(fp, "\r%79s\r\n", " ");
sprintf(lbuf, _("Broadcast Message from %s@%s"),
whom, hostname);
+ free(hostname);
fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
sprintf(lbuf, " (%s) at %d:%02d ...",
where, lt->tm_hour, lt->tm_min);
@@ -229,7 +229,6 @@ makemsg(char *fname, size_t *mbufsize, int print_banner)
}
fprintf(fp, "%79s\r\n", " ");
- free(hostname);
if (fname) {
/*