}
#ifdef TEST_PROGRAM
+
+static int parser_errcb(mnt_tab *tb, const char *filename, int line, int flag)
+{
+ fprintf(stderr, "%s:%d: parse error\n", filename, line);
+ return 0;
+}
+
mnt_tab *create_tab(const char *file)
{
mnt_tab *tb;
tb = mnt_new_tab(file);
if (!tb)
goto err;
+
+ mnt_tab_set_parser_errcb(tb, parser_errcb);
+
if (mnt_tab_parse_file(tb) != 0)
goto err;
return tb;
itr = mnt_new_iter(MNT_ITER_FORWARD);
if (!itr)
goto err;
+
while(mnt_tab_next_fs(tb, itr, &fs) == 0)
mnt_fs_print_debug(fs, stdout);
err:
/* parse /etc/{fs,m}tab */
if (mnt_tab_parse_file_line(fs, s) != 0)
goto err;
+
} else if (tb->fmt == MNT_FMT_MOUNTINFO) {
/* parse /proc/self/mountinfo */
if (mnt_parse_mountinfo_line(fs, s) != 0)
if (!fs->optstr && (fs->vfs_optstr || fs->fs_optstr)) {
fs->optstr = merge_optstr(fs->vfs_optstr, fs->fs_optstr);
if (!fs->optstr)
- goto err;
+ return -1;
}
DBG(DEBUG_TAB, fprintf(stderr,
- "libmount: %s: %d: SOURCE:%s, MNTPOINT:%s, TYPE:%s, "
+ "libmount: %s:%d: SOURCE:%s, MNTPOINT:%s, TYPE:%s, "
"OPTS:%s, FREQ:%d, PASSNO:%d\n",
tb->filename, *nlines,
fs->source, fs->target, fs->fstype,
return 0;
err:
- if (tb->errcb)
- return tb->errcb(tb, NULL, *nlines, 0);
+ DBG(DEBUG_TAB, fprintf(stderr,
+ "libmount: %s:%d: parse error\n", tb->filename, *nlines));
- return 0;
+ if (tb->errcb && tb->errcb(tb, tb->filename, *nlines, 0))
+ return -1; /* fatal error */
+
+ return 1; /* recoverable error */
}
/**
while (!feof(f)) {
int rc;
mnt_fs *fs = mnt_new_fs();
+
if (!fs)
goto error;
rc = mnt_tab_parse_next(tb, f, fs, &nlines);
if (!rc)
rc = mnt_tab_add_fs(tb, fs);
- else if (feof(f)) {
- mnt_free_fs(fs);
- break;
- }
if (rc) {
mnt_free_fs(fs);
- goto error;
+ if (rc == 1)
+ continue; /* recoverable error */
+ if (feof(f))
+ break;
+ goto error; /* fatal error */
}
}