osutil: arrange source code about proxy
authorMunkyu Im <munkyu.im@samsung.com>
Mon, 15 Sep 2014 11:27:18 +0000 (20:27 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 15 Oct 2014 05:45:15 +0000 (14:45 +0900)
Integrity duplicated codes.
Add logs.

Change-Id: I8f58db623270c32dba5687310e6553f67833cc69
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/emulator.c
tizen/src/util/osutil-darwin.c
tizen/src/util/osutil-linux.c
tizen/src/util/osutil-win32.c
tizen/src/util/osutil.c
tizen/src/util/osutil.h

index 18b67054616b69e0e754ce4def9f075da8951e6b..56dc9407177a63aaf6a7273689bf553ce3f9400c 100644 (file)
@@ -241,9 +241,13 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
         } else {
             proxy = g_strsplit(http_proxy, ":", -1);
         }
-        LOG_INFO("http_proxy address: %s, port: %s\n", proxy[0], proxy[1]);
-        set_emul_http_proxy_addr(proxy[0]);
-        set_emul_http_proxy_port(proxy[1]);
+        if(g_strv_length(proxy) > 1) {
+            if(proxy[0] != NULL && proxy[1] != NULL) {
+                LOG_INFO("http_proxy information= addr: %s, port: %s\n", proxy[0], proxy[1]);
+                set_emul_http_proxy_addr(proxy[0]);
+                set_emul_http_proxy_port(proxy[1]);
+            }
+        }
         if(proxy != NULL) {
             g_strfreev(proxy);
         }
index fcb7286f9ea3e7f8b4c721fb8da125baa7268aaa..b98f9b396c32652801b2c630066b221ae294d40e 100644 (file)
@@ -382,79 +382,12 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
     }
 }
 
-static int fd_isopen(int fd)
-{
-    struct flock lock;
-
-    lock.l_type = F_WRLCK;
-    lock.l_start = 0;
-    lock.l_whence = SEEK_SET;
-    lock.l_len = 0;
-    lock.l_pid = getpid();
-
-    return fcntl(fd, F_SETLK, &lock);
-}
-
-static int fd_unlock(int fd)
-{
-    struct flock lock;
-
-    lock.l_type = F_UNLCK;
-    lock.l_start = 0;
-    lock.l_whence = SEEK_SET;
-    lock.l_len = 0;
-
-    return fcntl(fd, F_SETLK, &lock);
-}
-
 bool make_sdcard_lock_os(char *sdcard)
 {
-    char *lock_file = g_strdup_printf("%s.lck", sdcard);
-    int fd = open(lock_file, O_CREAT|O_RDWR, 0666);
-    if (fd == -1)
-    {
-        perror("file open error : ");
-       return false;
-    }
-    if (fd_isopen(fd) == -1)
-    {
-        perror("file is lock ");
-        return false;
-    }
-    INFO("Get file lock: %s\n", lock_file);
-    return true;
-
+    return make_sdcard_lock(sdcard);
 }
 
 int remove_sdcard_lock_os(char *sdcard)
 {
-    errno = 0;
-    char *lock_file = g_strdup_printf("%s.lck", sdcard);
-    int fd = open(lock_file, O_RDWR, 0666);
-    if (fd == -1)
-    {
-        perror("file open error : ");
-        if(errno == ENOENT) {
-            return ERR_NOENT;
-        }
-        return ERR_UNLCK;
-    }
-
-    if (fd_unlock(fd) == -1)
-    {
-        perror("file unlock error ");
-        return ERR_UNLCK;
-    }
-
-    if (unlink(lock_file) < 0) {
-        perror("unlink error ");
-        return ERR_UNLCK;
-    }
-
-    if (remove(lock_file) < 0) {
-        perror("remove error ");
-        return ERR_UNLCK;
-    }
-    INFO("unlock success: %s\n", lock_file);
-    return ERR_SUCCESS;
+    return remove_sdcard_lock(sdcard);
 }
