]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: add --timeout option
authorKarel Zak <kzak@redhat.com>
Wed, 27 Apr 2011 15:39:25 +0000 (17:39 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 27 Apr 2011 15:39:25 +0000 (17:39 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/Makefile.am
misc-utils/findmnt.c

index 26d5935722918ec2968cc0f33b06880bb66705d9..d3ada1de1a88394aa6b5669a46bde16fb4e006a7 100644 (file)
@@ -77,7 +77,11 @@ bin_PROGRAMS += findmnt
 dist_man_MANS += findmnt.8
 findmnt_LDADD = $(ul_libmount_la)
 findmnt_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
-findmnt_SOURCES = findmnt.c $(top_srcdir)/lib/tt.c $(top_srcdir)/lib/mbsalign.c
+findmnt_SOURCES =      findmnt.c \
+                       $(top_srcdir)/lib/tt.c \
+                       $(top_srcdir)/lib/mbsalign.c \
+                       $(top_srcdir)/lib/strutils.c
+
 if !HAVE_LANGINFO
 findmnt_SOURCES += $(top_srcdir)/lib/langinfo.c
 endif
index 16c26a1ce969f3cd9c41eda993125889648a74bf..16827f192e3bd2b1ecc34755f44175024c862111 100644 (file)
@@ -38,6 +38,7 @@
 #include "nls.h"
 #include "c.h"
 #include "tt.h"
+#include "strutils.h"
 
 /* flags */
 enum {
@@ -633,7 +634,7 @@ static int poll_table(struct libmnt_table *tb, const char *tabfile,
 
                x = poll(fds, 1, timeout);
                if (x == 0)
-                       goto done;      /* timeout ? */
+                       break;  /* timeout */
                if (x < 0) {
                        warn(_("poll() failed"));
                        goto done;
@@ -697,7 +698,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        " -k, --kernel           search in kernel table of mounted \n"
         "                        filesystems (default)\n\n"
 
-       " -p, --poll             monitor changes in table of mounted filesystems\n\n"
+       " -p, --poll             monitor changes in table of mounted filesystems\n"
+       " -w, --timeout <num>    upper limit in millisecods which --poll will block\n\n"
 
        " -c, --canonicalize     canonicalize printed paths\n"
        " -d, --direction <word> search direction - 'forward' or 'backward'\n"
@@ -746,7 +748,7 @@ int main(int argc, char *argv[])
        struct libmnt_table *tb = NULL;
        char *tabfile = NULL;
        int direction = MNT_ITER_FORWARD;
-       int i, c, rc = -1;
+       int i, c, rc = -1, timeout = -1;
 
        /* table.h */
        struct tt *tt = NULL;
@@ -774,6 +776,7 @@ int main(int argc, char *argv[])
            { "submounts",    0, 0, 'R' },
            { "source",       1, 0, 'S' },
            { "target",       1, 0, 'T' },
+           { "timeout",      1, 0, 'w' },
 
            { NULL,           0, 0, 0 }
        };
@@ -788,7 +791,7 @@ int main(int argc, char *argv[])
        tt_flags |= TT_FL_TREE;
 
        while ((c = getopt_long(argc, argv,
-                               "acd:ehifo:O:pklmnrst:uvRS:T:", longopts, NULL)) != -1) {
+                               "acd:ehifo:O:pklmnrst:uvRS:T:w:", longopts, NULL)) != -1) {
                switch(c) {
                case 'a':
                        tt_flags |= TT_FL_ASCII;
@@ -879,6 +882,10 @@ int main(int argc, char *argv[])
                        set_match(COL_TARGET, optarg);
                        flags |= FL_NOSWAPMATCH;
                        break;
+               case 'w':
+                       timeout = strtol_or_err(optarg,
+                                       _("failed to parse timeout"));
+                       break;
                default:
                        usage(stderr);
                        break;
@@ -985,7 +992,7 @@ int main(int argc, char *argv[])
         */
        if (flags & FL_POLL)
                /* poll mode */
-               poll_table(tb, tabfile, -1, tt, direction);
+               rc = poll_table(tb, tabfile, timeout, tt, direction);
 
        else if ((tt_flags & TT_FL_TREE) && is_listall_mode())
                /* whole tree */