summaryrefslogtreecommitdiffstats
path: root/term-utils
Commit message (Collapse)AuthorAgeFilesLines
* write: don't use strftime()Karel Zak2016-07-141-6/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: try to find tty in get_terminal_name()Sami Kerola2016-07-041-13/+3Star
| | | | | | | | Try all standard terminal input/output file descriptors when finding tty name in get_germinal_name(). This should make all invocations of the function as robust as they can get. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: stop removing and adding /dev/ in front of tty stringSami Kerola2016-07-042-43/+39Star
| | | | | | | | | | | Add both path and tty name representations of tty's to control structure, that point to same string beginning from different depths. This way there is no need to removing and adding /dev/ in front of tty string all the time. Secondly this change makes it possible to use of get_terminal_name() from ttyutils.c. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: tell when effective gid and tty path group mismatchSami Kerola2016-07-041-2/+7
| | | | | | | | | | | | | | | | | | Most commonly this error happens when write(1) executable does not have correct group ownership and setgid bit. The earlier message was unclear what exactly was wrong. $ mesg is y $ write testuser write: you have write permission turned off Alternatively the 'getegid() == s.st_gid' could be considered unnecessary. Afterall if to write to destination tty is denied that does not go unnoticed at thet time when tty is opened. Reviewed-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: improve coding styleSami Kerola2016-07-041-36/+35Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: remove PUTC macroSami Kerola2016-07-041-10/+5Star
| | | | | | | | Function like macros make following the execution flow unnecessarily difficult, and deserves to be removed. Requested-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: make timestamp to be obviously just a clock timeSami Kerola2016-07-011-8/+9
| | | | | | | | | | By looking the code one will had hard time knowing that a slice of ctime() from characters 11 to 16 is HH:MM time format. Use of strftime("%H:%M") makes this a lot less mysterious. In same go make \007 hex printouts to be \a that is the same thing: alarm. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: remove unnecessary utmp variablesSami Kerola2016-07-011-17/+11Star
| | | | | | | | | | | glibc documentation tells getutent() calls are not thread safe, and recommends to copy the context of the structures when information is wished to be stored. This leads to excessive copying, that in this case is not relevant. write(1) is single threaded program and there is no reason to assume this would change in future. Reference: http://www.gnu.org/software/libc/manual/html_node/Manipulating-the-Database.html Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: improve function and variable namesSami Kerola2016-07-011-38/+35Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: add control structure to clarify what is going onSami Kerola2016-07-011-42/+54
| | | | | | This is done purely an improve readability of the source code. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: run atexit() checks at the end of executionSami Kerola2016-07-011-12/+17
| | | | | | | | | Earlier use of _exit() caused program to terminate abnormally from atexit() perspective and standard file descriptor close checks did not run resulting to blindness if writes were successful, or not. Easy fix is to avoid running _exit() altogether. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: use xstrncpy() from strutils.hSami Kerola2016-07-011-2/+2
| | | | | | | | Earlier if the tty path was exactly length of the maximum ut_line then last character of the path was overwrote by \0. This is in practise theoretical bug, as it is unheard that a tty device path could be 32 characters long. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: set atime value in term_chk() only when neededSami Kerola2016-07-011-4/+4
| | | | | | The search_utmp() is needs atime but main() does not, so remove the later. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: remove pointless fileno(3) callsSami Kerola2016-07-011-6/+6
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: get rid of function prototypesSami Kerola2016-07-011-141/+132Star
| | | | | | | Marking functions static and writing them in order where functions are introduced before use is enough. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: remove unused variableSami Kerola2016-07-011-4/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: don't modify argv[] when parse speedsKarel Zak2016-06-301-2/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-314-8/+8
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* build-sys: add --disable-plymouth-supportKarel Zak2016-05-261-2/+5
| | | | | | | | The plymouth support depends on Linux specific SOCK_* flags and all the feature is probably unnecessary in some cases (non-plymouth distros, etc.) Signed-off-by: Karel Zak <kzak@redhat.com>
* sulogin: agetty: use the plymouth local protocol instead the plymouth binaryWerner Fink2016-05-201-42/+6Star
| | | | | | | | | | | | | for stopping plymouthd. That do not depend on the existence of the plymouth binary if it e.g. becomes uninstalled or an other service is providing plymouthd facilities. [kzak@redhat.com: - fix compiler warnings [-Wpointer-sign] - use sizeof() for write_all() - cast to char* for read_all] Signed-off-by: Werner Fink <werner@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* script: improve coding style and the "done" messageKarel Zak2016-05-181-7/+5Star
| | | | | | Don't print the "done" message if the file does not exist. Signed-off-by: Karel Zak <kzak@redhat.com>
* setterm: remove unnecessary translation stringSami Kerola2016-05-091-8/+8
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* setterm: de-duplicate color option string parsingKarel Zak2016-05-091-44/+36Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* write: fix setuid related regressionWayne Pollock2016-05-071-7/+7
| | | | | | | | | | | | | | | | | | The write(1) is commonly a setuid binary, because common users cannot by default write to each others terminals. Since the commit in reference, that is part of releases v2.24 to v2.28, the write(1) has used access(2) to check capability to write to a destination terminal. The catch is that access(2) uses real UID and GID to when performing the accessibility. The obvious correction is to avoid access(2) when in context of setuid binaries. As a smaller fix, but equally important fix, ensure the 'msgsok' variable is initialized to indicate no access. Uninitialized variable will almost certainly do wrong thing at the time of check. Breaking-commit: 0233a8ea18bec17dd59cfe1fec8281 Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Wayne Pollock <profwaynepollock@gmail.com>
* scriptreplay: avoid re-implementing strtod_or_err()Sami Kerola2016-05-052-13/+5Star
| | | | | | And use isnan() to detect NaN. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* scriptreplay: improve error messageSami Kerola2016-05-051-2/+2
| | | | | | | Use human numbering for lines - that is start counting from 1. And tell in error message what the number means. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: check status of writes when closing outputsSami Kerola2016-04-171-2/+4
| | | | | | | This should make possible output issues more obvious, for example when a disk will get full. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: avoid trying fclose(NULL)Sami Kerola2016-04-171-1/+2
| | | | | | | | | | | | | Here is a one-liner to reproduce the issue. $ mkdir example && cd example && chmod 0500 . && script Script started, file is typescript script: cannot open typescript: Permission denied Script done, file is typescript Segmentation fault (core dumped) Addresses: https://bugs.launchpad.net/bugs/1537518 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: close file descriptors on execSami Kerola2016-04-171-6/+7
| | | | | | | | | The commands spawned from script(1) will never need access various file descriptors the script(1) is using. Reviewed-by: Ruediger Meier <sweet_f_a@gmx.de> Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: use empty-slave heuristic more carefullyKarel Zak2016-04-131-24/+28
| | | | | | | | | | | | | | | | | | | | | | | | | script(1) waits for empty slave FD (shell stdin) before it writes to master. This feature has been intorduiced by 54c6611d6f7b73609a5331f4d0bcf63c4af6429e to avoid misbehavior when we need to send EOF to the shell. Unfortunately, this feature has been used all time for all messages. This is wrong because command in the session (or shell) may ignore stdin at all and wait forever in busy loop is really bad idea. Test case: script /dev/null tailf /etc/passwd <enter> <enter> ... script process taking 100% CPU. This patch forces script to use empty-stave detection only when we need to write EOF. The busy loop has been modified to use nanosleep and it does not wait forever... Addresses: http://bugs.debian.org/820843 Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: remove atoi() from argv[] parsing [clang analyze]Karel Zak2016-03-291-7/+6Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: tweak spacing and wording, and restore filling in the man pageBenno Schulenberg2016-03-171-7/+9
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* agetty: tweak formatting and some wordings in the man pageBenno Schulenberg2016-03-081-52/+53
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* misc: never cast void* from malloc(3) and friendsRuediger Meier2016-03-071-1/+1
| | | | | | | | | | Such cast could hide serious compiler warnings in case we are missing includes (e.g. <stdlib.h> or "xalloc.h"). See http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: safer (and uniform) handling of return valueYuriy M. Kaminskiy2016-03-073-8/+8
| | | | | | When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: support \e{name} for issue fileKarel Zak2016-02-172-3/+18
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'compiler-warnings' of https://github.com/rudimeier/util-linuxKarel Zak2016-02-121-1/+2
|\ | | | | | | | | | | | | | | | | | | | | * 'compiler-warnings' of https://github.com/rudimeier/util-linux: exec_shell: prevent basename from modifying env lib/path: ifdef path_set_prefix() like in path.h lib: fix unused parameters and variables misc: fix some printf format strings include: add missing includes ipcs: ulong -> unsigned long libcommon: don't include sysinfo.h
| * misc: fix some printf format stringsRuediger Meier2016-02-111-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the warnings below for OSX clang and add a few more casts for timeval: lib/at.c:131:27: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'off_t' (aka 'long long') [-Wformat] printf("%16jd bytes ", st.st_size); ~~~~~ ^~~~~~~~~~ lib/strutils.c:522:52: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix); ~~~ ^~~~ lib/sysfs.c:468:42: warning: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] len = snprintf(buf, sizeof(buf), "%ju", num); ~~~ ^~~ libuuid/src/gen_uuid.c:316:34: warning: format specifies type 'unsigned long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Wformat] clock_seq, last.tv_sec, last.tv_usec, adjustment); ^~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* | agetty: add support for \e in issue file to print \033Karel Zak2016-02-112-0/+6
|/ | | | | Suggested-by: Victor Ananjevsky <ananasik@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* script: fix misspellingRuediger Meier2016-02-031-3/+3
|
* docs: fix typos found by codespellRuediger Meier2016-02-031-1/+1
| | | | | | Using "codespell" from https://github.com/lucasdemarchi/codespell Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* scriptreplay/newgrp: use signed int to store return of getopt_longFilipe Brandenburger2016-01-071-1/+1
| | | | Signed-off-by: Filipe Brandenburger <filbranden@google.com>
* Merge branch 'races' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak2015-12-021-8/+14
|\
| * mesg: fix multiple racesSami Kerola2015-11-221-8/+14
| | | | | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | agetty: don't ignore netlink on select()Karel Zak2015-11-241-3/+9
|/ | | | | | | | | | agetty uses NETLINK_ROUTE to be notified about network interface changes. Unfortunately, the code that monitor the netlink FD does not increment number of the monitored file descriptors when call select(2), so the netlink notifications are invisible for agetty. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1278906 Signed-off-by: Karel Zak <kzak@redhat.com>
* script, hwclock: check file exist with access(3) rather than stat(3)Sami Kerola2015-11-091-2/+1Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* agetty: fix chown(3), chmod(3) and open(3) raceSami Kerola2015-11-091-5/+5
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: be pedantic and use "%"SCNi64Karel Zak2015-10-161-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: don't assume that time_t is compatible with longIsaac Dunham2015-10-161-4/+6
| | | | | | | | | | time_t may change to 64-bit on 32-bit Linux kernels at some point; at that point, it may be desireable to test for issues with dates past 2038. [kzak@redhat.com: - use %jd rather than %lld] Signed-off-by: Karel Zak <kzak@redhat.com>
* setterm: remove dead code [coverity scan]Karel Zak2015-08-051-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>