summaryrefslogtreecommitdiffstats
path: root/term-utils/write.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | 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: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cleanup and fix --unknownopt issuesRuediger Meier2017-06-261-5/+5
| | | | | | | | | | | | | | | | 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>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* login-utils: switch to utmpx.hRuediger Meier2016-12-071-11/+11
| | | | | | | | 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>
* login-utils: avoid using the defined utmp sizes.Ruediger Meier2016-12-071-1/+1
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* 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-041-43/+38Star
| | | | | | | | | | | 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>
* misc: Fix various typosSebastian Rasmussen2016-05-311-1/+1
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.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>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+3
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: use usage() text element macrosSami Kerola2014-10-011-4/+4
| | | | | | | Translating these text elements should happen only once, which is more likely when the text macros are used properly. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: use manual tail usage() macroSami Kerola2014-10-011-0/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: use version printing macro everywhereSami Kerola2014-10-011-3/+1Star
| | | | | | | Only mount, umount, and blkid remains not using the macro because they are print also library references. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include/carefulputc: cleanup and add fputs_{quoted,nonblank}()Karel Zak2014-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* last, utmpdump, agetty, wall, write: avoid compatibility hacksSami Kerola2013-08-291-2/+2
| | | | | | | | In include/bits/utmp.h the ut_user and ut_time macros are marked with comment they are backwards compatibility hacks. It is probably best to avoid use of these macros where ever possible. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: change determination can user write to a terminalSami Kerola2013-08-291-4/+5
| | | | | | | | | | | | | Earlier test failed when user had write permission, but was not in special group that owns terminal devices, usually tty. This made write(1) to fail for root, if the root did not happen to be in tty group. In this commit root is granted ot write to anyone, even if they have mesg(1) turned off. For an user who is trying to write to own other session the group write bit is significant only for whether mesg(1) are enabled. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* include: carefulput: print determined char when unprintable char is foundSami Kerola2013-08-231-1/+1
| | | | | | This is done to allow reuse of the functin in last(1). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: spell and encode the name of Arkadiusz Miƛkiewicz correctlyBenno Schulenberg2013-02-061-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* write: stop using MAXHOSTNAMELENKarel Zak2012-10-191-3/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* write: Don't explicitly include <asm/param.h>.Thomas Schwinge2012-05-291-1/+0Star
| | | | | | | It doesn't exist on some systems, but will come in via <sys/param.h> on the others. Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
* write: Use PATH_MAX instead of MAXPATHLEN, as elsewhere.Thomas Schwinge2012-05-291-3/+3
| | | | Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
* term-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+3
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: fix path for freopen()Karel Zak2011-09-061-1/+1
| | | | | Reported-by: xinglp <xinglp@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* write: cleanup usage()Karel Zak2011-08-161-6/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* write: remove inconsistent periods from two error messagesBenno Schulenberg2011-08-151-2/+2
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* write: maintenance fixesSami Kerola2011-06-251-103/+90Star
| | | | | | | Use libc error printing facilities, remove void casting, clean up unused headers and alignt coding style with README.devel. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* write: long options & new usageSami Kerola2011-06-251-3/+34
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* build-sys: move write to term-utils directorySami Kerola2011-06-251-0/+359
Signed-off-by: Sami Kerola <kerolasa@iki.fi>