Commit Graph

19 Commits

Author SHA1 Message Date
Sami Kerola 8df3f8ef84 lib/pager: fix improper use of negative value [coverity scan]
The close(2) cannot accept a negative number.

CID: 360777
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:30:08 +02:00
Karel Zak 3b6ca044da lib/pager: fix compiler warning [-Wrestrict]
lib/pager.c: In function ‘pager_preexec’:
lib/pager.c:148:12: warning: passing argument 2 to restrict-qualified parameter aliases with argument 4 [-Wrestrict]

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-18 09:41:46 +02:00
Karel Zak 0f6adf8673 lib/exec_shell: (and pager) use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:38:24 +01:00
Karel Zak 1458c5c750 lib/pager: check open() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-11 14:42:49 +02:00
Karel Zak 99791a1984 lib/pager: use xalloc
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-02 12:07:36 +02:00
Karel Zak 535a4090b4 lib/pager: don't use pager if command not available
for example:
 # PAGER=foo dmesg -H
 sh: foo: command not found

the same problem is we have with fdisk 'l' command:

 # PAGER=foo fdisk /dev/sda
 Welcome to fdisk (util-linux 2.30-rc2-33-41b71).
 ...
 Command (m for help): l
 sh: foo: command not found

It seems better to don't use pager at all if not available.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-01 14:20:20 +02:00
Karel Zak e8f7acb0d3 lib: use unique ifdefs for tests
Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more
robust.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-04 11:44:37 +01:00
Karel Zak e132ae59ca lib/pager: fix test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 17:47:01 +02:00
Karel Zak a9fcbf6f6a lib/pager: restore signals setting by pager_close()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 13:02:37 +02:00
Karel Zak e215d467ca lib/pager: cleanup and extend API
* clean up function names

* add functions to temporary redirect to the pager and then restore
  original terminal output

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 12:07:25 +02:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Ruediger Meier 948d1f3114 include: add missing includes
lib/pager.c: signal.h ... raise(3p)
lib/sysfs.c: libgen.h ... basename(3p)
lib/exec_shell.c: libgen.h ... basename(3p)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-11 12:31:04 +01:00
Sami Kerola dc64469f4f lib/pager: use names when referring to standard file descriptors
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-06 10:18:37 +02:00
Sami Kerola d722ce211a lib: remove unused code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-06-07 12:24:40 +02:00
Karel Zak 9d48340d44 lib/pager: robust work with file descriptors [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 13:29:55 +02:00
Sami Kerola 3b1d28792d lib/pager: minor compiler warning fixes
Add missing function prototype, and declare structure before use of it.

lib/pager.c:162:6: warning: no previous prototype for function 'setup_pager' [-Wmissing-prototypes]
lib/pager.c:20:29: warning: tentative definition of variable with internal linkage has incomplete non-array type 'struct child_process' [-Wtentative-definition-incomplete-type]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:21 +02:00
Sami Kerola 838c5f6bb8 build: fix unused parameter warnings
pager.c:203:14: warning: unused parameter 'argc' [-Wunused-parameter]
pager.c:203:26: warning: unused parameter 'argv' [-Wunused-parameter]

randutils.c:108:14: warning: unused parameter 'argc' [-Wunused-parameter]
randutils.c:108:26: warning: unused parameter 'argv' [-Wunused-parameter]

optstr.c:774:37: warning: unused parameter 'optstr' [-Wunused-parameter]
optstr.c:774:51: warning: unused parameter 'value' [-Wunused-parameter]
optstr.c:774:65: warning: unused parameter 'valsz' [-Wunused-parameter]
optstr.c:774:79: warning: unused parameter 'next' [-Wunused-parameter]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:51:35 +02:00
Karel Zak 505abd8434 lib/pager: fix compiler warnings
pager.c: In function ‘start_command’:
pager.c:82:7: warning: unused variable ‘err’ [-Wunused-variable]
pager.c:49:25: warning: unused variable ‘fderr’ [-Wunused-variable]
pager.c:49:15: warning: unused variable ‘fdout’ [-Wunused-variable]
pager.c:48:25: warning: unused variable ‘need_err’ [-Wunused-variable]
pager.c:48:15: warning: unused variable ‘need_out’ [-Wunused-variable]

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23 11:57:50 +02:00
Davidlohr Bueso 35717a57ac lib: add pager functionality
When some program' output exceeds the terminal's dimensions, it is a nice
feature to call a pager that acts as calling 'less' to allow better user
navigation. This patch adds this functionality, based on what perf and git
have (ie: git log).

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 11:52:39 +02:00