From: Munkyu Im Date: Mon, 15 Sep 2014 11:27:18 +0000 (+0900) Subject: osutil: arrange source code about proxy X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~228^2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b92349a0ad8569a74bb7d1b5e0abcaf7f4f4f860;p=sdk%2Femulator%2Fqemu.git osutil: arrange source code about proxy Integrity duplicated codes. Add logs. Change-Id: I8f58db623270c32dba5687310e6553f67833cc69 Signed-off-by: Munkyu Im --- diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 18b6705461..56dc940717 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -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); } diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index fcb7286f9e..b98f9b396c 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -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); } diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index c75e4ca531..2cd47b1f37 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -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); +} diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index 29b3be1c0a..46bb9128e5 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -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; } - - diff --git a/tizen/src/util/osutil.c b/tizen/src/util/osutil.c index 3bcaf20193..a4d01df83d 100644 --- a/tizen/src/util/osutil.c +++ b/tizen/src/util/osutil.c @@ -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 diff --git a/tizen/src/util/osutil.h b/tizen/src/util/osutil.h index b85d6dbf42..ab4f7d5a14 100644 --- a/tizen/src/util/osutil.h +++ b/tizen/src/util/osutil.h @@ -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);