* [PATCH] wall: use xgethostname()
@ 2013-02-16 18:08 Sami Kerola
2013-03-04 11:30 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2013-02-16 18:08 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
term-utils/wall.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/term-utils/wall.c b/term-utils/wall.c
index e370807..c2ac7ad 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) {
/*
--
1.8.1.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-04 11:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-16 18:08 [PATCH] wall: use xgethostname() Sami Kerola
2013-03-04 11:30 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox