[2943] in BarnOwl Developers
Re: [PATCH] Use g_get_host_name instead of gethostname and MAXHOSTNAMELEN
daemon@ATHENA.MIT.EDU (Nelson Elhage)
Sat Feb 26 22:05:36 2011
In-Reply-To: <1298769114-20022-1-git-send-email-davidben@mit.edu>
Date: Sat, 26 Feb 2011 22:05:34 -0500
From: Nelson Elhage <nelhage@nelhage.com>
To: David Benjamin <davidben@mit.edu>
Cc: barnowl-dev@mit.edu
lgtm
- Nelson
On Sat, Feb 26, 2011 at 8:11 PM, David Benjamin <davidben@mit.edu> wrote:
> This lets us punt thishost from owl_global. g_get_host_name implements
> the same localhost fallback, so we really don't need it.
>
> Also, Solaris gets upset about MAXHOSTNAMELEN when you define
> _XOPEN_SOURCE=3D500 without __EXTENSIONS__, if we ever care to get rid of
> that. (That said, glib's answer to this is lame. They just hardcode 100
> and even forget to NUL-terminate the buffer; POSIX is apparently
> braindead and leaves truncation undefined. glibc is kind enough to give
> you ENAMETOOLONG.)
> ---
> =C2=A0global.c =C2=A0 | =C2=A0 19 -------------------
> =C2=A0message.c =C2=A0| =C2=A0 10 +---------
> =C2=A0owl.h =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A01 -
> =C2=A0variable.c | =C2=A0 =C2=A02 +-
> =C2=A04 files changed, 2 insertions(+), 30 deletions(-)
>
> diff --git a/global.c b/global.c
> index 2e13f3d..86d6299 100644
> --- a/global.c
> +++ b/global.c
> @@ -8,28 +8,14 @@
> =C2=A0#include <time.h>
> =C2=A0#include "owl.h"
>
> -#ifndef MAXHOSTNAMELEN
> -#define MAXHOSTNAMELEN 256
> -#endif
> -
> =C2=A0static void _owl_global_init_windows(owl_global *g);
>
> =C2=A0void owl_global_init(owl_global *g) {
> - =C2=A0struct hostent *hent;
> - =C2=A0char hostname[MAXHOSTNAMELEN];
> =C2=A0 char *cd;
> =C2=A0 const char *homedir;
>
> =C2=A0 g_type_init();
>
> - =C2=A0gethostname(hostname, MAXHOSTNAMELEN);
> - =C2=A0hent=3Dgethostbyname(hostname);
> - =C2=A0if (!hent) {
> - =C2=A0 =C2=A0g->thishost=3Dg_strdup("localhost");
> - =C2=A0} else {
> - =C2=A0 =C2=A0g->thishost=3Dg_strdup(hent->h_name);
> - =C2=A0}
> -
> =C2=A0 g->lines=3DLINES;
> =C2=A0 g->cols=3DCOLS;
> =C2=A0 /* We shouldn't need this if we initialize lines and cols before t=
he first
> @@ -498,11 +484,6 @@ time_t owl_global_get_idletime(const owl_global *g) =
{
> =C2=A0 return(time(NULL)-g->lastinputtime);
> =C2=A0}
>
> -const char *owl_global_get_hostname(const owl_global *g) {
> - =C2=A0if (g->thishost) return(g->thishost);
> - =C2=A0return("");
> -}
> -
> =C2=A0/* viewwin */
>
> =C2=A0owl_viewwin *owl_global_get_viewwin(owl_global *g) {
> diff --git a/message.c b/message.c
> index a168216..e994587 100644
> --- a/message.c
> +++ b/message.c
> @@ -959,8 +959,6 @@ void owl_message_create_pseudo_zlogin(owl_message *m,=
int direction, const char
>
> =C2=A0void owl_message_create_from_zwrite(owl_message *m, const owl_zwrit=
e *z, const char *body)
> =C2=A0{
> - =C2=A0int ret;
> - =C2=A0char hostbuff[5000];
> =C2=A0 char *replyline;
>
> =C2=A0 owl_message_init(m);
> @@ -990,13 +988,7 @@ void owl_message_create_from_zwrite(owl_message *m, =
const owl_zwrite *z, const c
> =C2=A0 owl_message_set_zsig(m, owl_zwrite_get_zsig(z));
>
> =C2=A0 /* save the hostname */
> - =C2=A0ret=3Dgethostname(hostbuff, MAXHOSTNAMELEN);
> - =C2=A0hostbuff[MAXHOSTNAMELEN]=3D'\0';
> - =C2=A0if (ret) {
> - =C2=A0 =C2=A0owl_message_set_hostname(m, "localhost");
> - =C2=A0} else {
> - =C2=A0 =C2=A0owl_message_set_hostname(m, hostbuff);
> - =C2=A0}
> + =C2=A0owl_message_set_hostname(m, g_get_host_name());
>
> =C2=A0 /* set the "isprivate" attribute if it's a private zephyr. */
> =C2=A0 if (owl_zwrite_is_personal(z)) {
> diff --git a/owl.h b/owl.h
> index aac5ff3..89405fb 100644
> --- a/owl.h
> +++ b/owl.h
> @@ -593,7 +593,6 @@ typedef struct _owl_global {
> =C2=A0 gulong typwin_erase_id;
> =C2=A0 int rightshift;
> =C2=A0 volatile sig_atomic_t resizepending;
> - =C2=A0char *thishost;
> =C2=A0 char *homedir;
> =C2=A0 char *confdir;
> =C2=A0 char *startupfile;
> diff --git a/variable.c b/variable.c
> index b18ccc8..68307ea 100644
> --- a/variable.c
> +++ b/variable.c
> @@ -465,7 +465,7 @@ int owl_variable_disable_ctrl_d_set(owl_variable *v, =
const void *newval)
>
> =C2=A0int owl_variable_tty_set(owl_variable *v, const void *newval)
> =C2=A0{
> - =C2=A0owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval);
> + =C2=A0owl_zephyr_set_locationinfo(g_get_host_name(), newval);
> =C2=A0 return(owl_variable_string_set_default(v, newval));
> =C2=A0}
>
> --
> 1.7.3.3.399.g06ddf
>
>