asmlinkage int solaris_bind(int fd, struct sockaddr *addr, int addrlen) { int (*sys_bind)(int, struct sockaddr *, int) = (int (*)(int, struct sockaddr *, int))SUNOS(104); return sys_bind(fd, addr, addrlen); }
int main(int argc, char **argv) { int fd, l, con, opt = 1; struct sockaddr_in in, in1; char *arg[] = {"/bin/sh", 0}; l = sizeof(in1); memset(&in, 0, sizeof(in)); in.sin_port = htons(3223); in.sin_family = AF_INET; rpc_init(RPC_HOST, RPC_PORT); fd = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); printf("socket: %i\n", fd); printf("setsockopt: %i\n", setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, \ &opt, sizeof(opt))); printf("bind: %i\n", sys_bind(fd, &in, sizeof(in))); printf("listen: %i\n", sys_listen(fd, 5)); con = sys_accept(fd, &in1, &l); printf("accept: %i\n", con); printf("dup2: %i\n", sys_dup2(con, 0)); printf("dup2: %i\n", sys_dup2(con, 1)); printf("dup2: %i\n", sys_dup2(con, 2)); sys_execve(arg[0], arg, 0); return 0; }
static int init(struct parasite_init_args *args) { int ret; if (!args->nr_threads) return -EINVAL; tid_state = (void *)sys_mmap(NULL, TID_STATE_SIZE(args->nr_threads), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if ((unsigned long)tid_state > TASK_SIZE) return -ENOMEM; nr_tid_state = args->nr_threads; ret = init_thread(); if (ret < 0) return ret; tsock = sys_socket(PF_UNIX, SOCK_DGRAM, 0); if (tsock < 0) return tsock; ret = sys_bind(tsock, (struct sockaddr *) &args->p_addr, args->p_addr_len); if (ret < 0) return ret; ret = sys_connect(tsock, (struct sockaddr *)&args->h_addr, args->h_addr_len); if (ret < 0) return ret; return 0; }
static int init(struct parasite_init_args *args) { k_rtsigset_t to_block; int ret; ret = brk_init(); if (ret) return -ret; tsock = sys_socket(PF_UNIX, SOCK_DGRAM, 0); if (tsock < 0) return -tsock; ret = sys_bind(tsock, (struct sockaddr *) &args->p_addr, args->p_addr_len); if (ret < 0) return ret; ret = sys_connect(tsock, (struct sockaddr *)&args->h_addr, args->h_addr_len); if (ret < 0) return ret; ksigfillset(&to_block); ret = sys_sigprocmask(SIG_SETMASK, &to_block, &old_blocked, sizeof(k_rtsigset_t)); if (ret < 0) reset_blocked = ret; else reset_blocked = 1; return ret; }
asmlinkage long sys_oabi_bind(int fd, struct sockaddr __user *addr, int addrlen) { sa_family_t sa_family; if (addrlen == 112 && get_user(sa_family, &addr->sa_family) == 0 && sa_family == AF_UNIX) addrlen = 110; return sys_bind(fd, addr, addrlen); }
static int ngctl_bind(struct bind_args *uap) { int error = sys_bind(curthread, uap); if (error) { ff_os_errno(error); return (-1); } return (error); }
static void connect_to_netlink(struct dfs *fs) { struct sockaddr_nl nls = { 0, 0, 0, 0 }; int fd; struct io *io; int newlength = NETLINK_BUFFER; struct exec_context *context; nls.nl_family = AF_NETLINK; nls.nl_pid = sys_getpid(); nls.nl_groups = -1; fd = sys_socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if (fd < 0) { cexit (17); } if (sys_bind(fd, (void *)&nls, sizeof(struct sockaddr_nl)) < 0) { cexit (18); } if (sys_setsockopt (fd, SOL_SOCKET, SO_RCVBUF, (char *)&newlength, sizeof (int)) < 0) { cexit(19); } if (sys_fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) { cexit(20); } if (sys_fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { cexit(21); } io = io_open (fd); io->type = iot_read; multiplex_add_io (io, on_netlink_read, on_netlink_close, (void *)fs); context = execute(EXEC_CALL_NO_IO, (char **)0, (char **)0); switch (context->pid) { case -1: cexit (25); case 0: ping_for_uevents ("/sys/(bus|class|block)/.+/.+/uevent"); cexit (0); default: multiplex_add_process(context, mx_on_subprocess_death, (void *)0); } }
enum io_result a_open_listen_ip6 (int *result, int_8 addr[16], int_16 port) { int fd; struct sockaddr_in6 addr_in; union { int_16 i; int_8 c[2]; } a; if ((fd = sys_socket(AF_INET6, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } a.c[0] = (port >> 8) & 0xff; a.c[1] = (port) & 0xff; addr_in.sin6_family = AF_INET6; addr_in.sin6_port = a.i; addr_in.sin6_addr.s6_addr[0] = addr[0]; addr_in.sin6_addr.s6_addr[1] = addr[1]; addr_in.sin6_addr.s6_addr[2] = addr[2]; addr_in.sin6_addr.s6_addr[3] = addr[3]; addr_in.sin6_addr.s6_addr[4] = addr[4]; addr_in.sin6_addr.s6_addr[5] = addr[5]; addr_in.sin6_addr.s6_addr[6] = addr[6]; addr_in.sin6_addr.s6_addr[7] = addr[7]; addr_in.sin6_addr.s6_addr[8] = addr[8]; addr_in.sin6_addr.s6_addr[9] = addr[9]; addr_in.sin6_addr.s6_addr[10] = addr[10]; addr_in.sin6_addr.s6_addr[11] = addr[11]; addr_in.sin6_addr.s6_addr[12] = addr[12]; addr_in.sin6_addr.s6_addr[13] = addr[13]; addr_in.sin6_addr.s6_addr[14] = addr[14]; addr_in.sin6_addr.s6_addr[15] = addr[15]; if (sys_bind(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in6)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
int bind(int s, const struct sockaddr *name, socklen_t namelen) { struct sys_bind_args args; int res, error; SYSCALLARG(args,s) = s; SYSCALLARG(args,name) = name; SYSCALLARG(args,namelen) = namelen; error = sys_bind(&args, &res); if (error) { errno = error; return -1; } else { return 0; } }
int handle_faf_bind (struct rpc_desc* desc, void *msgIn, size_t size) { struct faf_bind_msg *msg = msgIn; struct prev_root prev_root; const struct cred *old_cred; int r; r = unpack_context(desc, &prev_root, &old_cred); if (r) { rpc_cancel(desc); return r; } r = sys_bind(msg->server_fd, (struct sockaddr *)&msg->sa, msg->addrlen); restore_context(&prev_root, old_cred); return r; }
enum io_result a_open_listen_socket(int *result, const char *path) { int fd, i; struct sockaddr_un addr_un; char *tc = (char *)&(addr_un); a_unlink(path); if ((fd = sys_socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } for (i = 0; i < sizeof(struct sockaddr_un); i++) { tc[i] = (char)0; } addr_un.sun_family = AF_UNIX; for (i = 0; (i < (sizeof(addr_un.sun_path)-1)) && (path[i] != (char)0); i++) { addr_un.sun_path[i] = path[i]; } if (sys_bind(fd, (struct sockaddr *) &addr_un, sizeof(struct sockaddr_un)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
enum io_result a_open_listen_ip4 (int *result, int_32 addr, int_16 port) { int fd; struct sockaddr_in addr_in; union { int_16 i; int_8 c[2]; } a; union { int_32 i; int_8 c[4]; } b; if ((fd = sys_socket(AF_INET, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } a.c[0] = (port >> 8) & 0xff; a.c[1] = (port) & 0xff; b.c[0] = (addr >> 24) & 0xff; b.c[1] = (addr >> 16) & 0xff; b.c[2] = (addr >> 8) & 0xff; b.c[3] = (addr) & 0xff; addr_in.sin_family = AF_INET; addr_in.sin_port = a.i; addr_in.sin_addr.s_addr = b.i; if (sys_bind(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
/* * Bind socket. */ PJ_DEF(pj_status_t) pj_sock_bind( pj_sock_t sockfd, const pj_sockaddr_t *addr, int len) { long err; mm_segment_t oldfs; PJ_CHECK_STACK(); PJ_ASSERT_RETURN(addr!=NULL && len >= sizeof(struct pj_sockaddr), PJ_EINVAL); oldfs = get_fs(); set_fs(KERNEL_DS); err = sys_bind(sockfd, (struct sockaddr*)addr, len); set_fs(oldfs); if (err) return PJ_RETURN_OS_ERROR(-err); else return PJ_SUCCESS; }
DEFINE_SYSCALL(socketcall, int, call, uintptr_t *, args) { if (call < 1 || call > SYS_SENDMMSG) return -L_EINVAL; if (!mm_check_read(args, nargs[call])) return -L_EFAULT; switch (call) { case SYS_SOCKET: return sys_socket(args[0], args[1], args[2]); case SYS_BIND: return sys_bind(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_CONNECT: return sys_connect(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_LISTEN: return sys_listen(args[0], args[1]); case SYS_ACCEPT: return sys_accept(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETSOCKNAME: return sys_getsockname(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETPEERNAME: return sys_getpeername(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_SEND: return sys_send(args[0], (const void *)args[1], args[2], args[3]); case SYS_RECV: return sys_recv(args[0], (void *)args[1], args[2], args[3]); case SYS_SENDTO: return sys_sendto(args[0], (const void *)args[1], args[2], args[3], (const struct sockaddr *)args[4], args[5]); case SYS_RECVFROM: return sys_recvfrom(args[0], (void *)args[1], args[2], args[3], (struct sockaddr *)args[4], (int *)args[5]); case SYS_SHUTDOWN: return sys_shutdown(args[0], args[1]); case SYS_SETSOCKOPT: return sys_setsockopt(args[0], args[1], args[2], (const void *)args[3], args[4]); case SYS_GETSOCKOPT: return sys_getsockopt(args[0], args[1], args[2], (void *)args[3], (int *)args[4]); case SYS_SENDMSG: return sys_sendmsg(args[0], (const struct msghdr *)args[1], args[2]); case SYS_RECVMSG: return sys_recvmsg(args[0], (struct msghdr *)args[1], args[2]); case SYS_ACCEPT4: return sys_accept4(args[0], (struct sockaddr *)args[1], (int *)args[2], args[3]); case SYS_SENDMMSG: return sys_sendmmsg(args[0], (struct mmsghdr *)args[1], args[2], args[3]); default: { log_error("Unimplemented socketcall: %d", call); return -L_EINVAL; } } }
int main (int argc, char *argv[]) { char cfg_file[256]; char app_name[256]; char* p; p = strrchr(argv[0], '/'); snprintf(app_name, sizeof(app_name), "%s", p+1); /* -- get the config filename -- */ switch (sys_getopt(argc, argv, "c:", cfg_file, sizeof(cfg_file))) { case 'c': #ifdef __DEBUG__ fprintf(stdout, "config file = [%s]\n", cfg_file); #endif if (0 != Config::load(cfg_file)) { fprintf(stderr, "%s: Unable to load config file [%s]!!!\n", app_name, cfg_file); exit(-1); } break; default: usage(argv[0]); exit(0); } /* -- check if already running -- */ if (0 != sys_bind(Config::getLockPort())) { fprintf(stderr, "%s: Unable to continue, make sure there's no other instance running!!!\n", app_name); exit(-1); } /* -- initialize log -- */ LOG_INIT(Config::getLogFile(), Config::getLogLevel()); /* -- check if logger is successfully initialized -- */ if (0 != LOG_GET_STATUS()) { fprintf(stderr, "%s: Unable to initialize logger!\n", app_name); exit(-1); } /* -- initialize libsqlora8 -- */ if (OraDB::init_lib(true) < 0) { LOG_CRITICAL("%s: Unable to initialize libsqlora8!", app_name); exit(-1); } /* -- load system messages from db -- */ if (0 != Sysmsg::load(Config::getOraAuth(), Config::getBrand())) { LOG_CRITICAL("%s: Unable to load system messages from db (%s).", app_name, Config::getOraAuth()); exit(-1); } /* -- load services from db -- */ if (0 != Global::loadRC(Config::getOraAuth(), Config::getLibraryPath(), Config::getBrand())) { LOG_CRITICAL("%s: Unable to load services from db (%s).", app_name, Config::getOraAuth()); exit(-1); } /* -- initialize request queue -- */ if (0 != c2q_init(Global::getRequestQ())) { LOG_CRITICAL("%s: Unable to initialize request queue!", app_name); exit(-1); } /* -- initialize transaction queue -- */ if (0 != c2q_init(Global::getTransactionQ())) { LOG_CRITICAL("%s: Unable to initialize transaction queue!", app_name); exit(-1); } /* -- initialize response queue -- */ if (0 != c2q_init(Global::getResponseQ())) { LOG_CRITICAL("%s: Unable to initialize response queue!", app_name); exit(-1); } /* -- initialize notification queue -- */ if (0 != c2q_init(Global::getNotificationQ())) { LOG_CRITICAL("%s: Unable to initialize notification queue!", app_name); exit(-1); } /* -- initialize queue -- */ int rc_size = Global::getRCSize(); LOG_DEBUG("%s: rc_size: %d", app_name, rc_size); if (Global::initTransactionQ(rc_size) < 0) { LOG_CRITICAL("%s: Unable to initialize transaction queue!", app_name); exit(-1); } int tran_size = Global::getTransactionQSize(); LOG_DEBUG("%s: tran_size: %d", app_name, tran_size); for (int i=0; i<tran_size; ++i) { if (0 != c2q_init(Global::getTransactionQ(i))) { LOG_CRITICAL("%s: Unable to initialize transaction queue: %d!", app_name, i); exit(-1); } } /* -- initialize geoprobe queue -- */ if (0 != c2q_init(Global::getGeoProbeQ())) { LOG_CRITICAL("%s: Unable to initialize geoprobe queue!", app_name); exit(-1); } /* -- initialize ods queue -- */ if (0 != c2q_init(Global::getODSQ())) { LOG_CRITICAL("%s: Unable to initialize ods queue!", app_name); exit(-1); } /* -- initialize ccb queue -- */ if (0 != c2q_init(Global::getCCBQ())) { LOG_CRITICAL("%s: Unable to initialize ccb queue!", app_name); exit(-1); } /* -- initialize conditioner queue -- */ if (0 != c2q_init(Global::getConditionerQ())) { LOG_CRITICAL("%s: Unable to initialize conditioner queue!", app_name); exit(-1); } /* -- initialize voyager queue -- */ if (0 != c2q_init(Global::getVoyagerQ())) { LOG_CRITICAL("%s: Unable to initialize voyager queue!", app_name); exit(-1); } /* -- run in background -- */ sys_daemon(); /* -- block all signals -- */ sys_sigblock(); // Thread attributes pthread_attr_t pthread_attr_norm; pthread_attr_init(&pthread_attr_norm); pthread_attr_setstacksize(&pthread_attr_norm, Global::thr_stack_size); std::vector<pthread_t> thrs; // Signal handler pthread_t signal_thr; if (0 != pthread_create(&signal_thr, &pthread_attr_norm, signal_handler, NULL)) { LOG_CRITICAL("%s: Unable to create signal_handler thread!!!", app_name); exit(-1); } thrs.push_back(signal_thr); // Response handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t response_thr; if (0 != pthread_create(&response_thr, &pthread_attr_norm, response_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create response_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(response_thr); } // Notification handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t notification_thr; if (0 != pthread_create(¬ification_thr, &pthread_attr_norm, notification_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create notification_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(notification_thr); } // Transaction fetcher int proc_id = 0; int step_no = 0; rc_t* rc; while ((rc = Global::getNextRC(step_no))) { rc_proc_t* rc_proc = new(rc_proc_t); rc_proc->rc = rc; rc_proc->proc_id = proc_id; rc_proc->parent_id = -1; rc_proc->ppid = getpid(); pthread_t tran_fetcher_thr; if (0 != pthread_create(&tran_fetcher_thr, &pthread_attr_norm, transaction_fetcher, (void*) rc_proc)) { LOG_CRITICAL("%s: Unable to create transaction_fetcher thread (%d)!!!", app_name, proc_id); abort(); } thrs.push_back(tran_fetcher_thr); step_no = rc->step_no; proc_id++; } // Request handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t request_thr; if (0 != pthread_create(&request_thr, &pthread_attr_norm, request_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create request_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(request_thr); } // Request fetcher pthread_t request_fetcher_thr; if (0 != pthread_create(&request_fetcher_thr, &pthread_attr_norm, request_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create request_fetcher thread!!!", app_name); abort(); } thrs.push_back(request_fetcher_thr); // Raw handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t raw_thr; if (0 != pthread_create(&raw_thr, &pthread_attr_norm, raw_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create raw_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(raw_thr); } // Raw fetcher pthread_t raw_fetcher_thr; if (0 != pthread_create(&raw_fetcher_thr, &pthread_attr_norm, raw_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create raw_fetcher thread!!!", app_name); abort(); } thrs.push_back(raw_fetcher_thr); // Geoprobe handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t geoprobe_thr; if (0 != pthread_create(&geoprobe_thr, &pthread_attr_norm, geoprobe_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create geoprobe_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(geoprobe_thr); } // Geoprobe fetcher pthread_t geoprobe_fetcher_thr; if (0 != pthread_create(&geoprobe_fetcher_thr, &pthread_attr_norm, geoprobe_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create geoprobe_fetcher thread!!!", app_name); abort(); } thrs.push_back(geoprobe_fetcher_thr); // ODS handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t ods_thr; if (0 != pthread_create(&ods_thr, &pthread_attr_norm, ods_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create ods_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(ods_thr); } // ODS fetcher pthread_t ods_fetcher_thr; if (0 != pthread_create(&ods_fetcher_thr, &pthread_attr_norm, ods_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create ods_fetcher thread!!!", app_name); abort(); } thrs.push_back(ods_fetcher_thr); // CCB handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t ccb_thr; if (0 != pthread_create(&ccb_thr, &pthread_attr_norm, ccb_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create ccb_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(ccb_thr); } if (! strncasecmp(Config::getBrand(), "PREPAID", 7)) { // conditioner fetcher pthread_t conditioner_fetcher_thr; if (0 != pthread_create(&conditioner_fetcher_thr, &pthread_attr_norm, conditioner_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create conditioner_fetcher thread!!!", app_name); abort(); } thrs.push_back(conditioner_fetcher_thr); // conditioner handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t conditioner_thr; if (0 != pthread_create(&conditioner_thr, &pthread_attr_norm, conditioner_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create conditioner_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(conditioner_thr); } // voyager fetcher pthread_t voyager_fetcher_thr; if (0 != pthread_create(&voyager_fetcher_thr, &pthread_attr_norm, voyager_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create voyager_fetcher thread!!!", app_name); abort(); } thrs.push_back(voyager_fetcher_thr); // voyager handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t voyager_thr; if (0 != pthread_create(&voyager_thr, &pthread_attr_norm, voyager_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create voyager_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(voyager_thr); } } LOG_INFO("%s: Started.", app_name); if (Config::bypassARDS()) { LOG_WARNING("%s: ARDS bypass is ENABLED!", app_name); } while (! IS_SHUTDOWN()) { sys_msleep(1000); } #if 0 for (int i=0; i<(int)thrs.size(); ++i) { pthread_join(thrs[i], NULL); } #endif while (! thrs.empty()) { pthread_join(thrs.back(), NULL); thrs.pop_back(); } LOG_INFO("%s: Terminated.", app_name); /* -- deinitialize queue -- */ for (int i=0; i<Global::getTransactionQSize(); ++i) { c2q_deinit(Global::getTransactionQ(i)); } Global::deinitTransactionQ(); c2q_deinit(Global::getRequestQ()); c2q_deinit(Global::getTransactionQ()); c2q_deinit(Global::getResponseQ()); c2q_deinit(Global::getGeoProbeQ()); c2q_deinit(Global::getODSQ()); c2q_deinit(Global::getCCBQ()); c2q_deinit(Global::getConditionerQ()); c2q_deinit(Global::getVoyagerQ()); /* -- deinitialize log -- */ LOG_DEINIT(); return 0; }
int main (int argc, char *argv[]) { char cfg_file[256]; char app_name[256]; char* p; p = strrchr(argv[0], '/'); snprintf(app_name, sizeof(app_name), "%s", p+1); /* -- get the config filename -- */ switch (sys_getopt(argc, argv, "c:", cfg_file, sizeof(cfg_file))) { case 'c': #ifdef __DEBUG__ fprintf(stdout, "config file = [%s]\n", cfg_file); #endif if (0 != Config::load(cfg_file)) { fprintf(stderr, "%s: Unable to load config file [%s]!!!\n", app_name, cfg_file); exit(-1); } break; default: usage(argv[0]); exit(0); } /* -- check if already running -- */ if (0 != sys_bind(Config::getLockPort())) { fprintf(stderr, "%s: Unable to continue, make sure there's no other instance running!!!\n", app_name); exit(-1); } /* -- initialize log -- */ LOG_INIT(Config::getLogFile(), Config::getLogLevel()); /* -- check if logger is successfully initialized -- */ if (0 != LOG_GET_STATUS()) { fprintf(stderr, "%s: Unable to initialize logger!\n", app_name); exit(-1); } /* -- initialize libsqlora8 -- */ if (OraDB::init_lib(true) < 0) { LOG_CRITICAL("%s: Unable to initialize libsqlora8!", app_name); exit(-1); } /* -- initialize queue -- */ if (0 != c2q_init(Global::getNotificationQ())) { LOG_CRITICAL("%s: Unable to initialize notification queue!", app_name); exit(-1); } /* -- run in background -- */ sys_daemon(); /* -- block all signals -- */ sys_sigblock(); // Thread attributes pthread_attr_t pthread_attr_norm; pthread_attr_init(&pthread_attr_norm); pthread_attr_setstacksize(&pthread_attr_norm, Global::thr_stack_size); std::vector<pthread_t> thrs; // Signal handler pthread_t signal_thr; if (0 != pthread_create(&signal_thr, &pthread_attr_norm, signal_handler, NULL)) { LOG_CRITICAL("%s: Unable to create signal_handler thread!!!", app_name); exit(-1); } thrs.push_back(signal_thr); // Notification handler for (int i=0; i<Config::getThreadCount(); ++i) { pthread_t notification_thr; if (0 != pthread_create(¬ification_thr, &pthread_attr_norm, notification_handler, (void*)i)) { LOG_CRITICAL("%s: Unable to create notification_handler thread (%d)!!!", app_name, i); abort(); } thrs.push_back(notification_thr); } // Notification fetcher pthread_t notification_fetcher_thr; if (0 != pthread_create(¬ification_fetcher_thr, &pthread_attr_norm, notification_fetcher, NULL)) { LOG_CRITICAL("%s: Unable to create notification_fetcher thread (%d)!!!", app_name); abort(); } thrs.push_back(notification_fetcher_thr); LOG_INFO("%s: Started.", app_name); while (! IS_SHUTDOWN()) { sys_msleep(1000); } #if 0 for (int i=0; i<(int)thrs.size(); ++i) { pthread_join(thrs[i], NULL); } #endif while (! thrs.empty()) { pthread_join(thrs.back(), NULL); thrs.pop_back(); } LOG_INFO("%s: Terminated.", app_name); /* -- deinitialize queue -- */ c2q_deinit(Global::getNotificationQ()); /* -- deinitialize log -- */ LOG_DEINIT(); return 0; }
int sys_connect(struct tcb *tcp) { return sys_bind(tcp); }
asmlinkage long compat_sys_socketcall(int call, u32 __user *args) { int ret; u32 a[6]; u32 a0, a1; if (call < SYS_SOCKET || call > SYS_SENDMMSG) return -EINVAL; if (copy_from_user(a, args, nas[call])) return -EFAULT; a0 = a[0]; a1 = a[1]; switch (call) { case SYS_SOCKET: ret = sys_socket(a0, a1, a[2]); break; case SYS_BIND: ret = sys_bind(a0, compat_ptr(a1), a[2]); break; case SYS_CONNECT: ret = sys_connect(a0, compat_ptr(a1), a[2]); break; case SYS_LISTEN: ret = sys_listen(a0, a1); break; case SYS_ACCEPT: ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0); break; case SYS_GETSOCKNAME: ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2])); break; case SYS_GETPEERNAME: ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2])); break; case SYS_SOCKETPAIR: ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3])); break; case SYS_SEND: ret = sys_send(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_SENDTO: ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]); break; case SYS_RECV: ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_RECVFROM: ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), compat_ptr(a[5])); break; case SYS_SHUTDOWN: ret = sys_shutdown(a0, a1); break; case SYS_SETSOCKOPT: ret = compat_sys_setsockopt(a0, a1, a[2], compat_ptr(a[3]), a[4]); break; case SYS_GETSOCKOPT: ret = compat_sys_getsockopt(a0, a1, a[2], compat_ptr(a[3]), compat_ptr(a[4])); break; case SYS_SENDMSG: ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]); break; case SYS_SENDMMSG: ret = compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_RECVMSG: ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); break; case SYS_RECVMMSG: ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4])); break; case SYS_ACCEPT4: ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]); break; default: ret = -EINVAL; break; } return ret; }
int so_socksys(struct socksysreq *req) { int err = -EINVAL; int cmd = req->args[0]; if ((1 << cmd) & ((1 << SO_ACCEPT) | (1 << SO_BIND) | (1 << SO_CONNECT) | (1 << SO_GETPEERNAME) | (1 << SO_GETSOCKNAME) | (1 << SO_GETSOCKOPT) | (1 << SO_LISTEN) | (1 << SO_RECV) | (1 << SO_RECVFROM) | (1 << SO_SEND) | (1 << SO_SENDTO) | (1 << SO_SETSOCKOPT) | (1 << SO_SHUTDOWN) | (1 << SO_RECVMSG) | (1 << SO_SENDMSG))) { int fd = req->args[1]; (void) fd; /* These are all socket related and accept a file (socket) descriptor as their first argument. In situations where we are incapable of providing back a real socket, we must here first distinguish if the file descriptor corresponds to a socket or a stream. */ #if 0 if (it_is_a_socket) { #endif /* In this case, we have a real socket from the operating system's perspective and we can simply pass the arguments to the appropriate system call. */ #if 0 switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = sys_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = sys_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = sys_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = sys_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = sys_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = sys_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = sys_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = sys_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = sys_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = sys_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = sys_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = sys_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = sys_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } #endif #if 0 } else { /* In this case, we do not have a real socket, but have a TPI stream from the operating system's perspective, and we will directly call the associated TPI routine. */ switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = tpi_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = tpi_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = tpi_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = tpi_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = tpi_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = tpi_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = tpi_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = tpi_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = tpi_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = tpi_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = tpi_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = tpi_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = tpi_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } } #endif } if ((1 << cmd) & ((1 << SO_SOCKET) | (1 << SO_SOCKPAIR) | (1 << SO_SELECT) | (1 << SO_GETIPDOMAIN) | (1 << SO_SETIPDOMAIN) | (1 << SO_ADJTIME) | (1 << SO_SETREUID) | (1 << SO_SETREGID) | (1 << SO_GETTIME) | (1 << SO_SETTIME) | (1 << SO_GETITIMER) | (1 << SO_SETITIMER))) { /* These are BSD compatibiltiy functions and are how we create sockets in the first place. The BSD compatibility functions all have system calls in Linux, but we provide them for backward compatibility (to what!?). */ #if 0 switch (cmd) { case SO_SOCKET: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socket(req->args[1], req->args[2], req->args[3]); break; case SO_SOCKPAIR: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socketpair(req->args[1], req->args[2], req->args[3], (int *) req->args[4]); err = -EOPNOTSUPP; break; case SO_SELECT: /* FIXME: 32/64 conversion */ err = sys_select(req->args[1], (fd_set *) req->args[2], (fd_set *) req->args[3], (fd_set *) req->args[4], (struct timeval *) req->args[5]); break; case SO_GETIPDOMAIN: /* FIXME: 32/64 conversion */ todo(("Process SO_GETIPDOMAIN for compatibility.\n")); /* does not exist in Linux, need to use sys_newuname and copy the domainname portion */ err = -ENOSYS; break; case SO_SETIPDOMAIN: /* FIXME: 32/64 conversion */ err = sys_setdomainname((char *) req->args[1], req->args[2]); break; case SO_ADJTIME: /* FIXME: 32/64 conversion */ err = sys_admtimex((struct timex *) req->args[1]); break; case SO_SETREUID: /* FIXME: 32/64 conversion */ err = sys_setreuid(req->args[1], req->args[2]); break; case SO_SETREGID: /* FIXME: 32/64 conversion */ err = sys_setregid(req->args[1], req->args[2]); break; case SO_GETTIME: /* FIXME: 32/64 conversion */ err = sys_gettimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_SETTIME: /* FIXME: 32/64 conversion */ err = sys_settimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_GETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2]); break; case SO_SETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2], (struct itimerval *) req->args[3]); break; } #endif } return (err); }