void d7ap_stack_session_completed(uint8_t session_token, uint8_t* progress_bitmap, uint8_t* success_bitmap, uint8_t bitmap_byte_count) { DPRINT("[D7AP] session is completed"); error_t error; uint8_t request_id; session_t* session = get_session_by_session_token(session_token); assert(session != NULL); if (registered_client[session->client_id].transmitted_cb == NULL) goto free_session; for(uint8_t i = 0; i < session->request_nb; i++) { request_id = (uint8_t)(session->trans_id[i] & 0xFF); error = bitmap_get(progress_bitmap, request_id) && bitmap_get(success_bitmap, request_id) ? SUCCESS : FAIL; registered_client[session->client_id].transmitted_cb(session->trans_id[i], error); } switch_state(D7AP_STACK_STATE_IDLE); free_session: free_session(session); }
/** * Destroys the session related structures. */ int cdp_sessions_destroy() { int i; cdp_session_t *n,*x; if (session_lock){ lock_get(session_lock); lock_destroy(session_lock); lock_dealloc((void*)session_lock); session_lock=0; } for(i=0;i<sessions_hash_size;i++){ AAASessionsLock(i); for(x = sessions[i].head; x; x = n){ n = x->next; free_session(x); } lock_destroy(sessions[i].lock); lock_dealloc((void*)sessions[i].lock); } shm_free(sessions); shm_free(session_id1); shm_free(session_id2); return 1; }
/** * Removes and frees a session. * @param x - the session to remove; */ void del_session(cdp_session_t *x) { if (!x) return; if (sessions[x->hash].head == x) sessions[x->hash].head = x->next; else x->prev->next = x->next; if (sessions[x->hash].tail == x) sessions[x->hash].tail = x->prev; else x->next->prev = x->prev; free_session(x); }
static void flush_sessions(GWeb *web) { GList *list; for (list = g_list_first(web->session_list); list; list = g_list_next(list)) free_session(list->data); g_list_free(web->session_list); web->session_list = NULL; }
void BlenderSession::synchronize() { /* only used for viewport render */ if(!b_v3d) return; /* on session/scene parameter changes, we recreate session entirely */ SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background); SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background); if(session->params.modified(session_params) || scene->params.modified(scene_params)) { free_session(); create_session(); session->start(); return; } /* increase samples, but never decrease */ session->set_samples(session_params.samples); session->set_pause(BlenderSync::get_session_pause(b_scene, background)); /* copy recalc flags, outside of mutex so we can decide to do the real * synchronization at a later time to not block on running updates */ sync->sync_recalc(); /* try to acquire mutex. if we don't want to or can't, come back later */ if(!session->ready_to_reset() || !session->scene->mutex.try_lock()) { tag_update(); return; } /* data and camera synchronize */ sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state); if(b_rv3d) sync->sync_view(b_v3d, b_rv3d, width, height); else sync->sync_camera(b_render, b_engine.camera_override(), width, height); /* unlock */ session->scene->mutex.unlock(); /* reset if needed */ if(scene->need_reset()) { BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_scene, b_v3d, b_rv3d, scene->camera, width, height); session->reset(buffer_params, session_params.samples); /* reset time */ start_resize_time = 0.0; } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Reload the scene ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void BlenderSession::reload_session() { free_session(); last_redraw_time = 0.0f; create_session(); if(motion_blur && mb_type == INTERNAL) { bool stop_render; session->start("Interactive", false, load_internal_mb_sequence(stop_render), 0); } else { sync->sync_data(b_v3d, b_engine.camera_override()); if(interactive) session->start("Interactive", false, 0, 0); } } //reload_session()
static void process_detach(void) { HINTERNET internet_session; internet_session = get_internet_session(NULL); if(internet_session) InternetCloseHandle(internet_session); if (hCabinet) FreeLibrary(hCabinet); free_session(); free_tls_list(); }
static void process_detach(void) { HINTERNET internet_session; internet_session = get_internet_session(NULL); if(internet_session) InternetCloseHandle(internet_session); if (hCabinet) FreeLibrary(hCabinet); free_session(); free_tls_list(); #ifndef __REACTOS__ unregister_notif_wnd_class(); #endif }
static void cleanup_session(gpointer user_data) { struct connman_session *session = user_data; struct session_info *info = session->info; DBG("remove %s", session->session_path); g_slist_free(session->user_allowed_bearers); g_hash_table_destroy(session->service_hash); g_sequence_free(session->service_list); if (info->entry != NULL && info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) { __connman_service_disconnect(info->entry->service); } free_session(session); }
static int create_policy_config(struct connman_session *session, connman_session_config_func_t cb, struct user_config *user_config) { struct connman_session_config *config; if (session->policy == NULL) { config = connman_session_create_default_config(); if (config == NULL) { free_session(session); cleanup_user_config(user_config); return -ENOMEM; } return cb(session, config, user_config, 0); } return (*session->policy->create)(session, cb, user_config); }
static void cleanup_session(gpointer user_data) { struct connman_session *session = user_data; DBG("remove %s", session->session_path); cleanup_routing_table(session); cleanup_firewall_session(session); if (session->active) set_active_session(session, false); session_deactivate(session); update_session_state(session); g_slist_free(session->user_allowed_bearers); free_session(session); }
static int create_policy_config(struct connman_session *session, connman_session_config_func_t cb, struct creation_data *creation_data) { struct connman_session_config *config; if (!policy) { config = connman_session_create_default_config(); if (!config) { free_session(session); cleanup_creation_data(creation_data); return -ENOMEM; } return cb(session, config, creation_data, 0); } return policy->create(session, cb, creation_data); }
void protocol_start_session(DbXmlSessionData *session) { int r; DbXmlCredentials cred; DbXmlSessionOptions options; DbXmlSessionOptions *options_set; memset(&cred, 0, sizeof(DbXmlCredentials)); memset(&options, 0, sizeof(DbXmlSessionOptions)); if (initial_handshake(session) != 0) return; r = receive_credentials(session, &cred); if (r == 0) r = check_authentication(session, &cred); free_credentials(session, &cred); r = receive_session_options(session, &options); int init = -1; options_set = NULL; if (r == 0) init = r = initialize_session(session, &options, &options_set); session_response(session, r); if (r != 0) return; if (r == 0) r = send_session_options(session, options_set); free_session_options(session, &options); if (r == 0) protocol_request_response(session); if (init == 0) free_session(session); }
/** * Removes and frees a session. * \note must be called with a lock on the x->hash and it will unlock on exit. Do not use x after calling this * * @param x - the session to remove */ void del_session(cdp_session_t *x) { unsigned int hash; if (!x) return; hash = x->hash; if (hash < 0 || hash >= sessions_hash_size) { LM_ERR("del_session: x->hash :%d out of range of sessions_hash_size: %d !\n",hash, sessions_hash_size); return; } if (sessions[x->hash].head == x) sessions[x->hash].head = x->next; else if (x->prev) x->prev->next = x->next; if (sessions[x->hash].tail == x) sessions[x->hash].tail = x->prev; else if (x->next) x->next->prev = x->prev; AAASessionsUnlock(hash); free_session(x); }
int main(int argc, char **argv) { struct sockaddr_in sa; int master_fd; fd_set rdfdset, wrfdset; int selret; int on = 1; int portnbr = 23; int c, ii; int daemonize = 0; char *interface_name = NULL; struct ifreq interface; #ifdef USE_SYSLOG char *appname; appname = strrchr (argv [0], '/'); if (!appname) appname = argv [0]; else appname++; #endif /* check if user supplied a port number */ for (;;) { c = getopt( argc, argv, "i:p:l:hd"); if (c == EOF) break; switch (c) { case 'p': portnbr = atoi(optarg); break; case 'i': interface_name = strdup(optarg); break; case 'l': loginpath = strdup(optarg); break; case 'd': daemonize = 1; break; case 'h': default: show_usage(); exit(1); } } if (!loginpath) { loginpath = SHELLPATH; if (access(loginpath, X_OK) < 0) loginpath = "/bin/sh"; } if (access(loginpath, X_OK) < 0) { /* workaround: error_msg_and_die has doesn't understand variable argument lists yet */ fprintf(stderr,"\"%s\"",loginpath); perror_msg_and_die(" is no valid executable!\n"); } printf("telnetd: starting\n"); printf(" port: %i; interface: %s; login program: %s\n", portnbr, (interface_name)?interface_name:"any", loginpath); argv_init[0] = loginpath; sessions = 0; /* Grab a TCP socket. */ master_fd = socket(AF_INET, SOCK_STREAM, 0); if (master_fd < 0) { perror("socket"); return 1; } (void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); /* Set it to listen to specified port */ memset((void *)&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(portnbr); /* Set it to listen on the specified interface */ if (interface_name) { strcpy(interface.ifr_name, interface_name); /* use ioctl() here as BSD does not have setsockopt() */ if (ioctl(master_fd, SIOCGIFADDR, &interface) < 0) { printf("Please check the NIC you specified with -i option\n"); perror("ioctl SIOCGFADDR"); return 1; } sa.sin_addr = ((struct sockaddr_in *)(&interface.ifr_addr))->sin_addr; } else sa.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) { perror("bind"); return 1; } if (listen(master_fd, 1) < 0) { perror("listen"); return 1; } if (daemonize) { DEBUG_OUT(" daemonizing\n"); if (daemon(0, 1) < 0) perror_msg_and_die("daemon"); } #ifdef USE_SYSLOG openlog(appname , LOG_NDELAY | LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "%s (port: %i, ifname: %s, login: %s) startup succeeded\n"\ , appname, portnbr, (interface_name)?interface_name:"any", loginpath); closelog(); #endif maxfd = master_fd; do { struct tsession *ts; FD_ZERO(&rdfdset); FD_ZERO(&wrfdset); /* select on the master socket, all telnet sockets and their * ptys if there is room in their respective session buffers. */ FD_SET(master_fd, &rdfdset); ts = sessions; while (ts) { /* buf1 is used from socket to pty * buf2 is used from pty to socket */ if (ts->size1 > 0) { FD_SET(ts->ptyfd, &wrfdset); /* can write to pty */ } if (ts->size1 < BUFSIZE) { FD_SET(ts->sockfd, &rdfdset); /* can read from socket */ } if (ts->size2 > 0) { FD_SET(ts->sockfd, &wrfdset); /* can write to socket */ } if (ts->size2 < BUFSIZE) { FD_SET(ts->ptyfd, &rdfdset); /* can read from pty */ } ts = ts->next; } selret = select(maxfd + 1, &rdfdset, &wrfdset, 0, 0); if (!selret) break; /* First check for and accept new sessions. */ if (FD_ISSET(master_fd, &rdfdset)) { int fd, salen; salen = sizeof(sa); if ((fd = accept(master_fd, (struct sockaddr *)&sa, &salen)) < 0) { continue; } else { /* Create a new session and link it into our active list. */ struct tsession *new_ts; #ifdef USE_SYSLOG openlog(appname , LOG_NDELAY, LOG_DAEMON); syslog(LOG_INFO, "connection from: %s\n", inet_ntoa(sa.sin_addr)); closelog(); #endif new_ts = make_new_session(fd); if (new_ts) { new_ts->next = sessions; sessions = new_ts; if (fd > maxfd) maxfd = fd; } else { close(fd); } } } /* Then check for data tunneling. */ ts = sessions; while (ts) { /* For all sessions... */ int maxlen, w, r; struct tsession *next = ts->next; /* in case we free ts. */ if (ts->size1 && FD_ISSET(ts->ptyfd, &wrfdset)) { int processed, num_totty; char *ptr; /* Write to pty from buffer 1. */ maxlen = MIN(BUFSIZE - ts->wridx1, ts->size1); ptr = remove_iacs(ts->buf1 + ts->wridx1, maxlen, &processed, &num_totty); /* the difference between processed and num_totty is all the iacs we removed from the stream. Adjust buf1 accordingly. */ ts->wridx1 += processed - num_totty; ts->size1 -= processed - num_totty; w = write(ts->ptyfd, ptr, num_totty); if (w < 0) { perror("write"); free_session(ts); ts = next; continue; } ts->wridx1 += w; ts->size1 -= w; if (ts->wridx1 == BUFSIZE) ts->wridx1 = 0; } if (ts->size2 && FD_ISSET(ts->sockfd, &wrfdset)) { /* Write to socket from buffer 2. */ maxlen = MIN(BUFSIZE - ts->wridx2, ts->size2); w = write(ts->sockfd, ts->buf2 + ts->wridx2, maxlen); if (w < 0) { perror("write"); free_session(ts); ts = next; continue; } ts->wridx2 += w; ts->size2 -= w; if (ts->wridx2 == BUFSIZE) ts->wridx2 = 0; } if (ts->size1 < BUFSIZE && FD_ISSET(ts->sockfd, &rdfdset)) { /* Read from socket to buffer 1. */ maxlen = MIN(BUFSIZE - ts->rdidx1, BUFSIZE - ts->size1); r = read(ts->sockfd, ts->buf1 + ts->rdidx1, maxlen); if (!r || (r < 0 && errno != EINTR)) { free_session(ts); ts = next; continue; } if(!*(ts->buf1 + ts->rdidx1 + r - 1)) { r--; if(!r) continue; } ts->rdidx1 += r; ts->size1 += r; if (ts->rdidx1 == BUFSIZE) ts->rdidx1 = 0; } if (ts->size2 < BUFSIZE && FD_ISSET(ts->ptyfd, &rdfdset)) { /* Read from pty to buffer 2. */ maxlen = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2); r = read(ts->ptyfd, ts->buf2 + ts->rdidx2, maxlen); if (!r || (r < 0 && errno != EINTR)) { free_session(ts); ts = next; continue; } for (ii=0; ii < r; ii++) if (*(ts->buf2 + ts->rdidx2 + ii) == 3) fprintf(stderr, "found <CTRL>-<C> in data!\n"); ts->rdidx2 += r; ts->size2 += r; if (ts->rdidx2 == BUFSIZE) ts->rdidx2 = 0; } if (ts->size1 == 0) { ts->rdidx1 = 0; ts->wridx1 = 0; } if (ts->size2 == 0) { ts->rdidx2 = 0; ts->wridx2 = 0; } ts = next; } } while (1); return 0; }
int main (int argc, char **argv) { GMainLoop *loop = NULL; GstElement *pipeline = NULL; GstBus *bus = NULL; GstElement *conf = NULL; FsParticipant *part = NULL; GError *error = NULL; GInputStream *istream = NULL; gchar *send_socket, *recv_socket; TestSession *ses; gst_init (&argc, &argv); if (argc != 3) { g_print ("Usage: %s <send socket> <recv_socket>\n", argv[0]); return 1; } send_socket = argv[1]; recv_socket = argv[2]; if (unlink (send_socket) < 0 && errno != ENOENT) { g_print ("Could not delete send or recv sockets"); return 2; } g_print ("Press ENTER when the other side is ready\n"); loop = g_main_loop_new (NULL, FALSE); pipeline = gst_pipeline_new (NULL); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus, async_bus_cb, pipeline); gst_object_unref (bus); conf = gst_element_factory_make ("fsrtpconference", NULL); g_assert (conf); part = fs_conference_new_participant (FS_CONFERENCE (conf), &error); print_error (error); g_assert (part); g_assert (gst_bin_add (GST_BIN (pipeline), conf)); istream = g_unix_input_stream_new (0, FALSE); ses = add_audio_session (pipeline, FS_CONFERENCE (conf), 1, part, send_socket, recv_socket); g_input_stream_skip_async (istream, 1, G_PRIORITY_DEFAULT, NULL, skipped_cb, ses); g_assert (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE); g_main_loop_run (loop); g_assert (gst_element_set_state (pipeline, GST_STATE_NULL) != GST_STATE_CHANGE_FAILURE); g_object_unref (part); g_object_unref (istream); free_session (ses); gst_object_unref (pipeline); g_main_loop_unref (loop); return 0; }
int __connman_session_create(DBusMessage *msg) { const char *owner, *notify_path; char *session_path = NULL; DBusMessageIter iter, array; struct connman_session *session = NULL; struct creation_data *creation_data = NULL; bool user_allowed_bearers = false; bool user_connection_type = false; int err, i; char *str; owner = dbus_message_get_sender(msg); DBG("owner %s", owner); if (ecall_session && ecall_session->ecall) { /* * If there is an emergency call already going on, * ignore session creation attempt */ err = -EBUSY; goto err; } creation_data = g_try_new0(struct creation_data, 1); if (!creation_data) { err = -ENOMEM; goto err; } creation_data->pending = dbus_message_ref(msg); dbus_message_iter_init(msg, &iter); dbus_message_iter_recurse(&iter, &array); while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key, *val; dbus_message_iter_recurse(&array, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); switch (dbus_message_iter_get_arg_type(&value)) { case DBUS_TYPE_ARRAY: if (g_str_equal(key, "AllowedBearers")) { err = parse_bearers(&value, &creation_data->allowed_bearers); if (err < 0) goto err; user_allowed_bearers = true; } else { err = -EINVAL; goto err; } break; case DBUS_TYPE_STRING: if (g_str_equal(key, "ConnectionType")) { dbus_message_iter_get_basic(&value, &val); creation_data->type = connman_session_parse_connection_type(val); user_connection_type = true; } else { err = -EINVAL; goto err; } } dbus_message_iter_next(&array); } /* * If the user hasn't provided a configuration, we set * the default configuration. * * For AllowedBearers this is '*', ... */ if (!user_allowed_bearers) { add_default_bearer_types(&creation_data->allowed_bearers); if (!creation_data->allowed_bearers) { err = -ENOMEM; goto err; } } /* ... and for ConnectionType it is 'any'. */ if (!user_connection_type) creation_data->type = CONNMAN_SESSION_TYPE_ANY; dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter, ¬ify_path); if (!notify_path) { err = -EINVAL; goto err; } str = g_strdup(owner); for (i = 0; str[i] != '\0'; i++) if (str[i] == ':' || str[i] == '.') str[i] = '_'; session_path = g_strdup_printf("/sessions/%s%s", str, notify_path); g_free(str); if (!session_path) { err = -ENOMEM; goto err; } session = g_hash_table_lookup(session_hash, session_path); if (session) { g_free(session_path); session = NULL; err = -EEXIST; goto err; } session = g_try_new0(struct connman_session, 1); if (!session) { g_free(session_path); err = -ENOMEM; goto err; } creation_data->session = session; session->session_path = session_path; session->info = g_try_new0(struct session_info, 1); if (!session->info) { err = -ENOMEM; goto err; } session->info_last = g_try_new0(struct session_info, 1); if (!session->info_last) { err = -ENOMEM; goto err; } session->owner = g_strdup(owner); session->notify_path = g_strdup(notify_path); session->notify_watch = g_dbus_add_disconnect_watch(connection, session->owner, owner_disconnect, session, NULL); err = create_policy_config(session, session_policy_config_cb, creation_data); if (err < 0 && err != -EINPROGRESS) return err; return -EINPROGRESS; err: connman_error("Failed to create session"); free_session(session); cleanup_creation_data(creation_data); return err; }
static int session_create_cb(struct connman_session *session, struct connman_session_config *config, void *user_data, int err) { DBusMessage *reply; struct user_config *user_config = user_data; struct session_info *info, *info_last; DBG("session %p config %p", session, config); if (err != 0) goto out; session->policy_config = config; info = session->info; info_last = session->info_last; if (session->policy_config->ecall == TRUE) ecall_session = session; info->state = CONNMAN_SESSION_STATE_DISCONNECTED; info->config.type = apply_policy_on_type( session->policy_config->type, user_config->type); info->config.priority = session->policy_config->priority; info->config.roaming_policy = session->policy_config->roaming_policy; info->entry = NULL; session->user_allowed_bearers = user_config->allowed_bearers; user_config->allowed_bearers = NULL; err = apply_policy_on_bearers( session->policy_config->allowed_bearers, session->user_allowed_bearers, &info->config.allowed_bearers); if (err < 0) goto out; g_hash_table_replace(session_hash, session->session_path, session); DBG("add %s", session->session_path); if (g_dbus_register_interface(connection, session->session_path, CONNMAN_SESSION_INTERFACE, session_methods, NULL, NULL, session, NULL) == FALSE) { connman_error("Failed to register %s", session->session_path); g_hash_table_remove(session_hash, session->session_path); err = -EINVAL; goto out; } reply = g_dbus_create_reply(user_config->pending, DBUS_TYPE_OBJECT_PATH, &session->session_path, DBUS_TYPE_INVALID); g_dbus_send_message(connection, reply); user_config->pending = NULL; populate_service_list(session); info_last->state = info->state; info_last->config.priority = info->config.priority; info_last->config.roaming_policy = info->config.roaming_policy; info_last->entry = info->entry; info_last->config.allowed_bearers = info->config.allowed_bearers; session->append_all = TRUE; session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING); out: if (err < 0) { reply = __connman_error_failed(user_config->pending, -err); g_dbus_send_message(connection, reply); free_session(session); } cleanup_user_config(user_config); return err; }
static void init_session_list() { for(uint8_t i = 0; i < MODULE_D7AP_MAX_SESSION_COUNT; i++) { free_session(&sessions[i]); } }
int handle_session(SESSION** current_node,STUDENT_INFO** link_student_info) { SESSION* session_head = *current_node; MEMBER* member_head = session_head->member; if (session_head->type == DEL) { if (member_head->sli_num!=-1) //maybe there's one { MEMBER* tmp = member_head->next; if (tmp!=NULL) { printf("this session is nonsense!\n"); free_session(current_node); return 0; } else { deal_session_in_student_info(current_node,link_student_info,DEL); free_session(current_node); return 1; } } else { int start = -1; while(member_head!=NULL) { if (member_head->sli_num == start) { member_head = member_head->next; start++; } else { printf("this session is nonsense!\n"); free_session(current_node); return 0; } } deal_session_in_student_info(current_node,link_student_info,DEL); free_session(current_node); return 1; } } else { if (member_head->sli_num!=-1) //maybe there's one { printf("this session is nonsense!\n"); free_session(current_node); return 0; } else { int start = -1; while(member_head!=NULL) { if (member_head->sli_num == start) { member_head = member_head->next; start++; } else { printf("this session is nonsense!\n"); free_session(current_node); return 0; } } deal_session_in_student_info(current_node,link_student_info,session_head->type); free_session(current_node); return 1; } } }
static guint do_request(GWeb *web, const char *url, const char *type, GWebInputFunc input, int fd, gsize length, GWebResultFunc func, GWebRouteFunc route, gpointer user_data) { struct web_session *session; if (web == NULL || url == NULL) return 0; debug(web, "request %s", url); session = g_try_new0(struct web_session, 1); if (session == NULL) return 0; if (parse_url(session, url, web->proxy) < 0) { free_session(session); return 0; } debug(web, "address %s", session->address); debug(web, "port %u", session->port); debug(web, "host %s", session->host); debug(web, "flags %lu", session->flags); debug(web, "request %s", session->request); if (type != NULL) { session->content_type = g_strdup(type); debug(web, "content-type %s", session->content_type); } session->web = web; session->result_func = func; session->route_func = route; session->input_func = input; session->fd = fd; session->length = length; session->offset = 0; session->user_data = user_data; session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE); if (session->receive_buffer == NULL) { free_session(session); return 0; } session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); if (session->result.headers == NULL) { free_session(session); return 0; } session->receive_space = DEFAULT_BUFFER_SIZE; session->send_buffer = g_string_sized_new(0); session->current_header = g_string_sized_new(0); session->header_done = FALSE; session->body_done = FALSE; if (session->address == NULL && inet_aton(session->host, NULL) == 0) { session->resolv_action = g_resolv_lookup_hostname(web->resolv, session->host, resolv_result, session); if (session->resolv_action == 0) { free_session(session); return 0; } } else { struct addrinfo hints; char *port; int ret; if (session->address == NULL) session->address = g_strdup(session->host); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; hints.ai_family = session->web->family; if (session->addr != NULL) { freeaddrinfo(session->addr); session->addr = NULL; } port = g_strdup_printf("%u", session->port); ret = getaddrinfo(session->address, port, &hints, &session->addr); g_free(port); if (ret != 0 || session->addr == NULL) { free_session(session); return 0; } if (create_transport(session) < 0) { free_session(session); return 0; } } web->session_list = g_list_append(web->session_list, session); return web->next_query_id++; }
/******************************************************************* ** Function name: invoke_service_wrapper ** Descrption: ** This function is used to invoke a service call ** Parameters: ** tick - the number of milliseconds that have elapsed since the system was started, ** used to detect which session is idle for the longest time. ** req_msg - service request message ** req_msg_size - size of request message ** resp_msg - service response message ** resp_msg_size - size of response message ** Returns: ae_error_t *******************************************************************/ ae_error_t invoke_service_wrapper ( /* IN */ uint64_t tick, /* IN */ uint8_t* req_msg, /* IN */ uint32_t req_msg_size, /* OUT */ uint8_t* resp_msg, /* IN */ uint32_t resp_msg_size) { // check parameter ae_error_t ae_ret = AE_SUCCESS; pse_message_t* pse_req_msg = (pse_message_t*)req_msg; pse_message_t* pse_resp_msg = (pse_message_t*)resp_msg; pse_op_error_t op_ret; if (!req_msg || !resp_msg) { return PSE_OP_PARAMETER_ERROR; } // // make sure the header is inside enclave // if (req_msg_size < sizeof(pse_message_t)) { return PSE_OP_PARAMETER_ERROR; } // // if this mispredicts, we might overflow below // sgx_lfence(); if (pse_req_msg->payload_size > UINT32_MAX - sizeof(pse_message_t) // check potential overflow || req_msg_size != sizeof(pse_message_t) + pse_req_msg->payload_size) { return PSE_OP_PARAMETER_ERROR; } if (resp_msg_size < sizeof(pse_message_t) // make sure the header is inside enclave || pse_req_msg->exp_resp_size > UINT32_MAX - sizeof(pse_message_t) // check potential overflow || resp_msg_size < sizeof(pse_message_t) + pse_req_msg->exp_resp_size) { return PSE_OP_PARAMETER_ERROR; } // // put LFENCE here mostly for pse_req_msg->payload_size // check above. I don't think we use // pse_req_msg->exp_resp_size to calculate // any pointers. // sgx_lfence(); pse_session_t* session = sid2session(pse_req_msg->session_id); // ephemeral session must have been established if(!is_eph_session_active()) { // the ephemeral session is not active return PSE_OP_EPHEMERAL_SESSION_INVALID; } //if session is invalid (session not exists or established, or sequence num overflow) if (!is_isv_session_valid(session)) { return PSE_OP_SESSION_INVALID; } // update session tick update_session_tick_count(session, tick); //clear response message memset(resp_msg, 0, resp_msg_size); uint8_t* req = (uint8_t*)malloc(pse_req_msg->payload_size); uint8_t* resp= NULL; uint32_t session_seq_num = get_session_seq_num(session); do { BREAK_ON_MALLOC_FAIL(req, ae_ret) // decrypt service request message using session key if(false == decrypt_msg(pse_req_msg, req, (sgx_key_128bit_t*)session->active.AEK)) { ae_ret = PSE_OP_SERVICE_MSG_ERROR; break; } pse_req_hdr_t* req_hdr = (pse_req_hdr_t*)req; // check session sequence number if(req_hdr->seq_num != session_seq_num) { ae_ret = PSE_OP_SESSION_INVALID; //close session free_session(session); break; } // Dispatch the service request to the proper handler int i; int service_count = static_cast<int>(sizeof(service_handler) / sizeof(service_handler_t)); for (i = 0; i < service_count; i++) { // // might mispredict the end of the loop // sgx_lfence(); if (req_hdr->service_id == service_handler[i].service_id && req_hdr->service_cmd == service_handler[i].service_cmd) { if (pse_req_msg->payload_size != service_handler[i].req_size || pse_req_msg->exp_resp_size < service_handler[i].resp_size) // response message buffer must be large enough to hold response data { ae_ret = PSE_OP_SERVICE_MSG_ERROR; goto clean_up; } resp = (uint8_t*)malloc(service_handler[i].resp_size); if (resp == NULL) { ae_ret = PSE_OP_INTERNAL_ERROR; goto clean_up; } // // in case payload_size, req_size comparisons // mispredict // sgx_lfence(); // serve the request op_ret = service_handler[i].srv_pfn(session->isv_attributes, req, resp); if(op_ret != OP_SUCCESS) { ae_ret = error_reinterpret(op_ret); goto clean_up; } // set payload size for valid requests pse_resp_msg->payload_size = service_handler[i].resp_size; break; } } if (i == service_count) { // service_id or service_cmd mismatch resp = (uint8_t*)malloc(sizeof(pse_resp_hdr_t)); BREAK_ON_MALLOC_FAIL(resp, ae_ret) // for unknown requests, payload data only includes response header pse_resp_msg->payload_size = sizeof(pse_resp_hdr_t); // set error status ((pse_resp_hdr_t*)resp)->status = PSE_ERROR_UNKNOWN_REQ; } // prepare the response message pse_resp_hdr_t* resp_hdr = (pse_resp_hdr_t*)resp; pse_resp_msg->exp_resp_size = 0; pse_resp_msg->session_id = pse_req_msg->session_id; //set response header, status code is already set in service functions resp_hdr->seq_num = session_seq_num + 1; // addition overflow already checked in is_isv_session_valid() resp_hdr->service_id = req_hdr->service_id; resp_hdr->service_cmd = req_hdr->service_cmd; // update sequence number for current session set_session_seq_num(session, resp_hdr->seq_num + 1); // encrypt the response message if(false == encrypt_msg((pse_message_t*)pse_resp_msg, (uint8_t*)resp, (sgx_key_128bit_t*)session->active.AEK)) { ae_ret = PSE_OP_INTERNAL_ERROR; break; } } while (0); clean_up: SAFE_FREE(req); SAFE_FREE(resp); return ae_ret; }
int master_server(int port, void *data) { int lsock[MAXLISTENSOCK]; struct addrinfo *ai_head; struct xnbd_info *xnbd = (struct xnbd_info *) data; ai_head = net_getaddrinfo(NULL, port, PF_UNSPEC); if (!ai_head) return 0; nlistened = net_listen_all_addrinfo(ai_head, lsock); if (nlistened <= 0) err("no socket to listen to"); freeaddrinfo(ai_head); for (nfds_t i = 0; i < nlistened; i++) { eventfds[i].fd = lsock[i]; eventfds[i].events = POLLRDNORM; } for (nfds_t i = nlistened; i < MAXLISTENSOCK; i++) eventfds[i].fd = -1; set_sigactions(); sigset_t sigs_blocked; sigset_t orig_sigmask; /* * The master process does not want to get SIGCHLD anytime; when SIGCHLD received, some * system calls may fail with errno == EINTR. Only this ppoll() can be intrrupted. */ sigemptyset(&sigs_blocked); /* do now allow SIG_CHLD except ppoll() */ sigaddset(&sigs_blocked, SIGCHLD); sigaddset(&sigs_blocked, SIGINT); sigaddset(&sigs_blocked, SIGTERM); sigaddset(&sigs_blocked, SIGHUP); pthread_sigmask(SIG_BLOCK, &sigs_blocked, &orig_sigmask); GList *socklist = NULL; int restarting = 0; for (;;) { int nready; /* * N.B. If compiled with fake ppoll() support, the master * process may deadlock when a child process exited. * * For Debian's 2.6.18 kernels, ppoll() is equivalent to calling * sigprocmask(), poll(), and then sigprocmask(); it is not an * atomic system call. * * In this code, while the master process is running outside * this ppoll(), a delivered signal goes to pending state * until the process accepts the signal. The handler of the * signal is called just after the process unblocks the signal. * * In this ppoll(), the first sigprocmask() unblocks the * signal. Before the poll(), the signal handler is called. * poll() does not detect the signal, and does not return until * the next event comes. * * This means that ppoll() does not return -1 with errno == * EINTR, for the signal that deliverred while the process was * running outside ppoll(). * * For Debian's 2.6.26 kernels, it's ok. */ /* * In glibc-2.7, sysdeps/unix/sysv/linux/kernel-features.h says * pselect/ppoll were introduced just after 2.6.16-rc1. Due * to the way the kernel versions are advertised we can only * rely on 2.6.17 to have the code. On x86_64 and SH this * appeared first in 2.6.19-rc1, on ia64 in 2.6.22-rc1 and on * alpha just after 2.6.22-rc1. **/ if (need_exit) { dbg("need exit"); break; } if (got_sigchld) { dbg("got sigchld"); got_sigchld = 0; /* SIGCHLD */ for (;;) { int status; pid_t pid = waitpid(-1, &status, WNOHANG); /* no more exiting child process */ if (pid < 0) break; /* pid == 0: no more exiting child process. there still * remains one or more running process(es). */ if (pid == 0) break; struct xnbd_session *ses = find_session_with_pid(xnbd, pid); if (!ses) err("unknown session pid %d", pid); xnbd->sessions = g_list_remove(xnbd->sessions, ses); free_session(xnbd, ses); info("session (pid %d) exited", pid); if (WIFEXITED(status)) info(" with exit status=%d", WEXITSTATUS(status)); if (WIFSIGNALED(status)) info(" killed by signal=%d(%s)", WTERMSIG(status), sys_siglist[WTERMSIG(status)]); } } if (restarting && g_list_length(xnbd->sessions) == 0) { /* All sessions are stopped. Now start new sessions with existing sockets. */ info("All sessions are stopped. Now restart."); /* * invoke_new_session() manipulates xnbd->sessions, * adding an entry to it. The fixed list is used here * instead of xnbd->sessions. **/ for (GList *list = g_list_first(socklist); list != NULL; list = g_list_next(list)) { int csockfd = (int) ((long) list->data); /* See below */ invoke_new_session(xnbd, csockfd); } /* must be reinitialized with NULL */ g_list_free(socklist); socklist = NULL; info("restarting has done"); restarting = 0; } if (got_sighup) { info("got SIGHUP, restart %d process(es)", g_list_length(xnbd->sessions)); got_sighup = 0; /* notify all sessions of termination */ for (GList *list = g_list_first(xnbd->sessions); list != NULL; list = g_list_next(list)) { struct xnbd_session *s = (struct xnbd_session *) list->data; dbg("%p\n", s); /* * If a new connection is accepted during * restarting, send SIGHUP to the master server * again. **/ if (s->notifying) continue; s->notifying = 1; /* preserve connected sockets */ int csockfd = dup(s->clientfd); if (csockfd < 0) err("dup %d, %m", csockfd); /* it's ok because sizeof(void *) >= sizeof(int); 32bit =, 64bit > */ socklist = g_list_append(socklist, (void *) ((long) csockfd)); info("notify %d of termination", s->pid); ssize_t ret = write(s->event_notifier_fd, "0", 1); if (ret < 0) warn("notifiy failed"); } restarting = 1; } /* SIGCHLD must be blocked here, so that only this ppoll() detects that */ //raise(SIGCHLD); info("start polling"); nready = ppoll(eventfds, nlistened, NULL, &orig_sigmask); //printf("poll ready %d\n", nready); if (nready == -1) { /* signal catched */ if (errno == EINTR) { info("polling signal catched"); continue; } else err("poll, %s", strerror(errno)); } for (nfds_t i = 0; i < nlistened; i++) { int sockfd = eventfds[i].fd; if (sockfd < 0) continue; if (eventfds[i].revents & (POLLHUP | POLLNVAL)) err("unknown events, %x", eventfds[i].revents); if (eventfds[i].revents & (POLLRDNORM | POLLERR)) { /* if POLLERR, the next read() returns -1 */ /* POLLERR never occurs because we wait new connections */ int csockfd = net_accept(sockfd); if (csockfd < 0) { warn("accept() failed"); continue; } int ret; if (xnbd->readonly) ret = nbd_negotiate_with_client_readonly(csockfd, xnbd->disksize); else ret = nbd_negotiate_with_client(csockfd, xnbd->disksize); if (ret < 0) { warn("negotiation with the client failed"); continue; } info("csockfd %d", csockfd); invoke_new_session(xnbd, csockfd); } /* short cut */ nready -= 1; if (nready == 0) break; } } /* notify child processes */ shutdown_all_sessions(xnbd); return 0; }
int __connman_session_create(DBusMessage *msg) { const char *owner, *notify_path; char *session_path = NULL; DBusMessageIter iter, array; struct connman_session *session = NULL; struct user_config *user_config = NULL; connman_bool_t user_allowed_bearers = FALSE; connman_bool_t user_connection_type = FALSE; int err; owner = dbus_message_get_sender(msg); DBG("owner %s", owner); if (ecall_session != NULL && ecall_session->ecall == TRUE) { /* * If there is an emergency call already going on, * ignore session creation attempt */ err = -EBUSY; goto err; } user_config = g_try_new0(struct user_config, 1); if (user_config == NULL) { err = -ENOMEM; goto err; } user_config->pending = dbus_message_ref(msg); dbus_message_iter_init(msg, &iter); dbus_message_iter_recurse(&iter, &array); while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key, *val; dbus_message_iter_recurse(&array, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); switch (dbus_message_iter_get_arg_type(&value)) { case DBUS_TYPE_ARRAY: if (g_str_equal(key, "AllowedBearers") == TRUE) { err = parse_bearers(&value, &user_config->allowed_bearers); if (err < 0) goto err; user_allowed_bearers = TRUE; } else { err = -EINVAL; goto err; } break; case DBUS_TYPE_STRING: if (g_str_equal(key, "ConnectionType") == TRUE) { dbus_message_iter_get_basic(&value, &val); user_config->type = connman_session_parse_connection_type(val); user_connection_type = TRUE; } else { err = -EINVAL; goto err; } } dbus_message_iter_next(&array); } /* * If the user hasn't provided a configuration, we set * the default configuration. * * For AllowedBearers this is '*', ... */ if (user_allowed_bearers == FALSE) { user_config->allowed_bearers = g_slist_append(NULL, GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN)); if (user_config->allowed_bearers == NULL) { err = -ENOMEM; goto err; } } /* ... and for ConnectionType it is 'any'. */ if (user_connection_type == FALSE) user_config->type = CONNMAN_SESSION_TYPE_ANY; dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter, ¬ify_path); if (notify_path == NULL) { err = -EINVAL; goto err; } session_path = g_strdup_printf("/sessions%s", notify_path); if (session_path == NULL) { err = -ENOMEM; goto err; } session = g_hash_table_lookup(session_hash, session_path); if (session != NULL) { g_free(session_path); session = NULL; err = -EEXIST; goto err; } session = g_try_new0(struct connman_session, 1); if (session == NULL) { g_free(session_path); err = -ENOMEM; goto err; } session->session_path = session_path; session->info = g_try_new0(struct session_info, 1); if (session->info == NULL) { err = -ENOMEM; goto err; } session->info_last = g_try_new0(struct session_info, 1); if (session->info_last == NULL) { err = -ENOMEM; goto err; } session->owner = g_strdup(owner); session->notify_path = g_strdup(notify_path); session->notify_watch = g_dbus_add_disconnect_watch(connection, session->owner, owner_disconnect, session, NULL); err = assign_policy_plugin(session); if (err < 0) goto err; err = create_policy_config(session, session_create_cb, user_config); if (err < 0 && err != -EINPROGRESS) return err; return -EINPROGRESS; err: connman_error("Failed to create session"); free_session(session); cleanup_user_config(user_config); return err; }
/** * Deallocates the memory taken by a Accounting Session */ void AAADropAccSession(AAASession *s) { free_session(s); }
BlenderSession::~BlenderSession() { free_session(); }
int telnetd_main(int argc, char **argv) { #if !defined(CONFIG_FEATURE_TELNETD_INETD) || defined(IFX_INETD_ENHANCEMENT) int master_fd; #endif #ifndef CONFIG_FEATURE_TELNETD_INETD struct sockaddr_in sa; #endif /* CONFIG_FEATURE_TELNETD_INETD */ fd_set rdfdset, wrfdset; int selret; #ifndef CONFIG_FEATURE_TELNETD_INETD int on = 1; int portnbr = 23; #endif /* CONFIG_FEATURE_TELNETD_INETD */ int c; static const char options[] = #ifdef CONFIG_FEATURE_TELNETD_INETD #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT "f:l:t:"; #else /*CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT*/ "f:l:"; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ #else /* CONFIG_EATURE_TELNETD_INETD */ #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT "f:l:p:t:"; #else /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ "f:l:p:"; #endif /*CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT*/ #endif /* CONFIG_FEATURE_TELNETD_INETD */ int maxlen, w, r; #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT struct timeval time_val; int daemon_timeout_val = time(NULL) + 120; #endif #ifndef CONFIG_LOGIN loginpath = DEFAULT_SHELL; #endif for (;;) { c = getopt( argc, argv, options); if (c == EOF) break; switch (c) { case 'f': issuefile = optarg; break; case 'l': loginpath = optarg; break; #ifndef CONFIG_FEATURE_TELNETD_INETD case 'p': portnbr = atoi(optarg); break; #endif /* CONFIG_FEATURE_TELNETD_INETD */ #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT case 't': TIMEOUT = atoi(optarg); break; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT*/ default: bb_show_usage(); } } if (access(loginpath, X_OK) < 0) { bb_error_msg_and_die ("'%s' unavailable.", loginpath); } argv_init[0] = loginpath; openlog(bb_applet_name, 0, LOG_USER); #ifndef IFX_INETD_ENHANCEMENT #ifdef CONFIG_FEATURE_TELNETD_INETD maxfd = 1; sessions = make_new_session(); #else /* CONFIG_EATURE_TELNETD_INETD */ sessions = 0; /* Grab a TCP socket. */ master_fd = socket(AF_INET, SOCK_STREAM, 0); if (master_fd < 0) { bb_perror_msg_and_die("socket"); } (void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); /* Set it to listen to specified port. */ memset((void *)&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(portnbr); if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) { bb_perror_msg_and_die("bind"); } if (listen(master_fd, 1) < 0) { bb_perror_msg_and_die("listen"); } if (daemon(0, 0) < 0) bb_perror_msg_and_die("daemon"); maxfd = master_fd; #endif /* CONFIG_FEATURE_TELNETD_INETD */ #else /* IFX_INETD_ENHANCEMENT */ sessions = 0; master_fd = 0; maxfd = master_fd; #endif /* IFX_INETD_ENHANCEMENT */ do { struct tsession *ts; FD_ZERO(&rdfdset); FD_ZERO(&wrfdset); /* select on the master socket, all telnet sockets and their * ptys if there is room in their respective session buffers. */ #ifndef CONFIG_FEATURE_TELNETD_INETD FD_SET(master_fd, &rdfdset); #endif /* CONFIG_FEATURE_TELNETD_INETD */ ts = sessions; #ifndef CONFIG_FEATURE_TELNETD_INETD while (ts) { #endif /* CONFIG_FEATURE_TELNETD_INETD */ /* buf1 is used from socket to pty * buf2 is used from pty to socket */ if (ts->size1 > 0) { FD_SET(ts->ptyfd, &wrfdset); /* can write to pty */ } if (ts->size1 < BUFSIZE) { #ifdef CONFIG_FEATURE_TELNETD_INETD FD_SET(ts->sockfd_read, &rdfdset); /* can read from socket */ #else /* CONFIG_FEATURE_TELNETD_INETD */ FD_SET(ts->sockfd, &rdfdset); /* can read from socket */ #endif /* CONFIG_FEATURE_TELNETD_INETD */ } if (ts->size2 > 0) { #ifdef CONFIG_FEATURE_TELNETD_INETD FD_SET(ts->sockfd_write, &wrfdset); /* can write to socket */ #else /* CONFIG_FEATURE_TELNETD_INETD */ FD_SET(ts->sockfd, &wrfdset); /* can write to socket */ #endif /* CONFIG_FEATURE_TELNETD_INETD */ } if (ts->size2 < BUFSIZE) { FD_SET(ts->ptyfd, &rdfdset); /* can read from pty */ } #ifndef CONFIG_FEATURE_TELNETD_INETD ts = ts->next; } #endif /* CONFIG_FEATURE_TELNETD_INETD */ #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT time_val.tv_sec = 10; time_val.tv_usec = 0; selret = select(maxfd + 1, &rdfdset, &wrfdset, 0, &time_val); #else selret = select(maxfd + 1, &rdfdset, &wrfdset, 0, 0); #endif if (selret < 0) break; #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT // check if the currtime exceeded timeout time #ifndef CONFIG_FEATURE_TELNETD_INETD ts= sessions; while(ts) { struct tsession *next = ts->next; /* in case we free ts. */ #endif /* CONFIG_FEATURE_TELNETD_INETD */ if(ts->timeout_time < time(NULL)) { printf("Timed out \n"); syslog(LOG_ERR,"Session timed out\n"); #ifdef CONFIG_FEATURE_TELNETD_INETD exit(0); #else /* CONFIG_FEATURE_TELNETD_INETD */ daemon_timeout_val = time(NULL) + 120; free_session(ts); #endif/* CONFIG_FEATURE_TELNETD_INETD */ } #ifndef CONFIG_FEATURE_TELNETD_INETD ts= next; } #endif /* CONFIG_FEATURE_TELNETD_INETD */ if(selret == 0) { if(sessions == NULL && daemon_timeout_val < time(NULL)) { printf("Telnetd Timed out \n"); syslog(LOG_ERR,"Telnetd timed out\n"); exit(0); } else continue; } #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ #ifndef CONFIG_FEATURE_TELNETD_INETD daemon_timeout_val = time(NULL) + 120; /* First check for and accept new sessions. */ if (FD_ISSET(master_fd, &rdfdset)) { int fd, salen; salen = sizeof(sa); if ((fd = accept(master_fd, (struct sockaddr *)&sa, &salen)) < 0) { continue; } else { /* Create a new session and link it into our active list. */ struct tsession *new_ts = make_new_session(fd); if (new_ts) { new_ts->next = sessions; sessions = new_ts; if (fd > maxfd) maxfd = fd; } else { close(fd); } } } /* Then check for data tunneling. */ ts = sessions; while (ts) { /* For all sessions... */ #endif /* CONFIG_FEATURE_TELNETD_INETD */ #ifndef CONFIG_FEATURE_TELNETD_INETD struct tsession *next = ts->next; /* in case we free ts. */ #endif /* CONFIG_FEATURE_TELNETD_INETD */ if (ts->size1 && FD_ISSET(ts->ptyfd, &wrfdset)) { int num_totty; char *ptr; /* Write to pty from buffer 1. */ ptr = remove_iacs(ts, &num_totty); w = write(ts->ptyfd, ptr, num_totty); if (w < 0) { #ifdef CONFIG_FEATURE_TELNETD_INETD exit(0); #else /* CONFIG_FEATURE_TELNETD_INETD */ free_session(ts); ts = next; continue; #endif /* CONFIG_FEATURE_TELNETD_INETD */ } ts->wridx1 += w; ts->size1 -= w; if (ts->wridx1 == BUFSIZE) ts->wridx1 = 0; #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT //some activity in this session reset the timer ts->timeout_time = time(NULL)+ TIMEOUT; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ } #ifdef CONFIG_FEATURE_TELNETD_INETD if (ts->size2 && FD_ISSET(ts->sockfd_write, &wrfdset)) #else /* CONFIG_FEATURE_TELNETD_INETD */ if (ts->size2 && FD_ISSET(ts->sockfd, &wrfdset)) #endif /* CONFIG_FEATURE_TELNETD_INETD */ { /* Write to socket from buffer 2. */ maxlen = MIN(BUFSIZE - ts->wridx2, ts->size2); #ifdef CONFIG_FEATURE_TELNETD_INETD w = write(ts->sockfd_write, ts->buf2 + ts->wridx2, maxlen); if (w < 0) exit(0); #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT else ts->timeout_time = time(NULL)+TIMEOUT; #endif /*CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT*/ #else /* CONFIG_FEATURE_TELNETD_INETD */ w = write(ts->sockfd, ts->buf2 + ts->wridx2, maxlen); if (w < 0) { free_session(ts); ts = next; continue; } #endif /* CONFIG_FEATURE_TELNETD_INETD */ ts->wridx2 += w; ts->size2 -= w; if (ts->wridx2 == BUFSIZE) ts->wridx2 = 0; #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT //some activity in this session reset the timer ts->timeout_time = time(NULL)+ TIMEOUT; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ } #ifdef CONFIG_FEATURE_TELNETD_INETD if (ts->size1 < BUFSIZE && FD_ISSET(ts->sockfd_read, &rdfdset)) #else /* CONFIG_FEATURE_TELNETD_INETD */ if (ts->size1 < BUFSIZE && FD_ISSET(ts->sockfd, &rdfdset)) #endif /* CONFIG_FEATURE_TELNETD_INETD */ { /* Read from socket to buffer 1. */ maxlen = MIN(BUFSIZE - ts->rdidx1, BUFSIZE - ts->size1); #ifdef CONFIG_FEATURE_TELNETD_INETD r = read(ts->sockfd_read, ts->buf1 + ts->rdidx1, maxlen); if (!r || (r < 0 && errno != EINTR)) exit(0); #else /* CONFIG_FEATURE_TELNETD_INETD */ r = read(ts->sockfd, ts->buf1 + ts->rdidx1, maxlen); if (!r || (r < 0 && errno != EINTR)) { free_session(ts); ts = next; continue; } #endif /* CONFIG_FEATURE_TELNETD_INETD */ #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT //some activity in this session reset the timer ts->timeout_time = time(NULL)+ TIMEOUT; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ if(!*(ts->buf1 + ts->rdidx1 + r - 1)) { r--; if(!r) continue; } ts->rdidx1 += r; ts->size1 += r; if (ts->rdidx1 == BUFSIZE) ts->rdidx1 = 0; } if (ts->size2 < BUFSIZE && FD_ISSET(ts->ptyfd, &rdfdset)) { /* Read from pty to buffer 2. */ maxlen = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2); r = read(ts->ptyfd, ts->buf2 + ts->rdidx2, maxlen); if (!r || (r < 0 && errno != EINTR)) { #ifdef CONFIG_FEATURE_TELNETD_INETD exit(0); #else /* CONFIG_FEATURE_TELNETD_INETD */ free_session(ts); ts = next; continue; #endif /* CONFIG_FEATURE_TELNETD_INETD */ } ts->rdidx2 += r; ts->size2 += r; if (ts->rdidx2 == BUFSIZE) ts->rdidx2 = 0; #ifdef CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT //some activity in this session reset the timer ts->timeout_time = time(NULL)+ TIMEOUT; #endif /* CONFIG_FEATURE_TELNETD_INACTIVE_TIMEOUT */ } if (ts->size1 == 0) { ts->rdidx1 = 0; ts->wridx1 = 0; } if (ts->size2 == 0) { ts->rdidx2 = 0; ts->wridx2 = 0; } #ifndef CONFIG_FEATURE_TELNETD_INETD ts = next; } #endif /* CONFIG_FEATURE_TELNETD_INETD */ } while (1); return 0; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // DESTRUCTOR ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BlenderSession::~BlenderSession() { session->set_pause(false); free_session(); } //~BlenderSession()