All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/19] pull: various clean ups and couple bug fixes
@ 2013-06-02 17:51 Sami Kerola
  2013-06-02 17:51 ` [PATCH 01/19] lib: remove unused code Sami Kerola
                   ` (19 more replies)
  0 siblings, 20 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Hello,

This weeks patch series is bag of random clean ups, fixes, and features. 
The commits, and corresponding messages, are hopefully good enough so
that individual patches does not need much explaining.

If there is only one patch to get comments I hope it is the dmesg boot
time detection fix (0018).  Either that change is wrong, or there is not
a better way (at last at the moment) to determine system start time.


The following changes since commit 8225bb78a631d032121f9d7eed19481220933c88:

  libmount: more robust options string parsing (2013-05-30 13:29:34 +0200)

are available in the git repository at:

  git://github.com/kerolasa/lelux-utiliteetit.git 2013wk21

for you to fetch changes up to fdcb3a36c4d9a6154473b393481bea8595a22104:

  cal: fix few type mismatches (2013-06-02 17:10:22 +0100)

----------------------------------------------------------------
Sami Kerola (19):
      lib: remove unused code
      lscpu: add max MHz value to make cpu governor effects more visible
      docs: add lscpu max mhz to manual and bash completion
      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()
      rev: stop adding new line at the end when input does not have it
      rev: simplify new line detection and impossible test
      rev: reduce stream checking when closing read-only file descriptor
      dmesg: make time format parsing to use enum bit field
      dmesg: add --time-format option
      dmesg: add iso-8601 time format
      docs: add --time-format option and ISO-8601 format to manual
      dmesg: make usage() a little bit shorter
      dmesg: more deterministic boot time detection
      cal: fix few type mismatches

 bash-completion/lscpu   |   3 +-
 fdisks/sfdisk.8         |  33 +++-
 fdisks/sfdisk.c         | 406 ++++++++++++++++++------------------------------
 include/pathnames.h     |   3 +-
 lib/pager.c             |  10 --
 misc-utils/cal.c        |  12 +-
 sys-utils/dmesg.1       |  22 +++
 sys-utils/dmesg.c       | 148 ++++++++++++------
 sys-utils/lscpu.1       |   5 +
 sys-utils/lscpu.c       |  26 +++-
 tests/expected/misc/rev |   4 +-
 tests/ts/misc/rev       |   2 +
 text-utils/rev.c        |  17 +-
 13 files changed, 358 insertions(+), 333 deletions(-)



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/19] lib: remove unused code
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 02/19] lscpu: add max MHz value to make cpu governor effects more visible Sami Kerola
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 lib/pager.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/lib/pager.c b/lib/pager.c
index 5cf8c03..c6e74e8 100644
--- a/lib/pager.c
+++ b/lib/pager.c
@@ -40,16 +40,6 @@ static inline void close_pair(int fd[2])
 	close(fd[1]);
 }
 
-static inline void dup_devnull(int to)
-{
-	int fd = open(NULL_DEVICE, O_RDWR);
-
-	if (fd < 0)
-		err(EXIT_FAILURE, _("cannot open %s"), NULL_DEVICE);
-	dup2(fd, to);
-	close(fd);
-}
-
 static int start_command(struct child_process *cmd)
 {
 	int need_in;
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 02/19] lscpu: add max MHz value to make cpu governor effects more visible
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
  2013-06-02 17:51 ` [PATCH 01/19] lib: remove unused code Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 03/19] docs: add lscpu max mhz to manual and bash completion Sami Kerola
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The existing 'CPU MHz' is usually dynamic value, which CPU governor
changes up on needs of CPU demand.  Assuming lscpu is used to gather
information to a hardware inventory the dynamic value is misleading.  For
inventing the maximum MHz value is more sensible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/lscpu.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index dde227b..fbaaa31 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -148,6 +148,7 @@ struct lscpu_desc {
 	int	hyper;		/* hypervisor vendor ID */
 	int	virtype;	/* VIRT_PARA|FULL|NONE ? */
 	char	*mhz;
+	char	**mmhz;		/* maximum mega hertz */
 	char	*stepping;
 	char    *bogomips;
 	char	*flags;
@@ -230,6 +231,7 @@ enum {
 	COL_ADDRESS,
 	COL_CONFIGURED,
 	COL_ONLINE,
+	COL_MMHZ,
 };
 
 /* column description
@@ -252,7 +254,8 @@ static struct lscpu_coldesc coldescs[] =
 	[COL_POLARIZATION] = { "POLARIZATION", N_("CPU dispatching mode on virtual hardware") },
 	[COL_ADDRESS]      = { "ADDRESS", N_("physical address of a CPU") },
 	[COL_CONFIGURED]   = { "CONFIGURED", N_("shows if the hypervisor has allocated the CPU") },
-	[COL_ONLINE]       = { "ONLINE", N_("shows if Linux currently makes use of the CPU") }
+	[COL_ONLINE]       = { "ONLINE", N_("shows if Linux currently makes use of the CPU") },
+	[COL_MMHZ]	   = { "MMHZ", N_("shows the maximum mhz of the CPU") }
 };
 
 static int
@@ -777,6 +780,18 @@ read_configured(struct lscpu_desc *desc, int num)
 	desc->configured[num] = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", num);
 }
 
+static void
+read_max_mhz(struct lscpu_desc *desc, int num)
+{
+	if (!path_exist(_PATH_SYS_CPU "/cpu%d/cpufreq/cpuinfo_max_freq", num))
+		return;
+	if (!desc->mmhz)
+		desc->mmhz = xcalloc(desc->ncpuspos, sizeof(char *));
+	xasprintf(&(desc->mmhz[num]), "%.4f",
+		  (float)path_read_s32(_PATH_SYS_CPU
+				       "/cpu%d/cpufreq/cpuinfo_max_freq", num) / 1000);
+}
+
 static int
 cachecmp(const void *a, const void *b)
 {
@@ -965,6 +980,10 @@ get_cell_data(struct lscpu_desc *desc, int cpu, int col,
 			snprintf(buf, bufsz,
 				 is_cpu_online(desc, cpu) ? _("yes") : _("no"));
 		break;
+	case COL_MMHZ:
+		if (desc->mmhz)
+			xstrncpy(buf, desc->mmhz[cpu], bufsz);
+		break;
 	}
 	return buf;
 }
@@ -1272,6 +1291,8 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 		print_s(_("Stepping:"), desc->stepping);
 	if (desc->mhz)
 		print_s(_("CPU MHz:"), desc->mhz);
+	if (desc->mmhz)
+		print_s(_("CPU max MHz:"), desc->mmhz[0]);
 	if (desc->bogomips)
 		print_s(_("BogoMIPS:"), desc->bogomips);
 	if (desc->virtflag) {
@@ -1439,6 +1460,7 @@ int main(int argc, char *argv[])
 		read_polarization(desc, i);
 		read_address(desc, i);
 		read_configured(desc, i);
+		read_max_mhz(desc, i);
 	}
 
 	if (desc->caches)
@@ -1485,6 +1507,8 @@ int main(int argc, char *argv[])
 				columns[ncolumns++] = COL_POLARIZATION;
 			if (desc->addresses)
 				columns[ncolumns++] = COL_ADDRESS;
+			if (desc->mmhz)
+				columns[ncolumns++] = COL_MMHZ;
 		}
 		print_readable(desc, columns, ncolumns, mod);
 		break;
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 03/19] docs: add lscpu max mhz to manual and bash completion
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
  2013-06-02 17:51 ` [PATCH 01/19] lib: remove unused code Sami Kerola
  2013-06-02 17:51 ` [PATCH 02/19] lscpu: add max MHz value to make cpu governor effects more visible Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 bash-completion/lscpu | 3 ++-
 sys-utils/lscpu.1     | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/bash-completion/lscpu b/bash-completion/lscpu
index bce07c4..2736742 100644
--- a/bash-completion/lscpu
+++ b/bash-completion/lscpu
@@ -17,7 +17,8 @@ _lscpu_module()
 				POLARIZATION,
 				ADDRESS,
 				CONFIGURED,
-				ONLINE,"
+				ONLINE,
+				MMHZ"
 			compopt -o nospace
 			COMPREPLY=( $(compgen -W "$OPTS" -- $cur) )
 			return 0
diff --git a/sys-utils/lscpu.1 b/sys-utils/lscpu.1
index f747a35..19c964a 100644
--- a/sys-utils/lscpu.1
+++ b/sys-utils/lscpu.1
@@ -76,6 +76,11 @@ The workload is concentrated on few CPUs.
 For vertical polarization, the column also shows the degree of concentration,
 high, medium, or low.  This column contains data only if your hardware system
 and hypervisor support CPU polarization.
+.TP
+.B MMHZ
+Maximum megaherz value for the cpu.  Useful when lscpu is used as hardware
+inventory infomation gathering tool.  Notice that the megahertz value is
+dynamic, and driven by CPU governor depending on current resource need.
 .RE
 .SH OPTIONS
 .TP
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (2 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 03/19] docs: add lscpu max mhz to manual and bash completion Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-07 10:20   ` Karel Zak
  2013-06-02 17:51 ` [PATCH 05/19] sfdisk: clean up usage() functions Sami Kerola
                   ` (15 subsequent siblings)
  19 siblings, 1 reply; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 fdisks/sfdisk.c | 75 +++++++++++++++++++++++----------------------------------
 1 file changed, 30 insertions(+), 45 deletions(-)

diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index e639dad..f64f3cd 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
  */
@@ -137,12 +123,12 @@ sseek(char *dev, int fd, unsigned long s) {
 
     if ((out = lseek(fd, in, SEEK_SET)) != in) {
 	perror("lseek");
-	error(_("seek error on %s - cannot seek to %lu\n"), dev, s);
+	warnx(_("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;
@@ -192,7 +178,7 @@ get_sector(char *dev, int fd, unsigned long long sno) {
     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);
+	warnx(_("read error on %s - cannot read sector %llu"), dev, sno);
 	free(s);
 	return 0;
     }
@@ -223,7 +209,7 @@ write_sectors(char *dev, int fd) {
 		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"),
+		warnx(_("write error on %s - cannot write sector %llu"),
 		      dev, s->sectornumber);
 		return 0;
 	    }
@@ -261,7 +247,7 @@ 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"),
+	warnx(_("cannot open partition sector save file (%s)"),
 	      save_sector_file);
 	goto err;
     }
@@ -273,13 +259,13 @@ save_sectors(char *dev, int fdin) {
 		goto err;
 	    if (read(fdin, ss + 4, 512) != 512) {
 		perror("read");
-		error(_("read error on %s - cannot read sector %lu\n"),
+		warnx(_("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);
+		warnx(_("write error on %s"), save_sector_file);
 		goto err;
 	    }
 	}
@@ -309,12 +295,12 @@ restore_sectors(char *dev) {
 
     if (stat(restore_sector_file, &statbuf) < 0) {
 	perror(restore_sector_file);
-	error(_("cannot stat partition restore file (%s)\n"),
+	warnx(_("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;
     }
 
@@ -324,20 +310,20 @@ 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"),
+	warnx(_("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);
+	warnx(_("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);
+	warnx(_("cannot open device %s for writing"), dev);
 	goto err;
     }
 
@@ -348,7 +334,7 @@ restore_sectors(char *dev) {
 	    goto err;
 	if (write(fdout, ss + 4, 512) != 512) {
 	    perror(dev);
-	    error(_("error writing sector %lu on %s\n"), sno, dev);
+	    warnx(_("error writing sector %lu on %s"), sno, dev);
 	    goto err;
 	}
 	ss += 516;
@@ -360,7 +346,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 +458,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)
@@ -1436,7 +1422,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 +1656,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 +1677,12 @@ 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);
+	warnx(_("Failed writing the partition on %s"), dev);
 	return 0;
     }
     return 1;
@@ -2447,8 +2433,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 +2662,7 @@ main(int argc, char **argv) {
 	    break;
 	case 'T':
 	    list_types();
-	    exit(0);
+	    return EXIT_SUCCESS;
 	case 'U':
 	    unhidearg = optarg;
 	    unhide = 1;
@@ -2751,7 +2737,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 +2761,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 +2781,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 +2795,7 @@ main(int argc, char **argv) {
     else
 	do_fdisk(dev);
 
-    return 0;
+    return exit_status;
 }
 
 /*
@@ -3136,7 +3122,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);
@@ -3172,7 +3158,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 +3229,4 @@ do_fdisk(char *dev) {
 	      "(See fdisk(8).)\n"));
 
     sync();			/* superstition */
-    exit(exit_status);
 }
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 05/19] sfdisk: clean up usage() functions
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (3 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 06/19] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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 f64f3cd..cac8252 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2370,11 +2370,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"
@@ -2421,27 +2421,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
@@ -2557,7 +2559,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;
 
@@ -2578,8 +2579,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) {
@@ -2742,9 +2741,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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 06/19] sfdisk: use program_invocation_short_name to determine program name
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (4 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 05/19] sfdisk: clean up usage() functions Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 07/19] docs: correct sfdisk --activate instructions Sami Kerola
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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 cac8252..912b95d 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2549,7 +2549,6 @@ unsigned long long total_size;
 
 int
 main(int argc, char **argv) {
-    char *progn;
     int c;
     char *dev;
     int opt_size = 0;
@@ -2569,14 +2568,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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 07/19] docs: correct sfdisk --activate instructions
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (5 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 06/19] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 08/19] sfdisk: remove --unhide and related functions Sami Kerola
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 08/19] sfdisk: remove --unhide and related functions
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (6 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 07/19] docs: correct sfdisk --activate instructions Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 09/19] sfdisk: replace my_warn() with warnx() Sami Kerola
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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 912b95d..2d430de 100644
--- a/fdisks/sfdisk.c
+++ b/fdisks/sfdisk.c
@@ -2405,7 +2405,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"
@@ -2444,7 +2443,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
@@ -2487,7 +2486,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 },
@@ -2542,7 +2540,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;
@@ -2557,9 +2554,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);
@@ -2570,10 +2565,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) {
@@ -2657,10 +2648,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;
@@ -2760,10 +2747,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"));
@@ -3020,57 +3003,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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 09/19] sfdisk: replace my_warn() with warnx()
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (7 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 08/19] sfdisk: remove --unhide and related functions Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 10/19] rev: stop adding new line at the end when input does not have it Sami Kerola
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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 may break scripts, as there is no knowledge
whether some scripts are expecting not command name prefixed error
messages from this utility.  Same in programmer terms; the change
contains ABI change.

