Integrity duplicated codes.
Add logs.
Change-Id: I8f58db623270c32dba5687310e6553f67833cc69
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
} 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);
}
}
}
-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(char const *const exec_argv)
{
gchar link_path[PATH_MAX] = { 0, };
}
}
#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);
+}
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
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);