Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/libbb/login.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1953 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /* vi: set sw=4 ts=4: */
2 /*
3 * issue.c: issue printing code
4 *
5 * Copyright (C) 2003 Bastian Blank <waldi@tuxbox.org>
6 *
7 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 */
11
12 #include <sys/param.h> /* MAXHOSTNAMELEN */
13 #include <stdio.h>
14 #include <unistd.h>
15 #include "libbb.h"
16
17 #include <sys/utsname.h>
18 #include <time.h>
19
20 #define LOGIN " login: "
21
22 static const char fmtstr_d[] = "%A, %d %B %Y";
23 static const char fmtstr_t[] = "%H:%M:%S";
24
25 void print_login_issue(const char *issue_file, const char *tty)
26 {
27 FILE *fd;
28 int c;
29 char buf[256+1];
30 const char *outbuf;
31 time_t t;
32 struct utsname uts;
33
34 time(&t);
35 uname(&uts);
36
37 puts("\r"); /* start a new line */
38
39 fd = fopen(issue_file, "r");
40 if (!fd)
41 return;
42 while ((c = fgetc(fd)) != EOF) {
43 outbuf = buf;
44 buf[0] = c;
45 buf[1] = '\0';
46 if(c == '\n') {
47 buf[1] = '\r';
48 buf[2] = '\0';
49 }
50 if (c == '\\' || c == '%') {
51 c = fgetc(fd);
52 switch (c) {
53 case 's':
54 outbuf = uts.sysname;
55 break;
56 case 'n':
57 outbuf = uts.nodename;
58 break;
59 case 'r':
60 outbuf = uts.release;
61 break;
62 case 'v':
63 outbuf = uts.version;
64 break;
65 case 'm':
66 outbuf = uts.machine;
67 break;
68 case 'D':
69 case 'o':
70 c = getdomainname(buf, sizeof(buf) - 1);
71 buf[c >= 0 ? c : 0] = '\0';
72 break;
73 case 'd':
74 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
75 break;
76 case 't':
77 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
78 break;
79 case 'h':
80 gethostname(buf, sizeof(buf) - 1);
81 buf[sizeof(buf) - 1] = '\0';
82 break;
83 case 'l':
84 outbuf = tty;
85 break;
86 default:
87 buf[0] = c;
88 }
89 }
90 fputs(outbuf, stdout);
91 }
92 fclose(fd);
93 fflush(stdout);
94 }
95
96 void print_login_prompt(void)
97 {
98 char buf[MAXHOSTNAMELEN+1];
99
100 if (gethostname(buf, MAXHOSTNAMELEN) == 0)
101 fputs(buf, stdout);
102
103 fputs(LOGIN, stdout);
104 fflush(stdout);
105 }