Skip to content

Commit

Permalink
lib/utmp.c: Use the appropriate autotools macros for struct utmpx
Browse files Browse the repository at this point in the history
Recently, we started using utmpx instead of utmp, and we updated
<./configure.ac> to do the checks for 'struct utmpx' instead of
'struct utmp'.  However, I forgot to update the preprocessor
conditionals accordingly.

Fixes: 64bcb54 ("lib/, src/, configure.ac: Use utmpx instead of utmp")
Link: <#954>
Cc: Firas Khalil Khana <[email protected]>
Cc: "A. Wilfox" <https://github.com/awilfox>
Reviewed-by: Iker Pedrosa <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Feb 21, 2024
1 parent 2806b82 commit 1af6b68
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ get_session_host(char **out)

ut = get_current_utmp();

#if defined(HAVE_STRUCT_UTMP_UT_HOST)
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
if ((ut != NULL) && (ut->ut_host[0] != '\0')) {
char *hostname;

Expand Down Expand Up @@ -258,7 +258,7 @@ prepare_utmp(const char *name, const char *line, const char *host,
&& ('\0' != host[0])) {
hostname = XMALLOC(strlen(host) + 1, char);
strcpy (hostname, host);
#if defined(HAVE_STRUCT_UTMP_UT_HOST)
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
} else if ( (NULL != ut)
&& ('\0' != ut->ut_host[0])) {
hostname = XMALLOC(NITEMS(ut->ut_host) + 1, char);
Expand All @@ -283,34 +283,34 @@ prepare_utmp(const char *name, const char *line, const char *host,
/* XXX - assumes /dev/tty?? */
STRNCPY(utent->ut_id, line + 3);
}
#if defined(HAVE_STRUCT_UTMP_UT_NAME)
#if defined(HAVE_STRUCT_UTMPX_UT_NAME)
STRNCPY(utent->ut_name, name);
#endif
STRNCPY(utent->ut_user, name);
if (NULL != hostname) {
struct addrinfo *info = NULL;
#if defined(HAVE_STRUCT_UTMP_UT_HOST)
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
STRNCPY(utent->ut_host, hostname);
#endif
#if defined(HAVE_STRUCT_UTMP_UT_SYSLEN)
#if defined(HAVE_STRUCT_UTMPX_UT_SYSLEN)
utent->ut_syslen = MIN (strlen (hostname),
sizeof (utent->ut_host));
#endif
#if defined(HAVE_STRUCT_UTMP_UT_ADDR) || defined(HAVE_STRUCT_UTMP_UT_ADDR_V6)
#if defined(HAVE_STRUCT_UTMPX_UT_ADDR) || defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
if (getaddrinfo (hostname, NULL, NULL, &info) == 0) {
/* getaddrinfo might not be reliable.
* Just try to log what may be useful.
*/
if (info->ai_family == AF_INET) {
struct sockaddr_in *sa =
(struct sockaddr_in *) info->ai_addr;
# if defined(HAVE_STRUCT_UTMP_UT_ADDR)
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR)
memcpy (&(utent->ut_addr),
&(sa->sin_addr),
MIN (sizeof (utent->ut_addr),
sizeof (sa->sin_addr)));
# endif
# if defined(HAVE_STRUCT_UTMP_UT_ADDR_V6)
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
memcpy (utent->ut_addr_v6,
&(sa->sin_addr),
MIN (sizeof (utent->ut_addr_v6),
Expand All @@ -332,10 +332,10 @@ prepare_utmp(const char *name, const char *line, const char *host,
/* ut_exit is only for DEAD_PROCESS */
utent->ut_session = getsid (0);
if (gettimeofday (&tv, NULL) == 0) {
#if defined(HAVE_STRUCT_UTMP_UT_TIME)
#if defined(HAVE_STRUCT_UTMPX_UT_TIME)
utent->ut_time = tv.tv_sec;
#endif
#if defined(HAVE_STRUCT_UTMP_UT_XTIME)
#if defined(HAVE_STRUCT_UTMPX_UT_XTIME)
utent->ut_xtime = tv.tv_usec;
#endif
utent->ut_tv.tv_sec = tv.tv_sec;
Expand Down

0 comments on commit 1af6b68

Please sign in to comment.