]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: move message printing out from main()
authorSami Kerola <kerolasa@iki.fi>
Sat, 14 Nov 2020 11:32:54 +0000 (11:32 +0000)
committerSami Kerola <kerolasa@iki.fi>
Thu, 3 Dec 2020 20:09:14 +0000 (20:09 +0000)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/login.c

index b392e28e41de050b019a544e9cfe2cca51d425f2..0a325697f513ad4883078311b21cabcbfd9adef4 100644 (file)
@@ -400,6 +400,35 @@ static void motd(void)
        free(list);
 }
 
+/*
+ * Display message of the day and you have mail notifications
+ */
+static void display_login_messages()
+{
+       motd();
+
+#ifdef LOGIN_STAT_MAIL
+       /*
+        * This turns out to be a bad idea: when the mail spool
+        * is NFS mounted, and the NFS connection hangs, the
+        * login hangs, even root cannot login.
+        * Checking for mail should be done from the shell.
+        */
+       {
+               struct stat st;
+               char *mail;
+
+               mail = getenv("MAIL");
+               if (mail && stat(mail, &st) == 0 && st.st_size != 0) {
+                       if (st.st_mtime > st.st_atime)
+                               printf(_("You have new mail.\n"));
+                       else
+                               printf(_("You have mail.\n"));
+               }
+       }
+#endif
+}
+
 /*
  * Nice and simple code provided by Linus Torvalds 16-Feb-93.
  * Non-blocking stuff by Maciej W. Rozycki, macro@ds2.pg.gda.pl, 1999.
@@ -1450,30 +1479,8 @@ int main(int argc, char **argv)
 
        log_syslog(&cxt);
 
-       if (!cxt.quiet) {
-               motd();
-
-#ifdef LOGIN_STAT_MAIL
-               /*
-                * This turns out to be a bad idea: when the mail spool
-                * is NFS mounted, and the NFS connection hangs, the
-                * login hangs, even root cannot login.
-                * Checking for mail should be done from the shell.
-                */
-               {
-                       struct stat st;
-                       char *mail;
-
-                       mail = getenv("MAIL");
-                       if (mail && stat(mail, &st) == 0 && st.st_size != 0) {
-                               if (st.st_mtime > st.st_atime)
-                                       printf(_("You have new mail.\n"));
-                               else
-                                       printf(_("You have mail.\n"));
-                       }
-               }
-#endif
-       }
+       if (!cxt.quiet)
+               display_login_messages();
 
        /*
         * Detach the controlling terminal, fork, and create a new session