* Start the ISO format flags at bit 0 instead of bit 1.
* Remove unnecessary _8601 from ISO format flag names to
avoid line wrapping and to ease readability.
* ISO timestamps have date-time-timzone in common, so move
the TIMEZONE flag to bit 2 causing all timestamp masks
to have the first three bits set and the last four bits
as timestamp 'options'.
* Change the 'SPACE' flag to a 'T' flag, because it makes
the code and comments more concise.
* Add common ISO timestamp masks.
* Implement the ISO timestamp masks in all applicable code
using the strxxx_iso() functions.
Signed-off-by: J William Piggott <elseifthen@gmx.com>
* call wait() only when child exited
* suspend all session (including script master process) when child get
SIGSTOP and send SIGCONT to child when master process resume
This allows to suspend all session and later use "fg" shell command to
resume.
$ ps af
14722 pts/1 Ss 0:00 bash
4870 pts/1 S+ 0:00 \_ ./script
4871 pts/6 Ss+ 0:00 \_ bash -i
$ kill -SIGSTOP 4871
and script session on another terminal:
$ script
Script started, file is typescript
$
[1]+ Stopped ./script
$ fg 1
./script
... session again usable ...
^D
Script done, file is typescript
Signed-off-by: Karel Zak <kzak@redhat.com>
[kzak@redhat.com: - merge two patches from Antonio to the one,
- update the patch]
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Antonio Ospite <ao2@ao2.it>
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>
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>
* 'usage-part2' of https://github.com/rudimeier/util-linux:
misc: cosmetics, remove argument from usage(FILE*)
misc: cosmetics, remove argument from usage(int)
misc: never use usage(stderr)
misc: never use usage(ERROR)
misc: cleanup and fix --unknownopt issues
flock, getopt: write --help to stdout and return 0
tools: add checkusage.sh
Earlier when typescript file failed new line after the error did not cause
carriage return. Here is an example how prompt> travels to wrong place:
prompt> script 0500-perms/typescript
Script started, file is 0500-perms/typescript
script: cannot open 0500-perms/typescript: Permission denied
prompt>
But that wasn't quite as bad as what happen with timing file, that at
failure left terminal to state where a reset(1) run was needed.
[kzak@redhat.com: - move code to restore_tty()]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch is trivial and changes nothing, because
we were always using usage(stdout)
Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
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>
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(1) waits for empty slave FD (shell stdin) before it writes to
master. This feature has been intorduiced by 54c6611d6f
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>
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>
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>
[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>
* 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>
* 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>
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>
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>
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>
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>
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>
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>
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>