index c75e4ca53142c892465264860487ce6aa85c63e0..2cd47b1f371292885d6ee308db99b71b567c10d8 100644 (file)
@@ -156,83 +156,6 @@ void remove_vm_lock_os(void)
     }
 }
 
-static int fd_isopen(int fd)
-{
-    struct flock lock;
-
-    lock.l_type = F_WRLCK;
-    lock.l_start = 0;
-    lock.l_whence = SEEK_SET;
-    lock.l_len = 0;
-    lock.l_pid = getpid();
-
-    return fcntl(fd, F_SETLK, &lock);
-}
-
-static int fd_unlock(int fd)
-{
-    struct flock lock;
-
-    lock.l_type = F_UNLCK;
-    lock.l_start = 0;
-    lock.l_whence = SEEK_SET;
-    lock.l_len = 0;
-
-    return fcntl(fd, F_SETLK, &lock);
-}
-
-bool make_sdcard_lock_os(char *sdcard)
-{
-    char *lock_file = g_strdup_printf("%s.lck", sdcard);
-    int fd = open(lock_file, O_CREAT|O_RDWR, 0666);
-    if (fd == -1)
-    {
-        perror("file open error : ");
-       return false;
-    }
-    if (fd_isopen(fd) == -1)
-    {
-        perror("file is lock ");
-        return false;
-    }
-    INFO("Get file lock: %s\n", lock_file);
-    return true;
-
-}
-
-int remove_sdcard_lock_os(char *sdcard)
-{
-    errno = 0;
-    char *lock_file = g_strdup_printf("%s.lck", sdcard);
-    int fd = open(lock_file, O_RDWR, 0666);
-    if (fd == -1)
-    {
-        perror("file open error : ");
-        if(errno == ENOENT) {
-            return ERR_NOENT;
-        }
-        return ERR_UNLCK;
-    }
-
-    if (fd_unlock(fd) == -1)
-    {
-        perror("file unlock error ");
-        return ERR_UNLCK;
-    }
-
-    if (unlink(lock_file) < 0) {
-        perror("unlink error ");
-        return ERR_UNLCK;
-    }
-
-    if (remove(lock_file) < 0) {
-        perror("remove error ");
-        return ERR_UNLCK;
-    }
-    INFO("unlock success: %s\n", lock_file);
-    return ERR_SUCCESS;
-}
-
 void set_bin_path_os(char const *const exec_argv)
 {
     gchar link_path[PATH_MAX] = { 0, };
@@ -734,3 +657,13 @@ void nodejs_init(void)
     }
 }
 #endif
+bool make_sdcard_lock_os(char *sdcard)
+{
+    return make_sdcard_lock(sdcard);
+}
+
+
+int remove_sdcard_lock_os(char *sdcard)
+{
+    return remove_sdcard_lock(sdcard);
+}
index 29b3be1c0a8a1228da2a30cf6670ee2afcb34f8a..46bb9128e577182c1bfde42133e998de0ff52d3e 100644 (file)
@@ -400,7 +400,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha
 
 bool make_sdcard_lock_os(char *sdcard)
 {
-   char *lock_file = g_strdup_printf("%s.lck", sdcard);
+    char *lock_file = g_strdup_printf("%s.lck", sdcard);
 
     HANDLE hFile = CreateFile(lock_file, GENERIC_READ,
             0,
@@ -411,17 +411,18 @@ bool make_sdcard_lock_os(char *sdcard)
 
     if (hFile == INVALID_HANDLE_VALUE) {
         ERR("file open error : (%d)\n", GetLastError());
-               if(GetLastError() == 32) {
-                       if(strcmp(g_sdcard, sdcard) == 0) {
-                               INFO("try to mount same sdcard!\n");
-                       }
-                       return false;
-               }
+        if(GetLastError() == 32) {
+            if(strcmp(g_sdcard, sdcard) == 0) {
+                INFO("try to mount same sdcard!\n");
+            }
+            return false;
+        }
         return true;
     }
-       g_hFile = hFile;
-       strncpy(g_sdcard, sdcard, strlen(sdcard));
+    g_hFile = hFile;
     INFO("Get file lock: %s\n", lock_file);
+    strncpy(g_sdcard, sdcard, strlen(sdcard));
+    CloseHandle(hFile);
     return true;
 
 }
@@ -455,7 +456,6 @@ int remove_sdcard_lock_os(char *sdcard)
                 ERR("DeleteFile failed (%d)\n", GetLastError());
                 return ERR_UNLCK;
             }
-
             return ERR_SUCCESS;
         }
         return ERR_NOENT;
@@ -478,5 +478,3 @@ int remove_sdcard_lock_os(char *sdcard)
     return ERR_SUCCESS;
 
 }
-
-
index 3bcaf20193729de4fd6fcabf3c4074e16db52d99..a4d01df83d63f24f05c1a1b4c6bbbe5916988fb4 100644 (file)
@@ -44,7 +44,9 @@ MULTI_DEBUG_CHANNEL(emulator, osutil);
 
 
 const char *pac_tempfile = ".autoproxy";
-
+#ifndef CONFIG_WIN32
+static int g_fd;
+#endif
 inline size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
 {
     size_t written;
@@ -96,3 +98,86 @@ inline void remove_string(char *src, char *dst, const char *toremove)
 
     dst[j] = '\0';
 }
+
+#ifndef CONFIG_WIN32
+static int fd_lock(int fd)
+{
+    struct flock lock;
+
+    lock.l_type = F_WRLCK;
+    lock.l_start = 0;
+    lock.l_whence = SEEK_SET;
+    lock.l_len = 0;
+    lock.l_pid = getpid();
+
+    return fcntl(fd, F_SETLK, &lock);
+}
+
+static int fd_unlock(int fd)
+{
+    struct flock lock;
+
+    lock.l_type = F_UNLCK;
+    lock.l_start = 0;
+    lock.l_whence = SEEK_SET;
+    lock.l_len = 0;
+
+    return fcntl(fd, F_SETLK, &lock);
+}
+
+inline bool make_sdcard_lock(char *sdcard)
+{
+    char *lock_file = g_strdup_printf("%s.lck", sdcard);
+    int fd = open(lock_file, O_CREAT|O_RDWR, 0666);
+    if (fd == -1)
+    {
+        perror("file open error : ");
+        return false;
+    }
+    if (fd_lock(fd) == -1)
+    {
+        perror("file is lock ");
+        close(fd);
+        return false;
+    }
+
+    INFO("Get file lock: %s\n", lock_file);
+    g_fd = fd;
+    close(fd);
+    return true;
+
+}
+
+inline int remove_sdcard_lock(char *sdcard)
+{
+    errno = 0;
+    char *lock_file = g_strdup_printf("%s.lck", sdcard);
+    int fd = open(lock_file, O_RDWR, 0666);
+    if (fd == -1)
+    {
+        perror("file open error : ");
+        if(errno == ENOENT) {
+            return ERR_NOENT;
+        }
+        return ERR_UNLCK;
+    }
+
+    if (fd_unlock(fd) == -1)
+    {
+        perror("file unlock error ");
+        close(fd);
+        return ERR_UNLCK;
+    }
+
+    if (unlink(lock_file) < 0) {
+        perror("unlink error ");
+        close(fd);
+        return ERR_UNLCK;
+    }
+
+    INFO("unlock success: %s\n", lock_file);
+    close(fd);
+    close(g_fd);
+    return ERR_SUCCESS;
+}
+#endif
index b85d6dbf42a39d9743a0736eaf077fab9b2bf6ba..ab4f7d5a1499f851dd0de58f4225919338d8b797 100644 (file)
@@ -71,6 +71,10 @@ bool make_sdcard_lock_os(char *sdcard);
 int remove_sdcard_lock_os(char *sdcard);
 
 void set_bin_path_os(char const *const);
+#ifndef CONFIG_WIN32
+bool make_sdcard_lock(char *sdcard);
+int remove_sdcard_lock(char *sdcard);
+#endif
 
 void print_system_info_os(void);