Commit Graph

159 Commits

Author SHA1 Message Date
Karel Zak 646bba41fd dmesg: add --noescape
We have no way how to print the kernel message buffer in really raw
way. The new option --noescape disables all \x<hex> translations.

Addresses: https://github.com/karelzak/util-linux/issues/858
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-09 12:56:53 +02:00
Sami Kerola a7466bdcbe
po: remove possibility to translate static option arguments
These strings are expected to be wrote exactly as they are parsed, so make
translating them impossible.  Since mkfs.cramfs -N option arguments need
this treatment use opportunity to slice usage() output to multiple lines.

Addresses: https://bugs.debian.org/907568
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-24 09:29:52 +01:00
Karel Zak 3661aab4cf dmesg: fix output hex encoding
The current code ignores single-byte non-printable characters.

Reported-by: Marc Deslauriers <marc.deslauriers@canonical.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-01 11:43:58 +02:00
Karel Zak 2d27898844 dmesg: make strtok() use more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 14:18:29 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak 6963338ca5 dmesg: fix raw output
The commit 5f538ac40c has introduced
regression ("goto" to the wrong place, so timestamps in raw mode is
not printed at all).

Addresses: https://github.com/karelzak/util-linux/issues/614
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-05 15:59:59 +02:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Karel Zak dd83526ae3 dmesg: use xstrdup() in xalloc.h based util
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-13 10:52:57 +01:00
Karel Zak aec01d7211 dmesg: fix compiler warning [-Wuninitialized]
sys-utils/dmesg.c: In function ‘print_record.constprop.12’:
sys-utils/dmesg.c:1039:14: warning: ‘mesg_size’ may be used uninitialized in this function [-Wuninitialized]

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-28 10:45:06 +01:00
J William Piggott 4111bb3ab5 lib/timeutils: add common ISO timestamp masks
* 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>
2017-11-10 16:34:55 -05:00
Prarit Bhargava 5f538ac40c dmesg: Add --force-prefix option
The kernel outputs multi-line messages (kernel messages that contain
the end-of-line character '\n').  These message are currently displayed by
dmesg as

[965199.028940] runnable tasks:
                           task   PID         tree-key  switches  prio
wait-time             sum-exec        sum-sleep
                ----------------------------------------------------------------------------------------------------------

The kernel timestamps each of these lines with [965199.028940] and the
dmesg utility should do the same.

Add the 'force-prefix'/'-p' dmesg option to add decode & timestamp
information to each line of a multi-line message.

Notes: The new print_record() algorithm stores the decode & timestamp
information in buffers.  If the force-prefix option is used, the
message is split into separate lines and each line is prefixed with
the stored decode & timestamp information.  The splitting of the
message into separate lines is done using strtok() which requires
write access to the message buffer (ie, the const message buffer is
now copied into a writeable buffer).

Successfully tested by me by looking at sysrq-t and sysrq-w output.
All known good /tests passed with these changes.

