Commit Graph

577 Commits

Author SHA1 Message Date
Chris Hofstaedtler d0aa83147a hexdump: automatically use -C when called as hd
When invoking hexdump as hd enable the "Canonical" format to by
default, implying the -C option.

This is historic behaviour on Debian and apparently also on FreeBSD.
Some Debian users have asked for this to be restored, after Debian
switched to util-linux' hexdump and hd.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2020-07-23 12:23:56 +02:00
Michael Kerrisk (man-pages) 4f68c8b179 Manual pages: various: reword "allow(s) to"
The wording "allow(s) to" is not grammatical English. Reword various
pages to use a more correct form such "can be use to" or "allows
the [noun] of".

Aklong the way, fix a few nearby wording errors in some pages.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-07-14 14:08:54 +02:00
Sami Kerola d8bfcb4cc5
col: fix output when first line does not have newline character
Commit I made while back and has been part of util-linux v2.30 to v2.35 made
col(1) not to output anything when first line did not have newline character.

    printf "gone from output" | col

This commit fixes the issue.  Admittedly the col source code is unnecessarily
hard to work with.  It could be a good idea to refactor the col(1) as low
priority task, Assuming refactoring is done the first commit to get that done
should add tests that exhaust all possible input handling including all command
line option directives.

Addresses: https://github.com/karelzak/util-linux/issues/422
Fixes: b6b5272b03
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-06-20 22:17:30 +01:00
Bjarni Ingi Gislason 960a8d1b63 doc: text-utils/*: fix some warnings from "mandoc -T lint"
mandoc: ./text-utils/column.1:58:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:63:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:119:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:171:1: WARNING: skipping paragraph macro: sp after PP
mandoc: ./text-utils/column.1:170:2: WARNING: skipping paragraph macro: PP empty

mandoc: ./text-utils/hexdump.1:206:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/hexdump.1:356:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:359:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:362:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:366:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:369:2: STYLE: fill mode already disabled, skipping: nf

####

  There are no changes in the output from "nroff" and "groff", except
for a reformat of a paragraph caused by "fill-mode".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2020-06-15 11:28:01 +02:00
Michael Kerrisk (man-pages) 1538f6f636 Manual pages: wording fix: "another" ==> "other"
In several pages, there is a consistent wording problem: "another"
where "other" should be used. This wording problem can be
surprisingly confusing for native speakers, especially those
unaware that in some other languages, "another" and "other" can be
expressed with the same word.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-05-29 14:31:47 +02:00
Michael Kerrisk (man-pages) 3bc92f313a Manual pages: rename EXAMPLE section to EXAMPLES
Earlier, I patched various pages to consistently use EXAMPLE as a
section heading, rather than EXAMPLES.  (At that time, both headings
occurred in util-linux, with roughly equal frequency.)

Since then, I've observed that EXAMPLES is the more common usage
across a large corpus of manual pages. So, in Linux the man-pages
project, I switched to using EXAMPLES also. This patch makes the same
change for util-linux.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-05-28 14:51:54 +02:00
Sami Kerola 2eb527722a more: avoid libmagic telling an empty file is binary
My earlier change that took libmagic in use to identify mime-type of an input
file caused empty files to be marked binary.  Before the change empty files
were simply displayed as empty.  This change will restore that behavior.

Addresses: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-25 14:16:45 +02:00
Michael Kerrisk (man-pages) 67e63c1263 Manual pages: order NOTES / HISTORY / BUGS / EXAMPLE consistently
There is value in ensuring that manual page sections use consistently
named sections, as far as possible, and also that sections have a
consistent order within manual pages. This is one of a series of patches
to place manual page sections in a consistent order.

In this patch, we ensure that the NOTES, HISTORY, BUGS, and EXAMPLE
sections are always placed near the end of the page, just above
AUTHORS, COPYRIGHT, SEE ALSO, and AVAILABILITY.

One page is not fixed by this patch: term-utils/agetty.8. This page
is a mess of unusual section names, and probably requires an individual
edit.

Testing that no gross editing mistake (causing accidental loss or addition
of text) was performed as follows:

    $ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > a
    [Apply patch]
    $ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > b
    $ diff a b
    $ echo $?
    0

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-22 10:25:50 +02:00
Michael Kerrisk (man-pages) ade04bb89c Manual pages: order AUTHORS / COPYRIGHT / SEE ALSO / AVAILABILITY consistently
There is value in ensuring that manual page sections use consistently
named sections, as far as possible, and also that sections have a
consistent order within manual pages. This is one of a series of patches
to place manual page sections in a consistent order.

In this patch, we ensure that the AUTHORS, COPYRIGHT, SEE ALSO, and
AVAILABILITY sections are always placed at the end of the page.

Testing that no gross editing mistake (causing accidental loss or addition
of text) was performed as follows:

    $ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > a
    [Apply patch]
    $ cat $(grep '\.SH' -l $(find . -name '*.[1-9]') |sort) | sort > b
    $ diff a b
    $ echo $?
    0

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-22 10:25:49 +02:00
Michael Kerrisk (man-pages) 4259cff22e Manual pages: Standardize on ENVIRONMENT as section title
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.

But, let's make sure that the section is consistently titled
across pages. Currently we have ENVIRONMENT (many) or ENVIRONMENT
VARIABLES (3).  Let's standardize on ENVIRONMENT (which is also
what is suggested in man-pages(7)).

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-20 12:56:12 +02:00
Michael Kerrisk (man-pages) ef293e185e Manual pages: Standardize on CONFORMING TO as section title
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.

Currently we have STANDARDS (3) or CONFORMING TO (6).
Let's standardize on the latter (which is also what is
suggested in man-pages(7)).

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-20 12:56:12 +02:00
Michael Kerrisk (man-pages) bc281b0991 Manual pages: Standardize on EXAMPLE as section title
There is quite some value (in terms of readability and user
expectations) if consistent names are used for the sections
within manual pages. This patch is one of a series to bring
about this consistency.

Currently we have EXAMPLE (10) or EXAMPLES (23).
Let's standardize on the EXAMPLE (which is also what is
suggested in man-pages(7)) and used consistently across
a large number of pages in the Linux man-pages project.

(I realize the choice to go EXAMPLE, rather than EXAMPLES,
may be debatable. If necessary, I'd write a patch that instead
goes the other way, but I'd prefer to follow man-pages(7).)

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-20 12:56:12 +02:00
Michael Kerrisk (man-pages) 5a82980632 docs: (man) remove double quotes (") in .SH lines
Using double quotes in .SH lines containing multiple words is unneeded,
and in any case is not consistently done in the util-linux manual pages,
where double quotes are used in only around half of the cases.
(This usage was long ago elminated in the man-pages project, with
no ill effects reported to date.)

Remove these quotes, so that .SH lines are more uniform, in preparation
for some (more easily) scripted doiscovery of consistency problems in
(and possibly global fixes to) the manual pages.

Other than stripping the double quotes, this patch makes no changes to
the content of the manual pages.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-05-19 12:15:34 +02:00
Bjarni Ingi Gislason c5178f2796 docs: Some minor fixes in some manuals
Output is from: test-groff -b -e -mandoc -T utf8 -rF0 -t -w w -z

  [ "test-groff" is a developmental version of "groff" ]

Input file is ././misc-utils/kill.1

<./misc-utils/kill.1>:173 (macro BR): only 1 argument, but more are expected

Input file is ././misc-utils/lsblk.8

troff: backtrace: '/home/bg/git/groff/build/s-tmac/an-old.tmac':478: macro 'BR'
troff: backtrace: file '<./misc-utils/lsblk.8>':122
troff: <./misc-utils/lsblk.8>:122: warning: trailing space

Input file is ././sys-utils/mount.8

an-old.tmac: <./sys-utils/mount.8>:2427 (.RE): warning: extra .RE or .RS is missing before it; "an-RS-open" is 0.

Input file is ././sys-utils/unshare.1

<./sys-utils/unshare.1>:176 (macro BR): only 1 argument, but more are expected
<./sys-utils/unshare.1>:181 (macro BR): only 1 argument, but more are expected
<./sys-utils/unshare.1>:240 (macro BR): only 1 argument, but more are expected
<./sys-utils/unshare.1>:246 (macro BR): only 1 argument, but more are expected

Input file is ././term-utils/agetty.8

troff: backtrace: file '<./term-utils/agetty.8>':130
troff: <./term-utils/agetty.8>:130: warning: trailing space

Input file is ././text-utils/more.1

troff: backtrace: file '<./text-utils/more.1>':91
troff: <./text-utils/more.1>:91: warning: macro 'b' not defined

  The output from nroff and troff is unchanged, except for the word
"number" in text-utils/more.1, that was missing.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2020-05-18 10:35:25 +02:00
Sami Kerola 1f861935a7 more: make page and arrow up/down to update view
Aim was to introduce page and arrow up/down keys to more(1), but that
also required merging colon_command() and more_key_command() functions.

The more_key_commands enum is pointless from computers point of view.
The command identification performed in read_command() inline with
more_key_command() execution -- but that would be hard for humans, and
source code ought to serve both parties.

Reference: https://github.com/karelzak/util-linux/pull/1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-12 10:22:09 +02:00
Sami Kerola 09070e1a65 more: use libmagic to identify binary files
As the old commend said: 'This code would best be shared with the file(1)
program or, perhaps, more should not try to be so smart'.  Now at configure
time one can choose whether more(1) is sharing code with file(1), or not.

Addresses: http://bugs.debian.org/139205
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-12 10:22:09 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Sami Kerola ed292a08dd
include: add remove_entry() to env.h
A function to remove an command-line option argument, or environment
variable.

Requested-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1003#discussion_r403988092
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 837f49c6bf
more: fix moving backwards so that it can reach begining of the file
Moving backwards has worked fine until reaching start of file.  At that
point more printout had one line too much in output causing more seemingly
never to be able to reach the start.  That is now fixed, with clean ups to
skip_backwards() making it less confusing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola e3cb27f535
more: use getopt_long() to parse options
This commit also includes fix to how initial skip lines and search are
instructed in the code.  Earlier version was pretty close impossible to make
work with getopt_long() and had minor flaw - if both initial skip lines and
search were defined at the same time the skipping did not happen.  That is
now corrected.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 94bece3c22
more: remove underlining related code
Linux terminal handles underlining just fine without more executable needing
to do anything extra.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 6dcaaa9ef5
more: fix SIGSTOP and SIGCONT handling
When suspending only the more process.  Sending signal to process group
makes signal destination unnecessarily vague.  After the suspend is over
SIGCONT is expected, and it needs to ensure output terminal settings are
what more needs.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola c366ebc7ef
more: make execute() more robust and timely
The wait() is now a little more robust by being more tolerate rogue SIGCHLDs
and unblocked signals.  The repeated fork() and sleep() is removed, if first
try does not success give up without delay to provide user timely feedback.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola f3c044eeed
more: target all standard streams when calling fflush()
If streams need to be flushed do not try to be clever, just flush all of
them.  That lead to finding unnecessary print out in run_shell() that is
removed in this commit.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 21d096239c
more: remove kill_line() in favor of erase_prompt()
These functions did similar things, so there is no need for both of them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 508b2d79df
more: avoid defining special characters locally
The sys/ttydefaults.h can be used for CTRL() and rubout that is CERASE.  For
alarm it's best to keep things simple and call printf() alarm modifier.
QUIT was not in use, so it is just deleted.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola ba105bb5eb
more: use off_t and cc_t to clarify what variables attempt to represent
As a minor robustness improvement use ftello() to find out file position
rather than add and substract from old value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 437cec386f
more: do not reset parent process terminal in execute()
Only the terminal of the child process, that is the command being executed,
needs the reset.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 73ff5a9561
more: use single exit path to ensure resource freeing is unified
And be a little more complete all the allocations that can be released are,
but there is a small catch.  As mentioned in ncurses FAQ some leaks are
intentional, and that's the way they are.

Reference: https://invisible-island.net/ncurses/ncurses.faq.html#config_leaks
Reference: http://man7.org/linux/man-pages/man3/_nc_free_tinfo.3x.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:13:51 +01:00
Sami Kerola 5cd4550251
more: refactor and clarify code
Use the backspace provided dy terminfo, and if that is not possible use
fallback.

Simplify entering and exiting standard mode.  Now when these std_enter and
std_exit variables are initialized correctly they do not need to be checked
quite as complex way as earlier.

Do not call prepare_line_buffer() unnecessarily.  The line buffer needs only
to be prepared only at times of more(1) initialization and when terminal
size changes.

Add a function to print various separators, that is better than static
strings.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 63f96f682f
more: add display_file() to show files and stdin
Earlier main() inline code implemented input files and stdin displaying
separately.  With small restructuring this code can be shared.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 22ff9a38cb
more: simplify initterm()
Return rather than use long 'else' statement.  Also unwind some overly
compact variable set and test code, that can be best observed how
underlining settings are now handled.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 82129a6fca
more: move currently open file to control structure
Currently open file is needed a bit here and there.  Move it to control
structure to avoid passing it around.  This also makes fixing memory leak at
more_exit() very easy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 1f5d21ec33
more: move code blocks from more_key_command() to functions
The more_key_command() was overly long.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola b6818219fb
more: move runtime usage output to a function
This change also removes a ghost prompt that was left in place when printing
help.  When looking old commits the output fluke has been around at least
since util-linux v2.2.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola f53edc0ee6
more: restructure print_buf() if-else with continue
Replacing long 'else' with 'continue' allows dropping one level of
indentation.  Main aim is to improve code readability by reducing
complexity one needs to keep track while looking the code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola f8492042f5
more: tell in run time help what the 'v' will execute as editor
In same go use well known paths from system include file.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola 8fb5fe304a
more: drop setuid permissions before executing anything
Pagers are not expected to have setuid or setgid bits, but assuming such
mistake has taken place try to avoid privilege escalation.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola 474c61c0a8
more: do not allocate shell command buffer from stack
This change has three possitive effects:  Avoid expansion code when it is
not needed.  Stop wasting memory from stack for something rarely needed.
When command buffer is needed stop limiting it's size artificially.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-27 21:06:08 +00:00
Sami Kerola 823ef319b6
more: replace siglongjmp() and signal() calls with signalfd()
From man siglongjmp(3) 'longjmp() and siglongjmp() make programs hard to
understand and maintain.  If possible, an alternative should be used.'  That
manual page remark summarizes quite well why more(1) needs to move away from
jumping around.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-27 21:06:01 +00:00
Karel Zak 5b9b6d2a74 rev: (man) add note about limitations
Addresses: https://github.com/karelzak/util-linux/issues/972
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-09 11:03:30 +01:00
Karel Zak c2e82a4aaa hexdump: fix typo, dcl instead of dc1
Addresses: https://github.com/karelzak/util-linux/issues/976
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-09 10:54:28 +01:00
Karel Zak e0e2975998 rev: report line on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-04 13:20:56 +01:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Bjarni Ingi Gislason 1c4c602427 man pages: Change a HYPHEN-MINUS (-) to a minus (\-) for options and numbers
Change a HYPHEN-MINUS (code 0x55, 2D) to a minus (\-), if in front of

1) a name of an option

2) a negative number to be printed.

  See man-pages(7) [Debian package "manpages"].

  The output from "nroff" is unchanged.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Bjarni Ingi Gislason eb02489380 man pages: Add a comma after "e.g." and "i.e."
Add a comma (,) after "e.g." and "i.e.", or use English words
(man-pages(7) [package "manpages"]).

  Abbreviation points should be protected (usually with the
non-printing, zero width character '\&') from being interpreted as an
end of sentence, if they are not, and that independent of their current
place on the line.

  This is important when typing, as one does not usually know in
advance when the editor jumps to a new line.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Bjarni Ingi Gislason 47da68f1c9 man pages: Make the number of .RS/.RE equal
Add or remove one of the pairs .RS/.RE to make their number equal.

  The output from "nroff" and "groff" is unchanged.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Karel Zak dc626a7586 hexdump: add header file guards [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 16:13:52 +02:00