[systemd-devel] [RFC] link against util-linux for fstab parsing

Karel Zak kzak at redhat.com
Sat Feb 18 02:14:08 PST 2012


On Fri, Feb 17, 2012 at 04:47:51PM -0500, Dave Reisner wrote:
> +        tb = mnt_new_table();
> +        if (!tb) {
> +                return -ENOMEM;
> +        }
>  
> -        while ((me = getmntent(f))) {
> -                char *where, *what;
> -                int k;
> +        mnt_cache = mnt_new_cache();
> +        if (!mnt_cache) {
> +                r = -ENOMEM;
> +                goto finish;
> +        }

 The cache is completely unnecessary here as you don't search in the
 table (fstab).

>  
> -                if (!(what = fstab_node_to_udev_node(me->mnt_fsname))) {
> -                        r = -ENOMEM;
> -                        goto finish;
> -                }
> +        mnt_table_set_cache(tb, mnt_cache);
>  
> -                if (!(where = strdup(me->mnt_dir))) {
> -                        free(what);
> -                        r = -ENOMEM;
> -                        goto finish;
> -                }
> +        r = mnt_table_parse_fstab(tb, "/etc/fstab");

 Please, use mnt_table_parse_fstab(tb, NULL); The filename is there to
 overwrite library default.

>  finish:
> +        if (tb)
> +                mnt_free_table(tb);
> +        if (mnt_cache)
> +                mnt_free_cache(mnt_cache);

 like libc free() all mnt_free_* functions accept NULL.


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


More information about the systemd-devel mailing list