public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH] wall: use xgethostname()
Date: Sat, 16 Feb 2013 18:08:40 +0000	[thread overview]
Message-ID: <1361038120-5880-1-git-send-email-kerolasa@iki.fi> (raw)

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


             reply	other threads:[~2013-02-16 18:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-16 18:08 Sami Kerola [this message]
2013-03-04 11:30 ` [PATCH] wall: use xgethostname() Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1361038120-5880-1-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox