Commits

Michał Górny committed cc577d6

Always reset the context before performing mounts/umounts.

Comments (0)

Files changed (1)

 	mnt_free_context(b->mnt_context);
 }
 
+static void BootMountpoint_reset(struct libmnt_context *ctx) {
+	if (mnt_reset_context(ctx))
+		throw std::runtime_error("unable to reset mount context");
+	if (mnt_context_set_target(ctx, "/boot"))
+		throw std::runtime_error("unable to set mountpoint to /boot");
+}
+
 static PyObject *BootMountpoint_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
 	try {
 		struct libmnt_context *ctx = mnt_new_context();
 			throw std::runtime_error("unable to create libmount context");
 
 		try {
-			if (mnt_context_set_target(ctx, "/boot"))
-				throw std::runtime_error("unable to set mountpoint to /boot");
-
 			PyObject *self = type->tp_alloc(type, 0);
 
 			if (self != NULL) {
 		BootMountpoint *self = reinterpret_cast<BootMountpoint*>(args);
 		struct libmnt_context* const ctx = self->mnt_context;
 
+		BootMountpoint_reset(ctx);
+
 		struct libmnt_table *mtab;
 		if (mnt_context_get_mtab(ctx, &mtab))
 			throw std::runtime_error("unable to get mtab");
 		BootMountpoint *self = reinterpret_cast<BootMountpoint*>(args);
 		struct libmnt_context* const ctx = self->mnt_context;
 
+		BootMountpoint_reset(ctx);
+
 		struct libmnt_table *mtab;
 		if (mnt_context_get_mtab(ctx, &mtab))
 			throw std::runtime_error("unable to get mtab");
 			case MOUNTPOINT_NONE:
 				break;
 			case MOUNTPOINT_MOUNTED:
-				if (mnt_reset_context(ctx))
-					throw std::runtime_error("unable to reset mount context");
-				if (mnt_context_set_target(ctx, "/boot"))
-					throw std::runtime_error("unable to set mountpoint to /boot");
+				BootMountpoint_reset(ctx);
 
 				if (mnt_context_enable_lazy(ctx, true))
 					throw std::runtime_error("unable to enable lazy umount");
 
 				break;
 			case MOUNTPOINT_REMOUNTED_RW:
-				if (mnt_reset_context(ctx))
-					throw std::runtime_error("unable to reset mount context");
-				if (mnt_context_set_target(ctx, "/boot"))
-					throw std::runtime_error("unable to set mountpoint to /boot");
+				BootMountpoint_reset(ctx);
 
 				if (mnt_context_set_options(ctx, "remount,ro"))
 					throw std::runtime_error("unable to set mount options (to 'remount,ro')");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.