tzip: Fixed the problem that mount node information is left in /run/.deviced when... 47/170347/6
authorINSUN PYO <insun.pyo@samsung.com>
Mon, 19 Feb 2018 08:50:47 +0000 (17:50 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 20 Feb 2018 05:33:47 +0000 (05:33 +0000)
When deviced restarts, save the mount information in the /run/.deviced file to recover the existing mounts.
However, there was a bug in umount that the node is not removed in /run/.deviced.

Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: I2a78e3accf4146db1dedf3d711190de54b5f3664

src/tzip/tzip-utility.c
src/tzip/tzip-utility.h
src/tzip/tzip.c

index 45e2948..bfbd3b9 100644 (file)
@@ -847,6 +847,71 @@ out:
        return ret;
 }
 
+int tzip_clear_mount_info(void)
+{
+       int len;
+       int ret = 0;
+       FILE *fp;
+       char *file_entry = NULL;
+       gpointer key, value;
+       GHashTableIter iter;
+       struct tzip_mount_entry *entry;
+
+       /* no mount entry */
+       if (g_hash_table_size(hashmap) == 0) {
+               ret = unlink(TZIP_INFO_FILE);
+               if (ret < 0)
+                       _E("unlink fail %s, %d", TZIP_INFO_FILE, errno);
+
+               return ret;
+       }
+
+       fp = fopen(TZIP_INFO_TMP_FILE, "w");
+       if (fp == NULL) {
+               _E("fopen() Failed!!!");
+               return -EIO;
+       }
+
+       g_hash_table_iter_init(&iter, hashmap);
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               entry = (struct tzip_mount_entry*)value;
+
+               len = strlen(entry->zip_path) + strlen(entry->path) + 3;
+               file_entry = (char *)malloc(len);
+               if (!file_entry) {
+                       _E("Malloc failed");
+                       ret = -ENOMEM;
+                       goto out;
+               }
+               snprintf(file_entry, len, "%s:%s\n", entry->zip_path, entry->path);
+
+               len = strlen(file_entry);
+               if (fwrite(file_entry, sizeof(char), len, fp) != len) {
+                       _E(" fwrite Failed !!!! ");
+                       free(file_entry);
+                       ret = -EIO;
+                       goto out;
+               }
+
+               free(file_entry);
+       }
+
+out:
+       fclose(fp);
+
+       if (ret == 0) {
+               ret = unlink(TZIP_INFO_FILE);
+               if (ret < 0)
+                       _E("unlink fail %s, %d", TZIP_INFO_FILE, errno);
+
+               ret = rename(TZIP_INFO_TMP_FILE, TZIP_INFO_FILE);
+               if (ret < 0)
+                       _E("rename fail %s, %s, %d", TZIP_INFO_TMP_FILE, TZIP_INFO_FILE, errno);
+       }
+
+       return ret;
+}
+
 int tzip_remount_zipfs(const char *src_file, const char *mount_point)
 {
        int ret = 0;
index 89b986c..be8b3c5 100644 (file)
@@ -32,6 +32,7 @@
 #define DEFAULT_FILE_MODE 0755
 
 #define TZIP_INFO_FILE "/run/.deviced"
+#define TZIP_INFO_TMP_FILE "/run/.deviced.tmpfile"
 
 #define TZIP_MSGQ_NAME "/tzipmsgq"
 
@@ -99,6 +100,7 @@ void tzip_unlock(void);
 GHashTable *hashmap_init(void);
 GHashTable *get_hashmap(void);
 
+int tzip_clear_mount_info(void);
 int tzip_store_mount_info(const char* zip_path, const char* mount_path);
 int tzip_remount_zipfs(const char *src_file, const char *mount_point);
 
index 03af53d..e090719 100644 (file)
@@ -718,6 +718,9 @@ static int tzip_unmount_zipfs(const char *mount_point)
                _E("unlink failed");
        }
 
+       if (tzip_clear_mount_info())
+               _E("Failed to clear_mount_info %s", mount_point);
+
 out_unlock:
        tzip_unlock();
        free(tzip_path);