Karel: could you sign-off abi change, if not please drop this patch.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 fdisks/sfdisk.c | 219 ++++++++++++++++++++++++++------------------------------
 1 file changed, 103 insertions(+), 116 deletions(-)

diff --git a/fdisks/sfdisk.c b/fdisks/sfdisk.c
index 2d430de..c25616d 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
  */
@@ -405,7 +392,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;
@@ -422,7 +409,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;
 
@@ -454,28 +441,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"),
@@ -564,18 +551,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;
@@ -781,14 +768,14 @@ 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) {
 	perror(dev);
-	warnx(_("Error closing %s\n"), dev);
+	warnx(_("Error closing %s"), dev);
 	return 0;
     }
     printf("\n");
@@ -852,7 +839,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;
@@ -913,7 +900,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:
@@ -1096,17 +1083,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);
     }
 }
@@ -1117,12 +1104,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);
 	}
 
@@ -1180,13 +1167,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 */
 	}
@@ -1198,8 +1185,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;
 		}
 	    }
@@ -1210,7 +1197,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;
 		    }
@@ -1222,9 +1209,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;
 		    }
@@ -1235,12 +1222,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;
 		}
@@ -1256,9 +1243,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,
@@ -1272,8 +1259,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,
@@ -1292,8 +1279,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;
 	}
     }
@@ -1312,14 +1299,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;
 		}
@@ -1337,22 +1324,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? */
@@ -1367,7 +1354,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;
@@ -1376,10 +1363,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);
 	}
 
@@ -1407,11 +1394,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."));
 	}
     }
 
@@ -1429,7 +1416,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;
 	}
@@ -1444,7 +1431,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;
@@ -1507,7 +1494,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) {
@@ -1553,7 +1540,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;
     }
 
@@ -1561,7 +1548,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;
 	}
     }
@@ -1581,14 +1568,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);
@@ -1599,7 +1586,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);
@@ -1643,7 +1630,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;
     }
 }
@@ -1655,7 +1642,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);
     }
 
@@ -1850,11 +1837,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)
@@ -1887,11 +1874,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)
@@ -2016,7 +2003,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;
 	}
     }
@@ -2049,7 +2036,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 {
@@ -2089,8 +2076,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 */
@@ -2100,7 +2087,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;
     }
 
@@ -2134,7 +2121,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;
 	}
     }
@@ -2153,7 +2140,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;
@@ -2187,13 +2174,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;
     }
@@ -2207,7 +2194,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;
@@ -2220,7 +2207,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;
@@ -2237,7 +2224,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) ||
@@ -2251,7 +2238,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) ||
@@ -2262,7 +2249,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;
     }
@@ -2317,7 +2304,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++)
@@ -2350,9 +2337,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++)
@@ -2813,7 +2800,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;
     }
@@ -2964,7 +2951,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);
 	    }
 	}
@@ -2983,7 +2970,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;
     }
@@ -2992,12 +2979,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;
     }
 }
@@ -3028,13 +3015,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;
     }
 }
@@ -3045,7 +3032,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);
     }
 
@@ -3069,23 +3056,23 @@ do_fdisk(char *dev) {
 	errx(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"));
+		      "Use the --no-reread flag to suppress this check."));
 	    if (!force) {
-		warnx(_("Use the --force flag to overrule all checks.\n"));
+		warnx(_("Use the --force flag to overrule all checks."));
 		exit(EXIT_FAILURE);
 	    }
 	} else
-	    my_warn(_("OK\n"));
+	    warnx(_("OK"));
     }
 
     z = &oldp;
@@ -3114,7 +3101,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:
@@ -3148,9 +3135,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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 10/19] rev: stop adding new line at the end when input does not have it
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (8 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 09/19] sfdisk: replace my_warn() with warnx() Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 11/19] rev: simplify new line detection and impossible test Sami Kerola
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

When the rev(1) is executed twice outcome is expected to be exactly what
it was originally.  That includes not adding new line at the end of the
output.  The oneliner below demonstrates earlier issue.

$ printf "abc\n123" | rev | rev

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 tests/expected/misc/rev | 4 +++-
 tests/ts/misc/rev       | 2 ++
 text-utils/rev.c        | 3 ++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/expected/misc/rev b/tests/expected/misc/rev
index 263923f..41fdf4c 100644
--- a/tests/expected/misc/rev
+++ b/tests/expected/misc/rev
@@ -1,2 +1,4 @@
 53bbf0d98205319cee2ba589e205c68b  -
-b407c257ed73b43cb992e778f925f7a3  -
+35484965b7a2fd45a471c0d80cb9752c  -
+cba
+321
\ No newline at end of file
diff --git a/tests/ts/misc/rev b/tests/ts/misc/rev
index f36a799..035ce82 100755
--- a/tests/ts/misc/rev
+++ b/tests/ts/misc/rev
@@ -23,4 +23,6 @@ for I in {0..512}; do printf "%s " {a..z}; done | md5sum >> $TS_OUTPUT 2>&1
 for I in {0..512}; do printf "%s " {a..z}; done | \
 				    $TS_CMD_REV | md5sum >> $TS_OUTPUT 2>&1
 
+printf "abc\n123" | $TS_CMD_REV >> $TS_OUTPUT 2>&1
+
 ts_finalize
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 9554506..0456c2b 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -159,7 +159,8 @@ int main(int argc, char *argv[])
 				if (*t != 0)
 					putwchar(*t);
 			}
-			putwchar('\n');
+			if (!feof(fp))
+				putwchar('\n');
 		}
 
 		fflush(fp);
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 11/19] rev: simplify new line detection and impossible test
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (9 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 10/19] rev: stop adding new line at the end when input does not have it Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 12/19] rev: reduce stream checking when closing read-only file descriptor Sami Kerola
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The new line detection is earlier using only '\n' so there should not be
need to search for '\r' later.

The detection whether allocated address is pointing to null seems to be
unnecessary.  Assuming xmalloc() returned valid address space the address
should never be 0.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 text-utils/rev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/text-utils/rev.c b/text-utils/rev.c
index 0456c2b..1665772 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -154,11 +154,10 @@ int main(int argc, char *argv[])
 				len = wcslen(buf);
 			}
 