[kzak@redhat.com:

  - use snprintf()
  - cleanup \n usage (don't count line break to the
    message text in the parsers  and always print \n after the text
  - add the option to the man page
  - use --force-prefix for kmsg only, old syslog(2) API splits messages itself
  - strdup() the message text only on force-prefix]

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-01 15:37:00 +01:00
Karel Zak 8a6f0cfd96 Revert "dmesg: fragment concatenation"
* introduces regressions
* stupid code; parse_kmsg_record() called more than once for each record

This reverts commit 22eb2f0190.
2017-10-30 15:04:20 +01:00
Karel Zak fcd90d9ac7 dmesg: fix delimiter calculation
Reported-by: Laszlo Varkonyi <vlsoftsystems@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-16 14:15:56 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
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>
2017-06-27 12:28:36 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak c525260293 Merge branch 'usage-part1' of https://github.com/rudimeier/util-linux
* 'usage-part1' of https://github.com/rudimeier/util-linux:
  misc: no more errtryh()
  mkfs.cramfs: add --help and --version
  more: add --help and --version
  whereis: add --help and --version
  login: add --help and --version
  fsck: add --help and --version
  setarch: use errtryhelp()
  dmesg: do not accept any non-option arguments
  blkid: use errtryhelp instead of errtryh
  misc: remove superfluous null pointer checks for optarg
  uuidd: remove unused define
2017-06-26 13:42:25 +02:00
Ruediger Meier 488a21686f dmesg: do not accept any non-option arguments
'dmesg foo' is no valid syntax and gives an error now.
BTW we avoid the "dead increment of argc and argv.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:43 +02:00
Ivan Delalande 2e45524d96 dmesg: print only 2 hex digits for each hex-escaped byte
As buf is passed as a signed char buffer in fwrite_hex, fprintf will
print every byte from 0x80 as a signed-extended int causing each of
these bytes to be printed as "\xffffff80" and such, which can be pretty
confusing. Force fprintf to use the argument as a char to make it print
only 2 digits, e.g. "\x80".

Signed-off-by: Ivan Delalande <colona@arista.com>
2017-06-22 10:44:35 +02:00
Vinnie Magro 22eb2f0190 dmesg: fragment concatenation
When extended console is enabled, the kernel doesn't internally
concatenate message fragments, this change adds log fragment
concatenation to dmesg: instead of being printed as separate messages,
fragments are combined onto one line and printed with the timestamp of
the first line.

This doesn't work in all cases - such as if another message is logged in
between two fragment lines, but in this case the behavior matches the
previous output format (printed on the separate lines).

[kzak@redhat.com: - rename kmsg_read_buf to kmsg_saved_size,
                  - minor coding style fixes]

Signed-off-by: Vinnie Magro <vmagro@fb.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-20 11:26:23 +02:00
Karel Zak 682fd25dea dmesg: remove unnecessary header
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-31 09:18:10 +02:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
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>
2016-12-19 13:13:34 +01:00
Karel Zak bae57b5a3c misc: fix unsigned int usage for ctype.h functions
Reported-by: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 10:13:47 +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 eb2306e675
misc: fix declarations shadowing variables in the global scope [oclint]
Fixes multiple occurences of 'optarg' overwrites.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola f6f1356f1c
dmesg: drop core at impossible case in read_buffer() [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 54d172327b dmesg: fix indention
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 14:12:54 +02:00
Karel Zak 3c6e7c5414 dmesg: use strtimeval_iso()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 11:09:41 +02:00
Sami Kerola fdba1750fc
dmesg: --notime should not suppress --show-delta
The --show-delta is off by default, which means it can be only on when user
has requested to see these time stamps.  The --notime option should not turn
the delta outputing off, because then option order matters and no-one wants
that.  Example of the old output:

$ dmesg --notime --show-delta | sed -n 's/ version.*//p; q'
[<    0.000000>] Linux
$ dmesg --show-delta --notime | sed -n 's/ version.*//p; q'
Linux

Addresses: https://bugs.launchpad.net/bugs/1544595
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-16 23:09:26 +01:00
Benno Schulenberg 0825fe1621 dmesg: improve grammar and consistency of usage text
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:39 +01:00
Ruediger Meier c211401801 misc: always cast timeval.tv_usec to long rather than int
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-12 14:32:42 +01:00
Karel Zak 3a131296d1 dmesg: highlight -T issues in docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-25 15:43:03 +02:00
Karel Zak 5a34fb8a07 dmesg: use GMT in tests, add DMESG_TEST_BOOTIME
We don't want to hardcode anything to the test, just use
env.variable DMESG_TEST_BOOTIME.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-23 11:40:59 +01:00
Sami Kerola 5fac518cef tests: add test_dmesg that has fixed boot time
This allows testing time stamp formats.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-03-23 10:34:49 +01:00
Sami Kerola f1300e2cea dmesg: fix shadow declaration
sys-utils/dmesg.c:650:9: warning: declaration of 's' shadows a previous local [-Wshadow]
sys-utils/dmesg.c:619:12: warning: shadowed declaration is here [-Wshadow]

And since the code had to be touched deprecate loop printing one character
at a time, in favour of printf and instruction to repeat spaces the number
required.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-03-23 10:34:49 +01:00
Karel Zak 5d51dc2a7f colors: cleanup man pages, add hint to usage()
cfdisk, fdisk, calm dmesg and hexdump

Signed-off-by: Karel Zak <kzak@redhat.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-25 12:40:06 +01:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +01:00
Ingo Brückl b45c3da2e1 dmesg: Enable proper indent for messages containing line breaks
Messages containing line breaks somehow look broken when additional time,
facility or level information is displayed, because they partly appear in
time/facility/level column.

Indent them accordingly.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 11:03:34 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
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>
2015-01-06 11:27:38 +01:00
Karel Zak cd2876d252 build-sys: move all around clock_gettime() to monotonic.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:54:47 +01:00
Karel Zak 33ecab2b9c dmesg: improve reltime colors
[  +0.004034] sd 113:0:0:0: [sdb] Attached SCSI disk
[Oct10 13:04]  sdb: unknown partition table
[  +0.034011]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 sdb6 >

.. the "Oct10 13:04" is possible to colorize by "timebreak"
scheme (default is bold green).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 10:20:19 +02:00
Sami Kerola f627750083 textual: use version printing macro everywhere
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>
2014-10-01 12:33:23 +02:00
Benno Schulenberg 6269814950 textual: grammarize an error message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-10-01 09:37:07 +02:00
Sami Kerola d9bdd89db1 dmesg: avoid unnecessary variable assignment
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 18:35:38 +01:00
Karel Zak f4bc7f96a6 dmesg: support colors customization
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-13 12:13:02 +02:00
Karel Zak 08ca3e26a8 lib/timeutils: remove get_boot_time from libcommon
clock_gettime() needs -lrt, so let's keep this stuff
outside libcommon.la

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-06 13:16:05 +02:00