From: Munkyu Im Date: Thu, 16 Oct 2014 06:34:48 +0000 (+0900) Subject: sdcard: Fix multiple attach X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~230 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0610d7ba101dd7c32dc96b7a1cea45fef652a27b;p=sdk%2Femulator%2Fqemu.git sdcard: Fix multiple attach Lock is released when free fd or handle. Change-Id: I74956c0c136d504bc52eeb51bfd8a995f9cf15b9 Signed-off-by: Munkyu Im --- diff --git a/tizen/src/osutil-win32.c b/tizen/src/osutil-win32.c index b0a0ea9831..4e37441263 100644 --- a/tizen/src/osutil-win32.c +++ b/tizen/src/osutil-win32.c @@ -55,7 +55,6 @@ static qemu_timeval tv = { 0, 0 }; static time_t ti; static char buf_time[64]; extern char tizen_target_img_path[]; -HANDLE g_hFile; static char g_sdcard[256] = {0,}; static const char *pactempfile = ".autoproxy"; @@ -421,10 +420,8 @@ bool make_sdcard_lock_os(char *sdcard) } return true; } - g_hFile = hFile; INFO("Get file lock: %s\n", lock_file); strncpy(g_sdcard, sdcard, strlen(sdcard)); - CloseHandle(hFile); return true; } @@ -450,7 +447,6 @@ int remove_sdcard_lock_os(char *sdcard) } INFO("return ERR_SUCCESS\n"); - CloseHandle(g_hFile); g_sdcard[0] = '\0'; fSuccess = DeleteFile(lock_file); if (!fSuccess) { @@ -475,7 +471,12 @@ int remove_sdcard_lock_os(char *sdcard) return ERR_UNLCK; } CloseHandle(hFile2); - CloseHandle(g_hFile); + fSuccess = DeleteFile(lock_file); + if (!fSuccess) { + // Handle the error. + ERR("DeleteFile failed (%d)\n", GetLastError()); + return ERR_UNLCK; + } INFO("unlock success: %s\n", lock_file); return ERR_SUCCESS; diff --git a/tizen/src/osutil.c b/tizen/src/osutil.c index edd90b2d96..3092a2953e 100644 --- a/tizen/src/osutil.c +++ b/tizen/src/osutil.c @@ -44,17 +44,14 @@ 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 write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t written; written = fwrite(ptr, size, nmemb, stream); return written; } -inline void download_url(char *url) +void download_url(char *url) { CURL *curl; FILE *fp; @@ -85,7 +82,7 @@ inline void download_url(char *url) return; } -inline void remove_string(char *src, char *dst, const char *toremove) +void remove_string(char *src, char *dst, const char *toremove) { int len = strlen(toremove); int i, j; @@ -125,7 +122,7 @@ static int fd_unlock(int fd) return fcntl(fd, F_SETLK, &lock); } -inline bool make_sdcard_lock(char *sdcard) +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); @@ -142,13 +139,11 @@ inline bool make_sdcard_lock(char *sdcard) } INFO("Get file lock: %s\n", lock_file); - g_fd = fd; - close(fd); return true; } -inline int remove_sdcard_lock(char *sdcard) +int remove_sdcard_lock(char *sdcard) { errno = 0; char *lock_file = g_strdup_printf("%s.lck", sdcard); @@ -177,7 +172,6 @@ inline int remove_sdcard_lock(char *sdcard) 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 82c40a6975..e272869e61 100644 --- a/tizen/src/osutil.h +++ b/tizen/src/osutil.h @@ -85,6 +85,5 @@ void remove_string(char *, char *, const char *); char *get_timeofday(void); int get_number_of_processors(void); - #endif // __OS_UTIL_H__