shared: Replace mount_check() with syscommon_is_mounted() 66/296266/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 24 Jul 2023 11:36:56 +0000 (20:36 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 24 Jul 2023 11:36:56 +0000 (20:36 +0900)
Change-Id: I505117cb3ffcfb3e467bd2dd7df79d2d051b5f39
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/shared/common.c
src/shared/common.h
tests/usb-host-test/usb-host-test.c

index 67c22c7..98d68f4 100644 (file)
@@ -36,6 +36,7 @@
 #include <mntent.h>
 #include <system_info.h>
 #include <sys/mount.h>
+#include <libsyscommon/common.h>
 #include "log.h"
 #include "common.h"
 
@@ -71,32 +72,6 @@ static int terminate_processes_on_partition(const char *partition, bool force)
        return run_child(argc, argv);
 }
 
-int mount_check(const char *path)
-{
-       int ret = false;
-       struct mntent *mnt;
-       const char *table = "/etc/mtab";
-       FILE *fp;
-       int len;
-
-       fp = setmntent(table, "r");
-       if (!fp)
-               return ret;
-
-       len = strlen(path) + 1;
-       while (1) {
-               mnt = getmntent(fp);
-               if (mnt == NULL)
-                       break;
-               if (!strncmp(mnt->mnt_dir, path, len)) {
-                       ret = true;
-                       break;
-               }
-       }
-       endmntent(fp);
-       return ret;
-}
-
 static int get_num_processes_on_partition(const char *part_path)
 {
        FILE *fp;
@@ -135,7 +110,7 @@ void umount_partition_by_kill(const char *path, const int max_retry)
        char *cmd = NULL;
 
        /* if the path is not a mountpoint, do not perform umounting and killing */
-       if (!mount_check(path))
+       if (!syscommon_is_mounted(path))
                return;
 
        ret = asprintf(&cmd, "mount | grep \" on %s \" | awk '{print $1}'", path);
index da1e04c..27fd296 100644 (file)
@@ -198,7 +198,6 @@ static inline void __cleanup_fclose_func(FILE **f) {
 
 int run_child(int argc, const char *argv[]);
 int get_systemd_reboot_param(char *buf, unsigned bufsize);
-int mount_check(const char* path);
 void umount_partition_by_kill(const char *path, const int max_retry);
 bool is_emulator(void);
 int do_mkdir(const char *path, mode_t mode);
index f6cba3b..7a17d53 100644 (file)
@@ -26,6 +26,7 @@
 #include <libsyscommon/libsystemd.h>
 #include <libsyscommon/list.h>
 #include <libsyscommon/ini-parser.h>
+#include <libsyscommon/common.h>
 
 #include "core/log.h"
 #include "shared/device-notifier.h"
@@ -427,7 +428,7 @@ int start()
 
                /* Workaround: "modprobe usb_f_fs" doesn't guarantee that /sys/kernel/config is mounted */
                for (i = 0; i < 10; i++) {
-                       if (mount_check(CONFIGFS_PATH))
+                       if (syscommon_is_mounted(CONFIGFS_PATH))
                                break;
 
                        sleep (1);