static connection *connections_get_new_connection(server *srv) { connections *conns = srv->conns; size_t i; if (conns->size == 0) { conns->size = 128; conns->ptr = NULL; conns->ptr = malloc(sizeof(*conns->ptr) * conns->size); force_assert(NULL != conns->ptr); for (i = 0; i < conns->size; i++) { conns->ptr[i] = connection_init(srv); } } else if (conns->size == conns->used) { conns->size += 128; conns->ptr = realloc(conns->ptr, sizeof(*conns->ptr) * conns->size); force_assert(NULL != conns->ptr); for (i = conns->used; i < conns->size; i++) { conns->ptr[i] = connection_init(srv); } } connection_reset(srv, conns->ptr[conns->used]); #if 0 fprintf(stderr, "%s.%d: add: ", __FILE__, __LINE__); for (i = 0; i < conns->used + 1; i++) { fprintf(stderr, "%d ", conns->ptr[i]->fd); } fprintf(stderr, "\n"); #endif conns->ptr[conns->used]->ndx = conns->used; return conns->ptr[conns->used++]; }
int network_manager_init(DBusConnection *conn) { read_config(CONFIGDIR "/network.conf"); if (bnep_init()) { error("Can't init bnep module"); return -1; } /* * There is one socket to handle the incomming connections. NAP, * GN and PANU servers share the same PSM. The initial BNEP message * (setup connection request) contains the destination service * field that defines which service the source is connecting to. */ if (server_init(conn, conf_security, conf_master) < 0) return -1; /* Register network server if it doesn't exist */ btd_register_adapter_driver(&network_server_driver); if (connection_init(conn) < 0) return -1; btd_register_device_driver(&network_panu_driver); btd_register_device_driver(&network_gn_driver); btd_register_device_driver(&network_nap_driver); connection = dbus_connection_ref(conn); return 0; }
/** Load or save all variables */ static bool load_or_save_variables_at_path(bool save, const std::string &path) { bool result = false; debug(4, L"Open file for %s: '%s'", save?"saving":"loading", path.c_str()); /* OK to not use CLO_EXEC here because fishd is single threaded */ int fd = open(path.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600); if (fd >= 0) { /* Success */ result = true; connection_t c = {}; connection_init(&c, fd); if (save) { /* Save to the file */ write_loop(c.fd, SAVE_MSG, strlen(SAVE_MSG)); enqueue_all(&c); } else { /* Read from the file */ read_message(&c); } connection_destroy(&c); } return result; }
void core_engine_init(web_engine_t *engine, int http_port, int https_port) { connection_init(128); listen_init(&engine->http, http_port); //listen_init(&engine->https, https_port); }
void init(void) { app_init(); doi_init(); exchange_init(); group_init(); ipsec_init(); isakmp_doi_init(); libcrypto_init(); timer_init(); /* The following group are depending on timer_init having run. */ conf_init(); connection_init(); /* This depends on conf_init, thus check as soon as possible. */ log_reinit(); /* policy_init depends on conf_init having run. */ policy_init(); /* Depends on conf_init and policy_init having run */ cert_init(); crl_init(); sa_init(); transport_init(); virtual_init(); udp_init(); nat_t_init(); udp_encap_init(); vendor_init(); }
static DiaObject * annotation_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Annotation *annotation; Connection *conn; LineBBExtras *extra; DiaObject *obj; Point offs; Point defaultlen = { 1.0, 1.0 }; DiaFont* font; annotation = g_malloc0(sizeof(Annotation)); conn = &annotation->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = &conn->object; extra = &conn->extra_spacing; obj->type = &sadtannotation_type; obj->ops = &annotation_ops; connection_init(conn, 3, 0); font = dia_font_new_from_style(DIA_FONT_SANS,ANNOTATION_FONTHEIGHT); annotation->text = new_text("", font, ANNOTATION_FONTHEIGHT, &conn->endpoints[1], &color_black, ALIGN_CENTER); dia_font_unref(font); offs.x = .3 * ANNOTATION_FONTHEIGHT; if (conn->endpoints[1].y < conn->endpoints[0].y) offs.y = 1.3 * ANNOTATION_FONTHEIGHT; else offs.y = -.3 * ANNOTATION_FONTHEIGHT; point_add(&annotation->text->position,&offs); annotation->text_handle.id = HANDLE_MOVE_TEXT; annotation->text_handle.type = HANDLE_MINOR_CONTROL; annotation->text_handle.connect_type = HANDLE_NONCONNECTABLE; annotation->text_handle.connected_to = NULL; obj->handles[2] = &annotation->text_handle; extra->start_trans = extra->end_trans = ANNOTATION_ZLEN; extra->start_long = extra->end_long = ANNOTATION_LINE_WIDTH/2.0; annotation_update_data(annotation); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &annotation->connection.object; }
static Object * implements_load(ObjectNode obj_node, int version, const char *filename) { Implements *implements; AttributeNode attr; Connection *conn; Object *obj; if (implements_font == NULL) implements_font = font_getfont("Courier"); implements = g_malloc(sizeof(Implements)); conn = &implements->connection; obj = (Object *) implements; obj->type = &implements_type; obj->ops = &implements_ops; connection_load(conn, obj_node); connection_init(conn, 4, 0); implements->circle_diameter = 1.0; attr = object_find_attribute(obj_node, "diameter"); if (attr != NULL) implements->circle_diameter = data_real(attribute_first_data(attr)); implements->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) implements->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &implements->text_pos); implements->text_width = font_string_width(implements->text, implements_font, IMPLEMENTS_FONTHEIGHT); implements->text_handle.id = HANDLE_MOVE_TEXT; implements->text_handle.type = HANDLE_MINOR_CONTROL; implements->text_handle.connect_type = HANDLE_NONCONNECTABLE; implements->text_handle.connected_to = NULL; obj->handles[2] = &implements->text_handle; implements->circle_handle.id = HANDLE_CIRCLE_SIZE; implements->circle_handle.type = HANDLE_MINOR_CONTROL; implements->circle_handle.connect_type = HANDLE_NONCONNECTABLE; implements->circle_handle.connected_to = NULL; obj->handles[3] = &implements->circle_handle; implements->properties_dialog = NULL; implements_update_data(implements); return (Object *)implements; }
ProxyConnection* http_connector_connect( HttpService* service, SockAddress* address ) { Connection* conn; int s; s = socket_create_inet( SOCKET_STREAM ); if (s < 0) return NULL; conn = qemu_mallocz(sizeof(*conn)); if (conn == NULL) { socket_close(s); return NULL; } proxy_connection_init( conn->root, s, address, service->root, connection_free, connection_select, connection_poll ); if ( connection_init( conn ) < 0 ) { connection_free( conn->root ); return NULL; } return conn->root; }
/* creation here */ static DiaObject * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; LineBBExtras *extra; DiaObject *obj; if (message_font == NULL) { message_font = dia_font_new_from_style (DIA_FONT_SANS, MESSAGE_FONTHEIGHT); } message = g_malloc0(sizeof(Message)); conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &jackson_phenomenon_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text = g_strdup(""); message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y); message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; extra->start_long = extra->start_trans = extra->end_long = MESSAGE_WIDTH/2.0; extra->end_trans = MAX(MESSAGE_WIDTH,MESSAGE_ARROWLEN)/2.0; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; /* init type */ switch (GPOINTER_TO_INT(user_data)) { case 1: message->type=MSG_SHARED; break; case 2: message->type=MSG_REQ; break; default: message->type=MSG_SHARED; break; } if (GPOINTER_TO_INT(user_data)!=0) message->init=-1; else message->init=0; return &message->connection.object; }
int main(int argc , char *argv[]) { connection_init(); return 0; }
void ls(srv_config *sCon, srv_config *spCon){ printf("ls\n"); pasv(sCon, spCon); char *buff = "LIST\r\n"; send_data(sCon, buff, strlen(buff)); connection_init(spCon); closesocket(spCon->sock); }
static DiaObject * bus_load(ObjectNode obj_node, int version, const char *filename) { Bus *bus; Connection *conn; LineBBExtras *extra; DiaObject *obj; AttributeNode attr; DataNode data; int i; bus = g_malloc0(sizeof(Bus)); conn = &bus->connection; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &bus_type; obj->ops = &bus_ops; connection_load(conn, obj_node); attr = object_find_attribute(obj_node, "bus_handles"); bus->num_handles = 0; if (attr != NULL) bus->num_handles = attribute_num_data(attr); connection_init(conn, 2 + bus->num_handles, 0); data = attribute_first_data(attr); bus->handles = g_malloc(sizeof(Handle *)*bus->num_handles); bus->parallel_points = g_malloc(sizeof(Point)*bus->num_handles); for (i=0;i<bus->num_handles;i++) { bus->handles[i] = g_new0(Handle,1); bus->handles[i]->id = HANDLE_BUS; bus->handles[i]->type = HANDLE_MINOR_CONTROL; bus->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK; bus->handles[i]->connected_to = NULL; data_point(data, &bus->handles[i]->pos); obj->handles[2+i] = bus->handles[i]; data = data_next(data); } bus->line_color = color_black; attr = object_find_attribute(obj_node, "line_color"); if (attr != NULL) data_color(attribute_first_data(attr), &bus->line_color); extra->start_trans = extra->end_trans = extra->start_long = extra->end_long = LINE_WIDTH/2.0; bus_update_data(bus); return &bus->connection.object; }
static DiaObject * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; LineBBExtras *extra; DiaObject *obj; message = g_malloc0(sizeof(Message)); /* old defaults */ message->font_height = 0.8; message->font = dia_font_new_from_style (DIA_FONT_SANS, message->font_height); message->line_width = 0.1; conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &message_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text_color = color_black; message->line_color = attributes_get_foreground(); message->text = g_strdup(""); message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) + 0.5; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; extra->start_long = extra->start_trans = extra->end_long = message->line_width/2.0; extra->end_trans = MAX(message->line_width,MESSAGE_ARROWLEN)/2.0; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &message->connection.object; }
void irc_init(irc_t* irc, const char* server, const char* port, const char* nick) { privmsg_list = list_create(); notice_list = list_create(); irc->server = strdup(server); irc->port = strdup(port); irc->sockfd = connection_init(server, port); irc_send(irc, "NICK %s\r\n", nick); irc_send(irc, "USER %s * * :C IrcBot programmed by Nicholas Bailey, modified by bootnecklad\r\n", nick); }
static DiaObject * flow_load(ObjectNode obj_node, int version, DiaContext *ctx) { Flow *flow; AttributeNode attr; Connection *conn; DiaObject *obj; LineBBExtras *extra; flow = g_malloc0(sizeof(Flow)); conn = &flow->connection; obj = &conn->object; extra = &conn->extra_spacing; obj->type = &flow_type; obj->ops = &flow_ops; connection_load(conn, obj_node, ctx); connection_init(conn, 3, 0); flow->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) flow->text = data_text(attribute_first_data(attr), ctx); else { /* pathologic */ DiaFont *font = dia_font_new_from_style(DIA_FONT_SANS, FLOW_FONTHEIGHT); flow->text = new_text("", font, FLOW_FONTHEIGHT, &obj->position, &color_black, ALIGN_CENTER); dia_font_unref(font); } attr = object_find_attribute(obj_node, "type"); if (attr != NULL) flow->type = (FlowType)data_int(attribute_first_data(attr), ctx); flow->text_handle.id = HANDLE_MOVE_TEXT; flow->text_handle.type = HANDLE_MINOR_CONTROL; flow->text_handle.connect_type = HANDLE_NONCONNECTABLE; flow->text_handle.connected_to = NULL; flow->text_handle.pos = flow->text->position; obj->handles[2] = &flow->text_handle; extra->start_long = extra->end_long = extra->start_trans = FLOW_WIDTH/2.0; extra->end_trans = MAX(FLOW_WIDTH, FLOW_ARROWLEN) / 2.0; flow->textpos = flow->text->position; flow_update_data(flow); return &flow->connection.object; }
static DiaObject * bus_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Bus *bus; Connection *conn; LineBBExtras *extra; DiaObject *obj; Point defaultlen = { 5.0, 0.0 }; int i; bus = g_malloc0(sizeof(Bus)); conn = &bus->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = &conn->object; extra = &conn->extra_spacing; obj->type = &bus_type; obj->ops = &bus_ops; bus->num_handles = DEFAULT_NUMHANDLES; connection_init(conn, 2+bus->num_handles, 0); bus->line_color = attributes_get_foreground(); bus->handles = g_malloc(sizeof(Handle *)*bus->num_handles); bus->parallel_points = g_malloc(sizeof(Point)*bus->num_handles); for (i=0;i<bus->num_handles;i++) { bus->handles[i] = g_new0(Handle,1); bus->handles[i]->id = HANDLE_BUS; bus->handles[i]->type = HANDLE_MINOR_CONTROL; bus->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK; bus->handles[i]->connected_to = NULL; bus->handles[i]->pos = *startpoint; bus->handles[i]->pos.x += 5*((real)i+1)/(bus->num_handles+1); bus->handles[i]->pos.y += (i%2==0)?1.0:-1.0; obj->handles[2+i] = bus->handles[i]; } extra->start_trans = extra->end_trans = extra->start_long = extra->end_long = LINE_WIDTH/2.0; bus_update_data(bus); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &bus->connection.object; }
/* ==================== server_new() ==================== */ server_t *server_new(void) { server_t *server= (server_t*)zmalloc(sizeof(server_t)); memset(server, 0, sizeof(server_t)); server->cached_bytes = 0; connection_init(&server->connection); return server; }
static Object * implements_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Implements *implements; Connection *conn; Object *obj; Point defaultlen = { 1.0, 1.0 }; if (implements_font == NULL) implements_font = font_getfont("Courier"); implements = g_malloc(sizeof(Implements)); conn = &implements->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (Object *) implements; obj->type = &implements_type; obj->ops = &implements_ops; connection_init(conn, 4, 0); implements->text = strdup(""); implements->text_width = 0.0; implements->text_pos = conn->endpoints[1]; implements->text_pos.x -= 0.3; implements->circle_diameter = 0.7; implements->text_handle.id = HANDLE_MOVE_TEXT; implements->text_handle.type = HANDLE_MINOR_CONTROL; implements->text_handle.connect_type = HANDLE_NONCONNECTABLE; implements->text_handle.connected_to = NULL; obj->handles[2] = &implements->text_handle; implements->circle_handle.id = HANDLE_CIRCLE_SIZE; implements->circle_handle.type = HANDLE_MINOR_CONTROL; implements->circle_handle.connect_type = HANDLE_NONCONNECTABLE; implements->circle_handle.connected_to = NULL; obj->handles[3] = &implements->circle_handle; implements->properties_dialog = NULL; implements_update_data(implements); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)implements; }
static Object * message_load(ObjectNode obj_node, int version, const char *filename) { Message *message; AttributeNode attr; Connection *conn; Object *obj; if (message_font == NULL) message_font = font_getfont("Helvetica"); message = g_malloc(sizeof(Message)); conn = &message->connection; obj = (Object *) message; obj->type = &message_type; obj->ops = &message_ops; connection_load(conn, obj_node); connection_init(conn, 3, 0); message->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) message->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &message->text_pos); attr = object_find_attribute(obj_node, "type"); if (attr != NULL) message->type = (MessageType)data_int(attribute_first_data(attr)); if (message->text) message->text_width = font_string_width(message->text, message_font, MESSAGE_FONTHEIGHT); else message->text_width = 0; message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; message_update_data(message); return (Object *)message; }
static int conf_add_connection(const char *rel, const char *full) { char buf[PATH_MAX]; Connection *c; c = connections + nconnections; connection_init(c); c->name = xstrdup(rel); make_path(buf, full, "command"); c->command = read_data_string(buf); if(!c->command) { parse_error(buf,"cannot read command data",xsyserr()); return -1; } make_path(buf, full, "update"); if(read_data_list(buf, conf_add_update, c) < 0) { if (errno != ENOENT) { parse_error(buf,"unable to read update data",xsyserr()); return -1; } conf_add_update(c, "image"); conf_add_update(c, "beep"); } make_path(buf, full, "reset"); if(read_data_list(buf, conf_add_reset, c) < 0) { if (errno != ENOENT) { parse_error(buf,"unable to read reset data",xsyserr()); return -1; } conf_add_reset(c, "image-reset"); } make_path(buf, full, "folders"); if(read_data_list(buf, conf_add_folder, c) < 0) { if (errno != ENOENT) { parse_error(buf,"unable to read folder data",xsyserr()); return -1; } conf_add_folder(c, "INBOX"); } make_path(buf, full, "secret"); if(!dir_is_protected(buf)) { parse_error(buf,"\"secret\" directory has loose permissions",0); return -1; } nconnections++; return 0; }
int main(int argc, char *argv[]) { int sockfd; char *ret_str; struct sockaddr_in servaddr; SearpcClient *rpc_client; GError *error = NULL; #if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); #endif #ifdef WIN32 WSADATA wsadata; WSAStartup(0x0101, &wsadata); #endif memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(12345); inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr); if (connection_init(&sockfd, &servaddr)<0) exit(-1); /* create an rpc_client and supply the transport function. */ rpc_client = searpc_client_new(); rpc_client->send = transport_callback; rpc_client->arg = (void *)(long)sockfd; rpc_string_test(sockfd, &servaddr, rpc_client, error); if (connection_init(&sockfd, &servaddr)<0) exit(-1); rpc_client->arg = (void *)(long)sockfd; rpc_glist_test(sockfd, &servaddr, rpc_client, error); return 0; }
static DiaObject * constraint_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Constraint *constraint; Connection *conn; DiaObject *obj; Point defaultlen = { 1.0, 1.0 }; constraint = g_malloc0(sizeof(Constraint)); /* old defaults */ constraint->font_height = 0.8; constraint->font = dia_font_new_from_style (DIA_FONT_MONOSPACE, constraint->font_height); constraint->line_width = 0.1; conn = &constraint->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = &conn->object; obj->type = &constraint_type; obj->ops = &constraint_ops; connection_init(conn, 3, 0); constraint->text_color = color_black; constraint->line_color = attributes_get_foreground(); constraint->text = g_strdup(""); constraint->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); constraint->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) - 0.2; constraint->text_handle.id = HANDLE_MOVE_TEXT; constraint->text_handle.type = HANDLE_MINOR_CONTROL; constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE; constraint->text_handle.connected_to = NULL; obj->handles[2] = &constraint->text_handle; constraint->brtext = NULL; constraint_update_data(constraint); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return &constraint->connection.object; }
static Object * constraint_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Constraint *constraint; Connection *conn; Object *obj; Point defaultlen = { 1.0, 1.0 }; if (constraint_font == NULL) constraint_font = font_getfont("Courier"); constraint = g_malloc(sizeof(Constraint)); conn = &constraint->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (Object *) constraint; obj->type = &constraint_type; obj->ops = &constraint_ops; connection_init(conn, 3, 0); constraint->text = strdup("{}"); constraint->text_width = font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT); constraint->text_width = 0.0; constraint->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); constraint->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y); constraint->text_handle.id = HANDLE_MOVE_TEXT; constraint->text_handle.type = HANDLE_MINOR_CONTROL; constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE; constraint->text_handle.connected_to = NULL; obj->handles[2] = &constraint->text_handle; constraint->properties_dialog = NULL; constraint_update_data(constraint); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)constraint; }
int main(int argc, char* argv[]) { struct connection conn; iopoll_fd fds[2]; int selfpipe; int i; msg_debug_init(); testmode = getenv("TESTMODE") != 0; if ((shell_argv = malloc((argc + 3) * sizeof *argv)) == 0) die_oom(111); for (i = 1; i < argc; ++i) shell_argv[i-1] = argv[i]; for (; i < argc + 4; ++i) shell_argv[i-1] = 0; shell_argc = argc - 1; if ((path = getenv("PATH")) == 0) die1(111, "No PATH is set"); if ((devnull = open("/dev/null", O_RDWR)) == -1) die1sys(111, "Could not open \"/dev/null\""); if (!nonblock_on(0)) die1sys(111, "Could not set non-blocking status"); if ((selfpipe = selfpipe_init()) == -1) die1sys(111, "Could not create self-pipe"); init_slots(); connection_init(&conn, 0, 0); fds[0].fd = 0; fds[0].events = IOPOLL_READ; fds[1].fd = selfpipe; fds[1].events = IOPOLL_READ; for (;;) { if (iopoll_restart(fds, 2, -1) == -1) die1sys(111, "Poll failed"); if (fds[0].revents) if (connection_read(&conn, handle_packet) <= 0) break; if (fds[1].revents) { read(selfpipe, &i, 1); handle_child(WNOHANG); } } msg1("Waiting for remaining slots to complete"); while (slots_used > 0) handle_child(0); return 0; }
/** Load or save all variables */ static void load_or_save( int save) { const wcstring wdir = fishd_get_config(); char hostname[HOSTNAME_LEN]; connection_t c; int fd; if (wdir.empty()) return; std::string dir = wcs2string( wdir ); gethostname( hostname, HOSTNAME_LEN ); std::string name; name.append(dir); name.append("/"); name.append(FILE); name.append(hostname); debug( 4, L"Open file for %s: '%s'", save?"saving":"loading", name.c_str() ); /* OK to not use CLO_EXEC here because fishd is single threaded */ fd = open(name.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600); if( fd == -1 ) { debug( 1, L"Could not open load/save file. No previous saves?" ); wperror( L"open" ); return; } debug( 4, L"File open on fd %d", c.fd ); connection_init( &c, fd ); if( save ) { write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) ); enqueue_all( &c ); } else read_message( &c ); connection_destroy( &c ); }
static Object * constraint_load(ObjectNode obj_node, int version, const char *filename) { Constraint *constraint; AttributeNode attr; Connection *conn; Object *obj; if (constraint_font == NULL) constraint_font = font_getfont("Courier"); constraint = g_malloc(sizeof(Constraint)); conn = &constraint->connection; obj = (Object *) constraint; obj->type = &constraint_type; obj->ops = &constraint_ops; connection_load(conn, obj_node); connection_init(conn, 3, 0); constraint->text = NULL; attr = object_find_attribute(obj_node, "text"); if (attr != NULL) constraint->text = data_string(attribute_first_data(attr)); attr = object_find_attribute(obj_node, "text_pos"); if (attr != NULL) data_point(attribute_first_data(attr), &constraint->text_pos); constraint->text_width = font_string_width(constraint->text, constraint_font, CONSTRAINT_FONTHEIGHT); constraint->text_handle.id = HANDLE_MOVE_TEXT; constraint->text_handle.type = HANDLE_MINOR_CONTROL; constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE; constraint->text_handle.connected_to = NULL; obj->handles[2] = &constraint->text_handle; constraint->properties_dialog = NULL; constraint_update_data(constraint); return (Object *)constraint; }
static int relay_install (relay_server *relay) { client_t *client = calloc (1, sizeof (client_t)); connection_init (&client->connection, SOCK_ERROR, NULL); global_lock(); client_register (client); global_unlock(); client->shared_data = relay; client->ops = &relay_init_ops; client->flags |= CLIENT_ACTIVE; DEBUG1 ("adding relay client for %s", relay->localmount); client_add_worker (client); return 0; }
static Object * arc_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Arc *arc; Connection *conn; Object *obj; Point defaultlen = { 1.0, 1.0 }; /*arc_init_defaults();*/ arc = g_malloc(sizeof(Arc)); arc->line_width = attributes_get_default_linewidth(); arc->curve_distance = 1.0; arc->arc_color = attributes_get_foreground(); attributes_get_default_line_style(&arc->line_style, &arc->dashlength); arc->start_arrow = attributes_get_default_start_arrow(); arc->end_arrow = attributes_get_default_end_arrow(); conn = &arc->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (Object *) arc; obj->type = &arc_type;; obj->ops = &arc_ops; connection_init(conn, 3, 0); obj->handles[2] = &arc->middle_handle; arc->middle_handle.id = HANDLE_MIDDLE; arc->middle_handle.type = HANDLE_MINOR_CONTROL; arc->middle_handle.connect_type = HANDLE_NONCONNECTABLE; arc->middle_handle.connected_to = NULL; arc_update_data(arc); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)arc; }
static Object * message_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { Message *message; Connection *conn; Object *obj; if (message_font == NULL) message_font = font_getfont("Helvetica"); message = g_malloc(sizeof(Message)); conn = &message->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; conn->endpoints[1].x += 1.5; obj = (Object *) message; obj->type = &message_type; obj->ops = &message_ops; connection_init(conn, 3, 0); message->text = NULL; message->text_width = 0.0; message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x); message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y); message->text_handle.id = HANDLE_MOVE_TEXT; message->text_handle.type = HANDLE_MINOR_CONTROL; message->text_handle.connect_type = HANDLE_NONCONNECTABLE; message->text_handle.connected_to = NULL; obj->handles[2] = &message->text_handle; message_update_data(message); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (Object *)message; }
static DiaObject * wanlink_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2) { WanLink *wanlink; Connection *conn; DiaObject *obj; int i; Point defaultpoly = {0.0, 0.0}; Point defaultlen = { 5.0, 0.0 }; wanlink = g_malloc0(sizeof(WanLink)); conn = &wanlink->connection; conn->endpoints[0] = *startpoint; conn->endpoints[1] = *startpoint; point_add(&conn->endpoints[1], &defaultlen); obj = (DiaObject *) wanlink; obj->type = &wanlink_type; obj->ops = &wanlink_ops; connection_init(conn, 2, 0); for (i = 0; i < WANLINK_POLY_LEN ; i++) wanlink->poly[i] = defaultpoly; wanlink->width = FLASH_WIDTH; /* both colors where black at the time this was hardcoded ... */ wanlink->line_color = color_black; wanlink->fill_color = color_black; wanlink->line_color = attributes_get_foreground(); wanlink->fill_color = attributes_get_foreground(); wanlink_update_data(wanlink); *handle1 = obj->handles[0]; *handle2 = obj->handles[1]; return (DiaObject *)wanlink; }