-			t = buf + len - 1 - (*(buf+len-1)=='\r' || *(buf+len-1)=='\n');
-			for ( ; t >= buf; --t) {
-				if (*t != 0)
-					putwchar(*t);
-			}
+			if (*(t = buf + len - 1) == '\n')
+				--t;
+			for ( ; buf <= t; --t)
+				putwchar(*t);
 			if (!feof(fp))
 				putwchar('\n');
 		}
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 12/19] rev: reduce stream checking when closing read-only file descriptor
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (10 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 11/19] rev: simplify new line detection and impossible test Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 13/19] dmesg: make time format parsing to use enum bit field Sami Kerola
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 text-utils/rev.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/text-utils/rev.c b/text-utils/rev.c
index 1665772..1c44036 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -161,14 +161,11 @@ int main(int argc, char *argv[])
 			if (!feof(fp))
 				putwchar('\n');
 		}
-
-		fflush(fp);
 		if (ferror(fp)) {
 			warn("%s", filename);
 			rval = EXIT_FAILURE;
 		}
-		if (fclose(fp))
-			rval = EXIT_FAILURE;
+		fclose(fp);
 	} while(*argv);
 
 	free(buf);
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 13/19] dmesg: make time format parsing to use enum bit field
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (11 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 12/19] rev: reduce stream checking when closing read-only file descriptor Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-03  8:45   ` Karel Zak
  2013-06-02 17:51 ` [PATCH 14/19] dmesg: add --time-format option Sami Kerola
                   ` (6 subsequent siblings)
  19 siblings, 1 reply; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

This will pave way to add single option to define all time formats, such
as --time-format=[ctime|reltime|delta|none].

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/dmesg.c | 59 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 26 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index ae8e938..b882120 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -126,6 +126,13 @@ enum {
 	DMESG_METHOD_MMAP	/* mmap file with records (see --file) */
 };
 
+enum {
+	TIMEFTM_NONE	= (1 << 0),
+	TIMEFTM_CTIME	= (1 << 1),
+	TIMEFTM_DELTA	= (1 << 2),
+	TIMEFTM_RELTIME = (1 << 3),
+};
+
 struct dmesg_control {
 	/* bit arrays -- see include/bitops.h */
 	char levels[ARRAY_SIZE(level_names) / NBBY + 1];
@@ -152,16 +159,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 +693,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 (ctl->time_fmt & (TIMEFTM_DELTA | TIMEFTM_CTIME | TIMEFTM_RELTIME))
 				begin = parse_syslog_timestamp(begin + 1, &rec->tv);
-			else if (ctl->notime)
+
+			else if (ctl->time_fmt & TIMEFTM_NONE)
 				begin = skip_item(begin, end, "]");
 
 			if (begin < end && *begin == ' ')
@@ -855,12 +860,12 @@ static void print_record(struct dmesg_control *ctl,
 	/*
 	 * [sec.usec <delta>] or [ctime <delta>]
 	 */
-	if (ctl->delta) {
+	if (ctl->time_fmt & TIMEFTM_DELTA) {
 		if (ctl->color)
 			color_enable(DMESG_COLOR_TIME);
-		if (ctl->ctime)
+		if (ctl->time_fmt & TIMEFTM_CTIME)
 			printf("[%s ", record_ctime(ctl, rec, buf, sizeof(buf)));
-		else if (ctl->notime)
+		else if (ctl->time_fmt == TIMEFTM_NONE)
 			putchar('[');
 		else
 			printf("[%5d.%06d ", (int) rec->tv.tv_sec,
@@ -872,7 +877,7 @@ static void print_record(struct dmesg_control *ctl,
 	/*
 	 * [ctime]
 	 */
-	} else if (ctl->ctime) {
+	} else if (ctl->time_fmt & TIMEFTM_CTIME) {
 		if (ctl->color)
 			color_enable(DMESG_COLOR_TIME);
 		printf("[%s] ", record_ctime(ctl, rec, buf, sizeof(buf)));
@@ -883,7 +888,7 @@ static void print_record(struct dmesg_control *ctl,
 	/*
 	 * [reltime]
 	 */
-	else if (ctl->reltime) {
+	else if (ctl->time_fmt & TIMEFTM_RELTIME) {
 		double delta;
 		struct tm cur;
 
@@ -918,14 +923,15 @@ static void print_record(struct dmesg_control *ctl,
 	 * the [sec.usec] string.
 	 */
 	if (ctl->method == DMESG_METHOD_KMSG &&
-	    !ctl->notime && !ctl->delta && !ctl->ctime && !ctl->reltime) {
+	    !(ctl->time_fmt & TIMEFTM_NONE)
+	    && !(ctl->time_fmt & (TIMEFTM_CTIME | TIMEFTM_DELTA | TIMEFTM_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();
 	}
-
 mesg:
 	mesg = rec->mesg;
 	mesg_size = rec->mesg_size;
@@ -1065,7 +1071,7 @@ static int parse_kmsg_record(struct dmesg_control *ctl,
 		goto mesg;
 
 	/* C) timestamp */
-	if (ctl->notime)
+	if (ctl->time_fmt & TIMEFTM_NONE)
 		p = skip_item(p, end, ",;");
 	else
 		p = parse_kmsg_timestamp(p, &rec->tv);
@@ -1148,6 +1154,7 @@ int main(int argc, char *argv[])
 		.action = SYSLOG_ACTION_READ_ALL,
 		.method = DMESG_METHOD_KMSG,
 		.kmsg = -1,
+		.time_fmt = 0,
 	};
 	int colormode = UL_COLORMODE_NEVER;
 
@@ -1209,13 +1216,13 @@ int main(int argc, char *argv[])
 			ctl.action = SYSLOG_ACTION_CONSOLE_OFF;
 			break;
 		case 'd':
-			ctl.delta = 1;
+			ctl.time_fmt |= TIMEFTM_DELTA;
 			break;
 		case 'E':
 			ctl.action = SYSLOG_ACTION_CONSOLE_ON;
 			break;
 		case 'e':
-			ctl.reltime = 1;
+			ctl.time_fmt |= TIMEFTM_RELTIME;
 			break;
 		case 'F':
 			ctl.filename = optarg;
@@ -1228,7 +1235,7 @@ int main(int argc, char *argv[])
 				return EXIT_FAILURE;
 			break;
 		case 'H':
-			ctl.reltime = 1;
+			ctl.time_fmt |= TIMEFTM_RELTIME;
 			ctl.color = 1;
 			ctl.pager = 1;
 			break;
@@ -1273,10 +1280,10 @@ int main(int argc, char *argv[])
 		case 'T':
 			ctl.boot_time = get_boot_time();
 			if (ctl.boot_time)
-				ctl.ctime = 1;
+				ctl.time_fmt |= TIMEFTM_CTIME;
 			break;
 		case 't':
-			ctl.notime = 1;
+			ctl.time_fmt |= TIMEFTM_NONE;
 			break;
 		case 'u':
 			ctl.fltr_fac = 1;
@@ -1304,20 +1311,20 @@ 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))
+	if (ctl.raw && (ctl.fltr_lev || ctl.fltr_fac || ctl.decode ||
+			ctl.time_fmt & (TIMEFTM_NONE | TIMEFTM_DELTA | TIMEFTM_CTIME)))
 		errx(EXIT_FAILURE, _("--raw can't be used together with level, "
-		     "facility, decode, delta, ctime or notime options"));
+				     "facility, decode, delta, ctime or notime options"));
 
-	if (ctl.notime && (ctl.ctime || ctl.reltime))
+	if (ctl.time_fmt & TIMEFTM_NONE && (ctl.time_fmt & (TIMEFTM_CTIME | TIMEFTM_RELTIME)))
 		errx(EXIT_FAILURE, _("--notime can't be used together with --ctime or --reltime"));
-	if (ctl.reltime && ctl.ctime)
+	if ((ctl.time_fmt & TIMEFTM_RELTIME) && (ctl.time_fmt & TIMEFTM_CTIME))
 		errx(EXIT_FAILURE, _("--reltime can't be used together with --ctime "));
 
-	if (ctl.reltime) {
+	if (ctl.time_fmt & TIMEFTM_RELTIME) {
 		ctl.boot_time = get_boot_time();
 		if (!ctl.boot_time)
-			ctl.reltime = 0;
+			ctl.time_fmt &= TIMEFTM_RELTIME;
 	}
 
 	ctl.color = colors_init(colormode) ? 1 : 0;
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 14/19] dmesg: add --time-format option
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (12 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 13/19] dmesg: make time format parsing to use enum bit field Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 15/19] dmesg: add iso-8601 time format Sami Kerola
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/dmesg.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index b882120..6a8c64a 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -253,6 +253,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"
+		"                               [notime|ctime|delta|reltime]\n"), out);
 	fputs(USAGE_SEPARATOR, out);
 	fputs(USAGE_HELP, out);
 	fputs(USAGE_VERSION, out);
@@ -1142,6 +1144,19 @@ static int read_kmsg(struct dmesg_control *ctl)
 	return 0;
 }
 
+static int which_time_format(const char *optarg)
+{
+	if (!strcmp(optarg, "notime"))
+		return TIMEFTM_NONE;
+	if (!strcmp(optarg, "ctime"))
+		return TIMEFTM_CTIME;
+	if (!strcmp(optarg, "delta"))
+		return TIMEFTM_DELTA;
+	if (!strcmp(optarg, "reltime"))
+		return TIMEFTM_RELTIME;
+	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
+}
+
 int main(int argc, char *argv[])
 {
 	char *buf = NULL;
@@ -1157,6 +1172,9 @@ int main(int argc, char *argv[])
 		.time_fmt = 0,
 	};
 	int colormode = UL_COLORMODE_NEVER;
+	enum {
+		OPT_TIME_FORMAT = CHAR_MAX + 1,
+	};
 
 	static const struct option longopts[] = {
 		{ "buffer-size",   required_argument, NULL, 's' },
@@ -1183,6 +1201,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 }
 	};
 
@@ -1278,9 +1297,7 @@ int main(int argc, char *argv[])
 				ctl.bufsize = 4096;
 			break;
 		case 'T':
-			ctl.boot_time = get_boot_time();
-			if (ctl.boot_time)
-				ctl.time_fmt |= TIMEFTM_CTIME;
+			ctl.time_fmt |= TIMEFTM_CTIME;
 			break;
 		case 't':
 			ctl.time_fmt |= TIMEFTM_NONE;
@@ -1300,6 +1317,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);
@@ -1321,10 +1341,10 @@ int main(int argc, char *argv[])
 	if ((ctl.time_fmt & TIMEFTM_RELTIME) && (ctl.time_fmt & TIMEFTM_CTIME))
 		errx(EXIT_FAILURE, _("--reltime can't be used together with --ctime "));
 
-	if (ctl.time_fmt & TIMEFTM_RELTIME) {
+	if (ctl.time_fmt & (TIMEFTM_RELTIME | TIMEFTM_CTIME)) {
 		ctl.boot_time = get_boot_time();
 		if (!ctl.boot_time)
-			ctl.time_fmt &= TIMEFTM_RELTIME;
+			ctl.time_fmt &= TIMEFTM_RELTIME | TIMEFTM_CTIME;
 	}
 
 	ctl.color = colors_init(colormode) ? 1 : 0;
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 15/19] dmesg: add iso-8601 time format
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (13 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 14/19] dmesg: add --time-format option Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 16/19] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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 | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 6a8c64a..adfd6a5 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -131,6 +131,7 @@ enum {
 	TIMEFTM_CTIME	= (1 << 1),
 	TIMEFTM_DELTA	= (1 << 2),
 	TIMEFTM_RELTIME = (1 << 3),
+	TIMEFTM_ISO8601 = (1 << 4),
 };
 
 struct dmesg_control {
@@ -254,7 +255,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"
-		"                               [notime|ctime|delta|reltime]\n"), out);
+		"                               [notime|ctime|delta|reltime|iso]\n"), out);
 	fputs(USAGE_SEPARATOR, out);
 	fputs(USAGE_HELP, out);
 	fputs(USAGE_VERSION, out);
@@ -790,6 +791,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)
 {
@@ -888,6 +906,17 @@ static void print_record(struct dmesg_control *ctl,
 	}
 
 	/*
+	 * [iso-8601]
+	 */
+	else if (ctl->time_fmt & TIMEFTM_ISO8601) {
+		if (ctl->color)
+			color_enable(DMESG_COLOR_TIME);
+		printf("%s ", iso_8601_time(ctl, rec, buf, sizeof(buf)));
+		if (ctl->color)
+			color_disable();
+	}
+
+	/*
 	 * [reltime]
 	 */
 	else if (ctl->time_fmt & TIMEFTM_RELTIME) {
@@ -926,7 +955,8 @@ static void print_record(struct dmesg_control *ctl,
 	 */
 	if (ctl->method == DMESG_METHOD_KMSG &&
 	    !(ctl->time_fmt & TIMEFTM_NONE)
-	    && !(ctl->time_fmt & (TIMEFTM_CTIME | TIMEFTM_DELTA | TIMEFTM_RELTIME)))
+	    && !(ctl->time_fmt & (TIMEFTM_CTIME | TIMEFTM_DELTA |
+				  TIMEFTM_RELTIME | TIMEFTM_ISO8601)))
 	{
 		if (ctl->color)
 			color_enable(DMESG_COLOR_TIME);
@@ -1154,6 +1184,8 @@ static int which_time_format(const char *optarg)
 		return TIMEFTM_DELTA;
 	if (!strcmp(optarg, "reltime"))
 		return TIMEFTM_RELTIME;
+	if (!strcmp(optarg, "iso"))
+		return TIMEFTM_ISO8601;
 	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
 }
 
@@ -1341,7 +1373,7 @@ int main(int argc, char *argv[])
 	if ((ctl.time_fmt & TIMEFTM_RELTIME) && (ctl.time_fmt & TIMEFTM_CTIME))
 		errx(EXIT_FAILURE, _("--reltime can't be used together with --ctime "));
 
-	if (ctl.time_fmt & (TIMEFTM_RELTIME | TIMEFTM_CTIME)) {
+	if (ctl.time_fmt & (TIMEFTM_RELTIME | TIMEFTM_CTIME | TIMEFTM_ISO8601)) {
 		ctl.boot_time = get_boot_time();
 		if (!ctl.boot_time)
 			ctl.time_fmt &= TIMEFTM_RELTIME | TIMEFTM_CTIME;
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 16/19] docs: add --time-format option and ISO-8601 format to manual
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (14 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 15/19] dmesg: add iso-8601 time format Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-02 17:51 ` [PATCH 17/19] dmesg: make usage() a little bit shorter Sami Kerola
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 17/19] dmesg: make usage() a little bit shorter
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (15 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 16/19] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-03  8:56   ` Karel Zak
  2013-06-02 17:51 ` [PATCH 18/19] dmesg: more deterministic boot time detection Sami Kerola
                   ` (2 subsequent siblings)
  19 siblings, 1 reply; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The dmesg has rather long usage, so drop the timestamp format options
which are aliases of the more generic options.  Old options will remain
working as earlier.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/dmesg.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index adfd6a5..d80b3e9 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -234,8 +234,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);
@@ -248,14 +246,12 @@ 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(_("     --time-format <format>  show time stamp using format:\n"
-		"                               [notime|ctime|delta|reltime|iso]\n"), out);
+		"                               [notime|ctime|delta|reltime|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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 18/19] dmesg: more deterministic boot time detection
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (16 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 17/19] dmesg: make usage() a little bit shorter Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-03  9:35   ` Karel Zak
  2013-06-02 17:51 ` [PATCH 19/19] cal: fix few type mismatches Sami Kerola
  2013-06-07 10:28 ` [PATCH 00/19] pull: various clean ups and couple bug fixes Karel Zak
  19 siblings, 1 reply; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

This fixes an issue which made second in human readable time formats to
wiggle.  One would expect the two dmesg runs below would be identical,
but the half second sleep should almost always make some timestamps to
differ.

diff -q <(dmesg --ctime) <(sleep 0.5 ; dmesg --ctime)

Unfortunately this patch is not perfect.  The use of pid 1 directory
ctime is a bit off what kernel thinks is the start up time, which makes
the dmesg, journald, and kernel all to mutually disagree when system
started.  On my laptop the /proc/uptime consider start time to be
18:22:33, the old dmesg claimed 18:22:35, the new dmesg 18:22:42, and
journald 18:22:44.

In the heart of the problem is linux kernel that does not tell, in high
resolution accurancy, when start up happen.  I am almost sure the kernel
should log a message telling at boot, and at any time clock is skewed,
what time the kernel thinks it is.  A klog message such as 'kernel time
announcement: <epoc>.<milliseconds>' might solve most if not all
problems.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 include/pathnames.h |  3 ++-
 sys-utils/dmesg.c   | 27 ++++++++++++++-------------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/include/pathnames.h b/include/pathnames.h
index cc8a20b..84eabd4 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -48,7 +48,8 @@
 #define _PATH_SECURE		"/etc/securesingle"
 #define _PATH_USERTTY           "/etc/usertty"
 
-/* used in login-utils/shutdown.c */
+/* used in sys-utils/dmesg.c */
+#define _PATH_PROC_PID1		"/proc/1"
 
 /* used in login-utils/setpwnam.h and login-utils/islocal.c */
 #define _PATH_PASSWD		"/etc/passwd"
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index d80b3e9..da58c42 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -34,6 +34,7 @@
 #include "optutils.h"
 #include "mangle.h"
 #include "pager.h"
+#include "pathnames.h"
 
 /* Close the log.  Currently a NOP. */
 #define SYSLOG_ACTION_CLOSE          0
@@ -141,7 +142,7 @@ struct dmesg_control {
 
 	struct timeval	lasttime;	/* last printed timestamp */
 	struct tm	lasttm;		/* last localtime */
-	time_t		boot_time;	/* system boot time */
+	struct timeval	boot_time;	/* system boot time */
 
 	int		action;		/* SYSLOG_ACTION_* */
 	int		method;		/* DMESG_METHOD_* */
@@ -464,18 +465,17 @@ static int get_syslog_buffer_size(void)
 	return n > 0 ? n : 0;
 }
 
-static time_t get_boot_time(void)
+static struct timeval get_boot_time(void)
 {
-	struct sysinfo info;
-	struct timeval tv;
+	struct stat st;
+	struct timeval ret;
+	memset(&ret, 0, sizeof(struct timeval));
 
-	if (sysinfo(&info) != 0)
-		warn(_("sysinfo failed"));
-	else if (gettimeofday(&tv, NULL) != 0)
-		warn(_("gettimeofday failed"));
+	if (stat(_PATH_PROC_PID1, &st))
+		warn(_("stat failed %s"), _PATH_PROC_PID1);
 	else
-		return tv.tv_sec -= info.uptime;
-	return 0;
+		ret.tv_sec = st.st_ctime;
+	return ret;
 }
 
 /*
@@ -763,8 +763,9 @@ static struct tm *record_localtime(struct dmesg_control *ctl,
 				   struct dmesg_record *rec,
 				   struct tm *tm)
 {
-	time_t t = ctl->boot_time + rec->tv.tv_sec;
-	return localtime_r(&t, tm);
+	struct timeval res;
+	timeradd(&(ctl->boot_time), &(rec->tv), &res);
+	return localtime_r(&(res.tv_sec), tm);
 }
 
 static char *record_ctime(struct dmesg_control *ctl,
@@ -1371,7 +1372,7 @@ int main(int argc, char *argv[])
 
 	if (ctl.time_fmt & (TIMEFTM_RELTIME | TIMEFTM_CTIME | TIMEFTM_ISO8601)) {
 		ctl.boot_time = get_boot_time();
-		if (!ctl.boot_time)
+		if (!ctl.boot_time.tv_sec)
 			ctl.time_fmt &= TIMEFTM_RELTIME | TIMEFTM_CTIME;
 	}
 
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 19/19] cal: fix few type mismatches
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (17 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 18/19] dmesg: more deterministic boot time detection Sami Kerola
@ 2013-06-02 17:51 ` Sami Kerola
  2013-06-07 10:28 ` [PATCH 00/19] pull: various clean ups and couple bug fixes Karel Zak
  19 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-02 17:51 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

Sloppiness from commit e44fe4712140774b677de466affc31e0581ee335.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/cal.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index befadbe..d6fb32c 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -237,7 +237,7 @@ static char * ascii_day(char *, int);
 static int center_str(const char* src, char* dest, size_t dest_size, size_t width);
 static void center(const char *, size_t, int);
 static void day_array(int, int, long, int *);
-static int day_in_week(int, int, int);
+static int day_in_week(int, int, long);
 static int day_in_year(int, int, long);
 static void yearly(int, long, int);
 static int do_monthly(int, int, long, struct fmt_st*, int);
@@ -469,11 +469,11 @@ static int do_monthly(int day, int month, long year,
 		snprintf(lineout, sizeof(lineout), _("%s"), full_month[month - 1]);
 		center_str(lineout, out->s[pos], ARRAY_SIZE(out->s[pos]), width);
 		pos++;
-		snprintf(lineout, sizeof(lineout), _("%lu"), year);
+		snprintf(lineout, sizeof(lineout), _("%ld"), year);
 		center_str(lineout, out->s[pos], ARRAY_SIZE(out->s[pos]), width);
 		pos++;
 	} else {
-		snprintf(lineout, sizeof(lineout), _("%s %lu"),
+		snprintf(lineout, sizeof(lineout), _("%s %ld"),
 			full_month[month - 1], year);
 		center_str(lineout, out->s[pos], ARRAY_SIZE(out->s[pos]), width);
 		pos++;
@@ -514,7 +514,7 @@ static int two_header_lines(int month, long year)
 	char lineout[FMT_ST_CHARS];
 	size_t width = (julian ? J_WEEK_LEN : WEEK_LEN) - 1;
 	size_t len;
-	snprintf(lineout, sizeof(lineout), "%lu", year);
+	snprintf(lineout, sizeof(lineout), "%ld", year);
 	len = strlen(lineout);
 	len += strlen(full_month[month - 1]) + 1;
 	if (width < len)
@@ -602,7 +602,7 @@ static void yearly(int day, long year, int julian)
 		sep_len = HEAD_SEP;
 		week_len = WEEK_LEN;
 	}
-	snprintf(lineout, sizeof(lineout), "%lu", year);
+	snprintf(lineout, sizeof(lineout), "%ld", year);
 	/* 2013-04-28: The -1 near sep_len makes year header to be
 	 * aligned exactly how it has been aligned for long time, but it
 	 * is unexplainable.  */
@@ -699,7 +699,7 @@ static int day_in_year(int day, int month, long year)
  *	3 Sep. 1752 through 13 Sep. 1752, and returns invalid weekday
  *	during the period of 11 days.
  */
-static int day_in_week(int d, int m, int y)
+static int day_in_week(int d, int m, long y)
 {
 	static const int reform[] = {
 		SUNDAY, WEDNESDAY, TUESDAY, FRIDAY, SUNDAY, WEDNESDAY,
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 13/19] dmesg: make time format parsing to use enum bit field
  2013-06-02 17:51 ` [PATCH 13/19] dmesg: make time format parsing to use enum bit field Sami Kerola
@ 2013-06-03  8:45   ` Karel Zak
  0 siblings, 0 replies; 26+ messages in thread
From: Karel Zak @ 2013-06-03  8:45 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jun 02, 2013 at 06:51:19PM +0100, Sami Kerola wrote:
> +enum {
> +	TIMEFTM_NONE	= (1 << 0),
> +	TIMEFTM_CTIME	= (1 << 1),
> +	TIMEFTM_DELTA	= (1 << 2),
> +	TIMEFTM_RELTIME = (1 << 3),
> +};

 Do we really need to use the time formats as flags? Would be better
 to use it as a real enums?

 I know that it means that for "delta" we need more types, but it's
 probably better than assume arbitrary combination of all the types.

enum {
    DMESG_TIMEFTM_NONE = 0
    DMESG_TIMEFTM_TIME,           /* [time] */
	DMESG_TIMEFTM_CTIME,          /* [ctime] */
    DMESG_TIMEFTM_CTIME_DELTA,    /* [ctime <delta>] */
	DMESG_TIMEFTM_TIME_DELTA,     /* [time <delta>] */
    DMESG_TIMEFTM_DELTA,          /* [<delta>] */
	DMESG_TIMEFTM_RELTIME         /* [relative] */
};

and all you need is to set any default (DMESG_TIMEFTM_TIME) and clear the
default if --notime is specified.

In the code you can check for "if (ctl->time_fmt)" or add

    #define is_timefmt(c, f)   (c->time_fmt == (TIMEFTM_ ##f))

and use

    if (is_timefmt(ctl, DELTA))


  Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 17/19] dmesg: make usage() a little bit shorter
  2013-06-02 17:51 ` [PATCH 17/19] dmesg: make usage() a little bit shorter Sami Kerola
@ 2013-06-03  8:56   ` Karel Zak
  0 siblings, 0 replies; 26+ messages in thread
From: Karel Zak @ 2013-06-03  8:56 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jun 02, 2013 at 06:51:23PM +0100, Sami Kerola wrote:
> The dmesg has rather long usage, so drop the timestamp format options
> which are aliases of the more generic options.  Old options will remain
> working as earlier.
> 
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
>  sys-utils/dmesg.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
> index adfd6a5..d80b3e9 100644
> --- a/sys-utils/dmesg.c
> +++ b/sys-utils/dmesg.c
> @@ -234,8 +234,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);

 I'd like to keep the aliases in the usage() output. IMHO it's fine to use

    fputs(_(" -e, --reltime               alias to --time-format reltime");

 Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 18/19] dmesg: more deterministic boot time detection
  2013-06-02 17:51 ` [PATCH 18/19] dmesg: more deterministic boot time detection Sami Kerola
@ 2013-06-03  9:35   ` Karel Zak
  0 siblings, 0 replies; 26+ messages in thread
From: Karel Zak @ 2013-06-03  9:35 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jun 02, 2013 at 06:51:24PM +0100, Sami Kerola wrote:
> diff --git a/include/pathnames.h b/include/pathnames.h
> index cc8a20b..84eabd4 100644
> --- a/include/pathnames.h
> +++ b/include/pathnames.h
> @@ -48,7 +48,8 @@
>  #define _PATH_SECURE		"/etc/securesingle"
>  #define _PATH_USERTTY           "/etc/usertty"
>  
> -/* used in login-utils/shutdown.c */
> +/* used in sys-utils/dmesg.c */
> +#define _PATH_PROC_PID1		"/proc/1"
>  
>  /* used in login-utils/setpwnam.h and login-utils/islocal.c */
>  #define _PATH_PASSWD		"/etc/passwd"
> diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
> index d80b3e9..da58c42 100644
> --- a/sys-utils/dmesg.c
> +++ b/sys-utils/dmesg.c
> @@ -34,6 +34,7 @@
>  #include "optutils.h"
>  #include "mangle.h"
>  #include "pager.h"
> +#include "pathnames.h"
>  
>  /* Close the log.  Currently a NOP. */
>  #define SYSLOG_ACTION_CLOSE          0
> @@ -141,7 +142,7 @@ struct dmesg_control {
>  
>  	struct timeval	lasttime;	/* last printed timestamp */
>  	struct tm	lasttm;		/* last localtime */
> -	time_t		boot_time;	/* system boot time */
> +	struct timeval	boot_time;	/* system boot time */
>  
>  	int		action;		/* SYSLOG_ACTION_* */
>  	int		method;		/* DMESG_METHOD_* */
> @@ -464,18 +465,17 @@ static int get_syslog_buffer_size(void)
>  	return n > 0 ? n : 0;
>  }
>  
> -static time_t get_boot_time(void)
> +static struct timeval get_boot_time(void)
>  {
> -	struct sysinfo info;
> -	struct timeval tv;
> +	struct stat st;
> +	struct timeval ret;
> +	memset(&ret, 0, sizeof(struct timeval));
>  
> -	if (sysinfo(&info) != 0)
> -		warn(_("sysinfo failed"));
> -	else if (gettimeofday(&tv, NULL) != 0)
> -		warn(_("gettimeofday failed"));
> +	if (stat(_PATH_PROC_PID1, &st))
> +		warn(_("stat failed %s"), _PATH_PROC_PID1);

Nice idea, but what about the delay between kernel boot and init
start -- in this time kernel already writes to the log.

Maybe we need to study systemd code, I guess they already have all the
information:

# systemd-analyze time
Startup finished in 11.306s (firmware) + 31ms (loader) + 864ms
(kernel) + 1.971s (initrd) + 52.068s (userspace) = 1min 6.243s

>  	else
> -		return tv.tv_sec -= info.uptime;
> -	return 0;
> +		ret.tv_sec = st.st_ctime;
> +	return ret;
>  }

 stat() usually provides nanoseconds resolution

#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
     ret.tv_sec = st.st_ctime;
     ret.tv_usec = st.st_mtim.tv_nsec / 1000;
#endif

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values
  2013-06-02 17:51 ` [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
@ 2013-06-07 10:20   ` Karel Zak
  0 siblings, 0 replies; 26+ messages in thread
From: Karel Zak @ 2013-06-07 10:20 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jun 02, 2013 at 06:51:10PM +0100, Sami Kerola wrote:
>      if ((out = lseek(fd, in, SEEK_SET)) != in) {
>  	perror("lseek");
> -	error(_("seek error on %s - cannot seek to %lu\n"), dev, s);
> +	warnx(_("seek error on %s - cannot seek to %lu"), dev, s);
>  	return 0;

 I don't think that perror() + warnx() is elegant solution, just use
 warn() only.

 warn(_("seek failed %s" - cannot seek to %lu"), dev, s);

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 00/19] pull: various clean ups and couple bug fixes
  2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
                   ` (18 preceding siblings ...)
  2013-06-02 17:51 ` [PATCH 19/19] cal: fix few type mismatches Sami Kerola
@ 2013-06-07 10:28 ` Karel Zak
  2013-06-07 15:45   ` Sami Kerola
  19 siblings, 1 reply; 26+ messages in thread
From: Karel Zak @ 2013-06-07 10:28 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Jun 02, 2013 at 06:51:06PM +0100, Sami Kerola wrote:
>       lib: remove unused code
>       lscpu: add max MHz value to make cpu governor effects more visible
>       docs: add lscpu max mhz to manual and bash completion

 Applied.

>       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()

 Not applied.

>       rev: stop adding new line at the end when input does not have it
>       rev: simplify new line detection and impossible test
>       rev: reduce stream checking when closing read-only file descriptor

 Applied.

>       dmesg: make time format parsing to use enum bit field
>       dmesg: add --time-format option
>       dmesg: add iso-8601 time format
>       docs: add --time-format option and ISO-8601 format to manual
>       dmesg: make usage() a little bit shorter
>       dmesg: more deterministic boot time detection

 Not applied.

>       cal: fix few type mismatches

 Applied.


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 00/19] pull: various clean ups and couple bug fixes
  2013-06-07 10:28 ` [PATCH 00/19] pull: various clean ups and couple bug fixes Karel Zak
@ 2013-06-07 15:45   ` Sami Kerola
  0 siblings, 0 replies; 26+ messages in thread
From: Sami Kerola @ 2013-06-07 15:45 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

On 7 June 2013 11:28, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Jun 02, 2013 at 06:51:06PM +0100, Sami Kerola wrote:
>>       lib: remove unused code
>>       lscpu: add max MHz value to make cpu governor effects more visible
>>       docs: add lscpu max mhz to manual and bash completion
>
>  Applied.
>
>>       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()
>
>  Not applied.
>
>>       rev: stop adding new line at the end when input does not have it
>>       rev: simplify new line detection and impossible test
>>       rev: reduce stream checking when closing read-only file descriptor
>
>  Applied.
>
>>       dmesg: make time format parsing to use enum bit field
>>       dmesg: add --time-format option
>>       dmesg: add iso-8601 time format
>>       docs: add --time-format option and ISO-8601 format to manual
>>       dmesg: make usage() a little bit shorter
>>       dmesg: more deterministic boot time detection
>
>  Not applied.
>
>>       cal: fix few type mismatches
>
>  Applied.

Karel, thank you for comments and partial merge. My week has utterly
crazy, so I have not had time to react on the earlier message. I'll do
my best fixing the reported issues sometime in next 10 days.
Meanwhile, all reading this list, have a good week.

--
   Sami Kerola
   http://www.iki.fi/kerolasa/

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-06-07 15:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-02 17:51 [PATCH 00/19] pull: various clean ups and couple bug fixes Sami Kerola
2013-06-02 17:51 ` [PATCH 01/19] lib: remove unused code Sami Kerola
2013-06-02 17:51 ` [PATCH 02/19] lscpu: add max MHz value to make cpu governor effects more visible Sami Kerola
2013-06-02 17:51 ` [PATCH 03/19] docs: add lscpu max mhz to manual and bash completion Sami Kerola
2013-06-02 17:51 ` [PATCH 04/19] sfdisk: use libc error printing function, and symbolic exit values Sami Kerola
2013-06-07 10:20   ` Karel Zak
2013-06-02 17:51 ` [PATCH 05/19] sfdisk: clean up usage() functions Sami Kerola
2013-06-02 17:51 ` [PATCH 06/19] sfdisk: use program_invocation_short_name to determine program name Sami Kerola
2013-06-02 17:51 ` [PATCH 07/19] docs: correct sfdisk --activate instructions Sami Kerola
2013-06-02 17:51 ` [PATCH 08/19] sfdisk: remove --unhide and related functions Sami Kerola
2013-06-02 17:51 ` [PATCH 09/19] sfdisk: replace my_warn() with warnx() Sami Kerola
2013-06-02 17:51 ` [PATCH 10/19] rev: stop adding new line at the end when input does not have it Sami Kerola
2013-06-02 17:51 ` [PATCH 11/19] rev: simplify new line detection and impossible test Sami Kerola
2013-06-02 17:51 ` [PATCH 12/19] rev: reduce stream checking when closing read-only file descriptor Sami Kerola
2013-06-02 17:51 ` [PATCH 13/19] dmesg: make time format parsing to use enum bit field Sami Kerola
2013-06-03  8:45   ` Karel Zak
2013-06-02 17:51 ` [PATCH 14/19] dmesg: add --time-format option Sami Kerola
2013-06-02 17:51 ` [PATCH 15/19] dmesg: add iso-8601 time format Sami Kerola
2013-06-02 17:51 ` [PATCH 16/19] docs: add --time-format option and ISO-8601 format to manual Sami Kerola
2013-06-02 17:51 ` [PATCH 17/19] dmesg: make usage() a little bit shorter Sami Kerola
2013-06-03  8:56   ` Karel Zak
2013-06-02 17:51 ` [PATCH 18/19] dmesg: more deterministic boot time detection Sami Kerola
2013-06-03  9:35   ` Karel Zak
2013-06-02 17:51 ` [PATCH 19/19] cal: fix few type mismatches Sami Kerola
2013-06-07 10:28 ` [PATCH 00/19] pull: various clean ups and couple bug fixes Karel Zak
2013-06-07 15:45   ` Sami Kerola

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.