]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: Use defined() instead of #if[n]def
authorAlejandro Colomar <alx@kernel.org>
Tue, 20 Feb 2024 18:13:03 +0000 (19:13 +0100)
committerAlejandro Colomar <alx@kernel.org>
Wed, 21 Feb 2024 17:18:14 +0000 (18:18 +0100)
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cherry-picked-from: 2806b827d839 ("lib/utmp.c: Use defined() instead of #if[n]def")
[alx: This is needed by 1af6b68cbeb9 ("lib/utmp.c: Use the appropriate autotools macros for struct utmpx")]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c

index aee604d74d9e1f994dfdd7d2fbe3e627f96a04f2..d65816a0d02da91fa8bc45f1e54427cfae92c5df 100644 (file)
@@ -169,7 +169,7 @@ get_session_host(char **out)
 
        ut = get_current_utmp();
 
-#ifdef HAVE_STRUCT_UTMP_UT_HOST
+#if defined(HAVE_STRUCT_UTMP_UT_HOST)
        if ((ut != NULL) && (ut->ut_host[0] != '\0')) {
                hostname = XMALLOC(sizeof(ut->ut_host) + 1, char);
                strncpy (hostname, ut->ut_host, sizeof (ut->ut_host));
@@ -243,7 +243,7 @@ prepare_utmp(const char *name, const char *line, const char *host,
            && ('\0' != host[0])) {
                hostname = XMALLOC(strlen(host) + 1, char);
                strcpy (hostname, host);
-#ifdef HAVE_STRUCT_UTMP_UT_HOST
+#if defined(HAVE_STRUCT_UTMP_UT_HOST)
        } else if (   (NULL != ut)
                   && ('\0' != ut->ut_host[0])) {
                hostname = XMALLOC(sizeof(ut->ut_host) + 1, char);
@@ -269,16 +269,16 @@ prepare_utmp(const char *name, const char *line, const char *host,
                /* XXX - assumes /dev/tty?? */
                strncpy (utent->ut_id, line + 3, sizeof (utent->ut_id) - 1);
        }
-#ifdef HAVE_STRUCT_UTMP_UT_NAME
+#if defined(HAVE_STRUCT_UTMP_UT_NAME)
        strncpy (utent->ut_name, name,      sizeof (utent->ut_name));
 #endif
        strncpy (utent->ut_user, name,      sizeof (utent->ut_user) - 1);
        if (NULL != hostname) {
                struct addrinfo *info = NULL;
-#ifdef HAVE_STRUCT_UTMP_UT_HOST
+#if defined(HAVE_STRUCT_UTMP_UT_HOST)
                strncpy (utent->ut_host, hostname, sizeof (utent->ut_host) - 1);
 #endif
-#ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
+#if defined(HAVE_STRUCT_UTMP_UT_SYSLEN)
                utent->ut_syslen = MIN (strlen (hostname),
                                        sizeof (utent->ut_host));
 #endif
@@ -290,13 +290,13 @@ prepare_utmp(const char *name, const char *line, const char *host,
                        if (info->ai_family == AF_INET) {
                                struct sockaddr_in *sa =
                                        (struct sockaddr_in *) info->ai_addr;
-# ifdef HAVE_STRUCT_UTMP_UT_ADDR
+# if defined(HAVE_STRUCT_UTMP_UT_ADDR)
                                memcpy (&(utent->ut_addr),
                                        &(sa->sin_addr),
                                        MIN (sizeof (utent->ut_addr),
                                             sizeof (sa->sin_addr)));
 # endif
-# ifdef HAVE_STRUCT_UTMP_UT_ADDR_V6
+# if defined(HAVE_STRUCT_UTMP_UT_ADDR_V6)
                                memcpy (utent->ut_addr_v6,
                                        &(sa->sin_addr),
                                        MIN (sizeof (utent->ut_addr_v6),
@@ -318,10 +318,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) {
-#ifdef HAVE_STRUCT_UTMP_UT_TIME
+#if defined(HAVE_STRUCT_UTMP_UT_TIME)
                utent->ut_time = tv.tv_sec;
 #endif
-#ifdef HAVE_STRUCT_UTMP_UT_XTIME
+#if defined(HAVE_STRUCT_UTMP_UT_XTIME)
                utent->ut_xtime = tv.tv_usec;
 #endif
                utent->ut_tv.tv_sec  = tv.tv_sec;
@@ -350,7 +350,7 @@ setutmp(struct utmpx *ut)
        }
        endutxent();
 
-#ifndef USE_PAM
+#if !defined(USE_PAM)
        /* This is done by pam_lastlog */
        updwtmpx(_WTMP_FILE, ut);
 #endif