Integrity duplicated codes.
Add logs.
Change-Id: I8f58db623270c32dba5687310e6553f67833cc69
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
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 {
} 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);
}
}
}
-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);
}
}
}
-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, };
}
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);
+}
//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);
//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;
}
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,
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;
}
ERR("DeleteFile failed (%d)\n", GetLastError());
return ERR_UNLCK;
}
-
return ERR_SUCCESS;
}
return ERR_NOENT;
return ERR_SUCCESS;
}
-
-
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;
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
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);
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);
}
#ifndef _WIN32
+ int opt = 1;
ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(char *)&opt, sizeof(int));
if (ret < 0) {