summaryrefslogtreecommitdiffstats
path: root/term-utils/script.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-5/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: be sensitive to another SIGCHLD ssi_codesKarel Zak2018-09-051-2/+8
| | | | | | | | | The current signalfd handler cares on CLD_EXITED only. It's pretty insufficient as there is more situations (and codes) when child no more running. Addresses: https://github.com/karelzak/util-linux/issues/686 Signed-off-by: Karel Zak <kzak@redhat.com>
* script: fix printf format specifiersRuediger Meier2018-05-161-2/+2
| | | | | | Noticed on 32bit builds. Types changed in 0da73643. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* iscript: s/COLS/COLUMNS/ in start messageKarel Zak2018-05-141-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: record exit codeKarel Zak2018-05-141-17/+36
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: add more info to script headerKarel Zak2018-05-141-5/+33
| | | | | | | | | | | | | | | | This patch introduces [...] to store extra information about terminal to the typescript header. For example: Script started on 2018-05-14 12:52:32+02:00 [TERM="xterm-256color" TTY="/dev/pts/3" COLS="190" LINES="53"] or Script started on 2018-05-14 12:54:01+02:00 [<not executed on terminal>] if stdout is not terminal. Addresses: https://github.com/karelzak/util-linux/issues/583 Signed-off-by: Karel Zak <kzak@redhat.com>
* script: cleanup done timestamp messageKarel Zak2018-05-141-6/+9
| | | | | | | * always save "done" timestamp to typescript (use done() for this) * use FORMAT_TIMESTAMP_MAX as buffer size Signed-off-by: Karel Zak <kzak@redhat.com>
* script: use uint64_t for file sizesKarel Zak2018-05-141-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: add the -o/--output-limit option. Fix race test.Fred Mora2018-05-141-6/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | When script is used on a host with a relatively small free disk space, it is sometimes desirable to limit the size of the captured output. This can now be enforced with the --output-limit option. The --output-limit option lets the user specify a maximum size. The program uses the size parsing from strutils and thus supports the usual multiplicative suffixes (kiB, KB, MiB, MB, etc.). After the specified number of bytes have been written to the output file, the script program will terminate the child process. Due to buffering, the size of the output file might exceed the specified limit. This limit also does not include the start and done messages. The race test was throwing an error dur to a variable being "" in some cases. Quoting the variable in the equal test took care of that test. [kzak@redhat.com: - use done() to stop script - count also timing file - remove unnamed member initialization in ctl struct - add to bash-completion] Signed-off-by: Fred Mora <fmora@datto.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-1/+1
| | | | | | | Let's make it possible to use debug.h without environment variables. Suggested-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: add common ISO timestamp masksJ William Piggott2017-11-101-6/+2Star
| | | | | | | | | | | | | | | | | | | | | | * 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>
* script: simplify stdin usage in poll()Karel Zak2017-09-181-7/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: support sig{stop/cont}Karel Zak2017-09-081-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* script: fix ambiguity about the optional argument of the -t optionAntonio Ospite2017-07-181-8/+8
| | | | | | | | [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>
* 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: 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>
* Merge branch 'usage-part2' of https://github.com/rudimeier/util-linuxKarel Zak2017-06-261-3/+4
|\ | | | | | | | | | | | | | | | | | | | | * '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
| * misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | script: rename fixtty() to enable_rawmode_tty()Karel Zak2017-06-261-13/+14
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | script: ensure typescript and timing errors do not break terminalSami Kerola2017-06-261-7/+22
|/ | | | | | | | | | | | | | | | | | 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>
* script: always write stat and done message to typescript fileKarel Zak2017-04-181-4/+5
| | | | | | And remove usec from timestamp. Signed-off-by: Karel Zak <kzak@redhat.com>
* fix the position of newline in the time output of 'script'Rui Zhao (renyuneyun)2017-04-141-4/+9
| | | | | | | - move '\n' to fprintf - use `timeutils/strtime_iso()` instead of `strtime()` Signed-off-by: Rui Zhao (renyuneyun) <renyuneyun@gmail.com>
* script: don't call strftime() if not necessaryKarel Zak2017-04-131-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: fix start message showing in output file when -q is onRui Zhao (renyuneyun)2017-04-051-1/+2
| | | | Signed-off-by: Rui Zhao (renyuneyun) <renyuneyun@gmail.com>
* misc: add static keyword to where needed [smatch scan]Sami Kerola2017-02-201-1/+1
| | | | | | | text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be static? Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* term-utils/script: fix typo leading to syntax errorBert van Hall2017-01-181-1/+1
| | | | | | Introduced in edc7e42, this typo is actually invalid C. Fix this. Signed-off-by: Bert van Hall <bert.vanhall@avionic-design.de>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* script: improve SIG{TERM,QUIT,KILL} sensitivityKarel Zak2015-07-281-3/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: evaluate errno only if read() sets itRuediger Meier2015-07-031-7/+6Star
| | | | | | | | | [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>
* script: make sure errno is zeroKarel Zak2015-07-021-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: fix variable initialization warningSami Kerola2015-06-291-3/+3
| | | | | | | term-utils/script.c:402:19: warning: obsolete use of designated initializer without '=' [-Wpedantic] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: fix EOF problemsKarel Zak2015-06-171-26/+88
| | | | | | | | | | | | | | | | | * 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>
* script: improve poll debuggingKarel Zak2015-06-171-5/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: cleanup signals usageKarel Zak2015-06-171-11/+28
| | | | | | | | | * 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>
* script: debug poll() resultsKarel Zak2015-06-161-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: add support for SCRIPT_DEBUG=Karel Zak2015-06-161-2/+65
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: remove magic constants from poll codeKarel Zak2015-06-161-21/+33
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: rename control struct membersKarel Zak2015-06-161-32/+32
| | | | | | | 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>
* script: close timingfp also when -eKarel Zak2015-06-161-11/+10Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>