2 * Alternate Getty (agetty) 'agetty' is a versatile, portable, easy to use
3 * replacement for getty on SunOS 4.1.x or the SAC ttymon/ttyadm/sacadm/pmadm
4 * suite on Solaris and other SVR4 systems. 'agetty' was written by Wietse
5 * Venema, enhanced by John DiMarco, and further enhanced by Dennis Cronin.
7 * Ported to Linux by Peter Orbaek <poe@daimi.aau.dk>
8 * Adopt the mingetty features for a better support
9 * of virtual consoles by Werner Fink <werner@suse.de>
11 * This program is freely distributable.
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
31 #include <sys/socket.h>
34 #include <arpa/inet.h>
38 #include <sys/utsname.h>
43 #include "pathnames.h"
47 #include "color-names.h"
50 #ifdef USE_PLYMOUTH_SUPPORT
51 # include "plymouth-ctrl.h"
54 #ifdef HAVE_SYS_PARAM_H
55 # include <sys/param.h>
58 #if defined(__FreeBSD_kernel__)
63 # ifdef HAVE_LIBUTIL_H
71 # ifndef DEFAULT_VCTERM
72 # define DEFAULT_VCTERM "linux"
74 # if defined (__s390__) || defined (__s390x__)
75 # define DEFAULT_TTYS0 "dumb"
76 # define DEFAULT_TTY32 "ibm327x"
77 # define DEFAULT_TTYS1 "vt220"
79 # ifndef DEFAULT_STERM
80 # define DEFAULT_STERM "vt102"
82 #elif defined(__GNU__)
84 # ifndef DEFAULT_VCTERM
85 # define DEFAULT_VCTERM "hurd"
87 # ifndef DEFAULT_STERM
88 # define DEFAULT_STERM "vt102"
91 # ifndef DEFAULT_VCTERM
92 # define DEFAULT_VCTERM "vt100"
94 # ifndef DEFAULT_STERM
95 # define DEFAULT_STERM "vt100"
99 #ifdef __FreeBSD_kernel__
103 /* If USE_SYSLOG is undefined all diagnostics go to /dev/console. */
109 * Some heuristics to find out what environment we are in: if it is not
110 * System V, assume it is SunOS 4. The LOGIN_PROCESS is defined in System V
111 * utmp.h, which will select System V style getty.
118 * Things you may want to modify.
120 * If ISSUE_SUPPORT is not defined, agetty will never display the contents of
121 * the /etc/issue file. You will not want to spit out large "issue" files at
122 * the wrong baud rate. Relevant for System V only.
124 * You may disagree with the default line-editing etc. characters defined
125 * below. Note, however, that DEL cannot be used for interrupt generation
126 * and for line editing at the same time.
129 /* Displayed before the login prompt. */
131 # define ISSUE_SUPPORT
132 # if defined(HAVE_SCANDIRAT) && defined(HAVE_OPENAT)
134 # include "fileutils.h"
135 # define ISSUEDIR_SUPPORT
136 # define ISSUEDIR_EXT ".issue"
137 # define ISSUEDIR_EXTSIZ (sizeof(ISSUEDIR_EXT) - 1)
142 #define LOGIN "login: "
143 #define LOGIN_ARGV_MAX 16 /* Numbers of args for login */
149 # include <sys/inotify.h>
150 # include <linux/netlink.h>
151 # include <linux/rtnetlink.h>
152 # define AGETTY_RELOAD_FILENAME "/run/agetty.reload" /* trigger file */
153 # define AGETTY_RELOAD_FDNONE -2 /* uninitialized fd */
154 static int inotify_fd
= AGETTY_RELOAD_FDNONE
;
155 static int netlink_fd
= AGETTY_RELOAD_FDNONE
;
159 * When multiple baud rates are specified on the command line, the first one
160 * we will try is the first one specified.
162 #define FIRST_SPEED 0
164 /* Storage for command-line options. */
165 #define MAX_SPEED 10 /* max. nr. of baud rates */
168 int flags
; /* toggle switches, see below */
169 unsigned int timeout
; /* time-out period */
170 char *autolog
; /* login the user automatically */
171 char *chdir
; /* Chdir before the login */
172 char *chroot
; /* Chroot before the login */
173 char *login
; /* login program */
174 char *logopt
; /* options for login program */
175 char *tty
; /* name of tty */
176 char *vcline
; /* line of virtual console */
177 char *term
; /* terminal type */
178 char *initstring
; /* modem init string */
179 char *issue
; /* alternative issue file or directory */
180 char *erasechars
; /* string with erase chars */
181 char *killchars
; /* string with kill chars */
182 char *osrelease
; /* /etc/os-release data */
183 unsigned int delay
; /* Sleep seconds before prompt */
184 int nice
; /* Run login with this priority */
185 int numspeed
; /* number of baud rates to try */
186 int clocal
; /* CLOCAL_MODE_* */
187 int kbmode
; /* Keyboard mode if virtual console */
188 speed_t speeds
[MAX_SPEED
]; /* baud rates to be tried */
192 CLOCAL_MODE_AUTO
= 0,
197 #define F_PARSE (1<<0) /* process modem status messages */
198 #define F_ISSUE (1<<1) /* display /etc/issue or /etc/issue.d */
199 #define F_RTSCTS (1<<2) /* enable RTS/CTS flow control */
201 #define F_INITSTRING (1<<4) /* initstring is set */
202 #define F_WAITCRLF (1<<5) /* wait for CR or LF */
204 #define F_NOPROMPT (1<<7) /* do not ask for login name! */
205 #define F_LCUC (1<<8) /* support for *LCUC stty modes */
206 #define F_KEEPSPEED (1<<9) /* follow baud rate from kernel */
207 #define F_KEEPCFLAGS (1<<10) /* reuse c_cflags setup from kernel */
208 #define F_EIGHTBITS (1<<11) /* Assume 8bit-clean tty */
209 #define F_VCONSOLE (1<<12) /* This is a virtual console */
210 #define F_HANGUP (1<<13) /* Do call vhangup(2) */
211 #define F_UTF8 (1<<14) /* We can do UTF8 */
212 #define F_LOGINPAUSE (1<<15) /* Wait for any key before dropping login prompt */
213 #define F_NOCLEAR (1<<16) /* Do not clear the screen before prompting */
214 #define F_NONL (1<<17) /* No newline before issue */
215 #define F_NOHOSTNAME (1<<18) /* Do not show the hostname */
216 #define F_LONGHNAME (1<<19) /* Show Full qualified hostname */
217 #define F_NOHINTS (1<<20) /* Don't print hints */
218 #define F_REMOTE (1<<21) /* Add '-h fakehost' to login(1) command line */
220 #define serial_tty_option(opt, flag) \
221 (((opt)->flags & (F_VCONSOLE|(flag))) == (flag))
228 static const struct Speedtab speedtab
[] = {
300 static void init_special_char(char* arg
, struct options
*op
);
301 static void parse_args(int argc
, char **argv
, struct options
*op
);
302 static void parse_speeds(struct options
*op
, char *arg
);
303 static void update_utmp(struct options
*op
);
304 static void open_tty(char *tty
, struct termios
*tp
, struct options
*op
);
305 static void termio_init(struct options
*op
, struct termios
*tp
);
306 static void reset_vc (const struct options
*op
, struct termios
*tp
);
307 static void auto_baud(struct termios
*tp
);
308 static void list_speeds(void);
309 static void output_special_char (unsigned char c
, struct options
*op
,
310 struct termios
*tp
, FILE *fp
);
311 static void do_prompt(struct options
*op
, struct termios
*tp
);
312 static void next_speed(struct options
*op
, struct termios
*tp
);
313 static char *get_logname(struct options
*op
,
314 struct termios
*tp
, struct chardata
*cp
);
315 static void termio_final(struct options
*op
,
316 struct termios
*tp
, struct chardata
*cp
);
317 static int caps_lock(char *s
);
318 static speed_t
bcode(char *s
);
319 static void usage(void) __attribute__((__noreturn__
));
320 static void log_err(const char *, ...) __attribute__((__noreturn__
))
321 __attribute__((__format__(printf
, 1, 2)));
322 static void log_warn (const char *, ...)
323 __attribute__((__format__(printf
, 1, 2)));
324 static ssize_t
append(char *dest
, size_t len
, const char *sep
, const char *src
);
325 static void check_username (const char* nm
);
326 static void login_options_to_argv(char *argv
[], int *argc
, char *str
, char *username
);
327 static void reload_agettys(void);
328 static void print_issue_file(struct options
*op
, struct termios
*tp
);
330 /* Fake hostname for ut_host specified on command line. */
331 static char *fakehost
;
334 # include "closestream.h"
335 # ifndef DEBUG_OUTPUT
336 # define DEBUG_OUTPUT "/dev/tty10"
338 # define debug(s) do { fprintf(dbf,s); fflush(dbf); } while (0)
341 # define debug(s) do { ; } while (0)
344 int main(int argc
, char **argv
)
346 char *username
= NULL
; /* login name, given to /bin/login */
347 struct chardata chardata
; /* will be set by get_logname() */
348 struct termios termios
; /* terminal mode bits */
349 struct options options
= {
350 .flags
= F_ISSUE
, /* show /etc/issue (SYSV_STYLE) */
351 .login
= _PATH_LOGIN
, /* default login program */
352 .tty
= "tty1" /* default tty line */
354 char *login_argv
[LOGIN_ARGV_MAX
+ 1];
356 struct sigaction sa
, sa_hup
, sa_quit
, sa_int
;
359 setlocale(LC_ALL
, "");
360 bindtextdomain(PACKAGE
, LOCALEDIR
);
363 /* In case vhangup(2) has to called */
364 sa
.sa_handler
= SIG_IGN
;
365 sa
.sa_flags
= SA_RESTART
;
366 sigemptyset (&sa
.sa_mask
);
367 sigaction(SIGHUP
, &sa
, &sa_hup
);
368 sigaction(SIGQUIT
, &sa
, &sa_quit
);
369 sigaction(SIGINT
, &sa
, &sa_int
);
372 dbf
= fopen(DEBUG_OUTPUT
, "w");
373 for (int i
= 1; i
< argc
; i
++) {
379 #endif /* DEBUGGING */
381 /* Parse command-line arguments. */
382 parse_args(argc
, argv
, &options
);
384 login_argv
[login_argc
++] = options
.login
; /* set login program name */
386 /* Update the utmp file. */
388 update_utmp(&options
);
391 sleep(options
.delay
);
393 debug("calling open_tty\n");
395 /* Open the tty as standard { input, output, error }. */
396 open_tty(options
.tty
, &termios
, &options
);
398 /* Unmask SIGHUP if inherited */
400 sigaddset(&set
, SIGHUP
);
401 sigprocmask(SIG_UNBLOCK
, &set
, NULL
);
402 sigaction(SIGHUP
, &sa_hup
, NULL
);
404 tcsetpgrp(STDIN_FILENO
, getpid());
406 /* Default is to follow the current line speed and then default to 9600 */
407 if ((options
.flags
& F_VCONSOLE
) == 0 && options
.numspeed
== 0) {
408 options
.speeds
[options
.numspeed
++] = bcode("9600");
409 options
.flags
|= F_KEEPSPEED
;
412 /* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
413 debug("calling termio_init\n");
414 termio_init(&options
, &termios
);
416 /* Write the modem init string and DO NOT flush the buffers. */
417 if (serial_tty_option(&options
, F_INITSTRING
) &&
418 options
.initstring
&& *options
.initstring
!= '\0') {
419 debug("writing init string\n");
420 write_all(STDOUT_FILENO
, options
.initstring
,
421 strlen(options
.initstring
));
424 if (options
.flags
& F_VCONSOLE
|| options
.clocal
!= CLOCAL_MODE_ALWAYS
)
425 /* Go to blocking mode unless -L is specified, this change
426 * affects stdout, stdin and stderr as all the file descriptors
427 * are created by dup(). */
428 fcntl(STDOUT_FILENO
, F_SETFL
,
429 fcntl(STDOUT_FILENO
, F_GETFL
, 0) & ~O_NONBLOCK
);
431 /* Optionally detect the baud rate from the modem status message. */
432 debug("before autobaud\n");
433 if (serial_tty_option(&options
, F_PARSE
))
436 /* Set the optional timer. */
438 alarm(options
.timeout
);
440 /* Optionally wait for CR or LF before writing /etc/issue */
441 if (serial_tty_option(&options
, F_WAITCRLF
)) {
444 debug("waiting for cr-lf\n");
445 while (read(STDIN_FILENO
, &ch
, 1) == 1) {
446 /* Strip "parity bit". */
449 fprintf(dbf
, "read %c\n", ch
);
451 if (ch
== '\n' || ch
== '\r')
456 INIT_CHARDATA(&chardata
);
458 if (options
.autolog
) {
459 debug("doing auto login\n");
460 username
= options
.autolog
;
463 if (options
.flags
& F_NOPROMPT
) { /* --skip-login */
464 print_issue_file(&options
, &termios
);
465 } else { /* regular (auto)login */
466 if (options
.autolog
) {
467 /* Autologin prompt */
468 do_prompt(&options
, &termios
);
469 printf(_("%s%s (automatic login)\n"), LOGIN
, options
.autolog
);
471 /* Read the login name. */
472 debug("reading login name\n");
474 get_logname(&options
, &termios
, &chardata
)) == NULL
)
475 if ((options
.flags
& F_VCONSOLE
) == 0 && options
.numspeed
)
476 next_speed(&options
, &termios
);
484 if ((options
.flags
& F_VCONSOLE
) == 0) {
485 /* Finalize the termios settings. */
486 termio_final(&options
, &termios
, &chardata
);
488 /* Now the newline character should be properly written. */
489 write_all(STDOUT_FILENO
, "\r\n", 2);
492 sigaction(SIGQUIT
, &sa_quit
, NULL
);
493 sigaction(SIGINT
, &sa_int
, NULL
);
496 check_username(username
);
498 if (options
.logopt
) {
500 * The --login-options completely overwrites the default
501 * way how agetty composes login(1) command line.
503 login_options_to_argv(login_argv
, &login_argc
,
504 options
.logopt
, username
);
506 if (options
.flags
& F_REMOTE
) {
508 login_argv
[login_argc
++] = "-h";
509 login_argv
[login_argc
++] = fakehost
;
510 } else if (options
.flags
& F_NOHOSTNAME
)
511 login_argv
[login_argc
++] = "-H";
515 login_argv
[login_argc
++] = "-f";
517 login_argv
[login_argc
++] = "--";
518 login_argv
[login_argc
++] = username
;
522 login_argv
[login_argc
] = NULL
; /* last login argv */
524 if (options
.chroot
&& chroot(options
.chroot
) < 0)
525 log_err(_("%s: can't change root directory %s: %m"),
526 options
.tty
, options
.chroot
);
527 if (options
.chdir
&& chdir(options
.chdir
) < 0)
528 log_err(_("%s: can't change working directory %s: %m"),
529 options
.tty
, options
.chdir
);
530 if (options
.nice
&& nice(options
.nice
) < 0)
531 log_warn(_("%s: can't change process priority: %m"),
534 free(options
.osrelease
);
536 if (close_stream(dbf
) != 0)
537 log_err("write failed: %s", DEBUG_OUTPUT
);
540 /* Let the login program take care of password validation. */
541 execv(options
.login
, login_argv
);
542 log_err(_("%s: can't exec %s: %m"), options
.tty
, login_argv
[0]);
546 * Returns : @str if \u not found
547 * : @username if @str equal to "\u"
548 * : newly allocated string if \u mixed with something other
550 static char *replace_u(char *str
, char *username
)
552 char *entry
= NULL
, *p
= str
;
553 size_t usz
= username
? strlen(username
) : 0;
557 char *tp
, *old
= entry
;
559 if (memcmp(p
, "\\u", 2)) {
561 continue; /* no \u */
565 if (p
== str
&& sz
== 2) {
566 /* 'str' contains only '\u' */
571 tp
= entry
= malloc(sz
+ usz
);
573 log_err(_("failed to allocate memory: %m"));
576 /* copy chars before \u */
577 memcpy(tp
, str
, p
- str
);
582 memcpy(tp
, username
, usz
);
586 /* copy chars after \u + \0 */
587 memcpy(tp
, p
+ 2, sz
- (p
- str
) - 1);
596 return entry
? entry
: str
;
599 static void login_options_to_argv(char *argv
[], int *argc
,
600 char *str
, char *username
)
605 while (str
&& isspace(*str
))
609 while (p
&& *p
&& i
< LOGIN_ARGV_MAX
) {
612 while (isspace(*++p
))
615 argv
[i
++] = replace_u(str
, username
);
621 if (str
&& *str
&& i
< LOGIN_ARGV_MAX
)
622 argv
[i
++] = replace_u(str
, username
);
626 static void output_version(void)
628 static const char *features
[] = {
641 #ifdef ISSUEDIR_SUPPORT
647 #ifdef USE_PLYMOUTH_SUPPORT
663 printf( _("%s from %s"), program_invocation_short_name
, PACKAGE_STRING
);
665 for (i
= 0; features
[i
]; i
++) {
668 printf("%s", features
[i
]);
670 fputs(")\n", stdout
);
673 #define is_speed(str) (strlen((str)) == strspn((str), "0123456789,"))
675 /* Parse command-line arguments. */
676 static void parse_args(int argc
, char **argv
, struct options
*op
)
681 VERSION_OPTION
= CHAR_MAX
+ 1,
691 const struct option longopts
[] = {
692 { "8bits", no_argument
, NULL
, '8' },
693 { "autologin", required_argument
, NULL
, 'a' },
694 { "noreset", no_argument
, NULL
, 'c' },
695 { "chdir", required_argument
, NULL
, 'C' },
696 { "delay", required_argument
, NULL
, 'd' },
697 { "remote", no_argument
, NULL
, 'E' },
698 { "issue-file", required_argument
, NULL
, 'f' },
699 { "flow-control", no_argument
, NULL
, 'h' },
700 { "host", required_argument
, NULL
, 'H' },
701 { "noissue", no_argument
, NULL
, 'i' },
702 { "init-string", required_argument
, NULL
, 'I' },
703 { "noclear", no_argument
, NULL
, 'J' },
704 { "login-program", required_argument
, NULL
, 'l' },
705 { "local-line", optional_argument
, NULL
, 'L' },
706 { "extract-baud", no_argument
, NULL
, 'm' },
707 { "list-speeds", no_argument
, NULL
, LIST_SPEEDS_OPTION
},
708 { "skip-login", no_argument
, NULL
, 'n' },
709 { "nonewline", no_argument
, NULL
, 'N' },
710 { "login-options", required_argument
, NULL
, 'o' },
711 { "login-pause", no_argument
, NULL
, 'p' },
712 { "nice", required_argument
, NULL
, 'P' },
713 { "chroot", required_argument
, NULL
, 'r' },
714 { "hangup", no_argument
, NULL
, 'R' },
715 { "keep-baud", no_argument
, NULL
, 's' },
716 { "timeout", required_argument
, NULL
, 't' },
717 { "detect-case", no_argument
, NULL
, 'U' },
718 { "wait-cr", no_argument
, NULL
, 'w' },
719 { "nohints", no_argument
, NULL
, NOHINTS_OPTION
},
720 { "nohostname", no_argument
, NULL
, NOHOSTNAME_OPTION
},
721 { "long-hostname", no_argument
, NULL
, LONGHOSTNAME_OPTION
},
722 { "reload", no_argument
, NULL
, RELOAD_OPTION
},
723 { "version", no_argument
, NULL
, VERSION_OPTION
},
724 { "help", no_argument
, NULL
, HELP_OPTION
},
725 { "erase-chars", required_argument
, NULL
, ERASE_CHARS_OPTION
},
726 { "kill-chars", required_argument
, NULL
, KILL_CHARS_OPTION
},
730 while ((c
= getopt_long(argc
, argv
,
731 "8a:cC:d:Ef:hH:iI:Jl:L::mnNo:pP:r:Rst:Uw", longopts
,
735 op
->flags
|= F_EIGHTBITS
;
738 op
->autolog
= optarg
;
741 op
->flags
|= F_KEEPCFLAGS
;
747 op
->delay
= strtou32_or_err(optarg
, _("invalid delay argument"));
750 op
->flags
|= F_REMOTE
;
756 op
->flags
|= F_RTSCTS
;
762 op
->flags
&= ~F_ISSUE
;
765 init_special_char(optarg
, op
);
766 op
->flags
|= F_INITSTRING
;
769 op
->flags
|= F_NOCLEAR
;
775 /* -L and -L=always have the same meaning */
776 op
->clocal
= CLOCAL_MODE_ALWAYS
;
778 if (strcmp(optarg
, "=always") == 0)
779 op
->clocal
= CLOCAL_MODE_ALWAYS
;
780 else if (strcmp(optarg
, "=never") == 0)
781 op
->clocal
= CLOCAL_MODE_NEVER
;
782 else if (strcmp(optarg
, "=auto") == 0)
783 op
->clocal
= CLOCAL_MODE_AUTO
;
785 log_err(_("invalid argument of --local-line"));
789 op
->flags
|= F_PARSE
;
792 op
->flags
|= F_NOPROMPT
;
801 op
->flags
|= F_LOGINPAUSE
;
804 op
->nice
= strtos32_or_err(optarg
, _("invalid nice argument"));
810 op
->flags
|= F_HANGUP
;
813 op
->flags
|= F_KEEPSPEED
;
816 op
->timeout
= strtou32_or_err(optarg
, _("invalid timeout argument"));
822 op
->flags
|= F_WAITCRLF
;
825 op
->flags
|= F_NOHINTS
;
827 case NOHOSTNAME_OPTION
:
828 op
->flags
|= F_NOHOSTNAME
;
830 case LONGHOSTNAME_OPTION
:
831 op
->flags
|= F_LONGHNAME
;
833 case ERASE_CHARS_OPTION
:
834 op
->erasechars
= optarg
;
836 case KILL_CHARS_OPTION
:
837 op
->killchars
= optarg
;
842 case LIST_SPEEDS_OPTION
:
851 errtryhelp(EXIT_FAILURE
);
855 debug("after getopt loop\n");
857 if (argc
< optind
+ 1) {
858 log_warn(_("not enough arguments"));
859 errx(EXIT_FAILURE
, _("not enough arguments"));
862 /* Accept "tty", "baudrate tty", and "tty baudrate". */
863 if (is_speed(argv
[optind
])) {
864 /* Assume BSD style speed. */
865 parse_speeds(op
, argv
[optind
++]);
866 if (argc
< optind
+ 1) {
867 log_warn(_("not enough arguments"));
868 errx(EXIT_FAILURE
, _("not enough arguments"));
870 op
->tty
= argv
[optind
++];
872 op
->tty
= argv
[optind
++];
874 char *v
= argv
[optind
];
882 /* On virtual console remember the line which is used for */
883 if (strncmp(op
->tty
, "tty", 3) == 0 &&
884 strspn(op
->tty
+ 3, "0123456789") == strlen(op
->tty
+3))
885 op
->vcline
= op
->tty
+3;
887 if (argc
> optind
&& argv
[optind
])
888 op
->term
= argv
[optind
];
890 debug("exiting parseargs\n");
893 /* Parse alternate baud rates. */
894 static void parse_speeds(struct options
*op
, char *arg
)
897 char *str
= strdup(arg
);
900 log_err(_("failed to allocate memory: %m"));
902 debug("entered parse_speeds:\n");
903 for (cp
= strtok(str
, ","); cp
!= NULL
; cp
= strtok((char *)0, ",")) {
904 if ((op
->speeds
[op
->numspeed
++] = bcode(cp
)) <= 0)
905 log_err(_("bad speed: %s"), cp
);
906 if (op
->numspeed
>= MAX_SPEED
)
907 log_err(_("too many alternate speeds"));
909 debug("exiting parsespeeds\n");
915 /* Update our utmp entry. */
916 static void update_utmp(struct options
*op
)
920 pid_t pid
= getpid();
921 pid_t sid
= getsid(0);
922 char *vcline
= op
->vcline
;
923 char *line
= op
->tty
;
927 * The utmp file holds miscellaneous information about things started by
928 * /sbin/init and other system-related events. Our purpose is to update
929 * the utmp entry for the current process, in particular the process type
930 * and the tty line we are listening to. Return successfully only if the
931 * utmp file can be opened for update, and if we are able to find our
932 * entry in the utmp file.
934 utmpxname(_PATH_UTMP
);
938 * Find my pid in utmp.
940 * FIXME: Earlier (when was that?) code here tested only utp->ut_type !=
941 * INIT_PROCESS, so maybe the >= here should be >.
943 * FIXME: The present code is taken from login.c, so if this is changed,
944 * maybe login has to be changed as well (is this true?).
946 while ((utp
= getutxent()))
947 if (utp
->ut_pid
== pid
948 && utp
->ut_type
>= INIT_PROCESS
949 && utp
->ut_type
<= DEAD_PROCESS
)
953 memcpy(&ut
, utp
, sizeof(ut
));
955 /* Some inits do not initialize utmp. */
956 memset(&ut
, 0, sizeof(ut
));
957 if (vcline
&& *vcline
)
958 /* Standard virtual console devices */
959 strncpy(ut
.ut_id
, vcline
, sizeof(ut
.ut_id
));
961 size_t len
= strlen(line
);
963 if (len
>= sizeof(ut
.ut_id
))
964 ptr
= line
+ len
- sizeof(ut
.ut_id
);
967 strncpy(ut
.ut_id
, ptr
, sizeof(ut
.ut_id
));
971 strncpy(ut
.ut_user
, "LOGIN", sizeof(ut
.ut_user
));
972 strncpy(ut
.ut_line
, line
, sizeof(ut
.ut_line
));
974 strncpy(ut
.ut_host
, fakehost
, sizeof(ut
.ut_host
));
977 ut
.ut_type
= LOGIN_PROCESS
;
984 updwtmpx(_PATH_WTMP
, &ut
);
987 #endif /* SYSV_STYLE */
989 /* Set up tty as stdin, stdout & stderr. */
990 static void open_tty(char *tty
, struct termios
*tp
, struct options
*op
)
992 const pid_t pid
= getpid();
998 /* Set up new standard input, unless we are given an already opened port. */
1000 if (strcmp(tty
, "-") != 0) {
1001 char buf
[PATH_MAX
+1];
1002 struct group
*gr
= NULL
;
1008 /* Use tty group if available */
1009 if ((gr
= getgrnam("tty")))
1012 len
= snprintf(buf
, sizeof(buf
), "/dev/%s", tty
);
1013 if (len
< 0 || (size_t)len
>= sizeof(buf
))
1014 log_err(_("/dev/%s: cannot open as standard input: %m"), tty
);
1016 /* Open the tty as standard input. */
1017 if ((fd
= open(buf
, O_RDWR
|O_NOCTTY
|O_NONBLOCK
, 0)) < 0)
1018 log_err(_("/dev/%s: cannot open as standard input: %m"), tty
);
1021 * There is always a race between this reset and the call to
1022 * vhangup() that s.o. can use to get access to your tty.
1023 * Linux login(1) will change tty permissions. Use root owner and group
1024 * with permission -rw------- for the period between getty and login.
1026 if (fchown(fd
, 0, gid
) || fchmod(fd
, (gid
? 0620 : 0600))) {
1028 log_warn("%s: %m", buf
);
1030 log_err("%s: %m", buf
);
1033 /* Sanity checks... */
1034 if (fstat(fd
, &st
) < 0)
1035 log_err("%s: %m", buf
);
1036 if ((st
.st_mode
& S_IFMT
) != S_IFCHR
)
1037 log_err(_("/dev/%s: not a character device"), tty
);
1039 log_err(_("/dev/%s: not a tty"), tty
);
1041 if (((tid
= tcgetsid(fd
)) < 0) || (pid
!= tid
)) {
1042 if (ioctl(fd
, TIOCSCTTY
, 1) == -1)
1043 log_warn(_("/dev/%s: cannot get controlling tty: %m"), tty
);
1046 close(STDIN_FILENO
);
1049 if (op
->flags
& F_HANGUP
) {
1051 if (ioctl(fd
, TIOCNOTTY
))
1052 debug("TIOCNOTTY ioctl failed\n");
1055 * Let's close all file descriptors before vhangup
1056 * https://lkml.org/lkml/2012/6/5/145
1059 close(STDOUT_FILENO
);
1060 close(STDERR_FILENO
);
1065 log_err(_("/dev/%s: vhangup() failed: %m"), tty
);
1070 if (open(buf
, O_RDWR
|O_NOCTTY
|O_NONBLOCK
, 0) != 0)
1071 log_err(_("/dev/%s: cannot open as standard input: %m"), tty
);
1073 if (((tid
= tcgetsid(STDIN_FILENO
)) < 0) || (pid
!= tid
)) {
1074 if (ioctl(STDIN_FILENO
, TIOCSCTTY
, 1) == -1)
1075 log_warn(_("/dev/%s: cannot get controlling tty: %m"), tty
);
1081 * Standard input should already be connected to an open port. Make
1082 * sure it is open for read/write.
1085 if ((fcntl(STDIN_FILENO
, F_GETFL
, 0) & O_RDWR
) != O_RDWR
)
1086 log_err(_("%s: not open for read/write"), tty
);
1090 if (tcsetpgrp(STDIN_FILENO
, pid
))
1091 log_warn(_("/dev/%s: cannot set process group: %m"), tty
);
1093 /* Get rid of the present outputs. */
1095 close(STDOUT_FILENO
);
1096 close(STDERR_FILENO
);
1100 /* Set up standard output and standard error file descriptors. */
1103 /* set up stdout and stderr */
1104 if (dup(STDIN_FILENO
) != 1 || dup(STDIN_FILENO
) != 2)
1105 log_err(_("%s: dup problem: %m"), tty
);
1107 /* make stdio unbuffered for slow modem lines */
1108 setvbuf(stdout
, NULL
, _IONBF
, 0);
1111 * The following ioctl will fail if stdin is not a tty, but also when
1112 * there is noise on the modem control lines. In the latter case, the
1113 * common course of action is (1) fix your cables (2) give the modem
1114 * more time to properly reset after hanging up.
1116 * SunOS users can achieve (2) by patching the SunOS kernel variable
1117 * "zsadtrlow" to a larger value; 5 seconds seems to be a good value.
1118 * http://www.sunmanagers.org/archives/1993/0574.html
1120 memset(tp
, 0, sizeof(struct termios
));
1121 if (tcgetattr(STDIN_FILENO
, tp
) < 0)
1122 log_err(_("%s: failed to get terminal attributes: %m"), tty
);
1124 #if defined (__s390__) || defined (__s390x__)
1127 * Special terminal on first serial line on a S/390(x) which
1128 * is due legacy reasons a block terminal of type 3270 or
1129 * higher. Whereas the second serial line on a S/390(x) is
1130 * a real character terminal which is compatible with VT220.
1132 if (strcmp(op
->tty
, "ttyS0") == 0) /* linux/drivers/s390/char/con3215.c */
1133 op
->term
= DEFAULT_TTYS0
;
1134 else if (strncmp(op
->tty
, "3270/tty", 8) == 0) /* linux/drivers/s390/char/con3270.c */
1135 op
->term
= DEFAULT_TTY32
;
1136 else if (strcmp(op
->tty
, "ttyS1") == 0) /* linux/drivers/s390/char/sclp_vt220.c */
1137 op
->term
= DEFAULT_TTYS1
;
1141 #if defined(__FreeBSD_kernel__)
1146 * Detect if this is a virtual console or serial/modem line.
1147 * In case of a virtual console the ioctl KDGKBMODE succeeds
1148 * whereas on other lines it will fails.
1151 if (ioctl(STDIN_FILENO
, KDGKBMODE
, &op
->kbmode
) == 0)
1153 if (ioctl(STDIN_FILENO
, TIOCMGET
, &serial
) < 0 && (errno
== EINVAL
))
1156 op
->flags
|= F_VCONSOLE
;
1158 op
->term
= DEFAULT_VCTERM
;
1164 op
->term
= DEFAULT_STERM
;
1167 if (setenv("TERM", op
->term
, 1) != 0)
1168 log_err(_("failed to set the %s environment variable"), "TERM");
1171 /* Initialize termios settings. */
1172 static void termio_clear(int fd
)
1175 * Do not write a full reset (ESC c) because this destroys
1176 * the unicode mode again if the terminal was in unicode
1177 * mode. Also it clears the CONSOLE_MAGIC features which
1178 * are required for some languages/console-fonts.
1179 * Just put the cursor to the home position (ESC [ H),
1180 * erase everything below the cursor (ESC [ J), and set the
1181 * scrolling region to the full window (ESC [ r)
1183 write_all(fd
, "\033[r\033[H\033[J", 9);
1186 /* Initialize termios settings. */
1187 static void termio_init(struct options
*op
, struct termios
*tp
)
1189 speed_t ispeed
, ospeed
;
1191 #ifdef USE_PLYMOUTH_SUPPORT
1192 struct termios lock
;
1193 int i
= (plymouth_command(MAGIC_PING
) == 0) ? PLYMOUTH_TERMIOS_FLAGS_DELAY
: 0;
1195 plymouth_command(MAGIC_QUIT
);
1198 * Even with TTYReset=no it seems with systemd or plymouth
1199 * the termios flags become changed from under the first
1200 * agetty on a serial system console as the flags are locked.
1202 memset(&lock
, 0, sizeof(struct termios
));
1203 if (ioctl(STDIN_FILENO
, TIOCGLCKTRMIOS
, &lock
) < 0)
1205 if (!lock
.c_iflag
&& !lock
.c_oflag
&& !lock
.c_cflag
&& !lock
.c_lflag
)
1207 debug("termios locked\n");
1210 memset(&lock
, 0, sizeof(struct termios
));
1211 ioctl(STDIN_FILENO
, TIOCSLCKTRMIOS
, &lock
);
1214 if (op
->flags
& F_VCONSOLE
) {
1215 #if defined(IUTF8) && defined(KDGKBMODE)
1216 switch(op
->kbmode
) {
1218 setlocale(LC_CTYPE
, "C.UTF-8");
1219 op
->flags
|= F_UTF8
;
1225 setlocale(LC_CTYPE
, "POSIX");
1226 op
->flags
&= ~F_UTF8
;
1230 setlocale(LC_CTYPE
, "POSIX");
1231 op
->flags
&= ~F_UTF8
;
1235 if ((tp
->c_cflag
& (CS8
|PARODD
|PARENB
)) == CS8
)
1236 op
->flags
|= F_EIGHTBITS
;
1238 if ((op
->flags
& F_NOCLEAR
) == 0)
1239 termio_clear(STDOUT_FILENO
);
1247 if (op
->flags
& F_KEEPSPEED
|| !op
->numspeed
) {
1248 /* Save the original setting. */
1249 ispeed
= cfgetispeed(tp
);
1250 ospeed
= cfgetospeed(tp
);
1252 if (!ispeed
) ispeed
= TTYDEF_SPEED
;
1253 if (!ospeed
) ospeed
= TTYDEF_SPEED
;
1256 ospeed
= ispeed
= op
->speeds
[FIRST_SPEED
];
1260 * Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
1261 * Special characters are set after we have read the login name; all
1262 * reads will be done in raw mode anyway. Errors will be dealt with
1267 tp
->c_iflag
= tp
->c_iflag
& IUTF8
;
1268 if (tp
->c_iflag
& IUTF8
)
1269 op
->flags
|= F_UTF8
;
1274 tp
->c_oflag
&= OPOST
| ONLCR
;
1276 if ((op
->flags
& F_KEEPCFLAGS
) == 0)
1277 tp
->c_cflag
= CS8
| HUPCL
| CREAD
| (tp
->c_cflag
& CLOCAL
);
1280 * Note that the speed is stored in the c_cflag termios field, so we have
1281 * set the speed always when the cflag is reset.
1283 cfsetispeed(tp
, ispeed
);
1284 cfsetospeed(tp
, ospeed
);
1286 /* The default is to follow setting from kernel, but it's possible
1287 * to explicitly remove/add CLOCAL flag by -L[=<mode>]*/
1288 switch (op
->clocal
) {
1289 case CLOCAL_MODE_ALWAYS
:
1290 tp
->c_cflag
|= CLOCAL
; /* -L or -L=always */
1292 case CLOCAL_MODE_NEVER
:
1293 tp
->c_cflag
&= ~CLOCAL
; /* -L=never */
1295 case CLOCAL_MODE_AUTO
: /* -L=auto */
1299 #ifdef HAVE_STRUCT_TERMIOS_C_LINE
1303 tp
->c_cc
[VTIME
] = 0;
1305 /* Check for terminal size and if not found set default */
1306 if (ioctl(STDIN_FILENO
, TIOCGWINSZ
, &ws
) == 0) {
1311 if (ioctl(STDIN_FILENO
, TIOCSWINSZ
, &ws
))
1312 debug("TIOCSWINSZ ioctl failed\n");
1315 /* Optionally enable hardware flow control. */
1317 if (op
->flags
& F_RTSCTS
)
1318 tp
->c_cflag
|= CRTSCTS
;
1320 /* Flush input and output queues, important for modems! */
1321 tcflush(STDIN_FILENO
, TCIOFLUSH
);
1323 if (tcsetattr(STDIN_FILENO
, TCSANOW
, tp
))
1324 log_warn(_("setting terminal attributes failed: %m"));
1326 /* Go to blocking input even in local mode. */
1327 fcntl(STDIN_FILENO
, F_SETFL
,
1328 fcntl(STDIN_FILENO
, F_GETFL
, 0) & ~O_NONBLOCK
);
1330 debug("term_io 2\n");
1333 /* Reset virtual console on stdin to its defaults */
1334 static void reset_vc(const struct options
*op
, struct termios
*tp
)
1338 fl
|= (op
->flags
& F_KEEPCFLAGS
) == 0 ? 0 : UL_TTY_KEEPCFLAGS
;
1339 fl
|= (op
->flags
& F_UTF8
) == 0 ? 0 : UL_TTY_UTF8
;
1341 reset_virtual_console(tp
, fl
);
1343 if (tcsetattr(STDIN_FILENO
, TCSADRAIN
, tp
))
1344 log_warn(_("setting terminal attributes failed: %m"));
1346 /* Go to blocking input even in local mode. */
1347 fcntl(STDIN_FILENO
, F_SETFL
,
1348 fcntl(STDIN_FILENO
, F_GETFL
, 0) & ~O_NONBLOCK
);
1351 /* Extract baud rate from modem status message. */
1352 static void auto_baud(struct termios
*tp
)
1362 * This works only if the modem produces its status code AFTER raising
1363 * the DCD line, and if the computer is fast enough to set the proper
1364 * baud rate before the message has gone by. We expect a message of the
1367 * <junk><number><junk>
1369 * The number is interpreted as the baud rate of the incoming call. If the
1370 * modem does not tell us the baud rate within one second, we will keep
1371 * using the current baud rate. It is advisable to enable BREAK
1372 * processing (comma-separated list of baud rates) if the processing of
1373 * modem status messages is enabled.
1377 * Use 7-bit characters, don't block if input queue is empty. Errors will
1378 * be dealt with later on.
1380 iflag
= tp
->c_iflag
;
1381 /* Enable 8th-bit stripping. */
1382 tp
->c_iflag
|= ISTRIP
;
1383 vmin
= tp
->c_cc
[VMIN
];
1384 /* Do not block when queue is empty. */
1386 tcsetattr(STDIN_FILENO
, TCSANOW
, tp
);
1389 * Wait for a while, then read everything the modem has said so far and
1390 * try to extract the speed of the dial-in call.
1393 if ((nread
= read(STDIN_FILENO
, buf
, sizeof(buf
) - 1)) > 0) {
1395 for (bp
= buf
; bp
< buf
+ nread
; bp
++)
1396 if (isascii(*bp
) && isdigit(*bp
)) {
1397 if ((speed
= bcode(bp
))) {
1398 cfsetispeed(tp
, speed
);
1399 cfsetospeed(tp
, speed
);
1405 /* Restore terminal settings. Errors will be dealt with later on. */
1406 tp
->c_iflag
= iflag
;
1407 tp
->c_cc
[VMIN
] = vmin
;
1408 tcsetattr(STDIN_FILENO
, TCSANOW
, tp
);
1411 static char *xgethostname(void)
1414 size_t sz
= get_hostname_max() + 1;
1416 name
= malloc(sizeof(char) * sz
);
1418 log_err(_("failed to allocate memory: %m"));
1420 if (gethostname(name
, sz
) != 0) {
1424 name
[sz
- 1] = '\0';
1428 static char *xgetdomainname(void)
1430 #ifdef HAVE_GETDOMAINNAME
1432 const size_t sz
= get_hostname_max() + 1;
1434 name
= malloc(sizeof(char) * sz
);
1436 log_err(_("failed to allocate memory: %m"));
1438 if (getdomainname(name
, sz
) != 0) {
1442 name
[sz
- 1] = '\0';
1450 static char *read_os_release(struct options
*op
, const char *varname
)
1454 size_t varsz
= strlen(varname
);
1455 char *p
, *buf
= NULL
, *ret
= NULL
;
1457 /* read the file only once */
1458 if (!op
->osrelease
) {
1459 fd
= open(_PATH_OS_RELEASE_ETC
, O_RDONLY
);
1461 fd
= open(_PATH_OS_RELEASE_USR
, O_RDONLY
);
1463 log_warn(_("cannot open os-release file"));
1468 if (fstat(fd
, &st
) < 0 || st
.st_size
> 4 * 1024 * 1024)
1471 op
->osrelease
= malloc(st
.st_size
+ 1);
1473 log_err(_("failed to allocate memory: %m"));
1474 if (read_all(fd
, op
->osrelease
, st
.st_size
) != (ssize_t
) st
.st_size
) {
1475 free(op
->osrelease
);
1476 op
->osrelease
= NULL
;
1479 op
->osrelease
[st
.st_size
] = 0;
1481 buf
= strdup(op
->osrelease
);
1483 log_err(_("failed to allocate memory: %m"));
1489 p
+= strspn(p
, "\n\r");
1490 p
+= strspn(p
, " \t\n\r");
1493 if (strspn(p
, "#;\n") != 0) {
1494 p
+= strcspn(p
, "\n\r");
1497 if (strncmp(p
, varname
, varsz
) != 0) {
1498 p
+= strcspn(p
, "\n\r");
1502 p
+= strspn(p
, " \t\n\r");
1507 p
+= strspn(p
, " \t\n\r=\"");
1508 eol
= p
+ strcspn(p
, "\n\r");
1512 if (*eon
== '\t' || *eon
== ' ') {
1525 log_err(_("failed to allocate memory: %m"));
1535 #ifdef AGETTY_RELOAD
1536 static void open_netlink(void)
1538 struct sockaddr_nl addr
= { 0, };
1541 if (netlink_fd
!= AGETTY_RELOAD_FDNONE
)
1544 sock
= socket(AF_NETLINK
, SOCK_RAW
, NETLINK_ROUTE
);
1546 addr
.nl_family
= AF_NETLINK
;
1547 addr
.nl_pid
= getpid();
1548 addr
.nl_groups
= RTMGRP_IPV4_IFADDR
| RTMGRP_IPV6_IFADDR
;
1549 if (bind(sock
, (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
1556 static int process_netlink_msg(int *changed
)
1559 struct sockaddr_nl snl
;
1563 struct iovec iov
= {
1565 .iov_len
= sizeof(buf
)
1567 struct msghdr msg
= {
1569 .msg_namelen
= sizeof(snl
),
1572 .msg_control
= NULL
,
1573 .msg_controllen
= 0,
1577 rc
= recvmsg(netlink_fd
, &msg
, MSG_DONTWAIT
);
1579 if (errno
== EWOULDBLOCK
|| errno
== EAGAIN
)
1582 /* Failure, just stop listening for changes */
1584 netlink_fd
= AGETTY_RELOAD_FDNONE
;
1588 for (h
= (struct nlmsghdr
*)buf
; NLMSG_OK(h
, (unsigned int)rc
); h
= NLMSG_NEXT(h
, rc
)) {
1589 if (h
->nlmsg_type
== NLMSG_DONE
||
1590 h
->nlmsg_type
== NLMSG_ERROR
) {
1592 netlink_fd
= AGETTY_RELOAD_FDNONE
;
1603 static int process_netlink(void)
1606 while (process_netlink_msg(&changed
));
1610 static int wait_for_term_input(int fd
)
1612 char buffer
[sizeof(struct inotify_event
) + NAME_MAX
+ 1];
1615 if (inotify_fd
== AGETTY_RELOAD_FDNONE
) {
1616 /* make sure the reload trigger file exists */
1617 int reload_fd
= open(AGETTY_RELOAD_FILENAME
,
1618 O_CREAT
|O_CLOEXEC
|O_RDONLY
,
1621 /* initialize reload trigger inotify stuff */
1622 if (reload_fd
>= 0) {
1623 inotify_fd
= inotify_init1(IN_NONBLOCK
| IN_CLOEXEC
);
1625 inotify_add_watch(inotify_fd
, AGETTY_RELOAD_FILENAME
,
1626 IN_ATTRIB
| IN_MODIFY
);
1630 log_warn(_("failed to create reload file: %s: %m"),
1631 AGETTY_RELOAD_FILENAME
);
1640 if (inotify_fd
>= 0) {
1641 FD_SET(inotify_fd
, &rfds
);
1642 nfds
= max(nfds
, inotify_fd
);
1644 if (netlink_fd
>= 0) {
1645 FD_SET(netlink_fd
, &rfds
);
1646 nfds
= max(nfds
, netlink_fd
);
1649 /* If waiting fails, just fall through, presumably reading input will fail */
1650 if (select(nfds
+ 1, &rfds
, NULL
, NULL
, NULL
) < 0)
1653 if (FD_ISSET(fd
, &rfds
)) {
1656 } else if (netlink_fd
>= 0 && FD_ISSET(netlink_fd
, &rfds
)) {
1657 if (!process_netlink())
1660 /* Just drain the inotify buffer */
1661 } else if (inotify_fd
>= 0 && FD_ISSET(inotify_fd
, &rfds
)) {
1662 while (read(inotify_fd
, buffer
, sizeof (buffer
)) > 0);
1668 #endif /* AGETTY_RELOAD */
1670 #ifdef ISSUEDIR_SUPPORT
1671 static int issuedir_filter(const struct dirent
*d
)
1675 #ifdef _DIRENT_HAVE_D_TYPE
1676 if (d
->d_type
!= DT_UNKNOWN
&& d
->d_type
!= DT_REG
&&
1677 d
->d_type
!= DT_LNK
)
1680 if (*d
->d_name
== '.')
1683 namesz
= strlen(d
->d_name
);
1684 if (!namesz
|| namesz
< ISSUEDIR_EXTSIZ
+ 1 ||
1685 strcmp(d
->d_name
+ (namesz
- ISSUEDIR_EXTSIZ
), ISSUEDIR_EXT
))
1692 static FILE *issuedir_next_file(int dd
, struct dirent
**namelist
, int nfiles
, int *n
)
1694 while (*n
< nfiles
) {
1695 struct dirent
*d
= namelist
[*n
];
1701 if (fstatat(dd
, d
->d_name
, &st
, 0) ||
1702 !S_ISREG(st
.st_mode
))
1705 f
= fopen_at(dd
, d
->d_name
, O_RDONLY
|O_CLOEXEC
, "r" UL_CLOEXECSTR
);
1712 #endif /* ISSUEDIR_SUPPORT */
1714 #ifndef ISSUE_SUPPORT
1715 static void print_issue_file(struct options
*op
, struct termios
*tp
__attribute__((__unused__
)))
1717 if ((op
->flags
& F_NONL
) == 0) {
1718 /* Issue not in use, start with a new line. */
1719 write_all(STDOUT_FILENO
, "\r\n", 2);
1722 #else /* ISSUE_SUPPORT */
1724 static void print_issue_file(struct options
*op
, struct termios
*tp
)
1726 const char *filename
, *dirname
= NULL
;
1728 #ifdef ISSUEDIR_SUPPORT
1729 int dd
= -1, nfiles
= 0, i
;
1730 struct dirent
**namelist
= NULL
;
1732 if ((op
->flags
& F_NONL
) == 0) {
1733 /* Issue not in use, start with a new line. */
1734 write_all(STDOUT_FILENO
, "\r\n", 2);
1737 if (!(op
->flags
& F_ISSUE
))
1741 * The custom issue file or directory specified by: agetty -f <path>.
1742 * Note that nothing is printed if the file/dir does not exist.
1744 filename
= op
->issue
;
1748 if (stat(filename
, &st
) < 0)
1750 if (S_ISDIR(st
.st_mode
)) {
1755 /* The default /etc/issue and optional /etc/issue.d directory
1756 * as extension to the file. The /etc/issue.d directory is
1757 * ignored if there is no /etc/issue file. The file may be
1760 if (access(_PATH_ISSUE
, F_OK
|R_OK
) != 0)
1762 filename
= _PATH_ISSUE
;
1763 dirname
= _PATH_ISSUEDIR
;
1766 #ifdef ISSUEDIR_SUPPORT
1768 dd
= open(dirname
, O_RDONLY
|O_CLOEXEC
|O_DIRECTORY
);
1770 nfiles
= scandirat(dd
, ".", &namelist
, issuedir_filter
, versionsort
);
1777 f
= fopen(filename
, "r");
1780 int c
, oflag
= tp
->c_oflag
; /* Save current setting. */
1782 if ((op
->flags
& F_VCONSOLE
) == 0) {
1783 /* Map new line in output to carriage return & new line. */
1784 tp
->c_oflag
|= (ONLCR
| OPOST
);
1785 tcsetattr(STDIN_FILENO
, TCSADRAIN
, tp
);
1789 #ifdef ISSUEDIR_SUPPORT
1790 if (!f
&& i
< nfiles
)
1791 f
= issuedir_next_file(dd
, namelist
, nfiles
, &i
);
1795 while ((c
= getc(f
)) != EOF
) {
1797 output_special_char(getc(f
), op
, tp
, f
);
1807 if ((op
->flags
& F_VCONSOLE
) == 0) {
1808 /* Restore settings. */
1809 tp
->c_oflag
= oflag
;
1810 /* Wait till output is gone. */
1811 tcsetattr(STDIN_FILENO
, TCSADRAIN
, tp
);
1815 #ifdef ISSUEDIR_SUPPORT
1816 for (i
= 0; i
< nfiles
; i
++)
1823 #endif /* ISSUE_SUPPORT */
1825 /* Show login prompt, optionally preceded by /etc/issue contents. */
1826 static void do_prompt(struct options
*op
, struct termios
*tp
)
1828 #ifdef AGETTY_RELOAD
1831 print_issue_file(op
, tp
);
1833 if (op
->flags
& F_LOGINPAUSE
) {
1834 puts(_("[press ENTER to login]"));
1835 #ifdef AGETTY_RELOAD
1836 if (!wait_for_term_input(STDIN_FILENO
)) {
1838 if (op
->flags
& F_VCONSOLE
)
1839 termio_clear(STDOUT_FILENO
);
1846 if (!(op
->flags
& F_NOHINTS
) && !op
->autolog
&&
1847 (op
->flags
& F_VCONSOLE
)) {
1850 if (ioctl(STDIN_FILENO
, KDGKBLED
, &kb
) == 0) {
1851 char hint
[256] = { '\0' };
1854 if (access(_PATH_NUMLOCK_ON
, F_OK
) == 0)
1857 if (nl
&& (kb
& 0x02) == 0)
1858 append(hint
, sizeof(hint
), NULL
, _("Num Lock off"));
1860 else if (nl
== 0 && (kb
& 2) && (kb
& 0x20) == 0)
1861 append(hint
, sizeof(hint
), NULL
, _("Num Lock on"));
1863 if ((kb
& 0x04) && (kb
& 0x40) == 0)
1864 append(hint
, sizeof(hint
), ", ", _("Caps Lock on"));
1866 if ((kb
& 0x01) && (kb
& 0x10) == 0)
1867 append(hint
, sizeof(hint
), ", ", _("Scroll Lock on"));
1870 printf(_("Hint: %s\n\n"), hint
);
1873 #endif /* KDGKBLED */
1874 if ((op
->flags
& F_NOHOSTNAME
) == 0) {
1875 char *hn
= xgethostname();
1878 char *dot
= strchr(hn
, '.');
1880 struct addrinfo
*res
= NULL
;
1882 if ((op
->flags
& F_LONGHNAME
) == 0) {
1886 } else if (dot
== NULL
) {
1887 struct addrinfo hints
;
1889 memset(&hints
, 0, sizeof(hints
));
1890 hints
.ai_flags
= AI_CANONNAME
;
1892 if (!getaddrinfo(hn
, NULL
, &hints
, &res
)
1893 && res
&& res
->ai_canonname
)
1894 cn
= res
->ai_canonname
;
1897 write_all(STDOUT_FILENO
, cn
, strlen(cn
));
1898 write_all(STDOUT_FILENO
, " ", 1);
1906 /* Always show login prompt. */
1907 write_all(STDOUT_FILENO
, LOGIN
, sizeof(LOGIN
) - 1);
1911 /* Select next baud rate. */
1912 static void next_speed(struct options
*op
, struct termios
*tp
)
1914 static int baud_index
= -1;
1916 if (baud_index
== -1)
1918 * If the F_KEEPSPEED flags is set then the FIRST_SPEED is not
1919 * tested yet (see termio_init()).
1922 (op
->flags
& F_KEEPSPEED
) ? FIRST_SPEED
: 1 % op
->numspeed
;
1924 baud_index
= (baud_index
+ 1) % op
->numspeed
;
1926 cfsetispeed(tp
, op
->speeds
[baud_index
]);
1927 cfsetospeed(tp
, op
->speeds
[baud_index
]);
1928 tcsetattr(STDIN_FILENO
, TCSANOW
, tp
);
1931 /* Get user name, establish parity, speed, erase, kill & eol. */
1932 static char *get_logname(struct options
*op
, struct termios
*tp
, struct chardata
*cp
)
1934 static char logname
[BUFSIZ
];
1936 char c
; /* input character, full eight bits */
1937 char ascval
; /* low 7 bits of input character */
1939 static char *erase
[] = { /* backspace-space-backspace */
1940 "\010\040\010", /* space parity */
1941 "\010\040\010", /* odd parity */
1942 "\210\240\210", /* even parity */
1943 "\210\240\210", /* no parity */
1946 /* Initialize kill, erase, parity etc. (also after switching speeds). */
1950 * Flush pending input (especially important after parsing or switching
1953 if ((op
->flags
& F_VCONSOLE
) == 0)
1955 tcflush(STDIN_FILENO
, TCIFLUSH
);
1957 eightbit
= (op
->flags
& F_EIGHTBITS
);
1961 while (*logname
== '\0') {
1962 /* Write issue file and prompt */
1965 #ifdef AGETTY_RELOAD
1966 if (!wait_for_term_input(STDIN_FILENO
)) {
1967 /* refresh prompt -- discard input data, clear terminal
1968 * and call do_prompt() again
1970 if ((op
->flags
& F_VCONSOLE
) == 0)
1972 tcflush(STDIN_FILENO
, TCIFLUSH
);
1973 if (op
->flags
& F_VCONSOLE
)
1974 termio_clear(STDOUT_FILENO
);
1982 /* Read name, watch for break and end-of-line. */
1983 while (cp
->eol
== '\0') {
1987 debug("read from FD\n");
1988 if (read(STDIN_FILENO
, &c
, 1) < 1) {
1989 debug("read failed\n");
1991 /* The terminal could be open with O_NONBLOCK when
1992 * -L (force CLOCAL) is specified... */
1993 if (errno
== EINTR
|| errno
== EAGAIN
) {
2005 log_err(_("%s: read: %m"), op
->tty
);
2009 /* Do parity bit handling. */
2012 else if (c
!= (ascval
= (c
& 0177))) {
2013 uint32_t bits
; /* # of "1" bits per character */
2014 uint32_t mask
; /* mask with 1 bit up */
2015 for (bits
= 1, mask
= 1; mask
& 0177; mask
<<= 1) {
2019 cp
->parity
|= ((bits
& 1) ? 1 : 2);
2022 if (op
->killchars
&& strchr(op
->killchars
, ascval
))
2024 else if (op
->erasechars
&& strchr(op
->erasechars
, ascval
))
2029 /* Do erase, kill and end-of-line processing. */
2033 if (op
->numspeed
> 1)
2038 *bp
= 0; /* terminate logname */
2039 cp
->eol
= ascval
; /* set end-of-line char */
2043 cp
->erase
= ascval
; /* set erase character */
2045 if ((tp
->c_lflag
& ECHO
) == 0)
2046 write_all(1, erase
[cp
->parity
], 3);
2051 cp
->kill
= ascval
; /* set kill character */
2052 while (bp
> logname
) {
2053 if ((tp
->c_lflag
& ECHO
) == 0)
2054 write_all(1, erase
[cp
->parity
], 3);
2061 if (!isascii(ascval
) || !isprint(ascval
))
2063 if ((size_t)(bp
- logname
) >= sizeof(logname
) - 1)
2064 log_err(_("%s: input overrun"), op
->tty
);
2065 if ((tp
->c_lflag
& ECHO
) == 0)
2066 write_all(1, &c
, 1); /* echo the character */
2067 *bp
++ = ascval
; /* and store it */
2073 #ifdef HAVE_WIDECHAR
2074 if ((op
->flags
& (F_EIGHTBITS
|F_UTF8
)) == (F_EIGHTBITS
|F_UTF8
)) {
2075 /* Check out UTF-8 multibyte characters */
2079 len
= mbstowcs((wchar_t *)0, logname
, 0);
2081 log_err(_("%s: invalid character conversion for login name"), op
->tty
);
2083 wcs
= malloc((len
+ 1) * sizeof(wchar_t));
2085 log_err(_("failed to allocate memory: %m"));
2087 len
= mbstowcs(wcs
, logname
, len
+ 1);
2089 log_err(_("%s: invalid character conversion for login name"), op
->tty
);
2093 const wint_t wc
= *wcp
++;
2095 log_err(_("%s: invalid character 0x%x in login name"), op
->tty
, wc
);
2100 if ((op
->flags
& F_LCUC
) && (cp
->capslock
= caps_lock(logname
))) {
2102 /* Handle names with upper case and no lower case. */
2103 for (bp
= logname
; *bp
; bp
++)
2105 *bp
= tolower(*bp
); /* map name to lower case */
2111 /* Set the final tty mode bits. */
2112 static void termio_final(struct options
*op
, struct termios
*tp
, struct chardata
*cp
)
2114 /* General terminal-independent stuff. */
2116 /* 2-way flow control */
2117 tp
->c_iflag
|= IXON
| IXOFF
;
2118 tp
->c_lflag
|= ICANON
| ISIG
| ECHO
| ECHOE
| ECHOK
| ECHOKE
;
2119 /* no longer| ECHOCTL | ECHOPRT */
2120 tp
->c_oflag
|= OPOST
;
2121 /* tp->c_cflag = 0; */
2122 tp
->c_cc
[VINTR
] = DEF_INTR
;
2123 tp
->c_cc
[VQUIT
] = DEF_QUIT
;
2124 tp
->c_cc
[VEOF
] = DEF_EOF
;
2125 tp
->c_cc
[VEOL
] = DEF_EOL
;
2127 tp
->c_cc
[VSWTC
] = DEF_SWITCH
;
2128 #elif defined(VSWTCH)
2129 tp
->c_cc
[VSWTCH
] = DEF_SWITCH
;
2130 #endif /* __linux__ */
2132 /* Account for special characters seen in input. */
2133 if (cp
->eol
== CR
) {
2134 tp
->c_iflag
|= ICRNL
;
2135 tp
->c_oflag
|= ONLCR
;
2137 tp
->c_cc
[VERASE
] = cp
->erase
;
2138 tp
->c_cc
[VKILL
] = cp
->kill
;
2140 /* Account for the presence or absence of parity bits in input. */
2141 switch (cp
->parity
) {
2143 /* space (always 0) parity */
2147 tp
->c_cflag
|= PARODD
;
2151 tp
->c_cflag
|= PARENB
;
2152 tp
->c_iflag
|= INPCK
| ISTRIP
;
2156 tp
->c_cflag
&= ~CSIZE
;
2160 /* Account for upper case without lower case. */
2163 tp
->c_iflag
|= IUCLC
;
2166 tp
->c_lflag
|= XCASE
;
2169 tp
->c_oflag
|= OLCUC
;
2172 /* Optionally enable hardware flow control. */
2174 if (op
->flags
& F_RTSCTS
)
2175 tp
->c_cflag
|= CRTSCTS
;
2178 /* Finally, make the new settings effective. */
2179 if (tcsetattr(STDIN_FILENO
, TCSANOW
, tp
) < 0)
2180 log_err(_("%s: failed to set terminal attributes: %m"), op
->tty
);
2184 * String contains upper case without lower case.
2185 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=52940
2186 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=156242
2188 static int caps_lock(char *s
)
2192 for (capslock
= 0; *s
; s
++) {
2194 return EXIT_SUCCESS
;
2196 capslock
= isupper(*s
);
2201 /* Convert speed string to speed code; return 0 on failure. */
2202 static speed_t
bcode(char *s
)
2204 const struct Speedtab
*sp
;
2205 long speed
= atol(s
);
2207 for (sp
= speedtab
; sp
->speed
; sp
++)
2208 if (sp
->speed
== speed
)
2213 static void __attribute__((__noreturn__
)) usage(void)
2217 fputs(USAGE_HEADER
, out
);
2218 fprintf(out
, _(" %1$s [options] <line> [<baud_rate>,...] [<termtype>]\n"
2219 " %1$s [options] <baud_rate>,... <line> [<termtype>]\n"), program_invocation_short_name
);
2221 fputs(USAGE_SEPARATOR
, out
);
2222 fputs(_("Open a terminal and set its mode.\n"), out
);
2224 fputs(USAGE_OPTIONS
, out
);
2225 fputs(_(" -8, --8bits assume 8-bit tty\n"), out
);
2226 fputs(_(" -a, --autologin <user> login the specified user automatically\n"), out
);
2227 fputs(_(" -c, --noreset do not reset control mode\n"), out
);
2228 fputs(_(" -E, --remote use -r <hostname> for login(1)\n"), out
);
2229 fputs(_(" -f, --issue-file <file> display issue file\n"), out
);
2230 fputs(_(" -h, --flow-control enable hardware flow control\n"), out
);
2231 fputs(_(" -H, --host <hostname> specify login host\n"), out
);
2232 fputs(_(" -i, --noissue do not display issue file\n"), out
);
2233 fputs(_(" -I, --init-string <string> set init string\n"), out
);
2234 fputs(_(" -J --noclear do not clear the screen before prompt\n"), out
);
2235 fputs(_(" -l, --login-program <file> specify login program\n"), out
);
2236 fputs(_(" -L, --local-line[=<mode>] control the local line flag\n"), out
);
2237 fputs(_(" -m, --extract-baud extract baud rate during connect\n"), out
);
2238 fputs(_(" -n, --skip-login do not prompt for login\n"), out
);
2239 fputs(_(" -N --nonewline do not print a newline before issue\n"), out
);
2240 fputs(_(" -o, --login-options <opts> options that are passed to login\n"), out
);
2241 fputs(_(" -p, --login-pause wait for any key before the login\n"), out
);
2242 fputs(_(" -r, --chroot <dir> change root to the directory\n"), out
);
2243 fputs(_(" -R, --hangup do virtually hangup on the tty\n"), out
);
2244 fputs(_(" -s, --keep-baud try to keep baud rate after break\n"), out
);
2245 fputs(_(" -t, --timeout <number> login process timeout\n"), out
);
2246 fputs(_(" -U, --detect-case detect uppercase terminal\n"), out
);
2247 fputs(_(" -w, --wait-cr wait carriage-return\n"), out
);
2248 fputs(_(" --nohints do not print hints\n"), out
);
2249 fputs(_(" --nohostname no hostname at all will be shown\n"), out
);
2250 fputs(_(" --long-hostname show full qualified hostname\n"), out
);
2251 fputs(_(" --erase-chars <string> additional backspace chars\n"), out
);
2252 fputs(_(" --kill-chars <string> additional kill chars\n"), out
);
2253 fputs(_(" --chdir <directory> chdir before the login\n"), out
);
2254 fputs(_(" --delay <number> sleep seconds before prompt\n"), out
);
2255 fputs(_(" --nice <number> run login with this priority\n"), out
);
2256 fputs(_(" --reload reload prompts on running agetty instances\n"), out
);
2257 fputs(_(" --list-speeds display supported baud rates\n"), out
);
2258 printf( " --help %s\n", USAGE_OPTSTR_HELP
);
2259 printf( " --version %s\n", USAGE_OPTSTR_VERSION
);
2260 printf(USAGE_MAN_TAIL("agetty(8)"));
2265 static void list_speeds(void)
2267 const struct Speedtab
*sp
;
2269 for (sp
= speedtab
; sp
->speed
; sp
++)
2270 printf("%10ld\n", sp
->speed
);
2274 * Helper function reports errors to console or syslog.
2275 * Will be used by log_err() and log_warn() therefore
2276 * it takes a format as well as va_list.
2278 #define str2cpy(b,s1,s2) strcat(strcpy(b,s1),s2)
2280 static void dolog(int priority
, const char *fmt
, va_list ap
)
2289 * If the diagnostic is reported via syslog(3), the process name is
2290 * automatically prepended to the message. If we write directly to
2291 * /dev/console, we must prepend the process name ourselves.
2297 str2cpy(buf
, program_invocation_short_name
, ": ");
2298 bp
= buf
+ strlen(buf
);
2299 #endif /* USE_SYSLOG */
2300 vsnprintf(bp
, sizeof(buf
)-strlen(buf
), fmt
, ap
);
2303 * Write the diagnostic directly to /dev/console if we do not use the
2304 * syslog(3) facility.
2307 openlog(program_invocation_short_name
, LOG_PID
, LOG_AUTHPRIV
);
2308 syslog(priority
, "%s", buf
);
2311 /* Terminate with CR-LF since the console mode is unknown. */
2313 if ((fd
= open("/dev/console", 1)) >= 0) {
2314 write_all(fd
, buf
, strlen(buf
));
2317 #endif /* USE_SYSLOG */
2320 static void log_err(const char *fmt
, ...)
2325 dolog(LOG_ERR
, fmt
, ap
);
2328 /* Be kind to init(8). */
2333 static void log_warn(const char *fmt
, ...)
2338 dolog(LOG_WARNING
, fmt
, ap
);
2342 static void print_addr(sa_family_t family
, void *addr
)
2344 char buff
[INET6_ADDRSTRLEN
+ 1];
2346 inet_ntop(family
, addr
, buff
, sizeof(buff
));
2351 * Prints IP for the specified interface (@iface), if the interface is not
2352 * specified then prints the "best" one (UP, RUNNING, non-LOOPBACK). If not
2353 * found the "best" interface then prints at least host IP.
2355 static void output_iface_ip(struct ifaddrs
*addrs
,
2360 struct addrinfo hints
, *info
= NULL
;
2367 for (p
= addrs
; p
; p
= p
->ifa_next
) {
2371 p
->ifa_addr
->sa_family
!= family
)
2375 /* Filter out by interface name */
2376 if (strcmp(p
->ifa_name
, iface
) != 0)
2379 /* Select the "best" interface */
2380 if ((p
->ifa_flags
& IFF_LOOPBACK
) ||
2381 !(p
->ifa_flags
& IFF_UP
) ||
2382 !(p
->ifa_flags
& IFF_RUNNING
))
2387 switch (p
->ifa_addr
->sa_family
) {
2389 addr
= &((struct sockaddr_in
*) p
->ifa_addr
)->sin_addr
;
2392 addr
= &((struct sockaddr_in6
*) p
->ifa_addr
)->sin6_addr
;
2397 print_addr(family
, addr
);
2405 /* Hmm.. not found the best interface, print host IP at least */
2406 memset(&hints
, 0, sizeof(hints
));
2407 hints
.ai_family
= family
;
2408 if (family
== AF_INET6
)
2409 hints
.ai_flags
= AI_V4MAPPED
;
2411 host
= xgethostname();
2412 if (host
&& getaddrinfo(host
, NULL
, &hints
, &info
) == 0 && info
) {
2413 switch (info
->ai_family
) {
2415 addr
= &((struct sockaddr_in
*) info
->ai_addr
)->sin_addr
;
2418 addr
= &((struct sockaddr_in6
*) info
->ai_addr
)->sin6_addr
;
2422 print_addr(family
, addr
);
2430 * parses \x{argument}, if not argument specified then returns NULL, the @fd
2431 * has to point to one char after the sequence (it means '{').
2433 static char *get_escape_argument(FILE *fd
, char *buf
, size_t bufsz
)
2438 if (c
== EOF
|| (unsigned char) c
!= '{') {
2447 if ((unsigned char) c
!= '}' && i
< bufsz
- 1)
2448 buf
[i
++] = (unsigned char) c
;
2450 } while ((unsigned char) c
!= '}');
2456 static void output_special_char(unsigned char c
, struct options
*op
,
2457 struct termios
*tp
, FILE *fp
)
2464 char escname
[UL_COLORNAME_MAXSZ
];
2466 if (get_escape_argument(fp
, escname
, sizeof(escname
))) {
2467 const char *esc
= color_sequence_from_colorname(escname
);
2471 fputs("\033", stdout
);
2476 printf("%s", uts
.sysname
);
2480 printf("%s", uts
.nodename
);
2484 printf("%s", uts
.release
);
2488 printf("%s", uts
.version
);
2492 printf("%s", uts
.machine
);
2496 char *dom
= xgetdomainname();
2498 fputs(dom
? dom
: "unknown_domain", stdout
);
2505 char *host
= xgethostname();
2506 struct addrinfo hints
, *info
= NULL
;
2508 memset(&hints
, 0, sizeof(hints
));
2509 hints
.ai_flags
= AI_CANONNAME
;
2511 if (host
&& getaddrinfo(host
, NULL
, &hints
, &info
) == 0 && info
) {
2514 if (info
->ai_canonname
&&
2515 (canon
= strchr(info
->ai_canonname
, '.')))
2518 fputs(dom
? dom
: "unknown_domain", stdout
);
2531 tm
= localtime(&now
);
2536 if (c
== 'd') /* ISO 8601 */
2537 printf("%s %s %d %d",
2538 nl_langinfo(ABDAY_1
+ tm
->tm_wday
),
2539 nl_langinfo(ABMON_1
+ tm
->tm_mon
),
2541 tm
->tm_year
< 70 ? tm
->tm_year
+ 2000 :
2542 tm
->tm_year
+ 1900);
2544 printf("%02d:%02d:%02d",
2545 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
2549 printf ("%s", op
->tty
);
2553 const speed_t speed
= cfgetispeed(tp
);
2556 for (i
= 0; speedtab
[i
].speed
; i
++) {
2557 if (speedtab
[i
].code
== speed
) {
2558 printf("%ld", speedtab
[i
].speed
);
2566 char *var
= NULL
, varname
[64];
2569 if (get_escape_argument(fp
, varname
, sizeof(varname
))) {
2570 var
= read_os_release(op
, varname
);
2572 if (strcmp(varname
, "ANSI_COLOR") == 0)
2573 printf("\033[%sm", var
);
2578 } else if ((var
= read_os_release(op
, "PRETTY_NAME"))) {
2581 /* \S and PRETTY_NAME not found */
2584 fputs(uts
.sysname
, stdout
);
2597 while ((ut
= getutxent()))
2598 if (ut
->ut_type
== USER_PROCESS
)
2602 printf(P_("%d user", "%d users", users
), users
);
2604 printf ("%d ", users
);
2610 sa_family_t family
= c
== '4' ? AF_INET
: AF_INET6
;
2611 struct ifaddrs
*addrs
= NULL
;
2614 #ifdef AGETTY_RELOAD
2618 if (getifaddrs(&addrs
))
2621 if (get_escape_argument(fp
, iface
, sizeof(iface
)))
2622 output_iface_ip(addrs
, iface
, family
);
2624 output_iface_ip(addrs
, NULL
, family
);
2635 static void init_special_char(char* arg
, struct options
*op
)
2640 op
->initstring
= malloc(strlen(arg
) + 1);
2641 if (!op
->initstring
)
2642 log_err(_("failed to allocate memory: %m"));
2645 * Copy optarg into op->initstring decoding \ddd octal
2651 /* The \\ is converted to \ */
2658 /* Handle \000 - \177. */
2660 for (i
= 1; i
<= 3; i
++) {
2661 if (*p
>= '0' && *p
<= '7') {
2678 * Appends @str to @dest and if @dest is not empty then use @sep as a
2679 * separator. The maximal final length of the @dest is @len.
2681 * Returns the final @dest length or -1 in case of error.
2683 static ssize_t
append(char *dest
, size_t len
, const char *sep
, const char *src
)
2685 size_t dsz
= 0, ssz
= 0, sz
;
2688 if (!dest
|| !len
|| !src
)
2697 if (dsz
+ ssz
+ sz
+ 1 > len
)
2702 memcpy(p
, sep
, ssz
);
2708 return dsz
+ ssz
+ sz
;
2712 * Do not allow the user to pass an option as a user name
2713 * To be more safe: Use `--' to make sure the rest is
2714 * interpreted as non-options by the program, if it supports it.
2716 static void check_username(const char* nm
)
2721 if (strlen(nm
) > 42)
2730 log_err(_("checkname failed: %m"));
2733 static void reload_agettys(void)
2735 #ifdef AGETTY_RELOAD
2736 int fd
= open(AGETTY_RELOAD_FILENAME
, O_CREAT
|O_CLOEXEC
|O_WRONLY
,
2739 err(EXIT_FAILURE
, _("cannot open %s"), AGETTY_RELOAD_FILENAME
);
2741 if (futimens(fd
, NULL
) < 0 || close(fd
) < 0)
2742 err(EXIT_FAILURE
, _("cannot touch file %s"),
2743 AGETTY_RELOAD_FILENAME
);
2746 errx(EXIT_FAILURE
, _("--reload is unsupported on your system"));