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~241^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae6adf0ee442d5d1a7bedc0639f8776808ffa8c4;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/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index a4b706b1be..c05cfca001 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -1028,7 +1028,7 @@ static bool handle_sdcard(char* dataBuf, size_t dataLen) TRACE("sdcard path: [%s]\n", sdcard_img_path); //mloop_evcmd_usbdisk(sdcard_img_path); - if (make_sdcard_lock_os(sdcard_img_path) && !is_sdcard_attached) { + if (!is_sdcard_attached && make_sdcard_lock_os(sdcard_img_path)) { mloop_evcmd_sdcard(sdcard_img_path); is_sdcard_attached = true; } else { diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 5f47faddb5..22e20e41e6 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -309,9 +309,13 @@ static void prepare_basic_features(gchar * const kernel_cmdline) } else { proxy = g_strsplit(http_proxy, ":", -1); } - 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) { + 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/osutil-darwin.c b/tizen/src/osutil-darwin.c index 759aa197e0..2eda16e054 100644 --- a/tizen/src/osutil-darwin.c +++ b/tizen/src/osutil-darwin.c @@ -391,79 +391,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/osutil-linux.c b/tizen/src/osutil-linux.c index 653d5860a8..b8bc144daf 100644 --- a/tizen/src/osutil-linux.c +++ b/tizen/src/osutil-linux.c @@ -149,83 +149,6 @@ void make_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(gchar * exec_argv) { gchar link_path[PATH_MAX] = { 0, }; @@ -529,3 +452,14 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha } pclose(output); } + +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/osutil-win32.c b/tizen/src/osutil-win32.c index 28997fdf9b..b0a0ea9831 100644 --- a/tizen/src/osutil-win32.c +++ b/tizen/src/osutil-win32.c @@ -295,7 +295,7 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha //if exists url = (char*)malloc(dwLength); if (url == NULL) { - ERR( "Failed to allocate a buffer\n"); + ERR("Failed to allocate a buffer\n"); } else { memset(url, 0x00, dwLength); @@ -310,14 +310,14 @@ void get_host_proxy_os(char *http_proxy, char *https_proxy, char *ftp_proxy, cha //check manual proxy key exists lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength); if (lRet != ERROR_SUCCESS && dwLength == 0) { - ERR(stderr, "Failed to query value from %s\n", + ERR("Failed to query value from %s\n", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable"); RegCloseKey(hKey); return; } proxyenable = (BYTE*)malloc(dwLength); if (proxyenable == NULL) { - ERR( "Failed to allocate a buffer\n"); + ERR("Failed to allocate a buffer\n"); RegCloseKey(hKey); return; } @@ -402,7 +402,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, @@ -413,17 +413,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; } @@ -457,7 +458,6 @@ int remove_sdcard_lock_os(char *sdcard) ERR("DeleteFile failed (%d)\n", GetLastError()); return ERR_UNLCK; } - return ERR_SUCCESS; } return ERR_NOENT; @@ -480,5 +480,3 @@ int remove_sdcard_lock_os(char *sdcard) return ERR_SUCCESS; } - - diff --git a/tizen/src/osutil.c b/tizen/src/osutil.c index 07fc65d196..edd90b2d96 100644 --- a/tizen/src/osutil.c +++ b/tizen/src/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/osutil.h b/tizen/src/osutil.h index 27721e306b..82c40a6975 100644 --- a/tizen/src/osutil.h +++ b/tizen/src/osutil.h @@ -69,7 +69,10 @@ void check_vm_lock_os(void); void make_vm_lock_os(void); bool make_sdcard_lock_os(char *sdcard); int remove_sdcard_lock_os(char *sdcard); - +#ifndef CONFIG_WIN32 +bool make_sdcard_lock(char *sdcard); +int remove_sdcard_lock(char *sdcard); +#endif void set_bin_path_os(gchar *); void print_system_info_os(void); diff --git a/tizen/src/sdb.c b/tizen/src/sdb.c index 090c170f08..15d4c2a808 100644 --- a/tizen/src/sdb.c +++ b/tizen/src/sdb.c @@ -93,7 +93,7 @@ int inet_strtoip(const char* str, uint32_t *ip) int check_port_bind_listen(uint32_t port) { struct sockaddr_in addr; - int s, opt = 1; + int s = 1; int ret = -1; socklen_t addrlen = sizeof(addr); memset(&addr, 0, addrlen); @@ -109,6 +109,7 @@ int check_port_bind_listen(uint32_t port) } #ifndef _WIN32 + int opt = 1; ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)); if (ret < 0) {