summaryrefslogtreecommitdiffstats
path: root/shlibs/mount
diff options
context:
space:
mode:
authorKarel Zak2010-06-21 18:08:53 +0200
committerKarel Zak2011-01-03 12:28:39 +0100
commit9fd75d76cc383eaa4c01e57293bfecbb76ee3d8a (patch)
tree259ae3db2145083e6e819fd0c058c2c08150e0ee /shlibs/mount
parentlibblkid: use PRId64 in PT parser (diff)
downloadkernel-qcow2-util-linux-9fd75d76cc383eaa4c01e57293bfecbb76ee3d8a.tar.gz
kernel-qcow2-util-linux-9fd75d76cc383eaa4c01e57293bfecbb76ee3d8a.tar.xz
kernel-qcow2-util-linux-9fd75d76cc383eaa4c01e57293bfecbb76ee3d8a.zip
libmount: add mnt_tab_set_parser_errcb()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount')
-rw-r--r--shlibs/mount/src/mount.h.in3
-rw-r--r--shlibs/mount/src/mount.sym1
-rw-r--r--shlibs/mount/src/mountP.h3
-rw-r--r--shlibs/mount/src/tab_parse.c39
4 files changed, 35 insertions, 11 deletions
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in
index cd9159cca..b1d660747 100644
--- a/shlibs/mount/src/mount.h.in
+++ b/shlibs/mount/src/mount.h.in
@@ -266,7 +266,8 @@ extern int mnt_fs_print_debug(mnt_fs *ent, FILE *file);
/* tab-parse.c */
extern mnt_tab *mnt_new_tab_from_file(const char *filename);
extern int mnt_tab_parse_file(mnt_tab *tb);
-extern char *mnt_tab_strerror(mnt_tab *tb, char *buf, size_t buflen);
+extern int mnt_tab_set_parser_errcb(mnt_tab *tb,
+ int (*cb)(mnt_tab *tb, const char *filename, int line, int flag));
extern int mnt_tab_get_nerrs(mnt_tab *tb);
/* tab.c */
diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym
index 819be0f1d..f6035e4ba 100644
--- a/shlibs/mount/src/mount.sym
+++ b/shlibs/mount/src/mount.sym
@@ -124,6 +124,7 @@ global:
mnt_tab_parse_file;
mnt_tab_remove_fs;
mnt_tab_set_cache;
+ mnt_tab_set_parser_errcb;
mnt_tab_set_iter;
mnt_tab_strerror;
mnt_tab_update_file;
diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h
index 4a99bb4e6..63997544b 100644
--- a/shlibs/mount/src/mountP.h
+++ b/shlibs/mount/src/mountP.h
@@ -175,6 +175,9 @@ struct _mnt_tab {
mnt_cache *cache; /* canonicalized paths/tags cache */
+ int (*errcb)(mnt_tab *tb, const char *filename,
+ int line, int flag);
+
struct list_head ents; /* list of entries (mentry) */
};
diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c
index 680e1fc18..0c4059daa 100644
--- a/shlibs/mount/src/tab_parse.c
+++ b/shlibs/mount/src/tab_parse.c
@@ -354,6 +354,9 @@ static int mnt_tab_parse_next(mnt_tab *tb, FILE *f, mnt_fs *fs)
return 0;
err:
+ if (tb->errcb)
+ return tb->errcb(tb, NULL, tb->nlines, 0);
+
/* we don't report parse errors to caller; caller has to check
* errors by mnt_tab_get_nerrs() or internaly by MNT_ENTRY_ERR flag
*/
@@ -374,22 +377,19 @@ err:
* int rc;
*
* rc = mnt_tab_parse_file(tb);
- * if (rc) {
- * if (mnt_tab_get_nerrs(tb)) { / * parse error * /
- * mnt_tab_strerror(tb, buf, sizeof(buf));
- * fprintf(stderr, "%s: %s\n", progname, buf);
- * } else
- * perror(mnt_tab_get_name(tb)); / * system error * /
- * } else
+ * if (rc)
+ * perror(mnt_tab_get_name(tb)); / * system error * /
+ * else
* mnt_fprintf_tab(tb, stdout, NULL);
*
* mnt_free_tab(tb);
* </programlisting>
* </informalexample>
*
- * Returns: 0 on success and -1 in case of error. The parse errors is possible
- * to detect by mnt_tab_get_nerrs() and error message is possible to create by
- * mnt_tab_strerror().
+ * The libmount parser ignores broken (with syntax error) lines, these lines are
+ * reported to caller by errcb() function (see mnt_tab_set_parser_errcb()).
+ *
+ * Returns: 0 on success, -1 in case of error.
*/
int mnt_tab_parse_file(mnt_tab *tb)
{
@@ -458,6 +458,25 @@ mnt_tab *mnt_new_tab_from_file(const char *filename)
}
/**
+ * mnt_tab_set_parser_errcb:
+ * @tab: pointer to table
+ * @cb: pointer to callback function
+ *
+ * The error callback function is called by table parser (mnt_tab_parse_file())
+ * in case of sytax error. If the callback function does not return zero then
+ * parsing is aborted.
+ *
+ * Returns: 0 on success or -1 in case of error.
+ */
+int mnt_tab_set_parser_errcb(mnt_tab *tb,
+ int (*cb)(mnt_tab *tb, const char *filename, int line, int flag))
+{
+ assert(tb);
+ tb->errcb = cb;
+ return 0;
+}
+
+/**
* mnt_tab_get_nerrs:
* @tb: pointer to table
*