diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-05 14:43:06 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-23 23:29:29 +0200 |
commit | e2857b3d87306d93f0fba526f3e79f4f6806fb02 (patch) | |
tree | 80e0b279f908dec754abb1ee8fe497d087839026 /src/shared/mount-util.c | |
parent | 7d991d4818dcf55916c1076003c3508c91df9934 (diff) | |
download | systemd-e2857b3d87306d93f0fba526f3e79f4f6806fb02.tar.gz |
Add helper function for mnt_table_parse_{stream,mtab}
This wraps a few common steps. It is defined as inline function instead of in a
.c file to avoid having a .c file. With a .c file, we would have three choices:
- either link it into libshared, but then then libshared would have to be
linked to libmount.
- or compile the .c file into each target separately. This has the disdvantage
that configuration of every target has to be updated and stuff will be compiled
multiple times anyway, which is not too different from keeping this in the
header file.
- or create a new convenience library just for this. This also has the disadvantage
that the every target would have to be updated, and a separate library for a
10 line function seems overkill.
By keeping everything in a header file, we compile this a few times, but
otherwise it's the least painful option. The compiler can optimize most of the
function away, because it knows if 'source' is set or not.
Diffstat (limited to 'src/shared/mount-util.c')
-rw-r--r-- | src/shared/mount-util.c | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 056106488d..97cc7b44c5 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -38,12 +38,7 @@ int umount_recursive(const char *prefix, int flags) { again = false; - table = mnt_new_table(); - iter = mnt_new_iter(MNT_ITER_FORWARD); - if (!table || !iter) - return -ENOMEM; - - r = mnt_table_parse_mtab(table, NULL); + r = libmount_parse(NULL, NULL, &table, &iter); if (r < 0) return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m"); @@ -139,14 +134,9 @@ int bind_remount_recursive_with_mountinfo( if (!todo) return -ENOMEM; - table = mnt_new_table(); - iter = mnt_new_iter(MNT_ITER_FORWARD); - if (!table || !iter) - return -ENOMEM; - rewind(proc_self_mountinfo); - r = mnt_table_parse_stream(table, proc_self_mountinfo, "/proc/self/mountinfo"); + r = libmount_parse("/proc/self/mountinfo", proc_self_mountinfo, &table, &iter); if (r < 0) return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m"); |