Commit Graph

380 Commits

Author SHA1 Message Date
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
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>
2016-03-07 23:29:27 +01:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Karel Zak d689166b11 agetty: support \e{name} for issue file
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-17 12:53:20 +01:00
Karel Zak 173607a254 Merge branch 'compiler-warnings' of https://github.com/rudimeier/util-linux
* '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
2016-02-12 13:35:18 +01:00
Ruediger Meier 7231fb2a5b misc: fix some printf format strings
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>
2016-02-11 13:39:56 +01:00
Karel Zak 583627ef36 agetty: add support for \e in issue file to print \033
Suggested-by: Victor Ananjevsky <ananasik@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-11 12:33:57 +01:00
Ruediger Meier 23e35eca15 script: fix misspelling 2016-02-03 16:34:12 +01:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Filipe Brandenburger 94757eceb1 scriptreplay/newgrp: use signed int to store return of getopt_long
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-01-07 12:47:41 +01:00
Karel Zak 4ba2a6e515 Merge branch 'races' of git://github.com/kerolasa/lelux-utiliteetit 2015-12-02 10:27:43 +01:00
Karel Zak 5184d93630 agetty: don't ignore netlink on select()
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>
2015-11-24 17:44:38 +01:00
Sami Kerola 010d5a670b
mesg: fix multiple races
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:39 +00:00
Sami Kerola a4aeb5bd80 script, hwclock: check file exist with access(3) rather than stat(3)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-09 09:56:14 +01:00
Sami Kerola c3a9f86fcd agetty: fix chown(3), chmod(3) and open(3) race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-09 09:56:14 +01:00
Karel Zak c2f03da93d script: be pedantic and use "%"SCNi64
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-16 11:48:47 +02:00
Isaac Dunham 345208a5ab script: don't assume that time_t is compatible with long
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>
2015-10-16 11:31:22 +02:00
Karel Zak 2660801513 setterm: remove dead code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 11:51:04 +02:00
Karel Zak a359830c1a agetty: cleanup plymouth usage [coverity scan]
* use macros for paths
* check open() return value

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 11:48:01 +02:00
Karel Zak 5860c45eed script: improve SIG{TERM,QUIT,KILL} sensitivity
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-28 10:36:29 +02:00
Stef Walter e36deb6424 agetty: Reprompt once the network addresses change if address displayed
Several of the /etc/issue escape codes such as \4 and \6 depend on
the current addresses of the system that can change after the agetty
prompt is displayed.  This can cause stale data to be displayed
when a user looks at a VT, especially in cases of DHCP racing with
system start up.

Similar to the --reload mechanism, if we're displaying an address
in the issue output, and the user hasn't typed anything yet: then
redisplay the prompt with the new address.

