summaryrefslogtreecommitdiffstats
path: root/term-utils/agetty.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove isascii usageRosen Penev2019-08-081-1/+2
| | | | | | | There is a c_isascii function that can be used. isascii is deprecated and not available with some libcs like uClibc-ng where it can be compile time disabled.
* agetty: simplify code in dolog() preprocessor blocksSami Kerola2019-07-241-26/+20Star
| | | | | | | | Aim is to make dolog() a lot more readable and understandable, with downside of when (rarely?) USE_SYSLOG it not defined the function will use a bit more space from stack. I think that is price well worth paying. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: Remove superfluous fflush()Stanislav Brabec2019-06-211-2/+0Star
| | | | | | | | | | | | | | eval_issue_file() contains fflush(stdout). It comes from an old code that used fputs() to write to the console. In the new code, we write to a temporary memstream, and fclose(ie->output) fully replaces possible fflush(ie->output) in this implementation. The new print_issue_file() does not need it as well, as it uses unbuffered write_all(). Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* agetty: Switch to 8-bit processing in get_logname() for UTF-8 terminalsStanislav Brabec2019-03-041-1/+1
| | | | | | | | | If the terminal is in the UTF-8 mode, get_logname() should use 8-bit processing. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: Lubomir Rintel <lkundrak@v3.sk> Tested-by: Lubomir Rintel <lkundrak@v3.sk>
* agetty: Fix input of non-ASCII characters in get_logname()Stanislav Brabec2019-03-041-2/+0Star
| | | | | | | | | | | | | | | | | As login supports non-ASCII characters in the logname, agetty should be consistent. 8b58ffdd re-activated old and ASCII-only get_logname(), which restricted the input to ASCII only. As the code does not read whole characters, isascii(ascval) and isprint(ascval) returns nonsenses after entering a non-ASCII character. As keyboard maps don't contain unprintable non-control characters, it seems to be relatively safe to remove both checks. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: Lubomir Rintel <lkundrak@v3.sk> Tested-by: Lubomir Rintel <lkundrak@v3.sk>
* docs: fix typos [codespell]Sami Kerola2019-02-181-1/+1
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: Return old behavior with empty lognameStanislav Brabec2018-11-211-1/+1
| | | | | | | | c094fcd37 introduced a behavior change: When Return is entered with empty logname, nothing happens. As it confuses users, return back the old behavior: re-prompt. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* agetty: fix output of escaped charactersChristian Hesse2018-11-121-1/+1
| | | | Signed-off-by: Christian Hesse <mail@eworm.de>
* agetty: fix portability issuesSamuel Thibault2018-11-121-1/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: when logname is erased, re-enable reloadsStanislav Brabec2018-10-311-0/+3
| | | | | | | | | | | | | When user starts to enter logname, 8b58ffdd blocks issue reloads. Reloads remain blocked even if user deletes all typed characters. Make things visually consistent: If no characters are entered, re-enable reloads. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com> Reviewed-by: Lubomir Rintel <lkundrak@v3.sk> Tested-by: Lubomir Rintel <lkundrak@v3.sk>
* agetty: don't put the VC into canonical modeLubomir Rintel2018-10-221-8/+18
| | | | | | | | | | | | | | | | | The wait_for_term_input()'s select() needs to be tripped when the user starts typing. Otherwise the reloads can abort an already in-progress login. Coupled with \4 and \6 expansions that happen to be there on Fedora Server, this means reload on every netlink event. With a couple of IPv6 routers announcing their networks and temporary addresses in use can make it sometimes virtually impossible to log in. Seems like zero lflags do the job just fine on a Linux VT. Reset it to canonical mode before running login. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: don't use __u32Karel Zak2018-10-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: make output more robustKarel Zak2018-10-111-1/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: cleanup issue output change, remove boolKarel Zak2018-10-111-16/+14Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: move all issue variables to structKarel Zak2018-10-111-79/+101
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: Reload only if it is really neededStanislav Brabec2018-10-111-41/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If netlink event arrives and related escapes are part of issue, agetty reloads and re-display the prompt. Reload is triggered not only by IP address change, but also by IPv6 RAs. In some environments it causes reload several times in a minute, and even complicates the login. To prevent this, reload only if a real change appears. This consists of: split print_issue_file() to several functions: eval_issue_file() prints issue to memory. It does not affect terminal in any way. print_issue_file() prints issue file from memory. cmp_issue_file() compares the issue file and returns true, if reload is needed. The implementation requires additional change: do_prompt() does not evaluate the issue file. It is responsibility of calling function. Test suite: Use issue that contais \4 and/or \6 escape. After installing new instance, restart agetty by typing a letter and then Enter 6 times. To check whether reload happens, type a letter. When reload happens, letter disappears. 1. Unplug network cable. Wait a while and re-plug network cable. You should see 2 reloads on single stack and 3 reloads on dual stack. 2. Run a loop while : ; do sed -i '$areload_test' /etc/issue agetty --reload sleep 3 sed -i '/reload_test/d' /etc/issue agetty --reload sleep 3 done You should see regular reload every 3 seconds. 3. Run a loop while : ; do agetty --reload sleep 3 done Before: You see regular reload every 3 seconds. After: No reloads. 4. Run a loop while : ; do ifconfig lo 127.0.0.1 netmask 255.0.0.0 sleep 3 ifconfig lo 127.0.0.2 netmask 255.0.0.0 sleep 3 done Before: You see regular reload every 3 seconds. After: No reloads. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* agetty: Watch only protocol requested by issue escapesStanislav Brabec2018-10-111-5/+14
| | | | | | | To decrease number of reloads, watch only protocol requested by \4 and \6 escapes in issue file. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* agetty: rename variable changed to triggeredStanislav Brabec2018-10-111-5/+5
| | | | | | | | changed variable name is not correct. It does not say that network interface changed its address. It just says that the netlink message processing was triggered. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* agetty: cleanup code to copy to log stringsKarel Zak2018-10-031-5/+5
| | | | | | | | man utmp: String fields are terminated by a null byte ('\0') if they are shorter than the size of the field. Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: keep c_iflags unmodified on --autologinKarel Zak2018-06-061-4/+13
| | | | | | | | | | | | | | | agetty sets c_iflags according to interaction with serial line in get_logname(). For --autologin it does not read from the line, so we have no clue how to set the flags. The current behavior is to zeroize the flags. Unfortunately, it seems like bad idea, because the line may be already properly initialized by kernel (or systemd, etc.). The new behavior is not touch the flags on --autologin. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1252764 Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: Fix a use of uninitialised memory in an agetty error path.Steven Smith2017-11-211-6/+19
| | | | | | | | | | | | | | get_logname() assumes that when it calls read() it initializes c and errno, which isn't always true if we hit a whitelisted error or end of file. This occasionally shows up as agetty going into an infinite loop. Fix it by just delaying ten seconds and exiting when things go wrong, similarly to the behavior after a non-whitelisted error. [kzak@redhat.com: - interpret readres == 0 as c = 0 - ignore speed configurations for VCONSOLE] Signed-off-by: Steven Smith <sos22@srcf.ucam.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: add support for /etc/issue.dKarel Zak2017-11-071-22/+148
| | | | | | | | | | | | | | | | | | | | | | | | | The /etc/issue file has been originally designed to inform users about the system (version, name, etc.). In last years is growing number of additional tools (containers, maintenance tools and interfaces, ...) and many admins and downstream maintainer want to add some tool specific hints to the issue file, but it mess to share one file between more packages and/or scripts. The solution is /etc/issue.d directory. The directory is extension to the standard system /etc/issue. The /etc/issue file has to exist, otherwise the directory will be ignored. It means "rm /etc/issue" (or --onissue) is still the way how keep our system silent independently on 3rd-party installed files in the /etc/issue.d directory. The content of the files in the directory are printed after content of the /etc/issue. The files are printed in version-sort order and .issue file extension is required (00-foo.issue 01-bar.issue ...). The change is backwardly compatible. Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: remove unused flagKarel Zak2017-11-061-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix /etc/os-release parsingKarel Zak2017-10-051-0/+6
| | | | | | | | | | | | | | | | For example /etc/os-release: VERSION="26 (Twenty Six)" VERSION_ID=26 agetty for \S{VERSION} returns _ID=26 because the parser does nor check for '=' after variable name. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1498462 Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: keep returns in main()Karel Zak2017-08-071-3/+3
| | | | | | | Don't use list_speeds() as non-return function, it seems better to keep main() code consistent. Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix invalid usage crashSami Kerola2017-08-051-2/+2
| | | | | | | | | $ agetty agetty: not enough arguments: Success Segmentation fault (core dumped) Reference: 9325dbfd2018b2a3b510617f4aa13777fbbe23c3 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: add compile time features to --version outputSami Kerola2017-08-051-1/+45
| | | | | | | | | This command has a lot of compile time #ifdef code. It is time to add feature listing to --version output so understanding command behavior is easier. Proposed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: add --list-speeds optionSami Kerola2017-08-051-0/+15
| | | | | Proposed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: remove dead DO_DEVFS_FIDDLING code segmentSami Kerola2017-08-051-39/+0Star
| | | | | | | There is no ./configure option to enable this, and it is unlikely any distribution hot patching to enable fiddling when building package. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: fix --login-pause logicKarel Zak2017-07-311-2/+1Star
| | | | | | | Let's "eat" ENTER key when pressed after login pause prompt. Addresses: https://github.com/karelzak/util-linux/issues/491 Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: print /etc/issue on --skip-loginKarel Zak2017-07-101-1/+4
| | | | | | | | | | | | The current --skip-login implementation disables also issue file printing. This is unexpected behavior as /etc/issue may contains important information and we have --noissue for admins who don't want it. This patch forces /etc/issue printing if --noissue no specified. Addresses: https://github.com/karelzak/util-linux/issues/480 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-1/+1
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: consolidate all --help option descriptionsRuediger Meier2017-06-271-2/+2
| | | | | | | | Now we are always using the same text also for commands which had still hardcoded descriptions or where we can't use the standard print_usage_help_options macro. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cleanup and fix --unknownopt issuesRuediger Meier2017-06-261-7/+9
| | | | | | | | | | | | | | | | Fixed checkusage.sh warnings: rtcwake: --unknownopt, non-empty stdout rtcwake: --unknownopt, stderr too long: 21 blockdev: --unknownopt, stderr too long: 28 lsipc: --unknownopt, stderr too long: 77 pg: --unknownopt, stderr too long: 23 renice: --unknownopt, stderr too long: 18 sulogin: --unknownopt, stderr too long: 17 write: --unknownopt, stderr too long: 12 Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* agetty: fix login name DEL/CTRL^U issueKarel Zak2017-06-231-55/+15Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | agetty refresh prompt (/etc/issue file etc.) when requested by inotify or netlink. For this purpose we monitor some file descriptors by select(). The terminal input file descriptor is switched to non-canonical mode before select(). The goal is to be informed about user activity before new-line. The FD is immediately switched back to canonical mode when activity is detected. The side effect is that all not-read-yet chars in the input buffer are lost ... so we need to call read() before switch to canonical mode to save the chars. The original implementation has been based on TIOCSTI ioctl. It returns already read chars back to the terminal input buffer to make them useful for canonical mode. The problem was race (agetty writes to input buffer in the same time as user) and result was reordered chars in login name... so useless. This issue has been later fixed by extra buffer (commit 790119b8850ae13bb4254c5096a54b2aeb355b20) for already read data. And TIOCSTI ioctl has been removed. Unfortunately this solution is also wrong, because the buffer is maintained only by agetty and inaccessible for terminal when user edit (by DEL/CTRL^U) login name in canonical mode. The solution is simple -- just don't try to be smart and keep terminal in canonical mode all time (so terminal controls DEL, CTRL^U, etc) and flush input buffer (=discard unread data) and ask user for login name again after prompt reload. The agetty reload is very rarely situation and for user it's pretty obvious that he has to type login name again (as all terminal has been clear+redraw). Addresses: https://github.com/karelzak/util-linux/issues/454 Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1464148 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix ggc-7 fallthrough warningsSami Kerola2017-06-141-2/+2
| | | | | | | | | | | | | | | | | | | (Original patch and commit message edited by Rudi.) gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra. This warning can be silenced by using comment /* fallthrough */ which is also recognized by other tools like coverity. There are also other valid comments (see man gcc-7) but we consolidate this style now. We could have also used __attribute__((fallthrough)) but the comment looks nice and does not need to be ifdef'ed for compatibility. Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652 Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/ Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl> Suggested-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: make --remote to forward --nohostname as -H to loginSami Kerola2017-04-031-3/+6
| | | | | | | | | | | | Without this change an attempt to remove hostname printing required following rather clumsy agetty invocation. /sbin/agetty --nohostname --login-options '/bin/login -H -- \u' After the change --nohostname behaves similar way with --host option, that is when combined with --remote the effect is passed to login(1). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: remove variable that is set but not readSami Kerola2017-04-011-7/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: fix typoKarel Zak2017-03-271-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix characters reorder in login promptKarel Zak2017-03-271-12/+34
| | | | | | | | | | | | | | The current agetty uses TIOCSTI ioctl to return already read chars from login name back to the terminal (without read() before tcsetattr() we will lost data already written by user). The ioctl based solution is fragile due to race -- we can return chars when terminal already contains another new chars. The result is reordered chars in login name. The solution is to use extra buffer for already read data. Reported-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix a memory leak when parsing \S in issue filesMatthias Gerstner2017-02-271-0/+3
|
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-35/+35
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* agetty: fix ifdef typoRuediger Meier2016-12-211-1/+1
| | | | | | introduced in 77835be2 Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* agetty: re-add utmp.h for Debian GNU/kFreeBSDRuediger Meier2016-12-071-1/+7
| | | | | | | It's needed there to get login_tty(). On normal FreeBSD we would need libutil.h. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* login-utils: switch to utmpx.hRuediger Meier2016-12-071-13/+13
| | | | | | | | Now the build will fail on many non-Linux systems because utmpx.h is available everywhere but we still use non-POSIX features. We'll fix this next commit. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* agetty: remove obsolete HAVE_UPDWTMP fallbackRuediger Meier2016-12-071-20/+1Star
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* login-utils: remove _HAVE_UT_TV fallbackRuediger Meier2016-12-071-4/+0Star
| | | | | | | | | | _HAVE_UT_TV is glibc only. Moreover we want to move to utmpx where timeval is standard. Now utmp/subsecond (1173d0a6) should work on all supported systems. CC: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: always check setenv(3) return valueSami Kerola2016-08-121-1/+3
| | | | | | At least glibc setenv(3) can fail when system runs out of memory. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: move unreachable code to pre-processor #else segment [oclint]Sami Kerola2016-07-211-2/+3
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>