[systemd-devel] [PATCH] cdrom_id: unmount media on --eject-media if media mounted

Robert Milasan rmilasan at suse.com
Thu Jan 15 06:24:31 PST 2015


Signed-off-by: Robert Milasan <rmilasan at suse.com>
---
 src/udev/cdrom_id/cdrom_id.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index 6052f6a..72a1357 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -217,6 +217,39 @@ static int media_eject(struct udev *udev, int fd)
         return 0;
 }
 
+static int media_umount(const char *node)
+{
+        int err = 0;
+
+        if (!node) {
+                err = -1;
+                goto exit;
+        }
+
+        if (is_mounted(node)) {
+                pid_t pid;
+
+                pid = fork();
+                switch (pid) {
+                case 0:
+                        err = execl("/bin/umount", "/bin/umount",
node, NULL);
+                        if (err < 0) {
+                                log_error("umount failed\n");
+                                goto exit;
+                        }
+                case -1:
+                        log_error("failed to fork\n");
+                        err = -1;
+                        break;
+                default:
+                        break;
+                }
+        }
+
+exit:
+        return err;
+}
+
 static int cd_capability_compat(struct udev *udev, int fd)
 {
         int capability;
@@ -969,6 +1002,8 @@ work:
         }
 
         if (eject) {
+                log_debug("UNMOUNT_MEDIA (umount)\n");
+                media_umount(node);
                 log_debug("PREVENT_ALLOW_MEDIUM_REMOVAL (unlock)");
                 media_lock(udev, fd, false);
                 log_debug("START_STOP_UNIT (eject)");
-- 
1.8.4.5


More information about the systemd-devel mailing list