We use netlink to watch for address changes. We only open the netlink
socket if we display an address in the issue file.
2015-07-20 11:17:23 +02:00
Ruediger Meier 7dbcd80ee8 script: evaluate errno only if read() sets it
[kzak@redhat.com: - be careful with errno and DBG
                  - add EINTR check
                  (both suggested by Rudi]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-03 09:53:05 +02:00
Karel Zak e831c87670 script: make sure errno is zero
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-02 10:30:10 +02:00
Sami Kerola 14867b0f72 reset: deprecate the script, and remove reset.033c
Most distributions probably ship reset from ncurses, which means
util-linux reset(1) is unlikely to be in use anywhere.  Assuming the
previous being true it is almost unimaginable anyone one would be using
the alternative script, so remove it and mark the script deprecated.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 12:06:22 +02:00
Sami Kerola 0664d41dba script: fix variable initialization warning
term-utils/script.c:402:19: warning: obsolete use of designated
initializer without '=' [-Wpedantic]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 12:05:25 +02:00
Karel Zak a3b69ccb1c build-sys: use REALTIME_LIBS for script
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-29 10:55:37 +02:00
Karel Zak 63ddc7ba1e script: add note to BUGS man page section
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-25 11:55:42 +02:00
Karel Zak 54c6611d6f script: fix EOF problems
* remove STDIN from poll() if:

  * STDIN already closed -- poll returns POLLHUP, for example:

		echo "date" | script

  * detect EOF as returned by read(), for example:

		script -c "echo Hello" < /dev/null

* don't write to master when there is still something to read from
  slave (it means shell is not initialized yet or busy)

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-17 15:48:50 +02:00
Karel Zak 2e9418b7cc script: improve poll debugging
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-17 13:33:35 +02:00
Karel Zak d35ffe808a script: cleanup signals usage
* don't call anything from assert()
 * fork() block cleanup to make it more readable
 * restore original signal mask in child (do_shell())
 * close signal FD in child (do_shell())

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-17 13:25:46 +02:00
Karel Zak 1200cfbfbd script: debug poll() results
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-16 14:44:05 +02:00
Karel Zak a2b4dec553 script: add support for SCRIPT_DEBUG=
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-16 14:03:09 +02:00
Karel Zak da26af4ee1 script: remove magic constants from poll code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-16 13:11:05 +02:00
Karel Zak 3f19b85f97 script: rename control struct members
Sorry, but it's really ugly manner to use "xflg" where "x" is a command
line option as program variable and use it in code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-16 12:34:04 +02:00
Karel Zak 7e5796c916 script: close timingfp also when -e
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-16 12:26:00 +02:00
Sami Kerola 9580536a7f script: move timing file opening close to use of it
This allows removing almost immediate closure of file handle in the
doshell() function that does not use the file.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:37 +01:00
Sami Kerola 2ddadb5eda script: add noreturn function attributes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:37 +01:00
Sami Kerola 04639805e1 script: use gettime_monotonic() to get timing file timestamps
This moves the previous time to script control structure, and does
timeval calculation with timersub() that is more appropriate than
making a timeval to a double.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:36 +01:00
Sami Kerola b09feab9e4 script: use correct input type, move comment, and so on
Minor corrections.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:36 +01:00
Sami Kerola 8353549e02 script: replace strftime() workaround with CFLAGS = -Wno-format-y2k
Nowadays, gcc(1) provides the -Wno-format-y2k option to prevent the
warning, so that the above workaround is no longer required.

Reference: http://man7.org/linux/man-pages/man3/strftime.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:36 +01:00
Sami Kerola a8896ad5b7 script: move do_io() content to small functions
The do_io() got to be a bit long with relatively deep indentation.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:53:34 +01:00
Sami Kerola 076ffa48f3 script: add 'Script started' line always to capture file
The scriptreplay(1) will expect capture file always to have header.
Before this change the --quiet option together with timing caused
following replay error.

$ script --quiet --timing=timing
[...]
$ scriptreplay timing typescript
[...]
scriptreplay: unexpected end of file on typescript

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:52:51 +01:00
Sami Kerola 89a859d433 script: remove io vs signal race
Make do_io() to run poll() until all streams are empty.  This should
remove the signal from child versus io handling race for good.

Addresses: https://github.com/karelzak/util-linux/pull/62
Addresses: https://bugs.launchpad.net/bugs/264967
Addresses: https://bugs.debian.org/305808
CC: Wolfgang Richter <wolf@cs.cmu.edu>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:52:51 +01:00
Sami Kerola 6ddf53a5b4 script: merge doinput() and output() functions to do_io()
One item to poll() more is a lot less work for system than separete input
and output processes.

Addresses: https://github.com/karelzak/util-linux/pull/62
CC: Wolfgang Richter <wolf@cs.cmu.edu>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-08 21:52:36 +01:00
Sami Kerola cf470183ea script: use poll() rather than select()
Finalize the signalfd() change by adding file descriptors to poll() loop.

Addresses: https://github.com/karelzak/util-linux/pull/62
CC: Wolfgang Richter <wolf@cs.cmu.edu>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-06 14:53:56 +01:00
Sami Kerola cc1a88fb59 script: use signalfd() to catch signals
This is incomplete change.  Working command requires the subsequent
select() to poll() change as well.

Addresses: https://github.com/karelzak/util-linux/pull/62
CC: Wolfgang Richter <wolf@cs.cmu.edu>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-06 14:53:55 +01:00
Sami Kerola edc7e42076 script: add struct script_control and remove global variables
Fix also couple indentation issues.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-06 14:53:50 +01:00
Sami Kerola 93af8d8bf3 script: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-06 14:36:46 +01:00
Sami Kerola 6a40c65f81 tests: check script options work as expected
Options --flush and --timing remain unchecked, as I do not have an idea
how to check them reliably.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-06 14:36:38 +01:00
Stanislav Brabec 8fdc064ac3 script: Fix mangled EOF and hang on big endian
On s390 and other big endian machines, doinput() sends NUL instead of
EOF to the tty master. NUL does not even reach the slave, and it is
waiting for more data forever.

If STDIN is not a tty, the bug caused "^@" being into the log, and since
commit 032228c it also causes hang.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-15 12:56:46 +02:00
Karel Zak 890e103559 wall: do not use a temporary file.
The issue with using a temporary file in wall is that wall runs as setgid.
This means that an unprivileged user who runs wall can modify wall's
temporary files, even if those are mode 0600, so the unprivileged user can
edit and effectively suppress the banner. The fix is to simply not use
temporary files.

[kzak@redhat.com: - rewrite growing string functions
                  - use struct buffer
                  - add buf_print() function]

Signed-off-by: Karel Zak <kzak@redhat.com>
Co-Author: Jann Horn <jann@thejh.net>
2015-04-03 11:44:24 +02:00