aboutsummaryrefslogtreecommitdiff
path: root/loginutils/login.c
diff options
context:
space:
mode:
Diffstat (limited to 'loginutils/login.c')
-rw-r--r--loginutils/login.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/loginutils/login.c b/loginutils/login.c
index 8732b99f1..861382f12 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -118,18 +118,25 @@ static void die_if_nologin(void)
{
FILE *fp;
int c;
+ int empty = 1;
- if (access("/etc/nologin", F_OK))
+ fp = fopen_for_read("/etc/nologin");
+ if (!fp) /* assuming it does not exist */
return;
- fp = fopen_for_read("/etc/nologin");
- if (fp) {
- while ((c = getc(fp)) != EOF)
- bb_putchar((c=='\n') ? '\r' : c);
- fflush(stdout);
- fclose(fp);
- } else
+ while ((c = getc(fp)) != EOF) {
+ if (c == '\n')
+ bb_putchar('\r');
+ bb_putchar(c);
+ empty = 0;
+ }
+ if (empty)
puts("\r\nSystem closed for routine maintenance\r");
+
+ fclose(fp);
+ fflush(NULL);
+ /* Users say that they do need this prior to exit: */
+ tcdrain(STDOUT_FILENO);
exit(EXIT_FAILURE);
}
#else