Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors from library code, and exit in the caller #1198

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions lib/motd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
#include "string/strdup/xstrdup.h"


/*
Expand All @@ -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;
Expand All @@ -37,24 +36,26 @@ 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, ":"))) {
fp = fopen (motdfile, "r");
if (NULL != fp) {
while ((c = getc (fp)) != EOF) {
putchar (c);
}
fclose (fp);
if (fp == NULL)
continue;

while ((c = getc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
}
fflush (stdout);

free (motdlist);
return 0;
}

2 changes: 1 addition & 1 deletion lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <assert.h>
Expand Down Expand Up @@ -1180,7 +1181,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);
Expand Down
Loading