static void qemu_archipelago_close(BlockDriverState *bs) { int r, targetlen; char *target; struct xseg_request *req; BDRVArchipelagoState *s = bs->opaque; s->stopping = true; qemu_mutex_lock(&s->request_mutex); while (!s->th_is_signaled) { qemu_cond_wait(&s->request_cond, &s->request_mutex); } qemu_mutex_unlock(&s->request_mutex); qemu_thread_join(&s->request_th); qemu_cond_destroy(&s->request_cond); qemu_mutex_destroy(&s->request_mutex); qemu_cond_destroy(&s->archip_cond); qemu_mutex_destroy(&s->archip_mutex); targetlen = strlen(s->volname); req = xseg_get_request(s->xseg, s->srcport, s->vportno, X_ALLOC); if (!req) { archipelagolog("Cannot get XSEG request\n"); goto err_exit; } r = xseg_prep_request(s->xseg, req, targetlen, 0); if (r < 0) { xseg_put_request(s->xseg, req, s->srcport); archipelagolog("Cannot prepare XSEG close request\n"); goto err_exit; } target = xseg_get_target(s->xseg, req); memcpy(target, s->volname, targetlen); req->size = req->datalen; req->offset = 0; req->op = X_CLOSE; xport p = xseg_submit(s->xseg, req, s->srcport, X_ALLOC); if (p == NoPort) { xseg_put_request(s->xseg, req, s->srcport); archipelagolog("Cannot submit XSEG close request\n"); goto err_exit; } xseg_signal(s->xseg, p); wait_reply(s->xseg, s->srcport, s->port, req); xseg_put_request(s->xseg, req, s->srcport); err_exit: g_free(s->volname); g_free(s->segment_name); xseg_quit_local_signal(s->xseg, s->srcport); xseg_leave_dynport(s->xseg, s->port); xseg_leave(s->xseg); }
void receiving(void) { int expecting_len = 0; sending(expecting_len); while (1) { PRINT("%s: Waiting packet\n", __func__); if (wait_reply(__func__, unicast, ipsum_len, expecting)) { if (expecting_len > 0) { PRINT("Resend %d bytes -> FAIL\n", ipsum_len - expecting); expecting_len = 0; } else { PRINT("Waiting %d bytes -> resending\n", ipsum_len - expecting); expecting_len = expecting; } } sending(expecting_len); } }
/*********************************************************************** * wine_server_call (NTDLL.@) * * Perform a server call. * * PARAMS * req_ptr [I/O] Function dependent data * * RETURNS * Depends on server function being called, but usually an NTSTATUS code. * * NOTES * Use the SERVER_START_REQ and SERVER_END_REQ to help you fill out the * server request structure for the particular call. E.g: *| SERVER_START_REQ( event_op ) *| { *| req->handle = handle; *| req->op = SET_EVENT; *| ret = wine_server_call( req ); *| } *| SERVER_END_REQ; */ unsigned int wine_server_call( void *req_ptr ) { struct __server_request_info * const req = req_ptr; sigset_t old_set; unsigned int ret; pthread_functions.sigprocmask( SIG_BLOCK, &server_block_set, &old_set ); ret = send_request( req ); if (!ret) ret = wait_reply( req ); pthread_functions.sigprocmask( SIG_SETMASK, &old_set, NULL ); return ret; }
int toc_wait_signon() { /* Wait for the SIGNON to be approved */ char buf[BUF_LEN]; int res; res = wait_reply(buf, sizeof(buf)); if (res < 0) return res; if (state != STATE_SIGNON_ACK) { toc_debug_printf("State should be %d, but is %d instead\n",STATE_SIGNON_ACK, state); return -1; } return 0; }
void receiving(void) { sending(); while (1) { PRINT("%s: Waiting packet\n", __func__); if (wait_reply(__func__, unicast, ipsum_len, expecting)) { PRINT("Waiting %d bytes -> FAIL\n", ipsum_len - expecting); } sending(); } }
int fping_monitor(int sfd) { int err = 0; if (sfd < 0) return sfd; /* try to ping existing socket */ if (ack(sfd, 20) != 0) err = -1; /* check the reply */ if (!err && wait_reply(sfd, 20) != 0) err = -1; return err; }
/* give the manager a chance to view the updated container state. This * would naturally happen due to the manager noticing a change in * /proc/mdstat; however, pinging encourages this detection to happen * while an exclusive open() on the container is active */ int ping_manager(char *devname) { int sfd = connect_monitor(devname); struct metadata_update msg = { .len = -1 }; int err = 0; if (sfd < 0) return sfd; err = send_message(sfd, &msg, 20); /* check the reply */ if (!err && wait_reply(sfd, 20) != 0) err = -1; close(sfd); return err; }
int toc_signon(char *username, char *password) { char buf[BUF_LONG]; int res; struct signon so; toc_debug_printf("State = %d\n", state); strncpy(aim_username, username, sizeof(aim_username)); if ((res = write(toc_fd, FLAPON, strlen(FLAPON))) < 0) return res; /* Wait for signon packet */ state = STATE_FLAPON; if ((res = wait_reply(buf, sizeof(buf)) < 0)) return res; if (state != STATE_SIGNON_REQUEST) { toc_debug_printf( "State should be %d, but is %d instead\n", STATE_SIGNON_REQUEST, state); return -1; } /* Compose a response */ snprintf(so.username, sizeof(so.username), "%s", username); so.ver = ntohl(1); so.tag = ntohs(1); so.namelen = htons(strlen(so.username)); sflap_send((char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON); snprintf(buf, sizeof(buf), "toc_signon %s %d %s %s %s \"%s\"", login_host, login_port, normalize(username), roast_password(password), LANGUAGE, REVISION); toc_debug_printf("Send: %s\n", buf); return sflap_send(buf, -1, TYPE_DATA); }
static int qemu_archipelago_create_volume(Error **errp, const char *volname, char *segment_name, uint64_t size, xport mportno, xport vportno) { int ret, targetlen; struct xseg *xseg = NULL; struct xseg_request *req; struct xseg_request_clone *xclone; struct xseg_port *port; xport srcport = NoPort, sport = NoPort; char *target; /* Try default values if none has been set */ if (mportno == (xport) -1) { mportno = ARCHIPELAGO_DFL_MPORT; } if (vportno == (xport) -1) { vportno = ARCHIPELAGO_DFL_VPORT; } if (xseg_initialize()) { error_setg(errp, "Cannot initialize XSEG"); return -1; } xseg = xseg_join("posix", segment_name, "posixfd", NULL); if (!xseg) { error_setg(errp, "Cannot join XSEG shared memory segment"); return -1; } port = xseg_bind_dynport(xseg); srcport = port->portno; init_local_signal(xseg, sport, srcport); req = xseg_get_request(xseg, srcport, mportno, X_ALLOC); if (!req) { error_setg(errp, "Cannot get XSEG request"); return -1; } targetlen = strlen(volname); ret = xseg_prep_request(xseg, req, targetlen, sizeof(struct xseg_request_clone)); if (ret < 0) { error_setg(errp, "Cannot prepare XSEG request"); goto err_exit; } target = xseg_get_target(xseg, req); if (!target) { error_setg(errp, "Cannot get XSEG target.\n"); goto err_exit; } memcpy(target, volname, targetlen); xclone = (struct xseg_request_clone *) xseg_get_data(xseg, req); memset(xclone->target, 0 , XSEG_MAX_TARGETLEN); xclone->targetlen = 0; xclone->size = size; req->offset = 0; req->size = req->datalen; req->op = X_CLONE; xport p = xseg_submit(xseg, req, srcport, X_ALLOC); if (p == NoPort) { error_setg(errp, "Could not submit XSEG request"); goto err_exit; } xseg_signal(xseg, p); ret = wait_reply(xseg, srcport, port, req); if (ret < 0) { error_setg(errp, "wait_reply() error."); } xseg_put_request(xseg, req, srcport); xseg_quit_local_signal(xseg, srcport); xseg_leave_dynport(xseg, port); xseg_leave(xseg); return ret; err_exit: xseg_put_request(xseg, req, srcport); xseg_quit_local_signal(xseg, srcport); xseg_leave_dynport(xseg, port); xseg_leave(xseg); return -1; }
int toc_callback(int fd) { char *buf; char *c; char **args = NULL; char *dup,*raw; char *l; int numargs =0; buf = malloc(BUF_LONG); if (wait_reply(buf, BUF_LONG) < 0) { toc_signoff(); toc_debug_printf("need to do proper sign off on this\n"); toc_msg_printf(TOC_CONNECT_MSGS,"Connection Closed"); return -1; } dup = strdup(buf+sizeof(struct sflap_hdr)); raw = rindex(dup,':'); c=strtok(buf+sizeof(struct sflap_hdr),":"); /* Ditch the first part */ if (!strcasecmp(c,"UPDATE_BUDDY")) { char *uc, *t; int logged, evil, idle, type = 0; long signon; time_t time_idle; numargs = 7; args = (char **) malloc(sizeof(char *)*numargs); use_handler(TOC_RAW_HANDLE,TOC_UPDATE_BUDDY,raw); c = strtok(NULL,":"); /* c is name */ args[0] = strdup(c); l = strtok(NULL,":"); /* l is T/F logged status */ args[1] = strdup(l); t = strtok(NULL, ":"); args[2] = strdup(t); sscanf(t, "%d", &evil); t = strtok(NULL, ":"); args[3] = strdup(t); sscanf(t, "%ld", &signon); t = strtok(NULL, ":"); args[4] = strdup(t); sscanf(t, "%d", &idle); uc = strtok(NULL, ":"); args[5] = strdup(uc); if (!strncasecmp(l,"T",1)) logged = 1; else logged = 0; if (uc[0] == 'A') type |= UC_AOL; switch(uc[1]) { case 'A': type |= UC_ADMIN; break; case 'U': type |= UC_UNCONFIRMED; break; case 'O': type |= UC_NORMAL; break; default: break; } switch(uc[2]) { case 'U': type |= UC_UNAVAILABLE; break; default: break; } if (idle) { time(&time_idle); time_idle -= idle*60; } else time_idle = 0; serv_got_update(c, logged, evil, signon, time_idle, type); args[6] = NULL; use_handler(TOC_HANDLE,TOC_UPDATE_BUDDY,args); } else if (!strcasecmp(c, "ERROR")) { use_handler(TOC_RAW_HANDLE,TOC_ERROR,raw); c = strtok(NULL,":"); translate_toc_error_code(c); args = (char **) malloc(sizeof(char *)*1 + 1); numargs = 1; args[0] = strdup(c); use_handler(TOC_HANDLE,TOC_ERROR,args); toc_debug_printf("ERROR: %s",c); } else if (!strcasecmp(c, "NICK")) { use_handler(TOC_RAW_HANDLE,TOC_NICK,raw); c = strtok(NULL,":"); snprintf(aim_username, sizeof(aim_username), "%s", c); numargs = 2; args = (char **) malloc(sizeof(char *)*numargs); args[0] = strdup(c); args[1] = NULL; use_handler(TOC_HANDLE,TOC_NICK,args); } else if (!strcasecmp(c, "IM_IN")) { char *away, *message; int a = 0; use_handler(TOC_RAW_HANDLE,TOC_IM_IN,raw); c = strtok(NULL,":"); away = strtok(NULL,":"); message = away; while(*message && (*message != ':')) message++; message++; if (!strncasecmp(away, "T", 1)) a = 1; if ( serv_got_im(c, message,a) > 0 ) { numargs = 3; args = (char **) malloc(sizeof(char *)*numargs); args[0] = strdup(c); args[1] = strdup(message); args[2] = NULL; use_handler(TOC_HANDLE,TOC_IM_IN,args); } } else if (!strcasecmp(c, "GOTO_URL")) { char *name; char *url; char tmp[256]; use_handler(TOC_RAW_HANDLE,TOC_GOTO_URL,raw); name = strtok(NULL, ":"); url = strtok(NULL, ":"); snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url); /* fprintf(stdout, "Name: %s\n%s\n", name, url); printf("%s", grab_url(tmp));*/ numargs = 2; args = (char **) malloc(sizeof(char *)*numargs); args[0] = strdup(tmp); args[1] = NULL; use_handler(TOC_HANDLE,TOC_GOTO_URL,args); /* statusprintf("GOTO_URL: %s","tmp"); */ } else if (!strcasecmp(c, "EVILED")) { int lev; char *name = NULL; char *levc; use_handler(TOC_RAW_HANDLE,TOC_EVILED,raw); levc = strtok(NULL, ":"); sscanf(levc, "%d", &lev); name = strtok(NULL, ":"); toc_debug_printf("evil: %s | %d\n", name, lev); numargs = 3; my_evil = lev; args = (char **) malloc(sizeof(char *)*numargs); if ( name != NULL ) args[0] = strdup(name); else args[0] = NULL; args[1] = strdup(levc); args[2] = NULL; use_handler(TOC_HANDLE,TOC_EVILED,args); } else if (!strcasecmp(c, "CHAT_JOIN")) { char *name,*idc; int id; use_handler(TOC_RAW_HANDLE,TOC_CHAT_JOIN,raw); idc = strtok(NULL, ":"); sscanf(idc, "%d", &id); name = strtok(NULL, ":"); serv_got_joined_chat(id, name); numargs = 3; args = (char **) malloc(sizeof(char *)*numargs); args[0] = strdup(idc); args[1] = strdup(name); args[2] = NULL; use_handler(TOC_HANDLE,TOC_CHAT_JOIN,args); } else if (!strcasecmp(c, "DIR_STATUS")) { char *status; use_handler(TOC_RAW_HANDLE,TOC_DIR_STATUS,raw); status = strtok(NULL,":"); numargs = 2; args = (char **) malloc(sizeof(char *)*numargs); args[0] = strdup(status); args[1] = NULL; use_handler(TOC_HANDLE,TOC_DIR_STATUS,args); } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) { int id; char *in,*idc; char *buddy; LLE t; struct buddy_chat *b = NULL; use_handler(TOC_RAW_HANDLE,TOC_CHAT_UPDATE_BUDDY,raw); idc = strtok(NULL, ":"); sscanf(idc, "%d", &id); in = strtok(NULL, ":"); for ( TLL(buddy_chats,t) ) { b = (struct buddy_chat *)t->data; if (id == b->id) break; b = NULL; } if (!b) return -2; if (!strcasecmp(in, "T")) { while((buddy = strtok(NULL, ":")) != NULL) { /* * Fuxin aim causes a problem here */ AddToLL(b->in_room, buddy,NULL); if ( b->init_chat ) { args = (char **) malloc(sizeof(char *)*3); args[0] = strdup(b->name); args[1] = strdup(buddy); args[2] = NULL; use_handler(TOC_HANDLE,TOC_BUDDY_JOIN_CHAT,args); free(args[0]); free(args[1]); free(args); args = NULL; } } /* * init_chat is so that the user doenst get flooded * with user joined chat when he first joins a chat */ b->init_chat = 1; } else { while((buddy = strtok(NULL, ":")) != NULL) { RemoveFromLLByKey(b->in_room, buddy); /* * Since we might get multiple leave/joins at once * we allocate & deallocate here */ args = (char **) malloc(sizeof(char *)*3); args[0] = strdup(b->name); args[1] = strdup(buddy); args[2] = NULL; use_handler(TOC_HANDLE,TOC_BUDDY_LEFT_CHAT,args); free(args[0]); free(args[1]); free(args); args = NULL; } } } else if (!strcasecmp(c, "CHAT_LEFT")) {