1313#include <sys/types.h>
1414#include <unistd.h>
1515
16- /* This needs to be after sys/mount.h :( */
17- #include <libmount.h>
18-
1916#include "sd-device.h"
2017
2118#include "alloc-util.h"
2522#include "escape.h"
2623#include "fd-util.h"
2724#include "fstab-util.h"
25+ #include "libmount-util.h"
2826#include "linux-3.13/dm-ioctl.h"
2927#include "mount-setup.h"
3028#include "mount-util.h"
3836#include "util.h"
3937#include "virt.h"
4038
41- DEFINE_TRIVIAL_CLEANUP_FUNC (struct libmnt_table * , mnt_free_table );
42- DEFINE_TRIVIAL_CLEANUP_FUNC (struct libmnt_iter * , mnt_free_iter );
43-
4439static void mount_point_free (MountPoint * * head , MountPoint * m ) {
4540 assert (head );
4641 assert (m );
@@ -79,11 +74,10 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
7974 struct libmnt_fs * fs ;
8075 const char * path , * fstype ;
8176 _cleanup_free_ char * options = NULL ;
82- _cleanup_free_ char * p = NULL ;
8377 unsigned long remount_flags = 0u ;
8478 _cleanup_free_ char * remount_options = NULL ;
8579 bool try_remount_ro ;
86- MountPoint * m ;
80+ _cleanup_free_ MountPoint * m = NULL ;
8781
8882 r = mnt_table_next_fs (t , i , & fs );
8983 if (r == 1 )
@@ -95,18 +89,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
9589 if (!path )
9690 continue ;
9791
98- if (cunescape (path , UNESCAPE_RELAX , & p ) < 0 )
99- return log_oom ();
100-
10192 fstype = mnt_fs_get_fstype (fs );
10293
10394 /* Combine the generic VFS options with the FS-specific
10495 * options. Duplicates are not a problem here, because the only
10596 * options that should come up twice are typically ro/rw, which
106- * are turned into MS_RDONLY or the invertion of it.
97+ * are turned into MS_RDONLY or the inversion of it.
10798 *
10899 * Even if there are duplicates later in mount_option_mangle()
109- * it shouldn't hurt anyways as they override each other.
100+ * they shouldn't hurt anyways as they override each other.
110101 */
111102 if (!strextend_with_separator (& options , "," ,
112103 mnt_fs_get_vfs_options (fs ),
@@ -124,9 +115,9 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
124115 * and hence not worth spending time on. Also, in
125116 * unprivileged containers we might lack the rights to
126117 * unmount these things, hence don't bother. */
127- if (mount_point_is_api (p ) ||
128- mount_point_ignore (p ) ||
129- PATH_STARTSWITH_SET (p , "/dev" , "/sys" , "/proc" ))
118+ if (mount_point_is_api (path ) ||
119+ mount_point_ignore (path ) ||
120+ PATH_STARTSWITH_SET (path , "/dev" , "/sys" , "/proc" ))
130121 continue ;
131122
132123 /* If we are in a container, don't attempt to
@@ -172,12 +163,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
172163 if (!m )
173164 return log_oom ();
174165
175- free_and_replace (m -> path , p );
176- free_and_replace (m -> remount_options , remount_options );
166+ m -> path = strdup (path );
167+ if (!m -> path )
168+ return log_oom ();
169+
170+ m -> remount_options = TAKE_PTR (remount_options );
177171 m -> remount_flags = remount_flags ;
178172 m -> try_remount_ro = try_remount_ro ;
179173
180- LIST_PREPEND (mount_point , * head , m );
174+ LIST_PREPEND (mount_point , * head , TAKE_PTR ( m ) );
181175 }
182176
183177 return 0 ;
@@ -201,10 +195,8 @@ int swap_list_get(const char *swaps, MountPoint **head) {
201195
202196 for (;;) {
203197 struct libmnt_fs * fs ;
204-
205- MountPoint * swap ;
198+ _cleanup_free_ MountPoint * swap = NULL ;
206199 const char * source ;
207- _cleanup_free_ char * d = NULL ;
208200
209201 r = mnt_table_next_fs (t , i , & fs );
210202 if (r == 1 )
@@ -216,16 +208,15 @@ int swap_list_get(const char *swaps, MountPoint **head) {
216208 if (!source )
217209 continue ;
218210
219- r = cunescape (source , UNESCAPE_RELAX , & d );
220- if (r < 0 )
221- return r ;
222-
223211 swap = new0 (MountPoint , 1 );
224212 if (!swap )
225213 return - ENOMEM ;
226214
227- free_and_replace (swap -> path , d );
228- LIST_PREPEND (mount_point , * head , swap );
215+ swap -> path = strdup (source );
216+ if (!swap -> path )
217+ return - ENOMEM ;
218+
219+ LIST_PREPEND (mount_point , * head , TAKE_PTR (swap ));
229220 }
230221
231222 return 0 ;
0 commit comments