char *pkg_type;
char *so_path;
int (*dl_do_pre_exe)(char *, char *);
+ void *handle;
} preexec_list_t;
static void __preexec_list_free()
if (type_t->so_path) {
free(type_t->so_path);
}
+ if (type_t->handle) {
+ dlclose(type_t->handle);
+ }
free(type_t);
}
}
if (type_t->pkg_type == NULL) {
_E("no available memory\n");
free(type_t);
+ dlclose(handle);
+ handle = NULL;
__preexec_list_free();
fclose(preexec_file);
return;
_E("no available memory\n");
free(type_t->pkg_type);
free(type_t);
+ dlclose(handle);
+ handle = NULL;
__preexec_list_free();
fclose(preexec_file);
return;
}
+ type_t->handle = handle;
type_t->dl_do_pre_exe = func;
preexec_list = g_slist_append(preexec_list, (void *)type_t);
#ifdef PRELOAD_ACTIVATE
#include <dlfcn.h>
+#include <glib.h>
+
#define PRELOAD_FILE SHARE_PREFIX "/preload_list.txt"
#define PRELOAD_FILE_WRT SHARE_PREFIX "/preload_list_wrt.txt"
static char **g_argv;
static size_t max_cmdline_size = 0;
-static int (*dl_einit)() = NULL;
-static int (*dl_efini)() = NULL;
+static GSList *g_dlopen_handle_list = NULL;
+
+typedef struct handle_list_t {
+ int (*dl_einit)();
+ int (*dl_efini)();
+ void *handle;
+} handle_list_t;
static inline void __preload_init(int argc, char **argv)
{
return;
}
- while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > (char*)0) {
- soname[MAX_LOCAL_BUFSZ - 1] = 0;
- handle = dlopen(soname, RTLD_NOW);
- if (handle == NULL) {
+ while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) != NULL) {
+ size_t pos = strnlen(soname, MAX_LOCAL_BUFSZ);
+ if (pos > 0) {
+ soname[pos - 1] = '\0';
+ }
+
+ handle_list_t *entry = calloc(1, sizeof(handle_list_t));
+ if (!entry) {
+ _E("out of memory\n");
+ break;
+ }
+
+ entry->handle = dlopen(soname, RTLD_NOW);
+ if (entry->handle == NULL) {
+ free(entry);
continue;
}
- _D("preload %s# - handle : %x\n", soname, handle);
+ _D("preload %s# - handle : %x\n", soname, entry->handle);
- func = dlsym(handle, EFL_PREINIT_FUNC);
+ func = dlsym(entry->handle, EFL_PREINIT_FUNC);
if (func != NULL) {
_D("get pre-initialization function\n");
- dl_einit = func;
+ entry->dl_einit = func;
func = dlsym(handle, EFL_SHUTDOWN_FUNC);
if (func != NULL) {
_D("get shutdown function\n");
- dl_efini = func;
+ entry->dl_efini = func;
}
}
+ g_dlopen_handle_list = g_slist_prepend(g_dlopen_handle_list, entry);
}
-
fclose(preload_list);
preload_initialized = 1;
}
static inline int preinit_init()
{
- if (dl_einit != NULL) {
- dl_einit(0, NULL);
+ GSList *iter = NULL;
+ handle_list_t *entry;
+
+ for (iter = g_dlopen_handle_list; iter != NULL; iter = g_slist_next(iter)) {
+ entry = iter->data;
+ if (entry->dl_einit != NULL)
+ entry->dl_einit(0, NULL);
}
_D("pre-initialzation on");
return 0;
static inline int preinit_fini()
{
- if (dl_efini != NULL) {
- dl_efini();
+ GSList *iter = NULL;
+ handle_list_t *entry;
+
+ for (iter = g_dlopen_handle_list; iter != NULL; iter = g_slist_next(iter)) {
+ entry = iter->data;
+ if (entry->dl_efini != NULL)
+ entry->dl_efini();
+ if (entry->handle)
+ dlclose(entry->handle);
}
_D("pre-initialization off");
+ g_slist_free_full(g_dlopen_handle_list, free);
+ g_dlopen_handle_list = NULL;
return 0;
}
exit(0);
}
-static int g_dlopen_size = 5;
-static int g_dlopen_count = 0;
-static void** g_dlopen_handle_list = NULL;
+static int g_wrt_dlopen_size = 5;
+static int g_wrt_dlopen_count = 0;
+static void** g_wrt_dlopen_handle_list = NULL;
static inline int __preload_save_dlopen_handle(void *handle)
{
if (!handle) {
return 1;
}
- if (g_dlopen_count == g_dlopen_size || !g_dlopen_handle_list) {
+ if (g_wrt_dlopen_count == g_wrt_dlopen_size || !g_wrt_dlopen_handle_list) {
void** tmp =
- realloc(g_dlopen_handle_list, 2 * g_dlopen_size * sizeof(void *));
+ realloc(g_wrt_dlopen_handle_list, 2 * g_wrt_dlopen_size * sizeof(void *));
if (NULL == tmp) {
_E("out of memory\n");
dlclose(handle);
return 1;
}
- g_dlopen_size *= 2;
- g_dlopen_handle_list = tmp;
+ g_wrt_dlopen_size *= 2;
+ g_wrt_dlopen_handle_list = tmp;
}
- g_dlopen_handle_list[g_dlopen_count++] = handle;
+ g_wrt_dlopen_handle_list[g_wrt_dlopen_count++] = handle;
return 0;
}
static inline void __preload_fini_for_wrt()
{
int i = 0;
- if (!g_dlopen_handle_list) {
+ if (!g_wrt_dlopen_handle_list) {
return;
}
- for (i = 0; i < g_dlopen_count; ++i) {
- void *handle = g_dlopen_handle_list[i];
+ for (i = 0; i < g_wrt_dlopen_count; ++i)
+ {
+ void *handle = g_wrt_dlopen_handle_list[i];
if (handle) {
if (0 != dlclose(handle)) {
_E("dlclose failed\n");
}
}
}
- free(g_dlopen_handle_list);
- g_dlopen_handle_list = NULL;
- g_dlopen_size = 5;
- g_dlopen_count = 0;
+ free(g_wrt_dlopen_handle_list);
+ g_wrt_dlopen_handle_list = NULL;
+ g_wrt_dlopen_size = 5;
+ g_wrt_dlopen_count = 0;
}
static inline void __preload_init_for_wrt()
socklen_t salen,
int nsec);
-static inline void __set_sock_option(int fd, int cli)
+static inline int __set_sock_option(int fd, int cli)
{
int size;
- struct timeval tv = { 3, 200 * 1000 }; /* 3.2 sec */
+ struct timeval tv = { 3, 200 * 1000 }; /* 3.2 sec */
size = AUL_SOCK_MAXBUFF;
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
- if (cli) {
- setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ if (0 != setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) ||
+ 0 != setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)))
+ {
+ return 1;
+ }
+ if (cli && 0 != setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) {
+ return 1;
}
+ return 0;
}
int __create_server_sock(int pid)
return -1;
}
- __set_sock_option(fd, 0);
+ if (0 != __set_sock_option(fd, 0)) {
+ close(fd);
+ return -1;
+ }
if (listen(fd, 10) == -1) {
_E("listen error");
if (link(saddr.sun_path, p_saddr.sun_path) < 0) {
if (errno == EEXIST) {
_D("pg path - already exists");
- } else {
+ }
+ else {
_E("pg path - unknown create error");
}
}
return -1;
}
- __set_sock_option(fd, 1);
+ if (0 != __set_sock_option(fd, 1)) {
+ close(fd);
+ return -1;
+ }
return fd;
}
struct timeval timeout;
flags = fcntl(fd, F_GETFL, 0);
- fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+ if (0 != fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
+ return -1;
+ }
error = 0;
if ((ret = connect(fd, (struct sockaddr *)saptr, salen)) < 0) {
if (errno != EAGAIN && errno != EINPROGRESS) {
- fcntl(fd, F_SETFL, flags);
+ (void) fcntl(fd, F_SETFL, flags);
return (-2);
}
}
/* Do whatever we want while the connect is taking place. */
if (ret == 0) {
- goto done; /* connect completed immediately */
+ goto done; /* connect completed immediately */
}
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
timeout.tv_usec = nsec;
if ((ret = select(fd + 1, &readfds, &writefds, NULL,
- nsec ? &timeout : NULL)) == 0)
- {
- close(fd); /* timeout */
+ nsec ? &timeout : NULL)) == 0) {
+ close(fd); /* timeout */
errno = ETIMEDOUT;
return (-1);
}
if (FD_ISSET(fd, &readfds) || FD_ISSET(fd, &writefds)) {
len = sizeof(error);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
- return (-1); /* Solaris pending error */
+ return (-1); /* Solaris pending error */
}
- } else {
- return (-1); /* select error: sockfd not set*/
}
+ else {
+ return (-1); /* select error: sockfd not set*/
+ }
+
done:
(void) fcntl(fd, F_SETFL, flags);
if (error) {
}
if (getsockopt(*clifd, SOL_SOCKET, SO_PEERCRED, cr,
- (socklen_t *) &cl) < 0)
+ (socklen_t *) &cl) < 0)
{
_E("peer information error");
close(*clifd);
}
pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
- if (pkt == NULL) {
+ if(pkt == NULL) {
close(*clifd);
return NULL;
}
memset(pkt, 0, AUL_SOCK_MAXBUFF);
- __set_sock_option(*clifd, 1);
+ if (0 != __set_sock_option(*clifd, 1)) {
+ close(*clifd);
+ return NULL;
+ }
retry_recv:
/* receive single packet from socket */