* [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs
@ 2013-06-16 18:53 Sami Kerola
2013-06-16 18:53 ` [PATCH 01/15] renice: exit with non-zero value when arguments cause warnings Sami Kerola
` (16 more replies)
0 siblings, 17 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Hi Karel and others,
Half of the patches in this pull request are re-worked changes, which
were rejected earlier. The sfdisk error printing is now using plain
glibc warn() and err() functions. The dmesg time format selection is
much cleaner when done the way Karel proposed.
Unfortunately the most troubling dmesg patch is now dropped by me. I had
a look how systemd determines boot time, and it seem very early at
execution clock_gettime() is called, and results are saved. If dmesg
should agree with systemd when startup happen I see two possible options;
1. Make dmesg to get system startup time from systemd using dbus.
2. Make both dmesg and systemd to ask start up time from kernel.
I feel first option is not great. The systemd boot time stamp is similar
sort of approximation as reading fstat from /proc/1. Also asking when
system started from system itself feels more neutral than consulting a
software the system started.
If the second option is favored a kernel patch, such as the one below, is
needed and a bit coordination to make various programs to use the
boottime from kernel. Meanwhile it migth be fine that differnt programs
using differnet time stamps for klog messages.
Any opinions about klog time stamps?
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -157,6 +157,16 @@ static ssize_t rcu_expedited_store(struct kobject
*kobj,
}
KERNEL_ATTR_RW(rcu_expedited);
+/* High precision timestamp of the system boot. */
+static ssize_t boottime_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct timespec ts;
+ getboottime(&ts);
+ return sprintf(buf, "%ld.%ld\n", ts.tv_sec, ts.tv_nsec);
+}
+KERNEL_ATTR_RO(hp_uptime);
+
/*
* Make /sys/kernel/notes give the raw contents of our kernel .notes
* section.
*/
@@ -197,6 +207,7 @@ static struct attribute * kernel_attrs[] = {
&vmcoreinfo_attr.attr,
#endif
&rcu_expedited_attr.attr,
+ &hp_uptime_attr.attr,
NULL
};
And comments about & review of the patches are also highly appreciated.
The following changes since commit 76b86412c607ba47f43ef7c0535436bca2a660d2:
fdisk: don't use ptes[] in generic code (2013-06-12 17:39:09 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git 2013wk23
for you to fetch changes up to 314e07144b26e30a5bd5b0a41fb18fe3020dfe8a:
hexdump: use simple printing functions when possible (2013-06-16 19:00:33 +0100)
----------------------------------------------------------------
Sami Kerola (15):
renice: exit with non-zero value when arguments cause warnings
sfdisk: use libc error printing function, and symbolic exit values
sfdisk: clean up usage() functions
sfdisk: use program_invocation_short_name to determine program name
docs: correct sfdisk --activate instructions
sfdisk: remove --unhide and related functions
sfdisk: replace my_warn() with warnx()
dmesg: convert time format bitfield to enum
dmesg: add --time-format option
dmesg: add iso-8601 time format
docs: add --time-format option and ISO-8601 format to manual
dmesg: regroup time related options close to each other
sd-daemon: update files taken from systemd project
hexdump: remove unnecessary global variables
hexdump: use simple printing functions when possible
fdisks/sfdisk.8 | 33 +++-
fdisks/sfdisk.c | 451 ++++++++++++++++++-------------------------------
misc-utils/sd-daemon.c | 100 +++++------
misc-utils/sd-daemon.h | 14 +-
sys-utils/dmesg.1 | 22 +++
sys-utils/dmesg.c | 214 +++++++++++++----------
sys-utils/renice.c | 4 +-
text-utils/display.c | 16 +-
text-utils/hexdump.c | 4 +-
text-utils/hexdump.h | 2 -
10 files changed, 408 insertions(+), 452 deletions(-)
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 01/15] renice: exit with non-zero value when arguments cause warnings
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 02/15] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
` (15 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This commit also fixes potential error counter wrap, which theoretically
could make command to exit with a success when it internally failed just
correct amount of times.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/renice.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index 50b1642..c0378e1 100644
--- a/sys-utils/renice.c
+++ b/sys-utils/renice.c
@@ -138,6 +138,7 @@ main(int argc, char **argv)
if (pwd == NULL) {
warnx(_("unknown user %s"), *argv);
+ errs = 1;
continue;
}
who = pwd->pw_uid;
@@ -145,10 +146,11 @@ main(int argc, char **argv)
who = strtol(*argv, &endptr, 10);
if (who < 0 || *endptr) {
warnx(_("bad value %s"), *argv);
+ errs = 1;
continue;
}
}
- errs += donice(which, who, prio);
+ errs |= donice(which, who, prio);
}
return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 02/15] sfdisk: use libc error printing function, and symbolic exit values
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
2013-06-16 18:53 ` [PATCH 01/15] renice: exit with non-zero value when arguments cause warnings Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 03/15] sfdisk: clean up usage() functions Sami Kerola
` (14 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The commit removes all references to perror(), and replaces them with
either warn() or err().
References: http://marc.info/?l=util-linux-ng&m=137060043804592&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.c | 120 ++++++++++++++++++++------------------------------------
1 file changed, 43 insertions(+), 77 deletions(-)
diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index e639dad..cbbdfd5 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -27,8 +27,6 @@
* I changed the name to sfdisk to prevent confusion. - aeb, 970501
*/
-#define PROGNAME "sfdisk"
-
#include <stdio.h>
#include <stdlib.h> /* atoi, free */
#include <stdarg.h> /* varargs */
@@ -108,18 +106,6 @@ my_warn(char *s, ...) {
va_end(p);
}
-static void
-error(char *s, ...) {
- va_list p;
-
- va_start(p, s);
- fflush(stdout);
- fprintf(stderr, "\n" PROGNAME ": ");
- vfprintf(stderr, s, p);
- fflush(stderr);
- va_end(p);
-}
-
/*
* A. About seeking
*/
@@ -136,13 +122,12 @@ sseek(char *dev, int fd, unsigned long s) {
in = ((off_t) s << 9);
if ((out = lseek(fd, in, SEEK_SET)) != in) {
- perror("lseek");
- error(_("seek error on %s - cannot seek to %lu\n"), dev, s);
+ warn(_("seek error on %s - cannot seek to %lu"), dev, s);
return 0;
}
if (in != out) {
- error(_("seek error: wanted 0x%08x%08x, got 0x%08x%08x\n"),
+ warnx(_("seek error: wanted 0x%08x%08x, got 0x%08x%08x"),
(unsigned int)(in >> 32), (unsigned int)(in & 0xffffffff),
(unsigned int)(out >> 32), (unsigned int)(out & 0xffffffff));
return 0;
@@ -190,9 +175,7 @@ get_sector(char *dev, int fd, unsigned long long sno) {
s = xmalloc(sizeof(struct sector));
if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
- if (errno) /* 0 in case we read past end-of-disk */
- perror("read");
- error(_("read error on %s - cannot read sector %lu\n"), dev, sno);
+ warn(_("read error on %s - cannot read sector %llu"), dev, sno);
free(s);
return 0;
}
@@ -222,9 +205,8 @@ write_sectors(char *dev, int fd) {
if (!sseek(dev, fd, s->sectornumber))
return 0;
if (write(fd, s->data, sizeof(s->data)) != sizeof(s->data)) {
- perror("write");
- error(_("write error on %s - cannot write sector %lu\n"),
- dev, s->sectornumber);
+ warn(_("write error on %s - cannot write sector %llu"),
+ dev, s->sectornumber);
return 0;
}
s->to_be_written = 0;
@@ -260,9 +242,8 @@ save_sectors(char *dev, int fdin) {
fdout = open(save_sector_file, O_WRONLY | O_CREAT, 0444);
if (fdout < 0) {
- perror(save_sector_file);
- error(_("cannot open partition sector save file (%s)\n"),
- save_sector_file);
+ warn(_("cannot open partition sector save file (%s)"),
+ save_sector_file);
goto err;
}
@@ -272,14 +253,12 @@ save_sectors(char *dev, int fdin) {
if (!sseek(dev, fdin, s->sectornumber))
goto err;
if (read(fdin, ss + 4, 512) != 512) {
- perror("read");
- error(_("read error on %s - cannot read sector %lu\n"),
- dev, s->sectornumber);
+ warn(_("read error on %s - cannot read sector %llu"),
+ dev, s->sectornumber);
goto err;
}
if (write(fdout, ss, sizeof(ss)) != sizeof(ss)) {
- perror("write");
- error(_("write error on %s\n"), save_sector_file);
+ warn(_("write error on %s"), save_sector_file);
goto err;
}
}
@@ -308,13 +287,12 @@ restore_sectors(char *dev) {
unsigned long sno;
if (stat(restore_sector_file, &statbuf) < 0) {
- perror(restore_sector_file);
- error(_("cannot stat partition restore file (%s)\n"),
- restore_sector_file);
+ warn(_("cannot stat partition restore file (%s)"),
+ restore_sector_file);
goto err;
}
if (statbuf.st_size % 516) {
- error(_("partition restore file has wrong size - not restoring\n"));
+ warnx(_("partition restore file has wrong size - not restoring"));
goto err;
}
@@ -323,21 +301,18 @@ restore_sectors(char *dev) {
fdin = open(restore_sector_file, O_RDONLY);
if (fdin < 0) {
- perror(restore_sector_file);
- error(_("cannot open partition restore file (%s)\n"),
- restore_sector_file);
+ warn(_("cannot open partition restore file (%s)"),
+ restore_sector_file);
goto err;
}
if (read(fdin, ss, statbuf.st_size) != statbuf.st_size) {
- perror("read");
- error(_("error reading %s\n"), restore_sector_file);
+ warn(_("error reading %s"), restore_sector_file);
goto err;
}
fdout = open(dev, O_WRONLY);
if (fdout < 0) {
- perror(dev);
- error(_("cannot open device %s for writing\n"), dev);
+ warn(_("cannot open device %s for writing"), dev);
goto err;
}
@@ -347,8 +322,7 @@ restore_sectors(char *dev) {
if (!sseek(dev, fdout, sno))
goto err;
if (write(fdout, ss + 4, 512) != 512) {
- perror(dev);
- error(_("error writing sector %lu on %s\n"), sno, dev);
+ warn(_("error writing sector %lu on %s"), sno, dev);
goto err;
}
ss += 516;
@@ -360,7 +334,7 @@ restore_sectors(char *dev) {
goto err;
close(fdin);
if (close_fd(fdout) != 0) {
- error(_("write failed: %s"), dev);
+ warnx(_("write failed: %s"), dev);
return 0;
}
return 1;
@@ -472,7 +446,7 @@ get_cylindersize(char *dev, int fd, int silent) {
"the entire disk. Using fdisk on it is probably meaningless.\n"
"[Use the --force option if you really want this]\n"),
R.start);
- exit(1);
+ exit(EXIT_FAILURE);
}
#if 0
if (R.heads && B.heads != R.heads)
@@ -775,7 +749,7 @@ reread_ioctl(int fd) {
/* perror might change errno */
int err = errno;
- perror("BLKRRPART");
+ warn("BLKRRPART");
/* 2.6.8 returns EIO for a zero table */
if (err == EBUSY)
@@ -801,8 +775,7 @@ reread_disk_partition(char *dev, int fd) {
}
if (close_fd(fd) != 0) {
- perror(dev);
- warnx(_("Error closing %s\n"), dev);
+ warn(_("Error closing %s\n"), dev);
return 0;
}
printf("\n");
@@ -1436,7 +1409,7 @@ extended_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
break;
if (!msdos_signature(s)) {
- error(_("ERROR: sector %lu does not have an msdos signature\n"),
+ warnx(_("ERROR: sector %llu does not have an msdos signature"),
s->sectornumber);
break;
}
@@ -1670,7 +1643,7 @@ write_partitions(char *dev, int fd, struct disk_desc *z) {
if (no_write) {
warnx(_("-n flag was given: Nothing changed\n"));
- exit(0);
+ exit(EXIT_SUCCESS);
}
for (p = partitions; p < partitions + pno; p++) {
@@ -1691,12 +1664,11 @@ write_partitions(char *dev, int fd, struct disk_desc *z) {
}
}
if (!write_sectors(dev, fd)) {
- error(_("Failed writing the partition on %s\n"), dev);
+ warnx(_("Failed writing the partition on %s"), dev);
return 0;
}
if (fsync(fd)) {
- perror(dev);
- error(_("Failed writing the partition on %s\n"), dev);
+ warn(_("Failed writing the partition on %s"), dev);
return 0;
}
return 1;
@@ -2447,8 +2419,8 @@ activate_usage(char *progn) {
printf(_("%s device n1 n2 ... activate partitions n1 ..., inactivate the rest\n"),
progn);
printf(_("%s -An device activate partition n, inactivate the other ones\n"),
- PROGNAME);
- exit(1);
+ program_invocation_short_name);
+ exit(EXIT_FAILURE);
}
static void
@@ -2676,7 +2648,7 @@ main(int argc, char **argv) {
break;
case 'T':
list_types();
- exit(0);
+ return EXIT_SUCCESS;
case 'U':
unhidearg = optarg;
unhide = 1;
@@ -2751,7 +2723,7 @@ main(int argc, char **argv) {
if (opt_size)
printf(_("total: %llu blocks\n"), total_size);
- exit(exit_status);
+ return exit_status;
}
if (optind == argc) {
@@ -2775,16 +2747,16 @@ main(int argc, char **argv) {
do_list(argv[optind], 0);
optind++;
}
- exit(exit_status);
+ return exit_status;
}
if (activate) {
do_activate(argv + optind, argc - optind, activatearg);
- exit(exit_status);
+ return exit_status;
}
if (unhide) {
do_unhide(argv + optind, argc - optind, unhidearg);
- exit(exit_status);
+ return exit_status;
}
if (do_id) {
if ((do_id & PRINT_ID) != 0 && optind != argc - 2)
@@ -2795,7 +2767,7 @@ main(int argc, char **argv) {
errx(EXIT_FAILURE, _("usage: sfdisk --id device partition-number [Id]"));
do_change_id(argv[optind], argv[optind + 1],
(optind == argc - 2) ? 0 : argv[optind + 2]);
- exit(exit_status);
+ return exit_status;
}
if (optind != argc - 1)
@@ -2809,7 +2781,7 @@ main(int argc, char **argv) {
else
do_fdisk(dev);
- return 0;
+ return exit_status;
}
/*
@@ -2823,11 +2795,10 @@ my_open(char *dev, int rw, int silent) {
mode = (rw ? O_RDWR : O_RDONLY);
fd = open(dev, mode);
if (fd < 0 && !silent) {
- perror(dev);
if (rw)
- errx(EXIT_FAILURE, _("cannot open %s read-write"), dev);
+ err(EXIT_FAILURE, _("cannot open %s read-write"), dev);
else
- errx(EXIT_FAILURE, _("cannot open %s for reading"), dev);
+ err(EXIT_FAILURE, _("cannot open %s for reading"), dev);
}
return fd;
}
@@ -2920,10 +2891,8 @@ do_size(char *dev, int silent) {
return;
if (blkdev_get_sectors(fd, &size) == -1) {
- if (!silent) {
- perror(dev);
- errx(EXIT_FAILURE, _("Cannot get size of %s"), dev);
- }
+ if (!silent)
+ err(EXIT_FAILURE, _("Cannot get size of %s"), dev);
goto done;
}
@@ -3136,7 +3105,7 @@ do_reread(char *dev) {
fd = my_open(dev, 0, 0);
if (reread_ioctl(fd)) {
warnx(_("This disk is currently in use.\n"));
- exit(1);
+ exit(EXIT_FAILURE);
}
close(fd);
@@ -3154,10 +3123,8 @@ do_fdisk(char *dev) {
int interactive = isatty(0);
struct disk_desc *z;
- if (stat(dev, &statbuf) < 0) {
- perror(dev);
- errx(EXIT_FAILURE, _("Fatal error: cannot find %s"), dev);
- }
+ if (stat(dev, &statbuf) < 0)
+ err(EXIT_FAILURE, _("Fatal error: cannot find %s"), dev);
if (!S_ISBLK(statbuf.st_mode)) {
warnx(_("Warning: %s is not a block device\n"), dev);
no_reread = 1;
@@ -3172,7 +3139,7 @@ do_fdisk(char *dev) {
"Use the --no-reread flag to suppress this check.\n"));
if (!force) {
warnx(_("Use the --force flag to overrule all checks.\n"));
- exit(1);
+ exit(EXIT_FAILURE);
}
} else
my_warn(_("OK\n"));
@@ -3243,5 +3210,4 @@ do_fdisk(char *dev) {
"(See fdisk(8).)\n"));
sync(); /* superstition */
- exit(exit_status);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 03/15] sfdisk: clean up usage() functions
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
2013-06-16 18:53 ` [PATCH 01/15] renice: exit with non-zero value when arguments cause warnings Sami Kerola
2013-06-16 18:53 ` [PATCH 02/15] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 04/15] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
` (13 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Includes removal of unhide usage function, which was never implemented.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.c | 39 ++++++++++++++++++---------------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index cbbdfd5..96b4de2 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2356,11 +2356,11 @@ read_input(char *dev, int interactive, struct disk_desc *z) {
*/
static void usage(FILE * out)
{
- fputs(_("\nUsage:\n"), out);
+ fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <device> [...]\n"), program_invocation_short_name);
- fputs(_("\nOptions:\n"), out);
+ fputs(USAGE_OPTIONS, out);
fputs(_(" -s, --show-size list size of a partition\n"
" -c, --id change or print partition Id\n"
" --change-id change Id\n"
@@ -2407,27 +2407,29 @@ static void usage(FILE * out)
fputs(_("\nOverride the detected geometry using:\n"
" -C, --cylinders <number> set the number of cylinders to use\n"
" -H, --heads <number> set the number of heads to use\n"
- " -S, --sectors <number> set the number of sectors to use\n\n"), out);
+ " -S, --sectors <number> set the number of sectors to use\n"), out);
+ fprintf(out, USAGE_MAN_TAIL("sfdisk(8)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
static void
-activate_usage(char *progn) {
- puts(_("Usage:"));
- printf(_("%s device list active partitions on device\n"), progn);
- printf(_("%s device n1 n2 ... activate partitions n1 ..., inactivate the rest\n"),
- progn);
- printf(_("%s -An device activate partition n, inactivate the other ones\n"),
- program_invocation_short_name);
+activate_usage(void) {
+ char *p;
+ if (!strcmp(program_invocation_short_name, "activate"))
+ p = " ";
+ else
+ p = " --activate=";
+ fputs(USAGE_HEADER, stderr);
+ fputs(USAGE_SEPARATOR, stderr);
+ fprintf(stderr, _(" %s%sdevice list active partitions on device\n"),
+ program_invocation_short_name, p);
+ fprintf(stderr, _(" %s%sdevice n1 n2 ... activate partitions n1 ..., inactivate the rest\n"),
+ program_invocation_short_name, p);
+ fprintf(stderr, USAGE_MAN_TAIL("sfdisk(8)"));
exit(EXIT_FAILURE);
}
-static void
-unhide_usage(char *progn __attribute__ ((__unused__))) {
- exit(1);
-}
-
static const char short_opts[] = "cdfghilnqsu:vx1A::C:DGH:I:LN:O:RS:TU::V";
#define PRINT_ID 0400
@@ -2543,7 +2545,6 @@ main(int argc, char **argv) {
int activate = 0;
int do_id = 0;
int unhide = 0;
- int fdisk = 0;
char *activatearg = 0;
char *unhidearg = 0;
@@ -2564,8 +2565,6 @@ main(int argc, char **argv) {
else if (!strcmp(progn, "unhide"))
unhide = 1; /* equivalent to `sfdisk -U' */
#endif
- else
- fdisk = 1;
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch (c) {
@@ -2728,9 +2727,7 @@ main(int argc, char **argv) {
if (optind == argc) {
if (activate)
- activate_usage(fdisk ? "sfdisk -A" : progn);
- else if (unhide)
- unhide_usage(fdisk ? "sfdisk -U" : progn);
+ activate_usage();
else
usage(stderr);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 04/15] sfdisk: use program_invocation_short_name to determine program name
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (2 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 03/15] sfdisk: clean up usage() functions Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 05/15] docs: correct sfdisk --activate instructions Sami Kerola
` (12 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index 96b4de2..2b4969b 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2535,7 +2535,6 @@ unsigned long long total_size;
int
main(int argc, char **argv) {
- char *progn;
int c;
char *dev;
int opt_size = 0;
@@ -2555,14 +2554,10 @@ main(int argc, char **argv) {
if (argc < 1)
errx(EXIT_FAILURE, _("no command?"));
- if ((progn = strrchr(argv[0], '/')) == NULL)
- progn = argv[0];
- else
- progn++;
- if (!strcmp(progn, "activate"))
+ if (!strcmp(program_invocation_short_name, "activate"))
activate = 1; /* equivalent to `sfdisk -A' */
#if 0 /* not important enough to deserve a name */
- else if (!strcmp(progn, "unhide"))
+ else if (!strcmp(program_invocation_short_name, "unhide"))
unhide = 1; /* equivalent to `sfdisk -U' */
#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 05/15] docs: correct sfdisk --activate instructions
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (3 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 04/15] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 06/15] sfdisk: remove --unhide and related functions Sami Kerola
` (11 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The activate can be enabled by renaming the command to 'activate'. Quite
confusingly the option and command arguments are interchangeable, and
depending on which one is defined as --activate option argument the
command will behave different rather different ways.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.8 | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/fdisks/sfdisk.8 b/fdisks/sfdisk.8
index 57c9a68..2b166fa 100644
--- a/fdisks/sfdisk.8
+++ b/fdisks/sfdisk.8
@@ -223,8 +223,37 @@ and change nothing else. (Probably this fifth partition
is called /dev/hdb5, but you are free to call it something else,
like `/my_equipment/disks/2/5' or so).
.TP
-.BR \-A ", " \-\-activate " \fInumber\fR"
-Make the indicated partition(s) active, and all others inactive.
+\fB\-A\fR, \fB\-\-activate\fR [\fIdevice\fR or \fIpartition number\fR]
+The activate option will turn on bootable flag.
+.IP
+The activate option takes optional argument. When the option argument is
+not defined command will list partitions that has bootable flag set on
+for device given as command argument. For example.
+.IP
+.nf
+.if t .ft CW
+ % sfdisk --activate /dev/sda
+.fi
+When the activate has option argument, and command argument list, the
+partitions defined as command argument will be set to have bootable flag.
+Other partitions for the device are clered not to have bootable flag.
+For example the partitions 1 and 4 are set bootable, while 2 and 3 are
+cleared.
+.IP
+.nf
+.if t .ft CW
+ % sfdisk --activate=/dev/sda 1 4
+.fi
+If only a single partition must be activated then the partition number
+must be given as option argument, and device as command argument. For example.
+.IP
+.nf
+.if t .ft CW
+ % sfdisk --activate=1 /dev/sda
+.fi
+.IP
+The activate functionality is turned on when the program invocation name is
+.IR activate .
.TP
.BR \-c ", " \-\-id " \fInumber\fR [\fIId\fR]"
If no \fIId\fR argument given: print the partition Id of the indicated
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 06/15] sfdisk: remove --unhide and related functions
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (4 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 05/15] docs: correct sfdisk --activate instructions Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 07/15] sfdisk: replace my_warn() with warnx() Sami Kerola
` (10 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The --unhide was never implemented, and did not do anything.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.c | 70 +--------------------------------------------------------
1 file changed, 1 insertion(+), 69 deletions(-)
diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index 2b4969b..ae17e8d 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2391,7 +2391,6 @@ static void usage(FILE * out)
fputs(_(" -g, --show-geometry print the kernel's idea of the geometry\n"
" -G, --show-pt-geometry print geometry guessed from the partition table\n"), out);
fputs(_(" -A, --activate[=<device>] activate bootable flag\n"
- " -U, --unhide[=<dev>] set partition unhidden\n"
" -x, --show-extended also list extended partitions in the output,\n"
" or expect descriptors for them in the input\n"), out);
fputs(_(" --leave-last do not allocate the last cylinder\n"
@@ -2430,7 +2429,7 @@ activate_usage(void) {
exit(EXIT_FAILURE);
}
-static const char short_opts[] = "cdfghilnqsu:vx1A::C:DGH:I:LN:O:RS:TU::V";
+static const char short_opts[] = "cdfghilnqsu:vx1A::C:DGH:I:LN:O:RS:TV";
#define PRINT_ID 0400
#define CHANGE_ID 01000
@@ -2473,7 +2472,6 @@ static const struct option long_opts[] = {
{ "Linux", no_argument, NULL, 'L' },
{ "re-read", no_argument, NULL, 'R' },
{ "list-types", no_argument, NULL, 'T' },
- { "unhide", optional_argument, NULL, 'U' },
{ "no-reread", no_argument, NULL, OPT_NO_REREAD },
{ "IBM", no_argument, NULL, OPT_LEAVE_LAST },
{ "leave-last", no_argument, NULL, OPT_LEAVE_LAST },
@@ -2528,7 +2526,6 @@ static void do_pt_geom(char *dev, int silent);
static void do_fdisk(char *dev);
static void do_reread(char *dev);
static void do_change_id(char *dev, char *part, char *id);
-static void do_unhide(char **av, int ac, char *arg);
static void do_activate(char **av, int ac, char *arg);
unsigned long long total_size;
@@ -2543,9 +2540,7 @@ main(int argc, char **argv) {
int opt_reread = 0;
int activate = 0;
int do_id = 0;
- int unhide = 0;
char *activatearg = 0;
- char *unhidearg = 0;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -2556,10 +2551,6 @@ main(int argc, char **argv) {
errx(EXIT_FAILURE, _("no command?"));
if (!strcmp(program_invocation_short_name, "activate"))
activate = 1; /* equivalent to `sfdisk -A' */
-#if 0 /* not important enough to deserve a name */
- else if (!strcmp(program_invocation_short_name, "unhide"))
- unhide = 1; /* equivalent to `sfdisk -U' */
-#endif
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch (c) {
@@ -2643,10 +2634,6 @@ main(int argc, char **argv) {
case 'T':
list_types();
return EXIT_SUCCESS;
- case 'U':
- unhidearg = optarg;
- unhide = 1;
- break;
case 'V':
verify = 1;
break;
@@ -2746,10 +2733,6 @@ main(int argc, char **argv) {
do_activate(argv + optind, argc - optind, activatearg);
return exit_status;
}
- if (unhide) {
- do_unhide(argv + optind, argc - optind, unhidearg);
- return exit_status;
- }
if (do_id) {
if ((do_id & PRINT_ID) != 0 && optind != argc - 2)
errx(EXIT_FAILURE, _("usage: sfdisk --print-id device partition-number"));
@@ -3003,57 +2986,6 @@ do_activate(char **av, int ac, char *arg) {
}
static void
-set_unhidden(struct disk_desc *z, char *pnam) {
- int pno;
- unsigned char id;
-
- pno = asc_to_index(pnam, z);
- id = z->partitions[pno].p.sys_type;
- if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17)
- id -= 0x10;
- else
- errx(EXIT_FAILURE, _("partition %s has id %x and is not hidden"), pnam, id);
- z->partitions[pno].p.sys_type = id;
-}
-
-/*
- * maybe remove and make part of --change-id
- */
-static void
-do_unhide(char **av, int ac, char *arg) {
- char *dev = av[0];
- int fd, rw, i;
- struct disk_desc *z;
-
- z = &oldp;
-
- rw = !no_write;
- fd = my_open(dev, rw, 0);
-
- free_sectors();
- get_cylindersize(dev, fd, 1);
- get_partitions(dev, fd, z);
-
- /* unhide where desired */
- if (ac == 1)
- set_unhidden(z, arg);
- else
- for (i = 1; i < ac; i++)
- set_unhidden(z, av[i]);
-
- /* then write to disk */
- if (write_partitions(dev, fd, z))
- my_warn(_("Done\n\n"));
- else
- exit_status = 1;
-
- if (close_fd(fd) != 0) {
- my_warn(_("write failed"));
- exit_status = 1;
- }
-}
-
-static void
do_change_id(char *dev, char *pnam, char *id) {
int fd, rw, pno;
struct disk_desc *z;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 07/15] sfdisk: replace my_warn() with warnx()
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (5 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 06/15] sfdisk: remove --unhide and related functions Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 08/15] dmesg: convert time format bitfield to enum Sami Kerola
` (9 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This change adds program name in front of error messages. Often that
helps user to know which command sent message, when the command is
executed as part of script.
Unfortunately the prefixing can break scripts, as someone might have
wrote automation which expects output in the format it has always been.
In programmer terms, the change has an ABI change, which some may find
annoying.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
fdisks/sfdisk.c | 223 ++++++++++++++++++++++++++------------------------------
1 file changed, 104 insertions(+), 119 deletions(-)
diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index ae17e8d..dce56d5 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -93,19 +93,6 @@ int opt_list = 0;
char *save_sector_file = NULL;
char *restore_sector_file = NULL;
-static void
-my_warn(char *s, ...) {
- va_list p;
-
- va_start(p, s);
- if (!quiet) {
- fflush(stdout);
- vfprintf(stderr, s, p);
- fflush(stderr);
- }
- va_end(p);
-}
-
/*
* A. About seeking
*/
@@ -393,7 +380,7 @@ get_geometry(char *dev, int fd, int silent) {
{
g.heads = g.sectors = g.cylinders = g.start = 0;
if (!silent)
- warnx(_("Disk %s: cannot get geometry\n"), dev);
+ warnx(_("Disk %s: cannot get geometry"), dev);
}
R.start = g.start;
@@ -410,7 +397,7 @@ get_geometry(char *dev, int fd, int silent) {
if (fstat(fd, &s) == 0 && S_ISREG(s.st_mode))
R.total_size = (s.st_size >> 9);
else if (!silent)
- warnx(_("Disk %s: cannot get size\n"), dev);
+ warnx(_("Disk %s: cannot get size"), dev);
} else
R.total_size = sectors;
@@ -442,28 +429,28 @@ get_cylindersize(char *dev, int fd, int silent) {
B.cylinders = B.total_size / B.cylindersize;
if (R.start && !force) {
- my_warn(_("Warning: start=%lu - this looks like a partition rather than\n"
+ warnx(_("Warning: start=%lu - this looks like a partition rather than\n"
"the entire disk. Using fdisk on it is probably meaningless.\n"
- "[Use the --force option if you really want this]\n"),
+ "[Use the --force option if you really want this]"),
R.start);
exit(EXIT_FAILURE);
}
#if 0
if (R.heads && B.heads != R.heads)
- my_warn(_("Warning: HDIO_GETGEO says that there are %lu heads\n"),
+ warnx(_("Warning: HDIO_GETGEO says that there are %lu heads"),
R.heads);
if (R.sectors && B.sectors != R.sectors)
- my_warn(_("Warning: HDIO_GETGEO says that there are %lu sectors\n"),
+ warnx(_("Warning: HDIO_GETGEO says that there are %lu sectors"),
R.sectors);
if (R.cylinders && B.cylinders != R.cylinders
&& B.cylinders < 65536 && R.cylinders < 65536)
- my_warn(_("Warning: BLKGETSIZE/HDIO_GETGEO says that there are %lu cylinders\n"),
+ warnx(_("Warning: BLKGETSIZE/HDIO_GETGEO says that there are %lu cylinders"),
R.cylinders);
#endif
if (B.sectors > 63)
- my_warn(_("Warning: unlikely number of sectors (%lu) - usually at most 63\n"
- "This will give problems with all software that uses C/H/S addressing.\n"),
+ warnx(_("Warning: unlikely number of sectors (%lu) - usually at most 63\n"
+ "This will give problems with all software that uses C/H/S addressing."),
B.sectors);
if (!silent)
printf(_("\nDisk %s: %lu cylinders, %lu heads, %lu sectors/track\n"),
@@ -552,18 +539,18 @@ chs_ok(chs a, char *v, char *w) {
if (is_equal_chs(a, zero_chs))
return 1;
if (B.heads && aa.h >= B.heads) {
- my_warn(_("%s of partition %s has impossible value for head: "
- "%lu (should be in 0-%lu)\n"), w, v, aa.h, B.heads - 1);
+ warnx(_("%s of partition %s has impossible value for head: "
+ "%lu (should be in 0-%lu)"), w, v, aa.h, B.heads - 1);
ret = 0;
}
if (B.sectors && (aa.s == 0 || aa.s > B.sectors)) {
- my_warn(_("%s of partition %s has impossible value for sector: "
- "%lu (should be in 1-%lu)\n"), w, v, aa.s, B.sectors);
+ warnx(_("%s of partition %s has impossible value for sector: "
+ "%lu (should be in 1-%lu)"), w, v, aa.s, B.sectors);
ret = 0;
}
if (B.cylinders && aa.c >= B.cylinders) {
- my_warn(_("%s of partition %s has impossible value for cylinders: "
- "%lu (should be in 0-%lu)\n"), w, v, aa.c, B.cylinders - 1);
+ warnx(_("%s of partition %s has impossible value for cylinders: "
+ "%lu (should be in 0-%lu)"), w, v, aa.c, B.cylinders - 1);
ret = 0;
}
return ret;
@@ -769,13 +756,13 @@ reread_disk_partition(char *dev, int fd) {
if (reread_ioctl(fd) ) {
warnx(_("The command to re-read the partition table failed.\n"
"Run partprobe(8), kpartx(8) or reboot your system now,\n"
- "before using mkfs\n"));
+ "before using mkfs"));
return 0;
}
}
if (close_fd(fd) != 0) {
- warn(_("Error closing %s\n"), dev);
+ warn(_("Error closing %s"), dev);
return 0;
}
printf("\n");
@@ -839,7 +826,7 @@ static void
set_format(char c) {
switch (c) {
default:
- warnx(_("unrecognized format - using sectors\n"));
+ warnx(_("unrecognized format - using sectors"));
/* fallthrough */
case 'S':
specified_format = F_SECTOR;
@@ -900,7 +887,7 @@ out_partition_header(char *dev, int format, struct geometry G) {
switch (format) {
default:
- warnx(_("unimplemented format - using %s\n"),
+ warnx(_("unimplemented format - using %s"),
G.cylindersize ? _("cylinders") : _("sectors"));
/* fallthrough */
case F_CYLINDER:
@@ -1083,17 +1070,17 @@ out_partition(char *dev, int format, struct part_desc *p,
aa = chs_to_longchs(a);
bb = chs_to_longchs(b);
if (a.s && !is_equal_chs(a, b))
- warnx(_("\t\tstart: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
+ printf(_("\t\tstart: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
a = (size ? ulong_to_chs(end, G) : zero_chs);
b = p->p.end_chs;
aa = chs_to_longchs(a);
bb = chs_to_longchs(b);
if (a.s && !is_equal_chs(a, b))
- warnx(_("\t\tend: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
+ printf(_("\t\tend: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
if (G.cylinders && G.cylinders < 1024 && bb.c > G.cylinders)
- warnx(_("partition ends on cylinder %ld, beyond the end of the disk\n"),
+ printf(_("partition ends on cylinder %ld, beyond the end of the disk\n"),
bb.c);
}
}
@@ -1104,12 +1091,12 @@ out_partitions(char *dev, struct disk_desc *z) {
if (z->partno == 0) {
if (!opt_list)
- warnx(_("No partitions found\n"));
+ warnx(_("No partitions found"));
} else {
if (get_fdisk_geometry(z) && !dump) {
warnx(_("Warning: The partition table looks like it was made\n"
" for C/H/S=*/%ld/%ld (instead of %ld/%ld/%ld).\n"
- "For this listing I'll assume that geometry.\n"),
+ "For this listing I'll assume that geometry."),
F.heads, F.sectors, B.cylinders, B.heads, B.sectors);
}
@@ -1167,13 +1154,13 @@ partitions_ok(int fd, struct disk_desc *z) {
for (p = partitions; p - partitions < partno; p++)
if (p->size == 0) {
if (p->p.sys_type != EMPTY_PARTITION)
- my_warn(_("Warning: partition %s has size 0 but is not marked Empty\n"),
+ warnx(_("Warning: partition %s has size 0 but is not marked Empty"),
PNO(p));
else if (p->p.bootable != 0)
- my_warn(_("Warning: partition %s has size 0 and is bootable\n"),
+ warnx(_("Warning: partition %s has size 0 and is bootable"),
PNO(p));
else if (p->p.start_sect != 0)
- my_warn(_("Warning: partition %s has size 0 and nonzero start\n"),
+ warnx(_("Warning: partition %s has size 0 and nonzero start"),
PNO(p));
/* all this is probably harmless, no error return */
}
@@ -1185,8 +1172,8 @@ partitions_ok(int fd, struct disk_desc *z) {
q = p->ep;
if (p->start < q->start
|| p->start + p->size > q->start + q->size) {
- my_warn(_("Warning: partition %s is not contained in "
- "partition %s\n"), PNO(p), PNO(q));
+ warnx(_("Warning: partition %s is not contained in "
+ "partition %s"), PNO(p), PNO(q));
return 0;
}
}
@@ -1197,7 +1184,7 @@ partitions_ok(int fd, struct disk_desc *z) {
for (q = p + 1; q < partitions + partno; q++)
if (q->size && !is_extended(q->p.sys_type))
if (!((p->start > q->start) ? disj(q, p) : disj(p, q))) {
- my_warn(_("Warning: partitions %s and %s overlap\n"),
+ warnx(_("Warning: partitions %s and %s overlap"),
PNO(p), PNO(q));
return 0;
}
@@ -1209,9 +1196,9 @@ partitions_ok(int fd, struct disk_desc *z) {
for (q = partitions; q < partitions + partno; q++)
if (is_extended(q->p.sys_type))
if (p->start <= q->start && p->start + p->size > q->start) {
- my_warn(_("Warning: partition %s contains part of "
+ warnx(_("Warning: partition %s contains part of "
"the partition table (sector %llu),\n"
- "and will destroy it when filled\n"),
+ "and will destroy it when filled"),
PNO(p), q->start);
return 0;
}
@@ -1222,12 +1209,12 @@ partitions_ok(int fd, struct disk_desc *z) {
for (p = partitions; p < partitions + partno; p++)
if (p->size) {
if (p->start == 0) {
- my_warn(_("Warning: partition %s starts at sector 0\n"),
+ warnx(_("Warning: partition %s starts at sector 0"),
PNO(p));
return 0;
}
if (p->size && p->start + p->size > ds) {
- my_warn(_("Warning: partition %s extends past end of disk\n"),
+ warnx(_("Warning: partition %s extends past end of disk"),
PNO(p));
return 0;
}
@@ -1243,9 +1230,9 @@ partitions_ok(int fd, struct disk_desc *z) {
unsigned long long bytes = p->size * sector_size;
int giga = bytes / 1000000000;
int hectogiga = (giga + 50) / 100;
- my_warn(_("Warning: partition %s has size %d.%d TB (%llu bytes),\n"
+ warnx(_("Warning: partition %s has size %d.%d TB (%llu bytes),\n"
"which is larger than the %llu bytes limit imposed\n"
- "by the DOS partition table for %d-byte sectors\n"),
+ "by the DOS partition table for %d-byte sectors"),
PNO(p), hectogiga / 10, hectogiga % 10,
bytes,
(unsigned long long) UINT_MAX * sector_size,
@@ -1259,8 +1246,8 @@ partitions_ok(int fd, struct disk_desc *z) {
unsigned long long bytes = p->start * sector_size;
int giga = bytes / 1000000000;
int hectogiga = (giga + 50) / 100;
- my_warn(_("Warning: partition %s starts at sector %llu (%d.%d TB for %d-byte sectors),\n"
- "which exceeds the DOS partition table limit of %llu sectors\n"),
+ warnx(_("Warning: partition %s starts at sector %llu (%d.%d TB for %d-byte sectors),\n"
+ "which exceeds the DOS partition table limit of %llu sectors"),
PNO(p),
p->start,
hectogiga / 10,
@@ -1279,8 +1266,8 @@ partitions_ok(int fd, struct disk_desc *z) {
if (p->p.sys_type == EXTENDED_PARTITION)
ect++;
if (ect > 1 && !Linux) {
- my_warn(_("Among the primary partitions, at most one can be extended\n"
- " (although this is not a problem under Linux)\n"));
+ warnx(_("Among the primary partitions, at most one can be extended\n"
+ " (although this is not a problem under Linux)"));
return 0;
}
}
@@ -1299,14 +1286,14 @@ partitions_ok(int fd, struct disk_desc *z) {
|| p->start / B.cylindersize !=
p->ep->start / B.cylindersize)
&& (p->p.start_sect >= B.cylindersize)) {
- my_warn(_("Warning: partition %s does not start "
- "at a cylinder boundary\n"), PNO(p));
+ warnx(_("Warning: partition %s does not start "
+ "at a cylinder boundary"), PNO(p));
if (specified_format == F_CYLINDER)
return 0;
}
if ((p->start + p->size) % B.cylindersize) {
- my_warn(_("Warning: partition %s does not end "
- "at a cylinder boundary\n"), PNO(p));
+ warnx(_("Warning: partition %s does not end "
+ "at a cylinder boundary"), PNO(p));
if (specified_format == F_CYLINDER)
return 0;
}
@@ -1324,22 +1311,22 @@ partitions_ok(int fd, struct disk_desc *z) {
if (pno == -1)
pno = p - partitions;
else if (p - partitions < 4) {
- my_warn(_("Warning: more than one primary partition is marked "
+ warnx(_("Warning: more than one primary partition is marked "
"bootable (active)\n"
"This does not matter for LILO, but the DOS MBR will "
- "not boot this disk.\n"));
+ "not boot this disk."));
break;
}
if (p - partitions >= 4) {
- my_warn(_("Warning: usually one can boot from primary partitions "
- "only\nLILO disregards the `bootable' flag.\n"));
+ warnx(_("Warning: usually one can boot from primary partitions "
+ "only\nLILO disregards the `bootable' flag."));
break;
}
}
if (pno == -1 || pno >= 4)
- my_warn(_("Warning: no primary partition is marked bootable (active)\n"
+ warnx(_("Warning: no primary partition is marked bootable (active)\n"
"This does not matter for LILO, but the DOS MBR will "
- "not boot this disk.\n"));
+ "not boot this disk."));
}
/* Is chs as we expect? */
@@ -1354,7 +1341,7 @@ partitions_ok(int fd, struct disk_desc *z) {
if (!Linux && !chs_ok(b, PNO(p), _("start")))
return 0;
if (a.s && !is_equal_chs(a, b))
- my_warn(_("partition %s: start: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
+ warnx(_("partition %s: start: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)"),
PNO(p), aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
a = p->size ? ulong_to_chs(p->start + p->size - 1, B) : zero_chs;
b = p->p.end_chs;
@@ -1363,10 +1350,10 @@ partitions_ok(int fd, struct disk_desc *z) {
if (!Linux && !chs_ok(b, PNO(p), _("end")))
return 0;
if (a.s && !is_equal_chs(a, b))
- my_warn(_("partition %s: end: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)\n"),
+ warnx(_("partition %s: end: (c,h,s) expected (%ld,%ld,%ld) found (%ld,%ld,%ld)"),
PNO(p), aa.c, aa.h, aa.s, bb.c, bb.h, bb.s);
if (B.cylinders && B.cylinders < 1024 && bb.c > B.cylinders)
- my_warn(_("partition %s ends on cylinder %ld, beyond the end of the disk\n"),
+ warnx(_("partition %s ends on cylinder %ld, beyond the end of the disk"),
PNO(p), bb.c);
}
@@ -1394,11 +1381,11 @@ extended_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
warnx(_("Warning: shifted start of the extd partition "
"from %lld to %lld\n"
"(For listing purposes only. "
- "Do not change its contents.)\n"), ep->start, start);
+ "Do not change its contents.)"), ep->start, start);
} else {
warnx(_("Warning: extended partition does not start at a "
"cylinder boundary.\n"
- "DOS and Linux will interpret the contents differently.\n"));
+ "DOS and Linux will interpret the contents differently."));
}
}
@@ -1416,7 +1403,7 @@ extended_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
cp = s->data + 0x1be;
if (pno + 4 >= ARRAY_SIZE(z->partitions)) {
- warnx(_("too many partitions - ignoring those past nr (%zu)\n"),
+ warnx(_("too many partitions - ignoring those past nr (%zu)"),
pno - 1);
break;
}
@@ -1431,7 +1418,7 @@ extended_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z)
if (is_extended(p.sys_type)) {
partitions[pno].start = start + p.start_sect;
if (next)
- warnx(_("tree of partitions?\n"));
+ warnx(_("tree of partitions?"));
else
next = partitions[pno].start; /* follow `upper' branch */
moretodo = 1;
@@ -1494,7 +1481,7 @@ bsd_partition(char *dev, int fd, struct part_desc *ep, struct disk_desc *z) {
while (bp - bp0 < BSD_MAXPARTITIONS && bp - bp0 < l->d_npartitions) {
if (pno + 1 >= ARRAY_SIZE(z->partitions)) {
warnx(_("too many partitions - ignoring those "
- "past nr (%zu)\n"), pno - 1);
+ "past nr (%zu)"), pno - 1);
break;
}
if (bp->p_fstype != BSD_FS_UNUSED) {
@@ -1540,7 +1527,7 @@ msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
|| pt.sys_type == EZD_PARTITION
|| pt.sys_type == DM6_AUX1PARTITION
|| pt.sys_type == DM6_AUX3PARTITION) {
- warnx(_("detected Disk Manager - unable to handle that\n"));
+ warnx(_("detected Disk Manager - unable to handle that"));
return 0;
}
@@ -1548,7 +1535,7 @@ msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
if (sig <= 0x1ae) {
memcpy(&magic, s->data + sig, sizeof(magic));
if (magic == 0x55aa && (1 & *(unsigned char *)(s->data + sig + 2))) {
- warnx(_("DM6 signature found - giving up\n"));
+ warnx(_("DM6 signature found - giving up"));
return 0;
}
}
@@ -1568,14 +1555,14 @@ msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
for (i = 0; i < 4; i++) {
if (is_extended(partitions[i].p.sys_type)) {
if (!partitions[i].size) {
- warnx(_("strange..., an extended partition of size 0?\n"));
+ warnx(_("strange..., an extended partition of size 0?"));
continue;
}
extended_partition(dev, fd, &partitions[i], z);
}
if (!bsd_later && is_bsd(partitions[i].p.sys_type)) {
if (!partitions[i].size) {
- warnx(_("strange..., a BSD partition of size 0?\n"));
+ warnx(_("strange..., a BSD partition of size 0?"));
continue;
}
bsd_partition(dev, fd, &partitions[i], z);
@@ -1586,7 +1573,7 @@ msdos_partition(char *dev, int fd, unsigned long start, struct disk_desc *z) {
for (i = 0; i < 4; i++) {
if (is_bsd(partitions[i].p.sys_type)) {
if (!partitions[i].size) {
- warnx(_("strange..., a BSD partition of size 0?\n"));
+ warnx(_("strange..., a BSD partition of size 0?"));
continue;
}
bsd_partition(dev, fd, &partitions[i], z);
@@ -1630,7 +1617,7 @@ get_partitions(char *dev, int fd, struct disk_desc *z) {
&& !sun_partition(dev, fd, 0, z)
&& !amiga_partition(dev, fd, 0, z)) {
if (!opt_list)
- warnx(_(" %s: unrecognized partition table type\n"), dev);
+ warnx(_(" %s: unrecognized partition table type"), dev);
return;
}
}
@@ -1642,7 +1629,7 @@ write_partitions(char *dev, int fd, struct disk_desc *z) {
int pno = z->partno;
if (no_write) {
- warnx(_("-n flag was given: Nothing changed\n"));
+ warnx(_("-n flag was given: Nothing changed"));
exit(EXIT_SUCCESS);
}
@@ -1836,11 +1823,11 @@ get_ul(char *u, unsigned long *up, unsigned long def, int base) {
errno = 0;
val = strtoul(u, &nu, base);
if (errno == ERANGE) {
- warnx(_("number too big\n"));
+ warnx(_("number too big"));
return -1;
}
if (*nu) {
- warnx(_("trailing junk after number\n"));
+ warnx(_("trailing junk after number"));
return -1;
}
if (sign == 1)
@@ -1873,11 +1860,11 @@ get_ull(char *u, unsigned long long *up, unsigned long long def, int base) {
errno = 0;
val = strtoull(u, &nu, base);
if (errno == ERANGE) {
- warnx(_("number too big\n"));
+ warnx(_("number too big"));
return -1;
}
if (*nu) {
- warnx(_("trailing junk after number\n"));
+ warnx(_("trailing junk after number"));
return -1;
}
if (sign == 1)
@@ -2002,7 +1989,7 @@ compute_start_sect(struct part_desc *p, struct part_desc *ep) {
if (is_extended(p->p.sys_type) && boxes == ONESECTOR)
p->size = inc;
else if ((long long) old_size <= -delta) {
- my_warn(_("no room for partition descriptor\n"));
+ warnx(_("no room for partition descriptor"));
return 0;
}
}
@@ -2035,7 +2022,7 @@ build_surrounding_extended(struct part_desc *p, struct part_desc *ep,
ep->start = first_free(ep - p0, 1, eep, format, p->start, z);
ep->size = max_length(ep - p0, 1, eep, format, ep->start, z);
if (ep->start > p->start || ep->start + ep->size < p->start + p->size) {
- my_warn(_("cannot build surrounding extended partition\n"));
+ warnx(_("cannot build surrounding extended partition"));
return 0;
}
} else {
@@ -2075,8 +2062,8 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
if (interactive) {
if (pct == 0 && (show_extended || pno == 0))
- my_warn("\n");
- my_warn("%s:", partname(dev, lpno, 10));
+ putchar('\n');
+ warnx("%s:", partname(dev, lpno, 10));
}
/* read input line - skip blank lines when reading from a file */
@@ -2086,7 +2073,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
if (fno == RD_EOF) {
return -1;
} else if (fno > 10 && *(fields[10]) != 0) {
- warnx(_("too many input fields\n"));
+ warnx(_("too many input fields"));
return 0;
}
@@ -2120,7 +2107,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
}
if (ml == 0 && pno >= 4) {
/* no free blocks left - don't read any further */
- my_warn(_("No room for more\n"));
+ warnx(_("No room for more"));
return -1;
}
}
@@ -2139,7 +2126,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
else if (get_ull(fields[2], &ul, LINUX_NATIVE, 16))
return 0;
if (ul > 255) {
- my_warn(_("Illegal type\n"));
+ warnx(_("Illegal type"));
return 0;
}
p.p.sys_type = ul;
@@ -2173,13 +2160,13 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
p.size -= (p.size % unitsize(format));
}
if (p.size > ml1) {
- my_warn(_("Warning: given size (%lu) exceeds max allowable size (%lu)\n"),
+ warnx(_("Warning: given size (%llu) exceeds max allowable size (%llu)"),
(p.size + unitsize(0) - 1) / unitsize(0), ml1 / unitsize(0));
if (!force)
return 0;
}
if (p.size == 0 && pno >= 4 && (fno < 2 || !*(fields[1]))) {
- my_warn(_("Warning: empty partition\n"));
+ warnx(_("Warning: empty partition"));
if (!force)
return 0;
}
@@ -2193,7 +2180,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
}
if (p.start < ff1 && p.size > 0) {
- my_warn(_("Warning: bad partition start (earliest %lu)\n"),
+ warnx(_("Warning: bad partition start (earliest %llu)"),
(ff1 + unitsize(0) - 1) / unitsize(0));
if (!force)
return 0;
@@ -2206,7 +2193,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
else if (!strcmp(fields[3], "*") || !strcmp(fields[3], "+"))
ul = 0x80;
else {
- my_warn(_("unrecognized bootable flag - choose - or *\n"));
+ warnx(_("unrecognized bootable flag - choose - or *"));
return 0;
}
p.p.bootable = ul;
@@ -2223,7 +2210,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
if (fno < 5) {
bb = aa;
} else if (fno < 7) {
- my_warn(_("partial c,h,s specification?\n"));
+ warnx(_("partial c,h,s specification?"));
return 0;
} else if (get_ul(fields[4], &bb.c, aa.c, 0) ||
get_ul(fields[5], &bb.h, aa.h, 0) ||
@@ -2237,7 +2224,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
if (fno < 8) {
bb = aa;
} else if (fno < 10) {
- my_warn(_("partial c,h,s specification?\n"));
+ warnx(_("partial c,h,s specification?"));
return 0;
} else if (get_ul(fields[7], &bb.c, aa.c, 0) ||
get_ul(fields[8], &bb.h, aa.h, 0) ||
@@ -2248,7 +2235,7 @@ read_line(int pno, struct part_desc *ep, char *dev, int interactive,
if (pno > 3 && p.size && show_extended && p.p.sys_type != EMPTY_PARTITION
&& (is_extended(p.p.sys_type) != (pct == 1))) {
- my_warn(_("Extended partition not where expected\n"));
+ warnx(_("Extended partition not where expected"));
if (!force)
return 0;
}
@@ -2303,7 +2290,7 @@ read_partition_chain(char *dev, int interactive, struct part_desc *ep,
while (1) {
base = z->partno;
if (base + 4 > ARRAY_SIZE(z->partitions)) {
- warnx(_("too many partitions\n"));
+ warnx(_("too many partitions"));
break;
}
for (i = 0; i < 4; i++)
@@ -2336,9 +2323,9 @@ read_input(char *dev, int interactive, struct disk_desc *z) {
z->partno = 0;
if (interactive)
- my_warn(_("Input in the following format; absent fields get a default value.\n"
+ warnx(_("Input in the following format; absent fields get a default value.\n"
"<start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s>\n"
- "Usually you only need to specify <start> and <size> (and perhaps <type>).\n"));
+ "Usually you only need to specify <start> and <size> (and perhaps <type>)."));
eof = 0;
for (i = 0; i < 4; i++)
@@ -2798,7 +2785,7 @@ do_list(char *dev, int silent) {
if (verify) {
if (partitions_ok(fd, z))
- my_warn(_("%s: OK\n"), dev);
+ printf(_("%s: OK"), dev);
else
exit_status = 1;
}
@@ -2947,7 +2934,7 @@ do_activate(char **av, int ac, char *arg) {
else
printf("%s#%d\n", dev, pno);
if (z->partitions[pno].p.bootable != 0x80)
- my_warn(_("bad active byte: 0x%x instead of 0x80\n"),
+ warnx(_("bad active byte: 0x%x instead of 0x80"),
z->partitions[pno].p.bootable);
}
}
@@ -2966,7 +2953,7 @@ do_activate(char **av, int ac, char *arg) {
/* then write to disk */
if (write_partitions(dev, fd, z))
- my_warn(_("Done\n\n"));
+ warnx(_("Done"));
else
exit_status = 1;
}
@@ -2975,12 +2962,12 @@ do_activate(char **av, int ac, char *arg) {
if (z->partitions[pno].p.bootable)
i++;
if (i != 1)
- my_warn(_("You have %d active primary partitions. This does not matter for LILO,\n"
- "but the DOS MBR will only boot a disk with 1 active partition.\n"),
+ warnx(_("You have %d active primary partitions. This does not matter for LILO,\n"
+ "but the DOS MBR will only boot a disk with 1 active partition."),
i);
if (close_fd(fd) != 0) {
- my_warn(_("write failed"));
+ warnx(_("write failed"));
exit_status = 1;
}
}
@@ -3011,13 +2998,13 @@ do_change_id(char *dev, char *pnam, char *id) {
z->partitions[pno].p.sys_type = i;
if (write_partitions(dev, fd, z))
- my_warn(_("Done\n\n"));
+ warnx(_("Done"));
else
exit_status = 1;
done:
if (close_fd(fd) != 0) {
- my_warn(_("write failed"));
+ warnx(_("write failed"));
exit_status = 1;
}
}
@@ -3028,7 +3015,7 @@ do_reread(char *dev) {
fd = my_open(dev, 0, 0);
if (reread_ioctl(fd)) {
- warnx(_("This disk is currently in use.\n"));
+ warnx(_("This disk is currently in use."));
exit(EXIT_FAILURE);
}
@@ -3050,23 +3037,21 @@ do_fdisk(char *dev) {
if (stat(dev, &statbuf) < 0)
err(EXIT_FAILURE, _("Fatal error: cannot find %s"), dev);
if (!S_ISBLK(statbuf.st_mode)) {
- warnx(_("Warning: %s is not a block device\n"), dev);
+ warnx(_("Warning: %s is not a block device"), dev);
no_reread = 1;
}
fd = my_open(dev, !no_write, 0);
if (!no_write && !no_reread) {
- my_warn(_("Checking that no-one is using this disk right now ...\n"));
+ warnx(_("Checking that no-one is using this disk right now ..."));
if (reread_ioctl(fd)) {
warnx(_("\nThis disk is currently in use - repartitioning is probably a bad idea.\n"
"Umount all file systems, and swapoff all swap partitions on this disk.\n"
- "Use the --no-reread flag to suppress this check.\n"));
- if (!force) {
- warnx(_("Use the --force flag to overrule all checks.\n"));
- exit(EXIT_FAILURE);
- }
+ "Use the --no-reread flag to suppress this check."));
+ if (!force)
+ errx(EXIT_FAILURE, _("Use the --force flag to overrule all checks."));
} else
- my_warn(_("OK\n"));
+ warnx(_("OK"));
}
z = &oldp;
@@ -3095,7 +3080,7 @@ do_fdisk(char *dev) {
errx(EXIT_FAILURE, _("I don't like these partitions - nothing changed.\n"
"(If you really want this, use the --force option.)"));
else
- warnx(_("I don't like this - probably you should answer No\n"));
+ warnx(_("I don't like this - probably you should answer No"));
}
if (interactive) {
ask:
@@ -3129,9 +3114,9 @@ do_fdisk(char *dev) {
close(fd);
exit_status = 1;
}
- my_warn(_("If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)\n"
+ warnx(_("If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)\n"
"to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1\n"
- "(See fdisk(8).)\n"));
+ "(See fdisk(8).)"));
sync(); /* superstition */
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 08/15] dmesg: convert time format bitfield to enum
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (6 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 07/15] sfdisk: replace my_warn() with warnx() Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-07-01 9:36 ` Karel Zak
2013-06-16 18:53 ` [PATCH 09/15] dmesg: add --time-format option Sami Kerola
` (8 subsequent siblings)
16 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Foremost this commit makes time printing formats explicit.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/dmesg.c | 159 ++++++++++++++++++++++++++----------------------------
1 file changed, 77 insertions(+), 82 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index ae8e938..5677836 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -126,6 +126,17 @@ enum {
DMESG_METHOD_MMAP /* mmap file with records (see --file) */
};
+enum {
+ DMESG_TIMEFTM_NONE = 0,
+ DMESG_TIMEFTM_CTIME, /* [ctime] */
+ DMESG_TIMEFTM_CTIME_DELTA, /* [ctime <delta>] */
+ DMESG_TIMEFTM_DELTA, /* [<delta>] */
+ DMESG_TIMEFTM_RELTIME, /* [relative] */
+ DMESG_TIMEFTM_TIME, /* [time] */
+ DMESG_TIMEFTM_TIME_DELTA /* [time <delta>] */
+};
+#define is_timefmt(c, f) (c->time_fmt == (DMESG_TIMEFTM_ ##f))
+
struct dmesg_control {
/* bit arrays -- see include/bitops.h */
char levels[ARRAY_SIZE(level_names) / NBBY + 1];
@@ -152,16 +163,13 @@ struct dmesg_control {
char *filename;
char *mmap_buff;
size_t pagesize;
+ unsigned int time_fmt; /* time format */
unsigned int follow:1, /* wait for new messages */
raw:1, /* raw mode */
fltr_lev:1, /* filter out by levels[] */
fltr_fac:1, /* filter out by facilities[] */
decode:1, /* use "facility: level: " prefix */
- notime:1, /* don't print timestamp */
- delta:1, /* show time deltas */
- reltime:1, /* show human readable relative times */
- ctime:1, /* show human readable time */
pager:1, /* pipe output into a pager */
color:1; /* colorize messages */
};
@@ -689,9 +697,10 @@ static int get_next_syslog_record(struct dmesg_control *ctl,
if (*begin == '[' && (*(begin + 1) == ' ' ||
isdigit(*(begin + 1)))) {
- if (ctl->delta || ctl->ctime || ctl->reltime)
+
+ if (!is_timefmt(ctl, NONE))
begin = parse_syslog_timestamp(begin + 1, &rec->tv);
- else if (ctl->notime)
+ else
begin = skip_item(begin, end, "]");
if (begin < end && *begin == ' ')
@@ -852,79 +861,53 @@ static void print_record(struct dmesg_control *ctl,
printf("%-6s:%-6s: ", facility_names[rec->facility].name,
level_names[rec->level].name);
- /*
- * [sec.usec <delta>] or [ctime <delta>]
- */
- if (ctl->delta) {
- if (ctl->color)
- color_enable(DMESG_COLOR_TIME);
- if (ctl->ctime)
- printf("[%s ", record_ctime(ctl, rec, buf, sizeof(buf)));
- else if (ctl->notime)
- putchar('[');
- else
- printf("[%5d.%06d ", (int) rec->tv.tv_sec,
- (int) rec->tv.tv_usec);
- printf("<%12.06f>] ", record_count_delta(ctl, rec));
- if (ctl->color)
- color_disable();
+ if (ctl->color)
+ color_enable(DMESG_COLOR_TIME);
- /*
- * [ctime]
- */
- } else if (ctl->ctime) {
- if (ctl->color)
- color_enable(DMESG_COLOR_TIME);
- printf("[%s] ", record_ctime(ctl, rec, buf, sizeof(buf)));
- if (ctl->color)
- color_disable();
- }
-
- /*
- * [reltime]
- */
- else if (ctl->reltime) {
+ switch (ctl->time_fmt) {
double delta;
struct tm cur;
-
+ case DMESG_TIMEFTM_NONE:
+ break;
+ case DMESG_TIMEFTM_CTIME:
+ printf("[%s] ", record_ctime(ctl, rec, buf, sizeof(buf)));
+ break;
+ case DMESG_TIMEFTM_CTIME_DELTA:
+ printf("[%s <%12.06f>] ",
+ record_ctime(ctl, rec, buf, sizeof(buf)),
+ record_count_delta(ctl, rec));
+ break;
+ case DMESG_TIMEFTM_DELTA:
+ printf("[<%12.06f>] ", record_count_delta(ctl, rec));
+ break;
+ case DMESG_TIMEFTM_RELTIME:
record_localtime(ctl, rec, &cur);
delta = record_count_delta(ctl, rec);
-
- if (cur.tm_min != ctl->lasttm.tm_min ||
+ if (cur.tm_min != ctl->lasttm.tm_min ||
cur.tm_hour != ctl->lasttm.tm_hour ||
cur.tm_yday != ctl->lasttm.tm_yday) {
- if (ctl->color)
- color_enable(DMESG_COLOR_RELTIME);
printf("[%s] ", short_ctime(&cur, buf, sizeof(buf)));
} else {
- if (ctl->color)
- color_enable(DMESG_COLOR_TIME);
if (delta < 10)
printf("[ %+8.06f] ", delta);
else
printf("[ %+9.06f] ", delta);
}
- if (ctl->color)
- color_disable();
ctl->lasttm = cur;
+ break;
+ case DMESG_TIMEFTM_TIME:
+ printf("[%5d.%06d] ", (int)rec->tv.tv_sec, (int)rec->tv.tv_usec);
+ break;
+ case DMESG_TIMEFTM_TIME_DELTA:
+ printf("[%5d.%06d <%12.06f>] ", (int)rec->tv.tv_sec,
+ (int)rec->tv.tv_usec, record_count_delta(ctl, rec));
+ break;
+ default:
+ abort();
}
- /*
- * In syslog output the timestamp is part of the message and we don't
- * parse the timestamp by default. We parse the timestamp only if
- * --show-delta or --ctime is specified.
- *
- * In kmsg output we always parse the timesptamp, so we have to compose
- * the [sec.usec] string.
- */
- if (ctl->method == DMESG_METHOD_KMSG &&
- !ctl->notime && !ctl->delta && !ctl->ctime && !ctl->reltime) {
- if (ctl->color)
- color_enable(DMESG_COLOR_TIME);
- printf("[%5d.%06d] ", (int) rec->tv.tv_sec, (int) rec->tv.tv_usec);
- if (ctl->color)
- color_disable();
- }
+ if (ctl->color)
+ color_disable();
mesg:
mesg = rec->mesg;
@@ -1065,7 +1048,7 @@ static int parse_kmsg_record(struct dmesg_control *ctl,
goto mesg;
/* C) timestamp */
- if (ctl->notime)
+ if (is_timefmt(ctl, NONE))
p = skip_item(p, end, ",;");
else
p = parse_kmsg_timestamp(p, &rec->tv);
@@ -1136,18 +1119,22 @@ static int read_kmsg(struct dmesg_control *ctl)
return 0;
}
+#undef is_timefmt
+#define is_timefmt(c, f) (c.time_fmt == (DMESG_TIMEFTM_ ##f))
int main(int argc, char *argv[])
{
char *buf = NULL;
int c, nopager = 0;
int console_level = 0;
int klog_rc = 0;
+ int delta = 0;
ssize_t n;
static struct dmesg_control ctl = {
.filename = NULL,
.action = SYSLOG_ACTION_READ_ALL,
.method = DMESG_METHOD_KMSG,
.kmsg = -1,
+ .time_fmt = DMESG_TIMEFTM_TIME,
};
int colormode = UL_COLORMODE_NEVER;
@@ -1209,13 +1196,13 @@ int main(int argc, char *argv[])
ctl.action = SYSLOG_ACTION_CONSOLE_OFF;
break;
case 'd':
- ctl.delta = 1;
+ delta = 1;
break;
case 'E':
ctl.action = SYSLOG_ACTION_CONSOLE_ON;
break;
case 'e':
- ctl.reltime = 1;
+ ctl.time_fmt = DMESG_TIMEFTM_RELTIME;
break;
case 'F':
ctl.filename = optarg;
@@ -1228,7 +1215,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
break;
case 'H':
- ctl.reltime = 1;
+ ctl.time_fmt = DMESG_TIMEFTM_RELTIME;
ctl.color = 1;
ctl.pager = 1;
break;
@@ -1260,6 +1247,8 @@ int main(int argc, char *argv[])
break;
case 'r':
ctl.raw = 1;
+ ctl.time_fmt = DMESG_TIMEFTM_NONE;
+ delta = 0;
break;
case 'S':
ctl.method = DMESG_METHOD_SYSLOG;
@@ -1271,12 +1260,11 @@ int main(int argc, char *argv[])
ctl.bufsize = 4096;
break;
case 'T':
- ctl.boot_time = get_boot_time();
- if (ctl.boot_time)
- ctl.ctime = 1;
+ ctl.time_fmt = DMESG_TIMEFTM_CTIME;
break;
case 't':
- ctl.notime = 1;
+ ctl.time_fmt = DMESG_TIMEFTM_NONE;
+ delta = 0;
break;
case 'u':
ctl.fltr_fac = 1;
@@ -1304,22 +1292,29 @@ int main(int argc, char *argv[])
if (argc > 1)
usage(stderr);
- if (ctl.raw && (ctl.fltr_lev || ctl.fltr_fac || ctl.delta ||
- ctl.notime || ctl.ctime || ctl.decode))
- errx(EXIT_FAILURE, _("--raw can't be used together with level, "
- "facility, decode, delta, ctime or notime options"));
-
- if (ctl.notime && (ctl.ctime || ctl.reltime))
- errx(EXIT_FAILURE, _("--notime can't be used together with --ctime or --reltime"));
- if (ctl.reltime && ctl.ctime)
- errx(EXIT_FAILURE, _("--reltime can't be used together with --ctime "));
-
- if (ctl.reltime) {
+ if (is_timefmt(ctl, RELTIME) || is_timefmt(ctl, CTIME)) {
ctl.boot_time = get_boot_time();
if (!ctl.boot_time)
- ctl.reltime = 0;
+ ctl.time_fmt = DMESG_TIMEFTM_NONE;
}
+ if (delta)
+ switch (ctl.time_fmt) {
+ case DMESG_TIMEFTM_CTIME:
+ ctl.time_fmt = DMESG_TIMEFTM_CTIME_DELTA;
+ break;
+ case DMESG_TIMEFTM_TIME:
+ ctl.time_fmt = DMESG_TIMEFTM_TIME_DELTA;
+ break;
+ default:
+ ctl.time_fmt = DMESG_TIMEFTM_DELTA;
+ }
+
+ if (ctl.raw
+ && (ctl.fltr_lev || ctl.fltr_fac || ctl.decode || !is_timefmt(ctl, NONE)))
+ errx(EXIT_FAILURE, _("--raw can't be used together with level, "
+ "facility, decode, delta, ctime or notime options"));
+
ctl.color = colors_init(colormode) ? 1 : 0;
ctl.pager = nopager ? 0 : ctl.pager;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 09/15] dmesg: add --time-format option
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (7 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 08/15] dmesg: convert time format bitfield to enum Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 10/15] dmesg: add iso-8601 time format Sami Kerola
` (7 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/dmesg.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 5677836..2199e7f 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -257,6 +257,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -u, --userspace display userspace messages\n"), out);
fputs(_(" -w, --follow wait for new messages\n"), out);
fputs(_(" -x, --decode decode facility and level to readable string\n"), out);
+ fputs(_(" --time-format <format> show time stamp using format:\n"
+ " [delta|reltime|ctime|notime]\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
@@ -1119,6 +1121,19 @@ static int read_kmsg(struct dmesg_control *ctl)
return 0;
}
+static int which_time_format(const char *optarg)
+{
+ if (!strcmp(optarg, "notime"))
+ return DMESG_TIMEFTM_NONE;
+ if (!strcmp(optarg, "ctime"))
+ return DMESG_TIMEFTM_CTIME;
+ if (!strcmp(optarg, "delta"))
+ return DMESG_TIMEFTM_DELTA;
+ if (!strcmp(optarg, "reltime"))
+ return DMESG_TIMEFTM_RELTIME;
+ errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+}
+
#undef is_timefmt
#define is_timefmt(c, f) (c.time_fmt == (DMESG_TIMEFTM_ ##f))
int main(int argc, char *argv[])
@@ -1137,6 +1152,9 @@ int main(int argc, char *argv[])
.time_fmt = DMESG_TIMEFTM_TIME,
};
int colormode = UL_COLORMODE_NEVER;
+ enum {
+ OPT_TIME_FORMAT = CHAR_MAX + 1,
+ };
static const struct option longopts[] = {
{ "buffer-size", required_argument, NULL, 's' },
@@ -1163,6 +1181,7 @@ int main(int argc, char *argv[])
{ "nopager", no_argument, NULL, 'P' },
{ "userspace", no_argument, NULL, 'u' },
{ "version", no_argument, NULL, 'V' },
+ { "time-format", required_argument, NULL, OPT_TIME_FORMAT },
{ NULL, 0, NULL, 0 }
};
@@ -1281,6 +1300,9 @@ int main(int argc, char *argv[])
case 'x':
ctl.decode = 1;
break;
+ case OPT_TIME_FORMAT:
+ ctl.time_fmt = which_time_format(optarg);
+ break;
case '?':
default:
usage(stderr);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 10/15] dmesg: add iso-8601 time format
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (8 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 09/15] dmesg: add --time-format option Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-07-01 9:25 ` Karel Zak
2013-06-16 18:53 ` [PATCH 11/15] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
` (6 subsequent siblings)
16 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The ISO-8601 should be welcomed by anyone who tries to parse dmesg time
stamp, and compare them across servers. Time format tries to imitate
coreutils 'date --iso-8601=ns' output, but instead of having nanoseconds
the dmesg is using microseconds.
Reference: http://www.cs.tut.fi/~jkorpela/iso8601.html
Addresses: http://xkcd.com/1179/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/dmesg.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 2199e7f..be08f6c 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -133,7 +133,8 @@ enum {
DMESG_TIMEFTM_DELTA, /* [<delta>] */
DMESG_TIMEFTM_RELTIME, /* [relative] */
DMESG_TIMEFTM_TIME, /* [time] */
- DMESG_TIMEFTM_TIME_DELTA /* [time <delta>] */
+ DMESG_TIMEFTM_TIME_DELTA, /* [time <delta>] */
+ DMESG_TIMEFTM_ISO8601 /* 2013-06-13T22:11:00,123456+0100 */
};
#define is_timefmt(c, f) (c->time_fmt == (DMESG_TIMEFTM_ ##f))
@@ -258,7 +259,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -w, --follow wait for new messages\n"), out);
fputs(_(" -x, --decode decode facility and level to readable string\n"), out);
fputs(_(" --time-format <format> show time stamp using format:\n"
- " [delta|reltime|ctime|notime]\n"), out);
+ " [delta|reltime|ctime|notime|iso]\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
@@ -794,6 +795,23 @@ static char *short_ctime(struct tm *tm, char *buf, size_t bufsiz)
return buf;
}
+static char *iso_8601_time(struct dmesg_control *ctl, struct dmesg_record *rec,
+ char *buf, size_t bufsiz)
+{
+ struct tm tm;
+ size_t len;
+ record_localtime(ctl, rec, &tm);
+ if (strftime(buf, bufsiz, "%Y-%m-%dT%H:%M:%S", &tm) == 0) {
+ *buf = '\0';
+ return buf;
+ }
+ len = strlen(buf);
+ snprintf(buf + len, bufsiz - len, ",%06d", (int)rec->tv.tv_usec);
+ len = strlen(buf);
+ strftime(buf + len, bufsiz - len, "%z", &tm);
+ return buf;
+}
+
static double record_count_delta(struct dmesg_control *ctl,
struct dmesg_record *rec)
{
@@ -904,6 +922,9 @@ static void print_record(struct dmesg_control *ctl,
printf("[%5d.%06d <%12.06f>] ", (int)rec->tv.tv_sec,
(int)rec->tv.tv_usec, record_count_delta(ctl, rec));
break;
+ case DMESG_TIMEFTM_ISO8601:
+ printf("%s ", iso_8601_time(ctl, rec, buf, sizeof(buf)));
+ break;
default:
abort();
}
@@ -1131,6 +1152,8 @@ static int which_time_format(const char *optarg)
return DMESG_TIMEFTM_DELTA;
if (!strcmp(optarg, "reltime"))
return DMESG_TIMEFTM_RELTIME;
+ if (!strcmp(optarg, "iso"))
+ return DMESG_TIMEFTM_ISO8601;
errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
}
@@ -1314,7 +1337,7 @@ int main(int argc, char *argv[])
if (argc > 1)
usage(stderr);
- if (is_timefmt(ctl, RELTIME) || is_timefmt(ctl, CTIME)) {
+ if (is_timefmt(ctl, RELTIME) || is_timefmt(ctl, CTIME) || is_timefmt(ctl, ISO8601)) {
ctl.boot_time = get_boot_time();
if (!ctl.boot_time)
ctl.time_fmt = DMESG_TIMEFTM_NONE;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 11/15] docs: add --time-format option and ISO-8601 format to manual
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (9 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 10/15] dmesg: add iso-8601 time format Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 12/15] dmesg: regroup time related options close to each other Sami Kerola
` (5 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/dmesg.1 | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/sys-utils/dmesg.1 b/sys-utils/dmesg.1
index c060688..ce186d8 100644
--- a/sys-utils/dmesg.1
+++ b/sys-utils/dmesg.1
@@ -153,6 +153,28 @@ Wait for new messages. This feature is supported on systems with readable
/dev/kmsg only (since kernel 3.5.0).
.IP "\fB\-x\fR, \fB\-\-decode\fR"
Decode facility and level (priority) number to human readable prefixes.
+.IP "\fB\-\-time\-format\fR \fIformat\fR"
+Print time stam using format
+.IR ctime ,
+.IR delta ,
+.I reltime
+or
+.IR iso .
+The three first time formats are aliases of time format specific options.
+The
+.I iso
+is a
+.B dmesg
+implementation of ISO-8601 timestamp format. Purpose of this format is
+to make comparing of timestamps in between two system, and other parsing,
+easy. The defition of timestamp is YYYY-MM-DD<T stands for date and time
+separator>HH:MM:SS,<microseconds><-+><GMT-0 timezone offset>.
+.IP
+The
+.I iso
+time format has the same issue as
+.IR ctime ,
+the time may be inaccurate if a system is suspended and resumed.
.SH SEE ALSO
.BR syslogd (8)
.SH AUTHORS
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 12/15] dmesg: regroup time related options close to each other
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (10 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 11/15] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 13/15] sd-daemon: update files taken from systemd project Sami Kerola
` (4 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/dmesg.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index be08f6c..480c897 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -238,8 +238,6 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -C, --clear clear the kernel ring buffer\n"), out);
fputs(_(" -c, --read-clear read and clear all messages\n"), out);
fputs(_(" -D, --console-off disable printing messages to console\n"), out);
- fputs(_(" -d, --show-delta show time delta between printed messages\n"), out);
- fputs(_(" -e, --reltime show local time and time delta in readable format\n"), out);
fputs(_(" -E, --console-on enable printing messages to console\n"), out);
fputs(_(" -F, --file <file> use the file instead of the kernel log buffer\n"), out);
fputs(_(" -f, --facility <list> restrict output to defined facilities\n"), out);
@@ -252,14 +250,16 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -r, --raw print the raw message buffer\n"), out);
fputs(_(" -S, --syslog force to use syslog(2) rather than /dev/kmsg\n"), out);
fputs(_(" -s, --buffer-size <size> buffer size to query the kernel ring buffer\n"), out);
- fputs(_(" -T, --ctime show human readable timestamp (could be \n"
- " inaccurate if you have used SUSPEND/RESUME)\n"), out);
- fputs(_(" -t, --notime don't print messages timestamp\n"), out);
fputs(_(" -u, --userspace display userspace messages\n"), out);
fputs(_(" -w, --follow wait for new messages\n"), out);
fputs(_(" -x, --decode decode facility and level to readable string\n"), out);
+ fputs(_(" -d, --show-delta show time delta between printed messages\n"), out);
+ fputs(_(" -e, --reltime show local time and time delta in readable format\n"), out);
+ fputs(_(" -T, --ctime show human readable timestamp\n"), out);
+ fputs(_(" -t, --notime don't print messages timestamp\n"), out);
fputs(_(" --time-format <format> show time stamp using format:\n"
- " [delta|reltime|ctime|notime|iso]\n"), out);
+ " [delta|reltime|ctime|notime|iso]\n"
+ "Suspending/resume will make ctime and iso timestamps inaccurate.\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 13/15] sd-daemon: update files taken from systemd project
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (11 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 12/15] dmesg: regroup time related options close to each other Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 14/15] hexdump: remove unnecessary global variables Sami Kerola
` (3 subsequent siblings)
16 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Update sd-damoen.[hc] files from systemd upstream, using commit
fa3868c6d317b88715c55422b898f9070afe6575 as the sync point.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/sd-daemon.c | 100 ++++++++++++++++++++++---------------------------
misc-utils/sd-daemon.h | 14 +++----
2 files changed, 52 insertions(+), 62 deletions(-)
diff --git a/misc-utils/sd-daemon.c b/misc-utils/sd-daemon.c
index 763e079..485b301 100644
--- a/misc-utils/sd-daemon.c
+++ b/misc-utils/sd-daemon.c
@@ -25,18 +25,14 @@
***/
#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+# define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
-#ifdef __BIONIC__
-#include <linux/fcntl.h>
-#else
-#include <sys/fcntl.h>
-#endif
+#include <fcntl.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <errno.h>
@@ -47,22 +43,22 @@
#include <stddef.h>
#include <limits.h>
-#if defined(__linux__)
-#include <mqueue.h>
+#if defined(__linux__) && !defined(SD_DAEMON_DISABLE_MQ)
+# include <mqueue.h>
#endif
#include "sd-daemon.h"
#if (__GNUC__ >= 4)
-#ifdef SD_EXPORT_SYMBOLS
+# ifdef SD_EXPORT_SYMBOLS
/* Export symbols */
-#define _sd_export_ __attribute__ ((visibility("default")))
-#else
+# define _sd_export_ __attribute__ ((visibility("default")))
+# else
/* Don't export the symbols */
-#define _sd_export_ __attribute__ ((visibility("hidden")))
-#endif
+# define _sd_export_ __attribute__ ((visibility("hidden")))
+# endif
#else
-#define _sd_export_
+# define _sd_export_
#endif
_sd_export_ int sd_listen_fds(int unset_environment) {
@@ -75,7 +71,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
char *p = NULL;
unsigned long l;
- if (!(e = getenv("LISTEN_PID"))) {
+ e = getenv("LISTEN_PID");
+ if (!e) {
r = 0;
goto finish;
}
@@ -83,12 +80,12 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
errno = 0;
l = strtoul(e, &p, 10);
- if (errno != 0) {
+ if (errno > 0) {
r = -errno;
goto finish;
}
- if (!p || *p || l <= 0) {
+ if (!p || p == e || *p || l <= 0) {
r = -EINVAL;
goto finish;
}
@@ -99,7 +96,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
goto finish;
}
- if (!(e = getenv("LISTEN_FDS"))) {
+ e = getenv("LISTEN_FDS");
+ if (!e) {
r = 0;
goto finish;
}
@@ -107,12 +105,12 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
errno = 0;
l = strtoul(e, &p, 10);
- if (errno != 0) {
+ if (errno > 0) {
r = -errno;
goto finish;
}
- if (!p || *p) {
+ if (!p || p == e || *p) {
r = -EINVAL;
goto finish;
}
@@ -120,7 +118,8 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
int flags;
- if ((flags = fcntl(fd, F_GETFD)) < 0) {
+ flags = fcntl(fd, F_GETFD);
+ if (flags < 0) {
r = -errno;
goto finish;
}
@@ -152,7 +151,6 @@ _sd_export_ int sd_is_fifo(int fd, const char *path) {
if (fd < 0)
return -EINVAL;
- memset(&st_fd, 0, sizeof(st_fd));
if (fstat(fd, &st_fd) < 0)
return -errno;
@@ -162,7 +160,6 @@ _sd_export_ int sd_is_fifo(int fd, const char *path) {
if (path) {
struct stat st_path;
- memset(&st_path, 0, sizeof(st_path));
if (stat(path, &st_path) < 0) {
if (errno == ENOENT || errno == ENOTDIR)
@@ -272,15 +269,13 @@ _sd_export_ int sd_is_socket(int fd, int family, int type, int listening) {
if (family < 0)
return -EINVAL;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
if (family > 0) {
- union sockaddr_union sockaddr;
- socklen_t l;
-
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -295,19 +290,17 @@ _sd_export_ int sd_is_socket(int fd, int family, int type, int listening) {
}
_sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
- union sockaddr_union sockaddr;
- socklen_t l;
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
int r;
if (family != 0 && family != AF_INET && family != AF_INET6)
return -EINVAL;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
-
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -340,16 +333,14 @@ _sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, u
}
_sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
- union sockaddr_union sockaddr;
- socklen_t l;
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
int r;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
-
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -360,10 +351,10 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *p
return 0;
if (path) {
- if (length <= 0)
+ if (length == 0)
length = strlen(path);
- if (length <= 0)
+ if (length == 0)
/* Unnamed socket */
return l == offsetof(struct sockaddr_un, sun_path);
@@ -383,7 +374,7 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *p
}
_sd_export_ int sd_is_mq(int fd, const char *path) {
-#if !defined(__linux__)
+#if !defined(__linux__) || defined(SD_DAEMON_DISABLE_MQ)
return 0;
#else
struct mq_attr attr;
@@ -434,7 +425,8 @@ _sd_export_ int sd_notify(int unset_environment, const char *state) {
goto finish;
}
- if (!(e = getenv("NOTIFY_SOCKET")))
+ e = getenv("NOTIFY_SOCKET");
+ if (!e)
return 0;
/* Must be an abstract socket, or an absolute path */
@@ -443,7 +435,8 @@ _sd_export_ int sd_notify(int unset_environment, const char *state) {
goto finish;
}
- if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
+ fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+ if (fd < 0) {
r = -errno;
goto finish;
}
@@ -513,18 +506,15 @@ _sd_export_ int sd_booted(void) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
return 0;
#else
+ struct stat st;
- struct stat a, b;
-
- /* We simply test whether the systemd cgroup hierarchy is
- * mounted */
-
- if (lstat("/sys/fs/cgroup", &a) < 0)
- return 0;
+ /* We test whether the runtime unit file directory has been
+ * created. This takes place in mount-setup.c, so is
+ * guaranteed to happen very early during boot. */
- if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
+ if (lstat("/run/systemd/system/", &st) < 0)
return 0;
- return a.st_dev != b.st_dev;
+ return !!S_ISDIR(st.st_mode);
#endif
}
diff --git a/misc-utils/sd-daemon.h b/misc-utils/sd-daemon.h
index fe51159..daa3f4c 100644
--- a/misc-utils/sd-daemon.h
+++ b/misc-utils/sd-daemon.h
@@ -59,20 +59,20 @@ extern "C" {
You may find an up-to-date version of these source files online:
http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h
- http://cgit.freedesktop.org/systemd/systemd/plain/src/sd-daemon.c
+ http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c
This should compile on non-Linux systems, too, but with the
exception of the sd_is_xxx() calls all functions will become NOPs.
- See sd-daemon(7) for more information.
+ See sd-daemon(3) for more information.
*/
#ifndef _sd_printf_attr_
-#if __GNUC__ >= 4
-#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
-#else
-#define _sd_printf_attr_(a,b)
-#endif
+# if __GNUC__ >= 4
+# define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
+# else
+# define _sd_printf_attr_(a,b)
+# endif
#endif
/*
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 14/15] hexdump: remove unnecessary global variables
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (12 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 13/15] sd-daemon: update files taken from systemd project Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-09-02 23:22 ` Dave Reisner
2013-06-16 18:53 ` [PATCH 15/15] hexdump: use simple printing functions when possible Sami Kerola
` (2 subsequent siblings)
16 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/display.c | 6 +++---
text-utils/hexdump.c | 4 ++--
text-utils/hexdump.h | 2 --
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/text-utils/display.c b/text-utils/display.c
index 1f9a11b..41ddd8d 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -295,7 +295,7 @@ get(void)
int next(char **argv)
{
static int done;
- int statok;
+ int statok, exitval = 0;
if (argv) {
_argv = argv;
@@ -305,14 +305,14 @@ int next(char **argv)
if (*_argv) {
if (!(freopen(*_argv, "r", stdin))) {
warn("%s", *_argv);
- exitval = EXIT_FAILURE;
+ exitval = 1;
++_argv;
continue;
}
statok = done = 1;
} else {
if (done++)
- return(0);
+ return(exitval);
statok = 0;
}
if (skip)
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index e966cc3..411d809 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -47,11 +47,11 @@
FS *fshead; /* head of format strings */
ssize_t blocksize; /* data block size */
-int exitval; /* final exit value */
ssize_t length = -1; /* max bytes to read */
int main(int argc, char **argv)
{
+ int exitval; /* final exit value */
FS *tfs;
char *p;
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
for (tfs = fshead; tfs; tfs = tfs->nextfs)
rewrite(tfs);
- (void)next(argv);
+ exitval = next(argv);
display();
return exitval;
}
diff --git a/text-utils/hexdump.h b/text-utils/hexdump.h
index b9e67a1..b2ea1f1 100644
--- a/text-utils/hexdump.h
+++ b/text-utils/hexdump.h
@@ -73,8 +73,6 @@ typedef struct _fs { /* format strings */
extern FU *endfu;
extern FS *fshead; /* head of format strings list */
extern ssize_t blocksize; /* data block size */
-extern int deprecated; /* od compatibility */
-extern int exitval; /* final exit value */
extern ssize_t length; /* max bytes to read */
extern off_t skip; /* bytes to skip */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 15/15] hexdump: use simple printing functions when possible
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (13 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 14/15] hexdump: remove unnecessary global variables Sami Kerola
@ 2013-06-16 18:53 ` Sami Kerola
2013-07-01 9:01 ` Karel Zak
2013-06-17 12:31 ` [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Karel Zak
2013-07-01 9:39 ` Karel Zak
16 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-06-16 18:53 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This makes common cases 35-50% quicker.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/display.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/text-utils/display.c b/text-utils/display.c
index 41ddd8d..7698965 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -110,13 +110,13 @@ print(PR *pr, unsigned char *bp) {
break;
}
case F_P:
- (void)printf(pr->fmt, isprint(*bp) ? *bp : '.');
+ putchar_unlocked(isprint(*bp) ? *bp : '.');
break;
case F_STR:
(void)printf(pr->fmt, (char *)bp);
break;
case F_TEXT:
- (void)printf("%s", pr->fmt);
+ fputs_unlocked(pr->fmt, stdout);
break;
case F_U:
conv_u(pr, bp);
@@ -213,7 +213,7 @@ void display(void)
(void)printf(pr->fmt, (int64_t)eaddress);
break;
case F_TEXT:
- (void)printf("%s", pr->fmt);
+ fputs_unlocked(pr->fmt, stdout);
break;
}
}
@@ -250,7 +250,7 @@ get(void)
if (!need && vflag != ALL &&
!memcmp(curp, savp, nread)) {
if (vflag != DUP)
- (void)printf("*\n");
+ fputs_unlocked("*\n", stdout);
return(NULL);
}
if (need > 0)
@@ -281,7 +281,7 @@ get(void)
return(curp);
}
if (vflag == WAIT)
- (void)printf("*\n");
+ fputs_unlocked("*\n", stdout);
vflag = DUP;
address += blocksize;
need = blocksize;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (14 preceding siblings ...)
2013-06-16 18:53 ` [PATCH 15/15] hexdump: use simple printing functions when possible Sami Kerola
@ 2013-06-17 12:31 ` Karel Zak
2013-06-17 20:14 ` Sami Kerola
2013-07-01 9:39 ` Karel Zak
16 siblings, 1 reply; 27+ messages in thread
From: Karel Zak @ 2013-06-17 12:31 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 16, 2013 at 07:53:41PM +0100, Sami Kerola wrote:
> Unfortunately the most troubling dmesg patch is now dropped by me. I had
> a look how systemd determines boot time, and it seem very early at
> execution clock_gettime() is called, and results are saved. If dmesg
> should agree with systemd when startup happen I see two possible options;
>
> 1. Make dmesg to get system startup time from systemd using dbus.
>
> 2. Make both dmesg and systemd to ask start up time from kernel.
>
> I feel first option is not great. The systemd boot time stamp is similar
> sort of approximation as reading fstat from /proc/1. Also asking when
> system started from system itself feels more neutral than consulting a
> software the system started.
>
> If the second option is favored a kernel patch, such as the one below, is
> needed and a bit coordination to make various programs to use the
> boottime from kernel. Meanwhile it migth be fine that differnt programs
> using differnet time stamps for klog messages.
Note that the current dmesg(1) code uses sysinfo(2) which provides
uptime in seconds. It would be probably better to use /proc/uptime
where is uptime in sec.xx precision.
> Any opinions about klog time stamps?
>
>
> --- a/kernel/ksysfs.c
> +++ b/kernel/ksysfs.c
> @@ -157,6 +157,16 @@ static ssize_t rcu_expedited_store(struct kobject
> *kobj,
> }
> KERNEL_ATTR_RW(rcu_expedited);
>
> +/* High precision timestamp of the system boot. */
> +static ssize_t boottime_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct timespec ts;
> + getboottime(&ts);
> + return sprintf(buf, "%ld.%ld\n", ts.tv_sec, ts.tv_nsec);
> +}
> +KERNEL_ATTR_RO(hp_uptime);
> +
> /*
> * Make /sys/kernel/notes give the raw contents of our kernel .notes
> * section.
> */
> @@ -197,6 +207,7 @@ static struct attribute * kernel_attrs[] = {
> &vmcoreinfo_attr.attr,
> #endif
> &rcu_expedited_attr.attr,
> + &hp_uptime_attr.attr,
> NULL
> };
Would be better to use /proc (where is 'uptime' file) rather than
/sys/kernel ?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs
2013-06-17 12:31 ` [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Karel Zak
@ 2013-06-17 20:14 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-06-17 20:14 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 17 June 2013 13:31, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Jun 16, 2013 at 07:53:41PM +0100, Sami Kerola wrote:
>> Unfortunately the most troubling dmesg patch is now dropped by me. I had
>> a look how systemd determines boot time, and it seem very early at
>> execution clock_gettime() is called, and results are saved. If dmesg
>> should agree with systemd when startup happen I see two possible options;
>>
>> 1. Make dmesg to get system startup time from systemd using dbus.
>>
>> 2. Make both dmesg and systemd to ask start up time from kernel.
>>
>> I feel first option is not great. The systemd boot time stamp is similar
>> sort of approximation as reading fstat from /proc/1. Also asking when
>> system started from system itself feels more neutral than consulting a
>> software the system started.
>>
>> If the second option is favored a kernel patch, such as the one below, is
>> needed and a bit coordination to make various programs to use the
>> boottime from kernel. Meanwhile it migth be fine that differnt programs
>> using differnet time stamps for klog messages.
>
> Note that the current dmesg(1) code uses sysinfo(2) which provides
> uptime in seconds. It would be probably better to use /proc/uptime
> where is uptime in sec.xx precision.
I am aware of the sysinfo()'s limit to one second, which originally
started to annoy me.
http://markmail.org/message/zjp43ecruh5vduza
Unfortunately I were a bit vague what seems to be the problem. With
one second uptime resolution the seconds will start to flicker due
rounding error/feature. If uptime value is less precise than delta
time the small numbers of delta time start to affect rounding time
dependant way. Because of this rounding happening the way it does I
guess it is almost impossible to have all dmesg time stamps such way
that the following would not differ.
diff -q <(dmesg --ctime) <(sleep 0.5 ; dmesg --ctime)
I gave a shot to /proc/uptime value, and with it the new ISO 8601
format differed less than with just a second precision. But, IMHO,
having time stamps to flicker at all is not correct. Unstable output
will also cause trouble if someone intends to analyse system log with
for example logstash.
>> Any opinions about klog time stamps?
>>
>>
>> --- a/kernel/ksysfs.c
>> +++ b/kernel/ksysfs.c
>> @@ -157,6 +157,16 @@ static ssize_t rcu_expedited_store(struct kobject
>> *kobj,
>> }
>> KERNEL_ATTR_RW(rcu_expedited);
>>
>> +/* High precision timestamp of the system boot. */
>> +static ssize_t boottime_show(struct kobject *kobj,
>> + struct kobj_attribute *attr, char *buf)
>> +{
>> + struct timespec ts;
>> + getboottime(&ts);
>> + return sprintf(buf, "%ld.%ld\n", ts.tv_sec, ts.tv_nsec);
>> +}
>> +KERNEL_ATTR_RO(hp_uptime);
>> +
>> /*
>> * Make /sys/kernel/notes give the raw contents of our kernel .notes
>> * section.
>> */
>> @@ -197,6 +207,7 @@ static struct attribute * kernel_attrs[] = {
>> &vmcoreinfo_attr.attr,
>> #endif
>> &rcu_expedited_attr.attr,
>> + &hp_uptime_attr.attr,
>> NULL
>> };
>
> Would be better to use /proc (where is 'uptime' file) rather than
> /sys/kernel ?
Isn't the /sys new /proc? More seriously, I don't mind to where the
value is added if the idea itself is generally accepted as a
reasonable solution.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 15/15] hexdump: use simple printing functions when possible
2013-06-16 18:53 ` [PATCH 15/15] hexdump: use simple printing functions when possible Sami Kerola
@ 2013-07-01 9:01 ` Karel Zak
2013-07-01 10:58 ` Sami Kerola
0 siblings, 1 reply; 27+ messages in thread
From: Karel Zak @ 2013-07-01 9:01 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 16, 2013 at 07:53:56PM +0100, Sami Kerola wrote:
> This makes common cases 35-50% quicker.
What about portability and code readability?
It would be nice to have include/unlocked-io.h and add
AC_CHECK_DECLS_ONCE() for all *_unlocked functions.
See gnulib/lib/unlocked-io.h
gnulib/m4/unlocked-io.m4
.. then you can control all the behaviour by "#include unlocked-io.h"
rather than change all the code in the util(s). Maybe we can use the
functions in more utils where we intensively print something (e.g.
dmesg).
I guess we don't want separate m4 file for this stuff.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 10/15] dmesg: add iso-8601 time format
2013-06-16 18:53 ` [PATCH 10/15] dmesg: add iso-8601 time format Sami Kerola
@ 2013-07-01 9:25 ` Karel Zak
2013-07-01 10:54 ` Sami Kerola
0 siblings, 1 reply; 27+ messages in thread
From: Karel Zak @ 2013-07-01 9:25 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 16, 2013 at 07:53:51PM +0100, Sami Kerola wrote:
> sys-utils/dmesg.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
Applied, thanks. Notes:
> diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
> index 2199e7f..be08f6c 100644
> --- a/sys-utils/dmesg.c
> +++ b/sys-utils/dmesg.c
> @@ -133,7 +133,8 @@ enum {
> DMESG_TIMEFTM_DELTA, /* [<delta>] */
> DMESG_TIMEFTM_RELTIME, /* [relative] */
> DMESG_TIMEFTM_TIME, /* [time] */
> - DMESG_TIMEFTM_TIME_DELTA /* [time <delta>] */
> + DMESG_TIMEFTM_TIME_DELTA, /* [time <delta>] */
> + DMESG_TIMEFTM_ISO8601 /* 2013-06-13T22:11:00,123456+0100 */
dmesg --show-delta --time-format=iso
is unsupported, right? I have no problem with this restriction, but
it would be nice to add some warning to the code.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 08/15] dmesg: convert time format bitfield to enum
2013-06-16 18:53 ` [PATCH 08/15] dmesg: convert time format bitfield to enum Sami Kerola
@ 2013-07-01 9:36 ` Karel Zak
0 siblings, 0 replies; 27+ messages in thread
From: Karel Zak @ 2013-07-01 9:36 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 16, 2013 at 07:53:49PM +0100, Sami Kerola wrote:
> +#define is_timefmt(c, f) (c->time_fmt == (DMESG_TIMEFTM_ ##f))
[...]
> +#undef is_timefmt
> +#define is_timefmt(c, f) (c.time_fmt == (DMESG_TIMEFTM_ ##f))
Don't be lazy to use &ctl in code. You want to write readable and
maintainable code ;-)
Fixed.
Karel
Always code as if the person who ends up maintaining your code is a
violent psychopath who knows where you live.
http://c2.com/cgi/wiki?CodeForTheMaintainer
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
` (15 preceding siblings ...)
2013-06-17 12:31 ` [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Karel Zak
@ 2013-07-01 9:39 ` Karel Zak
16 siblings, 0 replies; 27+ messages in thread
From: Karel Zak @ 2013-07-01 9:39 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
Applied, thanks. Exceptions:
On Sun, Jun 16, 2013 at 07:53:41PM +0100, Sami Kerola wrote:
> Sami Kerola (15):
> renice: exit with non-zero value when arguments cause warnings
> sfdisk: use libc error printing function, and symbolic exit values
> sfdisk: clean up usage() functions
> sfdisk: use program_invocation_short_name to determine program name
> docs: correct sfdisk --activate instructions
> sfdisk: remove --unhide and related functions
Not applied (--unhide is valid operation, unimplemented was "unhide"
as command name).
> sfdisk: replace my_warn() with warnx()
> dmesg: convert time format bitfield to enum
> dmesg: add --time-format option
> dmesg: add iso-8601 time format
> docs: add --time-format option and ISO-8601 format to manual
> dmesg: regroup time related options close to each other
> sd-daemon: update files taken from systemd project
> hexdump: remove unnecessary global variables
> hexdump: use simple printing functions when possible
Not applied (the patch is too aggressive and unportable).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 10/15] dmesg: add iso-8601 time format
2013-07-01 9:25 ` Karel Zak
@ 2013-07-01 10:54 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-07-01 10:54 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 1 July 2013 10:25, Karel Zak <kzak@redhat.com> wrote:
> dmesg --show-delta --time-format=iso
>
> is unsupported, right? I have no problem with this restriction, but
> it would be nice to add some warning to the code.
I agree. Adding a warning is good idea. Unless someone else is quicker
I can do that someday.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 15/15] hexdump: use simple printing functions when possible
2013-07-01 9:01 ` Karel Zak
@ 2013-07-01 10:58 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-07-01 10:58 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 1 July 2013 10:01, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Jun 16, 2013 at 07:53:56PM +0100, Sami Kerola wrote:
>> This makes common cases 35-50% quicker.
>
> What about portability and code readability?
>
> It would be nice to have include/unlocked-io.h and add
> AC_CHECK_DECLS_ONCE() for all *_unlocked functions.
>
> See gnulib/lib/unlocked-io.h
> gnulib/m4/unlocked-io.m4
>
> .. then you can control all the behaviour by "#include unlocked-io.h"
> rather than change all the code in the util(s). Maybe we can use the
> functions in more utils where we intensively print something (e.g.
> dmesg).
>
> I guess we don't want separate m4 file for this stuff.
Good idea.
When I tested the putchar_unlocked() was more or less equally quick
with putchar(), but I chose to squeeze even the theoretical speed out
of the printing. For now it might be best, from portability point of
view, to 's/_unlocked//' and add later some clever build time
automation which will pick the most suitable function.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 14/15] hexdump: remove unnecessary global variables
2013-06-16 18:53 ` [PATCH 14/15] hexdump: remove unnecessary global variables Sami Kerola
@ 2013-09-02 23:22 ` Dave Reisner
2013-09-03 7:15 ` Sami Kerola
0 siblings, 1 reply; 27+ messages in thread
From: Dave Reisner @ 2013-09-02 23:22 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 16, 2013 at 07:53:55PM +0100, Sami Kerola wrote:
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> text-utils/display.c | 6 +++---
> text-utils/hexdump.c | 4 ++--
> text-utils/hexdump.h | 2 --
> 3 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/text-utils/display.c b/text-utils/display.c
> index 1f9a11b..41ddd8d 100644
> --- a/text-utils/display.c
> +++ b/text-utils/display.c
> @@ -295,7 +295,7 @@ get(void)
> int next(char **argv)
> {
> static int done;
> - int statok;
> + int statok, exitval = 0;
>
> if (argv) {
> _argv = argv;
> @@ -305,14 +305,14 @@ int next(char **argv)
> if (*_argv) {
> if (!(freopen(*_argv, "r", stdin))) {
> warn("%s", *_argv);
> - exitval = EXIT_FAILURE;
> + exitval = 1;
> ++_argv;
> continue;
> }
> statok = done = 1;
> } else {
> if (done++)
> - return(0);
> + return(exitval);
> statok = 0;
> }
> if (skip)
> diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
> index e966cc3..411d809 100644
> --- a/text-utils/hexdump.c
> +++ b/text-utils/hexdump.c
> @@ -47,11 +47,11 @@
>
> FS *fshead; /* head of format strings */
> ssize_t blocksize; /* data block size */
> -int exitval; /* final exit value */
> ssize_t length = -1; /* max bytes to read */
>
> int main(int argc, char **argv)
> {
> + int exitval; /* final exit value */
> FS *tfs;
> char *p;
>
> @@ -76,7 +76,7 @@ int main(int argc, char **argv)
> for (tfs = fshead; tfs; tfs = tfs->nextfs)
> rewrite(tfs);
>
> - (void)next(argv);
> + exitval = next(argv);
A little late to the game, but this commit breaks the return value of
hexdump and causes it to always return 1, even on successful invocation.
next(char**) will always return 1 for the usual (non-NULL) values of argv.
d
> display();
> return exitval;
> }
> diff --git a/text-utils/hexdump.h b/text-utils/hexdump.h
> index b9e67a1..b2ea1f1 100644
> --- a/text-utils/hexdump.h
> +++ b/text-utils/hexdump.h
> @@ -73,8 +73,6 @@ typedef struct _fs { /* format strings */
> extern FU *endfu;
> extern FS *fshead; /* head of format strings list */
> extern ssize_t blocksize; /* data block size */
> -extern int deprecated; /* od compatibility */
> -extern int exitval; /* final exit value */
> extern ssize_t length; /* max bytes to read */
> extern off_t skip; /* bytes to skip */
>
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 14/15] hexdump: remove unnecessary global variables
2013-09-02 23:22 ` Dave Reisner
@ 2013-09-03 7:15 ` Sami Kerola
2013-09-03 8:29 ` Karel Zak
0 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-09-03 7:15 UTC (permalink / raw)
To: Sami Kerola, util-linux
On 3 September 2013 00:22, Dave Reisner <d@falconindy.com> wrote:
> A little late to the game, but this commit breaks the return value of
> hexdump and causes it to always return 1, even on successful invocation.
> next(char**) will always return 1 for the usual (non-NULL) values of argv.
Hi Dave,
You are not late at all. Thanks to you broken hexdump was never
released to greater audience. I'll fix the issue in near future,
unless someone else is quicker.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 14/15] hexdump: remove unnecessary global variables
2013-09-03 7:15 ` Sami Kerola
@ 2013-09-03 8:29 ` Karel Zak
0 siblings, 0 replies; 27+ messages in thread
From: Karel Zak @ 2013-09-03 8:29 UTC (permalink / raw)
To: kerolasa; +Cc: Sami Kerola, util-linux
On Tue, Sep 03, 2013 at 08:15:18AM +0100, Sami Kerola wrote:
> On 3 September 2013 00:22, Dave Reisner <d@falconindy.com> wrote:
> > A little late to the game, but this commit breaks the return value of
I'm happy that you play the game with us, better later than never :-)
> > hexdump and causes it to always return 1, even on successful invocation.
> > next(char**) will always return 1 for the usual (non-NULL) values of argv.
>
> You are not late at all. Thanks to you broken hexdump was never
> released to greater audience. I'll fix the issue in near future,
> unless someone else is quicker.
BTW, Ondrej Oprala is working on hexdump refactoring for v2.25 (for
v2.24 is too late). So, I hope that one day we will have more
readable and maintainable code.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2013-09-03 8:29 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-16 18:53 [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Sami Kerola
2013-06-16 18:53 ` [PATCH 01/15] renice: exit with non-zero value when arguments cause warnings Sami Kerola
2013-06-16 18:53 ` [PATCH 02/15] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
2013-06-16 18:53 ` [PATCH 03/15] sfdisk: clean up usage() functions Sami Kerola
2013-06-16 18:53 ` [PATCH 04/15] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
2013-06-16 18:53 ` [PATCH 05/15] docs: correct sfdisk --activate instructions Sami Kerola
2013-06-16 18:53 ` [PATCH 06/15] sfdisk: remove --unhide and related functions Sami Kerola
2013-06-16 18:53 ` [PATCH 07/15] sfdisk: replace my_warn() with warnx() Sami Kerola
2013-06-16 18:53 ` [PATCH 08/15] dmesg: convert time format bitfield to enum Sami Kerola
2013-07-01 9:36 ` Karel Zak
2013-06-16 18:53 ` [PATCH 09/15] dmesg: add --time-format option Sami Kerola
2013-06-16 18:53 ` [PATCH 10/15] dmesg: add iso-8601 time format Sami Kerola
2013-07-01 9:25 ` Karel Zak
2013-07-01 10:54 ` Sami Kerola
2013-06-16 18:53 ` [PATCH 11/15] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
2013-06-16 18:53 ` [PATCH 12/15] dmesg: regroup time related options close to each other Sami Kerola
2013-06-16 18:53 ` [PATCH 13/15] sd-daemon: update files taken from systemd project Sami Kerola
2013-06-16 18:53 ` [PATCH 14/15] hexdump: remove unnecessary global variables Sami Kerola
2013-09-02 23:22 ` Dave Reisner
2013-09-03 7:15 ` Sami Kerola
2013-09-03 8:29 ` Karel Zak
2013-06-16 18:53 ` [PATCH 15/15] hexdump: use simple printing functions when possible Sami Kerola
2013-07-01 9:01 ` Karel Zak
2013-07-01 10:58 ` Sami Kerola
2013-06-17 12:31 ` [PATCH 00/15] pull: sfdisk and dmesg resubmission, plus bits and bobs Karel Zak
2013-06-17 20:14 ` Sami Kerola
2013-07-01 9:39 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox