Util-Linux package development
 help / color / mirror / Atom feed
* Re: fdisk
From: Karel Zak @ 2011-06-27 14:21 UTC (permalink / raw)
  To: Bruce Dubbs; +Cc: util-linux
In-Reply-To: <4E04D6A3.4060105@gmail.com>

On Fri, Jun 24, 2011 at 01:25:39PM -0500, Bruce Dubbs wrote:
> On my system, a block appears to be 2-512 byte sectors, but is it
> always so?

 Yes. It's stupid legacy (the same thing you can found in
 /proc/partitions).

 I hope that one day we will have better and nicer fdisk with 
 human readable sizes ;-)

    Karel

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

^ permalink raw reply

* Re: [PATCH] blkdev: add blkdev_get_physector_size()
From: Karel Zak @ 2011-06-27 14:22 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1308625104.3690.1.camel@offworld>

On Mon, Jun 20, 2011 at 10:58:24PM -0400, Davidlohr Bueso wrote:
>  include/blkdev.h |    3 +++
>  lib/blkdev.c     |   14 ++++++++++++++
>  2 files changed, 17 insertions(+), 0 deletions(-)

 Applied with minor changes, thanks.

    Karel

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

^ permalink raw reply

* Re: [PATCH] mkfs.minix: check for misalignment
From: Karel Zak @ 2011-06-27 14:23 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1308625906.3690.2.camel@offworld>

On Mon, Jun 20, 2011 at 11:11:46PM -0400, Davidlohr Bueso wrote:
>  disk-utils/mkfs.minix.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)

 Applied with a small change, thanks.

> @@ -653,6 +653,11 @@ int main(int argc, char ** argv) {
>  		DEV = open(device_name,O_RDWR | O_EXCL);
>  	else
>  		DEV = open(device_name,O_RDWR);
> +
> +	if (blkdev_is_misaligned(DEV))
> +		warnx(_("warning: %s is misaligned"), device_name);

 It makes sense for block devices only.

    Karel

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

^ permalink raw reply

* Re: [PATCH] lscpu: fix bogomips detection for s390
From: Karel Zak @ 2011-06-27 14:24 UTC (permalink / raw)
  To: Heiko Carstens; +Cc: util-linux
In-Reply-To: <20110621112433.GA4198@osiris.boeblingen.de.ibm.com>

On Tue, Jun 21, 2011 at 01:24:33PM +0200, Heiko Carstens wrote:
>  sys-utils/lscpu.c |    2 ++
>  1 file changed, 2 insertions(+)

 Applied, thanks.

    Karel

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

^ permalink raw reply

* Re: Pentecost weekend pull request
From: Karel Zak @ 2011-06-27 15:29 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux
In-Reply-To: <BANLkTimNPg6VVNS+MQ-9cMgs_ppCQYVE=A@mail.gmail.com>

On Sat, Jun 25, 2011 at 05:26:35PM +0200, Sami Kerola wrote:
> All the patches are available in the git repository at:
>  git://github.com/kerolasa/lelux-utiliteetit.git wknd23

 Applied, thanks!

    Karel

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

^ permalink raw reply

* Re: mount: if mount -a crashes on one partition, remaining should be probed
From: Karel Zak @ 2011-06-27 15:59 UTC (permalink / raw)
  To: Marek Otahal; +Cc: util-linux
In-Reply-To: <201106071151.18570.markotahal@gmail.com>

On Tue, Jun 07, 2011 at 11:51:17AM +0200, Marek Otahal wrote:
> with 2.6.39 kernel I can get in conditions when mounting a btrfs
> partition segfaults (I already reported upstream -
> http://article.gmane.org/gmane.comp.file-systems.btrfs/11135 ).

 If the oops occur in any process (except init) then the process is
 usually killed by kernel... so it really does not seem like mount(8)
 bug.

    Karel

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

^ permalink raw reply

* Re: fdisk
From: Mike Frysinger @ 2011-06-27 19:27 UTC (permalink / raw)
  To: Karel Zak; +Cc: Bruce Dubbs, util-linux
In-Reply-To: <20110627142119.GB6418@nb.net.home>

[-- Attachment #1: Type: Text/Plain, Size: 440 bytes --]

On Monday, June 27, 2011 10:21:19 Karel Zak wrote:
> On Fri, Jun 24, 2011 at 01:25:39PM -0500, Bruce Dubbs wrote:
> > On my system, a block appears to be 2-512 byte sectors, but is it
> > always so?
> 
>  Yes. It's stupid legacy (the same thing you can found in
>  /proc/partitions).
> 
>  I hope that one day we will have better and nicer fdisk with
>  human readable sizes ;-)

and merge duplicated code with cfdisk ;)
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply

* [BUG] umount does not work for disconected nfs mounts
From: Konstantin Khlebnikov @ 2011-06-28  8:18 UTC (permalink / raw)
  To: util-linux, Petr Uzel, Karel Zak

commit 33cee6675edecbd27c0628f8b7c74c7d88fc02b2
http://git.kernel.org/?p=utils/util-linux/util-linux-ng.git;a=commitdiff;h=33cee6675edecbd27c0628f8b7c74c7d88fc02b2;hp=fde25e6be6e00a0998eb58b4b9d0d0b9ad65dbfd
"umount: allow unmounting loopdev specified by associated file"
broke umounting (by mountpoint) for broken nfs mounts,
because now umount always call stat() for target argument and umount hang inside nfs-rpc:

[<ffffffff8163df3f>] rpc_wait_bit_killable+0x1f/0x40
[<ffffffff8163eb85>] __rpc_execute+0xe5/0x2f0
[<ffffffff8163eebe>] rpc_execute+0x3e/0x50
[<ffffffff816372f0>] rpc_run_task+0x70/0x90
[<ffffffff816373fe>] rpc_call_sync+0x3e/0x70
[<ffffffff812228f3>] nfs3_rpc_wrapper.constprop.11+0x43/0x70
[<ffffffff81223bd2>] nfs3_proc_getattr+0x42/0x80
[<ffffffff81212955>] __nfs_revalidate_inode+0x95/0x1f0
[<ffffffff81212bf1>] nfs_revalidate_inode+0x31/0x60
[<ffffffff81212cca>] nfs_getattr+0x5a/0x110
[<ffffffff8112caea>] vfs_getattr+0x1a/0x30
[<ffffffff8112cce3>] vfs_fstatat+0x53/0x70
[<ffffffff8112cd36>] vfs_stat+0x16/0x20
[<ffffffff8112d0c5>] sys_newstat+0x15/0x30
[<ffffffff816c45bb>] tracesys+0xd9/0xde
[<ffffffffffffffff>] 0xffffffffffffffff

so mount /mnt/nfs get stuck, umounting by device is still possible.

^ permalink raw reply

* Re: [BUG] umount does not work for disconected nfs mounts
From: Petr Uzel @ 2011-06-28  8:57 UTC (permalink / raw)
  To: util-linux; +Cc: khlebnikov
In-Reply-To: <4E098E3B.5060707@openvz.org>

[-- Attachment #1: Type: text/plain, Size: 1687 bytes --]

On Tue, Jun 28, 2011 at 12:18:03PM +0400, Konstantin Khlebnikov wrote:
> commit 33cee6675edecbd27c0628f8b7c74c7d88fc02b2
> http://git.kernel.org/?p=utils/util-linux/util-linux-ng.git;a=commitdiff;h=33cee6675edecbd27c0628f8b7c74c7d88fc02b2;hp=fde25e6be6e00a0998eb58b4b9d0d0b9ad65dbfd
> "umount: allow unmounting loopdev specified by associated file"
> broke umounting (by mountpoint) for broken nfs mounts,
> because now umount always call stat() for target argument and umount hang inside nfs-rpc:
> 
> [<ffffffff8163df3f>] rpc_wait_bit_killable+0x1f/0x40
> [<ffffffff8163eb85>] __rpc_execute+0xe5/0x2f0
> [<ffffffff8163eebe>] rpc_execute+0x3e/0x50
> [<ffffffff816372f0>] rpc_run_task+0x70/0x90
> [<ffffffff816373fe>] rpc_call_sync+0x3e/0x70
> [<ffffffff812228f3>] nfs3_rpc_wrapper.constprop.11+0x43/0x70
> [<ffffffff81223bd2>] nfs3_proc_getattr+0x42/0x80
> [<ffffffff81212955>] __nfs_revalidate_inode+0x95/0x1f0
> [<ffffffff81212bf1>] nfs_revalidate_inode+0x31/0x60
> [<ffffffff81212cca>] nfs_getattr+0x5a/0x110
> [<ffffffff8112caea>] vfs_getattr+0x1a/0x30
> [<ffffffff8112cce3>] vfs_fstatat+0x53/0x70
> [<ffffffff8112cd36>] vfs_stat+0x16/0x20
> [<ffffffff8112d0c5>] sys_newstat+0x15/0x30
> [<ffffffff816c45bb>] tracesys+0xd9/0xde
> [<ffffffffffffffff>] 0xffffffffffffffff

Shouldn't this be handled in the kernel? Or is stat() really
supposed to fail in such way with broken nfs?

> 
> so mount /mnt/nfs get stuck, umounting by device is still possible.

We might first scan through mtab to check if umount arg is known
mountpoint and only if we fail, we would look for associated loopfile.

Karel?


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply

* Re: [BUG] umount does not work for disconected nfs mounts
From: Konstantin Khlebnikov @ 2011-06-28  9:14 UTC (permalink / raw)
  To: util-linux, khlebnikov
In-Reply-To: <20110628085724.GE22770@foxbat.suse.cz>

Petr Uzel wrote:
> On Tue, Jun 28, 2011 at 12:18:03PM +0400, Konstantin Khlebnikov wrote:
>> commit 33cee6675edecbd27c0628f8b7c74c7d88fc02b2
>> http://git.kernel.org/?p=utils/util-linux/util-linux-ng.git;a=commitdiff;h=33cee6675edecbd27c0628f8b7c74c7d88fc02b2;hp=fde25e6be6e00a0998eb58b4b9d0d0b9ad65dbfd
>> "umount: allow unmounting loopdev specified by associated file"
>> broke umounting (by mountpoint) for broken nfs mounts,
>> because now umount always call stat() for target argument and umount hang inside nfs-rpc:
>>
>> [<ffffffff8163df3f>] rpc_wait_bit_killable+0x1f/0x40
>> [<ffffffff8163eb85>] __rpc_execute+0xe5/0x2f0
>> [<ffffffff8163eebe>] rpc_execute+0x3e/0x50
>> [<ffffffff816372f0>] rpc_run_task+0x70/0x90
>> [<ffffffff816373fe>] rpc_call_sync+0x3e/0x70
>> [<ffffffff812228f3>] nfs3_rpc_wrapper.constprop.11+0x43/0x70
>> [<ffffffff81223bd2>] nfs3_proc_getattr+0x42/0x80
>> [<ffffffff81212955>] __nfs_revalidate_inode+0x95/0x1f0
>> [<ffffffff81212bf1>] nfs_revalidate_inode+0x31/0x60
>> [<ffffffff81212cca>] nfs_getattr+0x5a/0x110
>> [<ffffffff8112caea>] vfs_getattr+0x1a/0x30
>> [<ffffffff8112cce3>] vfs_fstatat+0x53/0x70
>> [<ffffffff8112cd36>] vfs_stat+0x16/0x20
>> [<ffffffff8112d0c5>] sys_newstat+0x15/0x30
>> [<ffffffff816c45bb>] tracesys+0xd9/0xde
>> [<ffffffffffffffff>] 0xffffffffffffffff
>
> Shouldn't this be handled in the kernel? Or is stat() really
> supposed to fail in such way with broken nfs?

It depends on used mount options, IIRR in "soft" mode it by default fail with EIO after 3-6 minutes timeout,
in "hard" mode syscalls never returns EIO.

BTW linux support bindmounting for individual files,
so argument can refer to regular file not only for loop device image.

>
>>
>> so mount /mnt/nfs get stuck, umounting by device is still possible.
>
> We might first scan through mtab to check if umount arg is known
> mountpoint and only if we fail, we would look for associated loopfile.

Yes, it seems is the best solution

>
> Karel?
>
>
> Petr
>
> --
> Petr Uzel
> IRC: ptr_uzl @ freenode


^ permalink raw reply

* [PATCH 1/4] script: option --force added
From: Sami Kerola @ 2011-06-28 10:43 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

The --force will allow default output destination, e.g.
typescript file, to be hard or symbolic link.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.1 |    3 +++
 term-utils/script.c |   21 ++++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/term-utils/script.1 b/term-utils/script.1
index 725bdb2..f618ec3 100644
--- a/term-utils/script.1
+++ b/term-utils/script.1
@@ -84,6 +84,9 @@ termination on signal termination exit code is 128+n.
 Flush output after each write. This is nice for telecooperation:
 One person does `mkfifo foo; script -f foo' and another can
 supervise real-time what is being done using `cat foo'.
+.It Fl Fl force
+Allow default output destination, e.g. typescript file, to be
+hard or symbolic link. The command will follow symbolic link.
 .It Fl q, Fl Fl quiet
 Be quiet.
 .It Fl t, Fl Fl timing[=FILE]
diff --git a/term-utils/script.c b/term-utils/script.c
index 603d392..1753849 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -101,6 +101,7 @@ int	eflg = 0;
 int	fflg = 0;
 int	qflg = 0;
 int	tflg = 0;
+int	forceflg = 0;
 
 int die;
 int resized;
@@ -109,14 +110,13 @@ static void
 die_if_link(char *fn) {
 	struct stat s;
 
+	if (forceflg)
+		return;
 	if (lstat(fn, &s) == 0 && (S_ISLNK(s.st_mode) || s.st_nlink > 1))
-	        /* FIXME: there is no [options] to allow/force this to happen.  */
 		errx(EXIT_FAILURE,
-			_("Warning: `%s' is a link.\n"
-			  "Use `%s [options] %s' if you really "
-			  "want to use it.\n"
-			  "Program not started.\n"),
-			fn, program_invocation_short_name, fn);
+		     _("error: output file `%s' is a link\n"
+		       "Use --force if you really want to use it.\n"
+		       "Program not started."), fn);
 }
 
 static void __attribute__((__noreturn__))
@@ -132,6 +132,7 @@ usage(FILE *out)
 		" -c, --command COMMAND   run command rather than interactive shell\n"
 		" -r, --return            return exit code of the child process\n"
 		" -f, --flush             run flush after each write\n"
+		"     --force             use output file even it would be a link\n"
 		" -q, --quiet             be quiet\n"
 		" -t, --timing=FILE       output timing data to stderr, or to file\n"
 		" -V, --version           output version information and exit\n"
@@ -157,11 +158,14 @@ main(int argc, char **argv) {
 	int ch;
 	FILE *timingfd = stderr;
 
+	enum { FORCE_OPTION = CHAR_MAX + 1 };
+
 	static const struct option longopts[] = {
 		{ "append",	no_argument,	   0, 'a' },
 		{ "command",	required_argument, 0, 'c' },
 		{ "return",	no_argument,	   0, 'e' },
 		{ "flush",	no_argument,	   0, 'f' },
+		{ "force",	no_argument,	   0, FORCE_OPTION, },
 		{ "quiet",	no_argument,	   0, 'q' },
 		{ "timing",	optional_argument, 0, 't' },
 		{ "version",	no_argument,	   0, 'V' },
@@ -175,7 +179,7 @@ main(int argc, char **argv) {
 	textdomain(PACKAGE);
 
 	while ((ch = getopt_long(argc, argv, "ac:efqt::Vh", longopts, NULL)) != -1)
-		switch((char)ch) {
+		switch(ch) {
 		case 'a':
 			aflg++;
 			break;
@@ -188,6 +192,9 @@ main(int argc, char **argv) {
 		case 'f':
 			fflg++;
 			break;
+		case FORCE_OPTION:
+			forceflg = 1;
+			break;
 		case 'q':
 			qflg++;
 			break;
-- 
1.7.5.2


^ permalink raw reply related

* [PATCH 2/4] script: remove unnecessary void casting
From: Sami Kerola @ 2011-06-28 10:43 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa
In-Reply-To: <1309257806-1418-1-git-send-email-kerolasa@iki.fi>

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.c |   56 +++++++++++++++++++++++++-------------------------
 1 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 1753849..601a91d 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -289,7 +289,7 @@ doinput() {
 	register int cc;
 	char ibuf[BUFSIZ];
 
-	(void) fclose(fscript);
+	fclose(fscript);
 
 	while (die == 0) {
 		if ((cc = read(0, ibuf, BUFSIZ)) > 0) {
@@ -326,8 +326,8 @@ void
 resize(int dummy __attribute__ ((__unused__))) {
 	resized = 1;
 	/* transmit window change information to the child */
-	(void) ioctl(0, TIOCGWINSZ, (char *)&win);
-	(void) ioctl(slave, TIOCSWINSZ, (char *)&win);
+	ioctl(0, TIOCGWINSZ, (char *)&win);
+	ioctl(slave, TIOCSWINSZ, (char *)&win);
 }
 
 /*
@@ -350,9 +350,9 @@ dooutput(FILE *timingfd) {
 	ssize_t wrt;
 	ssize_t fwrt;
 
-	(void) close(0);
+	close(0);
 #ifdef HAVE_LIBUTIL
-	(void) close(slave);
+	close(slave);
 #endif
 	tvec = time((time_t *)NULL);
 	my_strftime(obuf, sizeof obuf, "%c\n", localtime(&tvec));
@@ -396,7 +396,7 @@ dooutput(FILE *timingfd) {
 			fail();
 		}
 		if (fflg)
-			(void) fflush(fscript);
+			fflush(fscript);
 	} while(1);
 
 	if (flgs)
@@ -413,18 +413,18 @@ doshell() {
 
 	t = open(_PATH_DEV_TTY, O_RDWR);
 	if (t >= 0) {
-		(void) ioctl(t, TIOCNOTTY, (char *)0);
-		(void) close(t);
+		ioctl(t, TIOCNOTTY, (char *)0);
+		close(t);
 	}
 #endif
 
 	getslave();
-	(void) close(master);
-	(void) fclose(fscript);
-	(void) dup2(slave, 0);
-	(void) dup2(slave, 1);
-	(void) dup2(slave, 2);
-	(void) close(slave);
+	close(master);
+	fclose(fscript);
+	dup2(slave, 0);
+	dup2(slave, 1);
+	dup2(slave, 2);
+	close(slave);
 
 	master = -1;
 
@@ -450,13 +450,13 @@ fixtty() {
 	rtt = tt;
 	cfmakeraw(&rtt);
 	rtt.c_lflag &= ~ECHO;
-	(void) tcsetattr(0, TCSANOW, &rtt);
+	tcsetattr(0, TCSANOW, &rtt);
 }
 
 void
 fail() {
 
-	(void) kill(0, SIGTERM);
+	kill(0, SIGTERM);
 	done();
 }
 
@@ -471,12 +471,12 @@ done() {
 			my_strftime(buf, sizeof buf, "%c\n", localtime(&tvec));
 			fprintf(fscript, _("\nScript done on %s"), buf);
 		}
-		(void) fclose(fscript);
-		(void) close(master);
+		fclose(fscript);
+		close(master);
 
 		master = -1;
 	} else {
-		(void) tcsetattr(0, TCSADRAIN, &tt);
+		tcsetattr(0, TCSADRAIN, &tt);
 		if (!qflg)
 			printf(_("Script done, file is %s\n"), fname);
 #ifdef HAVE_LIBUTEMPTER
@@ -497,8 +497,8 @@ done() {
 void
 getmaster() {
 #if HAVE_LIBUTIL && HAVE_PTY_H
-	(void) tcgetattr(0, &tt);
-	(void) ioctl(0, TIOCGWINSZ, (char *)&win);
+	tcgetattr(0, &tt);
+	ioctl(0, TIOCGWINSZ, (char *)&win);
 	if (openpty(&master, &slave, NULL, &tt, &win) < 0) {
 		warn(_("openpty failed"));
 		fail();
@@ -525,12 +525,12 @@ getmaster() {
 				ok = access(line, R_OK|W_OK) == 0;
 				*tp = 'p';
 				if (ok) {
-					(void) tcgetattr(0, &tt);
-				    	(void) ioctl(0, TIOCGWINSZ, 
+					tcgetattr(0, &tt);
+					ioctl(0, TIOCGWINSZ,
 						(char *)&win);
 					return;
 				}
-				(void) close(master);
+				close(master);
 				master = -1;
 			}
 		}
@@ -550,9 +550,9 @@ getslave() {
 		warn(_("open failed: %s"), line);
 		fail();
 	}
-	(void) tcsetattr(slave, TCSANOW, &tt);
-	(void) ioctl(slave, TIOCSWINSZ, (char *)&win);
+	tcsetattr(slave, TCSANOW, &tt);
+	ioctl(slave, TIOCSWINSZ, (char *)&win);
 #endif
-	(void) setsid();
-	(void) ioctl(slave, TIOCSCTTY, 0);
+	setsid();
+	ioctl(slave, TIOCSCTTY, 0);
 }
-- 
1.7.5.2


^ permalink raw reply related

* [PATCH 3/4] script: include-what-you-use header check
From: Sami Kerola @ 2011-06-28 10:43 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa
In-Reply-To: <1309257806-1418-1-git-send-email-kerolasa@iki.fi>

The tool proposed;

script.c should add these lines:

script.c should remove these lines:
- #include <sys/file.h>  // lines 53-53
- #include <sys/types.h>  // lines 48-48
- #include "c.h"  // lines 61-61

and the change nearly did what the tool told. We should keep on
using c.h, not err.h. The config.h is not needed, it's added
automaticly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 601a91d..39bc5ef 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -45,17 +45,20 @@
 #include <stdlib.h>
 #include <paths.h>
 #include <time.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <termios.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
-#include <sys/file.h>
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
 #include <getopt.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <libintl.h>
+#include <limits.h>
+#include <locale.h>
+#include <stddef.h>
 
 #include "nls.h"
 #include "c.h"
-- 
1.7.5.2


^ permalink raw reply related

* [PATCH 4/4] script: remove magic constants and a type mismatch fix
From: Sami Kerola @ 2011-06-28 10:43 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa
In-Reply-To: <1309257806-1418-1-git-send-email-kerolasa@iki.fi>

The type mismatch; doinput: int -> ssize_t

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/script.c |   68 ++++++++++++++++++++++++++------------------------
 1 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 39bc5ef..fccc0c4 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -71,6 +71,8 @@
 #include <utempter.h>
 #endif
 
+#define DEFAULT_OUTPUT "typescript"
+
 void finish(int);
 void done(void);
 void fail(void);
@@ -164,16 +166,16 @@ main(int argc, char **argv) {
 	enum { FORCE_OPTION = CHAR_MAX + 1 };
 
 	static const struct option longopts[] = {
-		{ "append",	no_argument,	   0, 'a' },
-		{ "command",	required_argument, 0, 'c' },
-		{ "return",	no_argument,	   0, 'e' },
-		{ "flush",	no_argument,	   0, 'f' },
-		{ "force",	no_argument,	   0, FORCE_OPTION, },
-		{ "quiet",	no_argument,	   0, 'q' },
-		{ "timing",	optional_argument, 0, 't' },
-		{ "version",	no_argument,	   0, 'V' },
-		{ "help",	no_argument,	   0, 'h' },
-		{ NULL,		0, 0, 0 }
+		{ "append",	no_argument,	   NULL, 'a' },
+		{ "command",	required_argument, NULL, 'c' },
+		{ "return",	no_argument,	   NULL, 'e' },
+		{ "flush",	no_argument,	   NULL, 'f' },
+		{ "force",	no_argument,	   NULL, FORCE_OPTION, },
+		{ "quiet",	no_argument,	   NULL, 'q' },
+		{ "timing",	optional_argument, NULL, 't' },
+		{ "version",	no_argument,	   NULL, 'V' },
+		{ "help",	no_argument,	   NULL, 'h' },
+		{ NULL,		0, NULL, 0 }
 	};
 
 	setlocale(LC_ALL, "");
@@ -184,28 +186,28 @@ main(int argc, char **argv) {
 	while ((ch = getopt_long(argc, argv, "ac:efqt::Vh", longopts, NULL)) != -1)
 		switch(ch) {
 		case 'a':
-			aflg++;
+			aflg = 1;
 			break;
 		case 'c':
 			cflg = optarg;
 			break;
 		case 'e':
-			eflg++;
+			eflg = 1;
 			break;
 		case 'f':
-			fflg++;
+			fflg = 1;
 			break;
 		case FORCE_OPTION:
 			forceflg = 1;
 			break;
 		case 'q':
-			qflg++;
+			qflg = 1;
 			break;
 		case 't':
 			if (optarg)
 				if ((timingfd = fopen(optarg, "w")) == NULL)
 					err(EXIT_FAILURE, _("cannot open timing file %s"), optarg);
-			tflg++;
+			tflg = 1;
 			break;
 		case 'V':
 			printf(_("%s from %s\n"), program_invocation_short_name,
@@ -225,7 +227,7 @@ main(int argc, char **argv) {
 	if (argc > 0)
 		fname = argv[0];
 	else {
-		fname = "typescript";
+		fname = DEFAULT_OUTPUT;
 		die_if_link(fname);
 	}
 	if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) {
@@ -289,20 +291,20 @@ main(int argc, char **argv) {
 
 void
 doinput() {
-	register int cc;
+	register ssize_t cc;
 	char ibuf[BUFSIZ];
 
 	fclose(fscript);
 
 	while (die == 0) {
-		if ((cc = read(0, ibuf, BUFSIZ)) > 0) {
+		if ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) {
 			ssize_t wrt = write(master, ibuf, cc);
-			if (wrt == -1) {
+			if (wrt < 0) {
 				warn (_("write failed"));
 				fail();
 			}
 		}
-		else if (cc == -1 && errno == EINTR && resized)
+		else if (cc < 0 && errno == EINTR && resized)
 			resized = 0;
 		else
 			break;
@@ -329,7 +331,7 @@ void
 resize(int dummy __attribute__ ((__unused__))) {
 	resized = 1;
 	/* transmit window change information to the child */
-	ioctl(0, TIOCGWINSZ, (char *)&win);
+	ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&win);
 	ioctl(slave, TIOCSWINSZ, (char *)&win);
 }
 
@@ -353,7 +355,7 @@ dooutput(FILE *timingfd) {
 	ssize_t wrt;
 	ssize_t fwrt;
 
-	close(0);
+	close(STDIN_FILENO);
 #ifdef HAVE_LIBUTIL
 	close(slave);
 #endif
@@ -388,7 +390,7 @@ dooutput(FILE *timingfd) {
 			fprintf(timingfd, "%f %zd\n", newtime - oldtime, cc);
 			oldtime = newtime;
 		}
-		wrt = write(1, obuf, cc);
+		wrt = write(STDOUT_FILENO, obuf, cc);
 		if (wrt < 0) {
 			warn (_("write failed"));
 			fail();
@@ -424,9 +426,9 @@ doshell() {
 	getslave();
 	close(master);
 	fclose(fscript);
-	dup2(slave, 0);
-	dup2(slave, 1);
-	dup2(slave, 2);
+	dup2(slave, STDIN_FILENO);
+	dup2(slave, STDOUT_FILENO);
+	dup2(slave, STDERR_FILENO);
 	close(slave);
 
 	master = -1;
@@ -453,13 +455,13 @@ fixtty() {
 	rtt = tt;
 	cfmakeraw(&rtt);
 	rtt.c_lflag &= ~ECHO;
-	tcsetattr(0, TCSANOW, &rtt);
+	tcsetattr(STDIN_FILENO, TCSANOW, &rtt);
 }
 
 void
 fail() {
 
-	kill(0, SIGTERM);
+	kill(getpid(), SIGTERM);
 	done();
 }
 
@@ -479,7 +481,7 @@ done() {
 
 		master = -1;
 	} else {
-		tcsetattr(0, TCSADRAIN, &tt);
+		tcsetattr(STDIN_FILENO, TCSADRAIN, &tt);
 		if (!qflg)
 			printf(_("Script done, file is %s\n"), fname);
 #ifdef HAVE_LIBUTEMPTER
@@ -500,8 +502,8 @@ done() {
 void
 getmaster() {
 #if HAVE_LIBUTIL && HAVE_PTY_H
-	tcgetattr(0, &tt);
-	ioctl(0, TIOCGWINSZ, (char *)&win);
+	tcgetattr(STDIN_FILENO, &tt);
+	ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&win);
 	if (openpty(&master, &slave, NULL, &tt, &win) < 0) {
 		warn(_("openpty failed"));
 		fail();
@@ -528,8 +530,8 @@ getmaster() {
 				ok = access(line, R_OK|W_OK) == 0;
 				*tp = 'p';
 				if (ok) {
-					tcgetattr(0, &tt);
-					ioctl(0, TIOCGWINSZ,
+					tcgetattr(STDIN_FILENO, &tt);
+					ioctl(STDIN_FILENO, TIOCGWINSZ,
 						(char *)&win);
 					return;
 				}
-- 
1.7.5.2


^ permalink raw reply related

* Re: [BUG] umount does not work for disconected nfs mounts
From: Karel Zak @ 2011-06-29  6:40 UTC (permalink / raw)
  To: util-linux, khlebnikov
In-Reply-To: <20110628085724.GE22770@foxbat.suse.cz>

On Tue, Jun 28, 2011 at 10:57:24AM +0200, Petr Uzel wrote:
> > so mount /mnt/nfs get stuck, umounting by device is still possible.
> 
> We might first scan through mtab to check if umount arg is known
> mountpoint and only if we fail, we would look for associated loopfile.

 Yes, go ahead.

    Karel

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

^ permalink raw reply

* Re: [BUG] umount does not work for disconected nfs mounts
From: Mike Frysinger @ 2011-06-29  6:44 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: util-linux, khlebnikov
In-Reply-To: <4E099B86.1030802@parallels.com>

On Tue, Jun 28, 2011 at 05:14, Konstantin Khlebnikov wrote:
> Petr Uzel wrote:
>> On Tue, Jun 28, 2011 at 12:18:03PM +0400, Konstantin Khlebnikov wrote:
>>> commit 33cee6675edecbd27c0628f8b7c74c7d88fc02b2
>>>
>>> http://git.kernel.org/?p=utils/util-linux/util-linux-ng.git;a=commitdiff;h=33cee6675edecbd27c0628f8b7c74c7d88fc02b2;hp=fde25e6be6e00a0998eb58b4b9d0d0b9ad65dbfd
>>> "umount: allow unmounting loopdev specified by associated file"
>>> broke umounting (by mountpoint) for broken nfs mounts,
>>> because now umount always call stat() for target argument and umount hang
>>> inside nfs-rpc:
>>
>> Shouldn't this be handled in the kernel? Or is stat() really
>> supposed to fail in such way with broken nfs?
>
> It depends on used mount options, IIRR in "soft" mode it by default fail
> with EIO after 3-6 minutes timeout,
> in "hard" mode syscalls never returns EIO.

i noticed this recently.  one of the reasons i love `umount -lf` with
broken nfs mounts is that it works immediately.  any attempt to access
said broken mount in this situation is wrong as it inherently implies
it has to wait for a timeout (if one ever comes as Konstantin noted).

other than my personal usage on the command line, it makes shutdown
scripts obnoxiously slow to the point of being useless.
-mike

^ permalink raw reply

* [PATCH] umount: do not hang with disconnected NFS mounts
From: Petr Uzel @ 2011-06-29  8:24 UTC (permalink / raw)
  To: util-linux; +Cc: Konstantin Khlebnikov

[-- Attachment #1: Type: text/plain, Size: 2629 bytes --]

Since util-linux commit f4612577c942a3683b97632ad0b49671897c2070,
umount stat(2)s its argument to check whether it can be associated
with some loop device. This could hang with broken NFS mounts.

Fix by first checking mtab if umount's argument is mounted and only if
we fail, check if there is a loop device associated.

http://marc.info/?l=util-linux-ng&m=130924963804836&w=2

Reported-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 mount/umount.c |   42 ++++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/mount/umount.c b/mount/umount.c
index 0349cb3..96c940e 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -600,6 +600,7 @@ umount_file (char *arg) {
 	int fstab_has_user, fstab_has_users, fstab_has_owner, fstab_has_group;
 	int ok, status = 0;
 	struct stat statbuf;
+	char *loopdev = NULL;
 
 	if (!*arg) {		/* "" would be expanded to `pwd` */
 		die(2, _("Cannot unmount \"\"\n"));
@@ -608,26 +609,7 @@ umount_file (char *arg) {
 
 	file = canonicalize(arg); /* mtab paths are canonicalized */
 
-	/* if file is a regular file, check if it is associated
-	 * with some loop device
-	 */
-	if (!stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) {
-		char *loopdev = NULL;
-		switch (find_loopdev_by_backing_file(file, &loopdev)) {
-		case 0:
-			if (verbose)
-				printf(_("%s is associated with %s, trying to unmount it\n"),
-				       arg, loopdev);
-			file = loopdev;
-			break;
-		case 2:
-			if (verbose)
-				printf(_("%s is associated with more than one loop device: not unmounting\n"),
-				       arg);
-			break;
-		}
-	}
-
+try_loopdev:
 	if (verbose > 1)
 		printf(_("Trying to unmount %s\n"), file);
 
@@ -659,6 +641,26 @@ umount_file (char *arg) {
 	if (!mc && verbose)
 		printf(_("Could not find %s in mtab\n"), file);
 
+	/* not found in mtab - check if it is associated with some loop device
+	 * (only if it is a regular file)
+	 */
+	if (!mc && !loopdev && !stat(file, &statbuf) && S_ISREG(statbuf.st_mode)) {
+		switch (find_loopdev_by_backing_file(file, &loopdev)) {
+		case 0:
+			if (verbose)
+				printf(_("%s is associated with %s\n"),
+				       arg, loopdev);
+			file = loopdev;
+			goto try_loopdev;
+			break;
+		case 2:
+			if (verbose)
+				printf(_("%s is associated with more than one loop device: not unmounting\n"),
+				       arg);
+			break;
+		}
+	}
+
 	if (mc) {
 		/*
 		 * helper - umount helper (e.g. pam_mount)
-- 
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related

* Re: [PATCH] umount: do not hang with disconnected NFS mounts
From: Karel Zak @ 2011-06-29  9:12 UTC (permalink / raw)
  To: util-linux, Konstantin Khlebnikov
In-Reply-To: <20110629082408.GA27888@foxbat.suse.cz>

On Wed, Jun 29, 2011 at 10:24:09AM +0200, Petr Uzel wrote:
> Since util-linux commit f4612577c942a3683b97632ad0b49671897c2070,
> umount stat(2)s its argument to check whether it can be associated
> with some loop device. This could hang with broken NFS mounts.
> 
> Fix by first checking mtab if umount's argument is mounted and only if
> we fail, check if there is a loop device associated.
> 
> http://marc.info/?l=util-linux-ng&m=130924963804836&w=2
> 
> Reported-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
> ---
>  mount/umount.c |   42 ++++++++++++++++++++++--------------------
>  1 files changed, 22 insertions(+), 20 deletions(-)

 Applied, thanks (also to Konstantin)!

    Karel

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

^ permalink raw reply

* Re: [PATCH 1/4] script: option --force added
From: Karel Zak @ 2011-06-29  9:34 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux
In-Reply-To: <1309257806-1418-1-git-send-email-kerolasa@iki.fi>

On Tue, Jun 28, 2011 at 12:43:23PM +0200, Sami Kerola wrote:
> The --force will allow default output destination, e.g.
> typescript file, to be hard or symbolic link.

 Applied, thanks.

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

^ permalink raw reply

* Re: [PATCH 2/4] script: remove unnecessary void casting
From: Karel Zak @ 2011-06-29  9:35 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux
In-Reply-To: <1309257806-1418-2-git-send-email-kerolasa@iki.fi>

On Tue, Jun 28, 2011 at 12:43:24PM +0200, Sami Kerola wrote:
>  term-utils/script.c |   56 +++++++++++++++++++++++++-------------------------
>  1 files changed, 28 insertions(+), 28 deletions(-)

 Applied, thanks.

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

^ permalink raw reply

* Re: [PATCH 3/4] script: include-what-you-use header check
From: Karel Zak @ 2011-06-29  9:35 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux
In-Reply-To: <1309257806-1418-3-git-send-email-kerolasa@iki.fi>

On Tue, Jun 28, 2011 at 12:43:25PM +0200, Sami Kerola wrote:
>  term-utils/script.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)

 Applied, thanks.

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

^ permalink raw reply

* Re: [PATCH 4/4] script: remove magic constants and a type mismatch fix
From: Karel Zak @ 2011-06-29  9:44 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux
In-Reply-To: <1309257806-1418-4-git-send-email-kerolasa@iki.fi>

On Tue, Jun 28, 2011 at 12:43:26PM +0200, Sami Kerola wrote:
>  term-utils/script.c |   68 ++++++++++++++++++++++++++------------------------
>  1 files changed, 35 insertions(+), 33 deletions(-)

 Applied.

>>  void
>  fail() {
>  
> -	kill(0, SIGTERM);
> +	kill(getpid(), SIGTERM);
>  	done();
>  }

 I think we want to use zero rather than getpid()...

    Karel

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

^ permalink raw reply

* Re: [PATCH 6/6] sfdisk: fix for data type mismatches
From: Karel Zak @ 2011-06-29 10:50 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux
In-Reply-To: <BANLkTik2HR3BCHFta13hg_QK6nXEZm19Pw@mail.gmail.com>

On Tue, Jun 14, 2011 at 10:00:56PM +0200, Sami Kerola wrote:
> Yes are right, that was silly. I reviewed the patch and changed data
> types to size_t. The fix is pushed with force to my git.

 Merged.

> p.s. The style in the file is really horrible. How about doing the
> following, which will unify the style within the file without changing
> everything.
> 
> indent -linux -i4 -psl -brf sfdisk.c

 Hmm.. I don't like such patches, but you're right that the file is
 horrible. Fixed....

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

^ permalink raw reply

* [git pull] mkfs fixes
From: Sami Kerola @ 2011-06-29 12:03 UTC (permalink / raw)
  To: util-linux

The following changes since commit 37b94458bd0f4a178233ad0366a727bf5bde879f:

  sfdisk: fix coding style. (2011-06-29 12:47:38 +0200)

are available in the git repository at:
  https://github.com/kerolasa/lelux-utiliteetit mkfs

Sami Kerola (4):
      mkfs: add long options
      docs: add long options to mkfs.8
      mkfs: include-what-you-use header check
      mkfs: coding style fixes

 disk-utils/mkfs.8 |   44 ++++++-------
 disk-utils/mkfs.c |  189 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 133 insertions(+), 100 deletions(-)

diff --git a/disk-utils/mkfs.8 b/disk-utils/mkfs.8
index 6a39633..88699c1 100644
--- a/disk-utils/mkfs.8
+++ b/disk-utils/mkfs.8
@@ -1,15 +1,12 @@
 .\" -*- nroff -*-
 .TH MKFS 8 "Jun 1995" "Version 1.9"
+.TH MKFS "8" "June 2011" "util-linux" "System Administration Utilities"
 .SH NAME
 mkfs \- build a Linux file system
 .SH SYNOPSIS
+.SH SYNOPSIS
 .B mkfs
-.RB [ \-V ]
-.RB [ \-t
-.IR fstype ]
-.RI [ fs-options ]
-.I filesys
-.RI [ blocks ]
+[\fIoptions\fR] [\fI-t type fs-options\fR] \fIdevice \fR[\fIsize\fR]
 .SH DESCRIPTION
 .B mkfs
 is used to build a Linux file system on a device, usually
@@ -19,8 +16,9 @@ is either the device name (e.g.
 .IR /dev/hda1 ,
 .IR /dev/sdb2 ),
 or a regular file that shall contain the file system.
-.I blocks
-is the number of blocks to be used for the file system.
+The
+.I size
+argument is the number of blocks to be used for the file system.
 .PP
 The exit code returned by
 .B mkfs
@@ -49,14 +47,7 @@ Please see the file system-specific builder manual pages for
 further details.
 .SH OPTIONS
 .TP
-.B -V
-Produce verbose output, including all file system-specific commands
-that are executed.
-Specifying this option more than once inhibits execution of any
-file system-specific commands.
-This is really only useful for testing.
-.TP
-.BI -t \ fstype
+\fB\-t\fR, \fB\-\-type\fR=\fITYPE\fR
 Specifies the type of file system to be built.
 If not specified, the default file system type
 (currently ext2) is used.
@@ -67,20 +58,25 @@ system builder.
 Although not guaranteed, the following options are supported
 by most file system builders.
 .TP
-.B -c
-Check the device for bad blocks before building the file system.
+\fB\-V\fR, \fB\-\-verbose\fR
+Produce verbose output, including all file system-specific commands
+that are executed.
+Specifying this option more than once inhibits execution of any
+file system-specific commands.
+This is really only useful for testing.
 .TP
-.BI -l \ filename
-Read the bad blocks list from
-.I filename
+\fB\-V\fR, \fB\-\-version\fR
+output version information and exit
+\fB\-V\fR will output version information only when it is the
+only parameter.
 .TP
-.B -v
-Produce verbose output.
+\fB\-h\fR, \fB\-\-help\fR
+Display help and exit.
 .SH BUGS
 All generic options must precede and not be combined with
 file system-specific options.
 Some file system-specific programs do not support the
-.I -v
+.I -V
 (verbose) option, nor return meaningful exit codes.
 Also, some file system-specific programs do not automatically
 detect the device size and require the
diff --git a/disk-utils/mkfs.c b/disk-utils/mkfs.c
index e22c512..ce845a5 100644
--- a/disk-utils/mkfs.c
+++ b/disk-utils/mkfs.c
@@ -2,8 +2,6 @@
  * mkfs		A simple generic frontend for the for the mkfs program
  *		under Linux.  See the manual page for details.
  *
- * Usage:	mkfs [-V] [-t fstype] [fs-options] device [size]
- *
  * Authors:	David Engel, <david@ods.com>
  *		Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *		Ron Sommeling, <sommel@sci.kun.nl>
@@ -15,91 +13,130 @@
  *	
  */

-
+#include <getopt.h>
+#include <limits.h>
 #include <stdio.h>
-#include <unistd.h>
+#include <stdlib.h>
 #include <string.h>
-#include <nls.h>
+#include <unistd.h>

+#include "c.h"
+#include "nls.h"
 #include "xalloc.h"

 #ifndef DEFAULT_FSTYPE
-# define DEFAULT_FSTYPE		"ext2"
+#define DEFAULT_FSTYPE	"ext2"
 #endif

 #define SEARCH_PATH	"PATH=" FS_SEARCH_PATH
 #define PROGNAME	"mkfs.%s"


-int main(int argc, char *argv[])
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
+{
+	fprintf(out,
+		_("Usage: %s [options] [-t type fs-options] device [size]\n"),
+		program_invocation_short_name);
+
+	fprintf(out, _("\nOptions:\n"
+		       " -t, --type=TYPE  file system type, when undefined ext2 is used\n"
+		       "     fs-options   parameters to real file system builder\n"
+		       "     device       path to a device\n"
+		       "     size         number of blocks on the device\n"
+		       " -V, --verbose    explain what is done\n"
+		       "                  defining -V more than once will cause a dry-run\n"
+		       " -V, --version    output version information and exit\n"
+		       "                  -V as version must be only option\n"
+		       " -h, --help       display this help and exit\n"));
+
+	fprintf(out, _("\nFor more information see mkfs(8).\n"));
+
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+static void __attribute__ ((__noreturn__)) print_version(void)
+{
+	printf(_("%s (%s)\n"),
+	       program_invocation_short_name, PACKAGE_STRING);
+	exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
 {
-  char *progname;	/* name of executable to be called */
-  char *fstype = NULL;
-  int i, more = 0, verbose = 0;
-  char *oldpath, *newpath;
-  char *program_name, *p;
-
-  program_name = argv[0];
-  if ((p = strrchr(program_name, '/')) != NULL)
-	  program_name = p+1;
-
-  setlocale(LC_ALL, "");
-  bindtextdomain(PACKAGE, LOCALEDIR);
-  textdomain(PACKAGE);
-
-  if (argc == 2 &&
-      (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
-	  printf(_("%s (%s)\n"), program_name, PACKAGE_STRING);
-	  exit(EXIT_SUCCESS);
-  }
-
-  /* Check commandline options. */
-  opterr = 0;
-  while ((more == 0) && ((i = getopt(argc, argv, "Vt:")) != -1))
-    switch (i) {
-    case 'V':
-      verbose++;
-      break;
-    case 't':
-      fstype = optarg;
-      break;
-    default:
-      optind--;
-      more = 1;
-      break;		/* start of specific arguments */
-    }
-  if (optind == argc)
-	  errx(EXIT_FAILURE, _("Usage: mkfs [-V] [-t fstype] [fs-options]
device [size]"));
-
-  /* If -t wasn't specified, use the default */
-  if (fstype == NULL)
-    fstype = DEFAULT_FSTYPE;
-
-  /* Set PATH and program name */
-  oldpath = getenv("PATH");
-  if (!oldpath)
-	  oldpath = "/bin";
-
-  newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
-  sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
-  putenv(newpath);
-
-  progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
-  sprintf(progname, PROGNAME, fstype);
-  argv[--optind] = progname;
-
-  if (verbose) {
-    printf(_("mkfs (%s)\n"), PACKAGE_STRING);
-    i = optind;
-    while (argv[i])
-      printf("%s ", argv[i++]);
-    printf("\n");
-    if (verbose > 1)
-      return 0;
-  }
-
-  /* Execute the program */
-  execvp(progname, argv+optind);
-  perror(progname);
-  return 1;
+	char *progname;		/* name of executable to be called */
+	char *fstype = NULL;
+	int i, more = 0, verbose = 0;
+	char *oldpath, *newpath;
+
+	enum { VERSION_OPTION = CHAR_MAX + 1 };
+
+	static const struct option longopts[] = {
+		{"type", required_argument, NULL, 't'},
+		{"version", no_argument, NULL, VERSION_OPTION},
+		{"help", no_argument, NULL, 'h'},
+		{NULL, 0, NULL, 0}
+	};
+
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+
+	if (argc == 2 && !strcmp(argv[1], "-V"))
+		print_version();
+
+	/* Check commandline options. */
+	opterr = 0;
+	while ((more == 0)
+	       && ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL))
+		   != -1))
+		switch (i) {
+		case 'V':
+			verbose++;
+			break;
+		case 't':
+			fstype = optarg;
+			break;
+		case 'h':
+			usage(stdout);
+		case VERSION_OPTION:
+			print_version();
+		default:
+			optind--;
+			more = 1;
+			break;	/* start of specific arguments */
+		}
+	if (optind == argc)
+		usage(stderr);
+
+	/* If -t wasn't specified, use the default */
+	if (fstype == NULL)
+		fstype = DEFAULT_FSTYPE;
+
+	/* Set PATH and program name */
+	oldpath = getenv("PATH");
+	if (!oldpath)
+		oldpath = "/bin";
+
+	newpath = xmalloc(strlen(oldpath) + sizeof(SEARCH_PATH) + 3);
+	sprintf(newpath, "%s:%s\n", SEARCH_PATH, oldpath);
+	putenv(newpath);
+
+	progname = xmalloc(sizeof(PROGNAME) + strlen(fstype) + 1);
+	sprintf(progname, PROGNAME, fstype);
+	argv[--optind] = progname;
+
+	if (verbose) {
+		printf(_("mkfs (%s)\n"), PACKAGE_STRING);
+		i = optind;
+		while (argv[i])
+			printf("%s ", argv[i++]);
+		printf("\n");
+		if (verbose > 1)
+			return EXIT_SUCCESS;
+	}
+
+	/* Execute the program */
+	execvp(progname, argv + optind);
+	perror(progname);
+	return EXIT_FAILURE;
 }

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

^ permalink raw reply related

* Re: [PATCH] dmesg.c: print human readable timestamp
From: Karel Zak @ 2011-06-29 14:59 UTC (permalink / raw)
  To: corentin.labbe; +Cc: util-linux
In-Reply-To: <4DD6593D.2090202@geomatys.fr>

On Fri, May 20, 2011 at 02:06:21PM +0200, corentin.labbe wrote:
> 
> This patch add the -H option to dmesg which allow to print human
> readable time instead of the number of seconds since boot.

 Nice idea, but it's not so simple :-(

 The time stamp used for printk() is not based on normal system time
 (as you know from gettimeofday()). It uses cpu_clock() (IMHO to
 keep printk() robust and without xtime_lock).

 The problem is that the cpu_clock is not updated after system resume,
 so if you suspend (e.g. pm-suspend(8)) and resume than the dmesg -H
 command prints nonsenses...

 For example (copy & past from /var/log/messages):

  Jun 27 23:39:53 nb kernel: [50065.238635] PM: Syncing filesystems  ... done.
  Jun 28 20:23:29 nb kernel: [50065.284226] Freezing user space  processes ... (elapsed 0.09 seconds) done.
                              ^^^^^
 The first line is before suspend and second is after resume. The time
 stamp [50065.xxxxxx] is still the same although the system was
 suspended for almost whole day.
 
 The same system, the latest kernel message:

    # date
    Wed Jun 29 16:29:28 CEST 2011

    # mount /dev/sdb1 /mnt/test

    # ./sys-utils/dmesg -H | tail -1 
    [Tue Jun 28 11:10:41 2011] EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts: (null)


  Karel


^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox