summaryrefslogtreecommitdiffstats
path: root/term-utils/script.c
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* script: move timing file opening close to use of itSami Kerola2015-06-081-14/+17
| | | | | | | | 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>
* script: add noreturn function attributesSami Kerola2015-06-081-2/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: use gettime_monotonic() to get timing file timestampsSami Kerola2015-06-081-12/+12
| | | | | | | | 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>
* script: use correct input type, move comment, and so onSami Kerola2015-06-081-13/+11Star
| | | | | | Minor corrections. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: replace strftime() workaround with CFLAGS = -Wno-format-y2kSami Kerola2015-06-081-12/+3Star
| | | | | | | | 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>
* script: move do_io() content to small functionsSami Kerola2015-06-081-50/+58
| | | | | | The do_io() got to be a bit long with relatively deep indentation. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: add 'Script started' line always to capture fileSami Kerola2015-06-081-5/+3Star
| | | | | | | | | | | | | | 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>
* script: remove io vs signal raceSami Kerola2015-06-081-7/+13
| | | | | | | | | | | | 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>
* script: merge doinput() and output() functions to do_io()Sami Kerola2015-06-081-172/+59Star
| | | | | | | | | | 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>
* script: use poll() rather than select()Sami Kerola2015-06-061-88/+114
| | | | | | | | | 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>
* script: use signalfd() to catch signalsSami Kerola2015-06-061-33/+14Star
| | | | | | | | | | 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>
* script: add struct script_control and remove global variablesSami Kerola2015-06-061-244/+249
| | | | | | Fix also couple indentation issues. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* script: remove function prototypesSami Kerola2015-06-061-256/+243Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* tests: check script options work as expectedSami Kerola2015-06-061-2/+19
| | | | | | | 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>
* script: Fix mangled EOF and hang on big endianStanislav Brabec2015-05-151-2/+2
| | | | | | | | | | | 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>
* Fix "Script started" buffering raceStanislav Brabec2015-02-101-0/+1
| | | | | | | | | | | | | | | script -c "echo Hallo World" </dev/null >script.log ; cat script.log Before: Hallo World Script started, file is typescript Script started, file is typescript Script done, file is typescript After: Script started, file is typescript Hallo World Script done, file is typescript
* 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>
* script: may be hangsAndreas Henriksson2014-10-141-4/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: use usage() text element macrosSami Kerola2014-10-011-2/+2
| | | | | | | 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-2/+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>
* script: clean up code to genenrate Star/Done messagesKarel Zak2014-06-231-9/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* script: silence the done message on --quiet as wellAndreas Henriksson2014-06-231-1/+2
| | | | | | | | | | Apparently James Hunts patch (which he provided a long time ago) is no longer covering it all. This followup patch also silences the "Script done ..." message when --quiet is used. Signed-off-by: Andreas Henriksson <andreas@fatal.se>
* script: --quiet option is not quiet.James Hunt2014-06-231-1/+2
| | | | | | | | | | | Specifying 'script --quiet ...' still produces the 'Script started' message in the typescript file. The --quiet option implies that the script program should not log any of its output to the typescript file. Originally reported at: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=693966 Signed-off-by: Andreas Henriksson <andreas@fatal.se>