From 2a583e945dd302a842ee62effa66a0ce29fd00ea Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 15 Nov 2024 23:55:18 +0100 Subject: [PATCH] lib/, src/: motd(): Report errors instead of exiting from library code Signed-off-by: Alejandro Colomar --- lib/motd.c | 13 +++++++------ lib/prototypes.h | 2 +- src/login.c | 5 ++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/motd.c b/lib/motd.c index bed9efae2..a2efc4ea1 100644 --- a/lib/motd.c +++ b/lib/motd.c @@ -17,7 +17,6 @@ #include "defines.h" #include "getdef.h" #include "prototypes.h" -#include "string/strdup/xstrdup.h" /* @@ -27,7 +26,7 @@ * it to the user's terminal at login time. The MOTD_FILE configuration * option is a colon-delimited list of filenames. */ -void +int motd(void) { FILE *fp; @@ -37,11 +36,12 @@ motd(void) int c; motdfile = getdef_str ("MOTD_FILE"); - if (NULL == motdfile) { - return; - } + if (NULL == motdfile) + return 0; - motdlist = xstrdup (motdfile); + motdlist = strdup(motdfile); + if (motdlist == NULL) + return -1; mb = motdlist; while (NULL != (motdfile = strsep(&mb, ":"))) { @@ -57,4 +57,5 @@ motd(void) fflush (stdout); free (motdlist); + return 0; } diff --git a/lib/prototypes.h b/lib/prototypes.h index f85c14663..79bd0fdd6 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -222,7 +222,7 @@ extern void login_prompt (char *, int); extern void mailcheck (void); /* motd.c */ -extern void motd (void); +extern int motd(void); /* myname.c */ extern /*@null@*//*@only@*/struct passwd *get_my_pwent (void); diff --git a/src/login.c b/src/login.c index 349df16d8..2866b1523 100644 --- a/src/login.c +++ b/src/login.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1175,7 +1176,9 @@ int main (int argc, char **argv) * this */ #ifndef USE_PAM - motd (); /* print the message of the day */ + if (motd() == -1) + exit(EXIT_FAILURE); + if ( getdef_bool ("FAILLOG_ENAB") && (0 != faillog.fail_cnt)) { failprint (&faillog); -- 2.47.2