void adc_msg_free(struct adc_message* msg) { if (!msg) return; ADC_MSG_ASSERT(msg); msg->references--; if (msg->references == 0) { #ifdef ADC_MSG_NULL_ON_FREE if (msg->cache) { *msg->cache = 0; } #endif msg_free(msg->cache); if (msg->feature_cast_include) { list_clear(msg->feature_cast_include, &hub_free); list_destroy(msg->feature_cast_include); msg->feature_cast_include = 0; } if (msg->feature_cast_exclude) { list_clear(msg->feature_cast_exclude, &hub_free); list_destroy(msg->feature_cast_exclude); msg->feature_cast_exclude = 0; } msg_free(msg); } }
static void check_unit_destroy(check_unit *cunit) { if (cunit->cdata != NULL) { cunit->cdata->finished_keys_count ++; if (cunit->cdata->finished_keys_count >= cunit->cdata->keys_count) { aeStop(cunit->cdata->loop); } } if (cunit->key != NULL) { sdsfree(cunit->key); cunit->key = NULL; } if (cunit->result1 != NULL) { msg_put(cunit->result1); msg_free(cunit->result1); cunit->result1 = NULL; } if (cunit->result2 != NULL) { msg_put(cunit->result2); msg_free(cunit->result2); cunit->result2 = NULL; } rmt_free(cunit); }
struct msg * msg_get(mbuf_base *mb, int request, int kind) { struct msg *msg; if (mb == NULL) { return NULL; } msg = _msg_get(); if (msg == NULL) { return NULL; } msg->mb = mb; msg->request = request ? 1 : 0; if (request) { if (kind == REDIS_DATA_TYPE_RDB) { msg->parser = redis_parse_req_rdb; } else if(kind == REDIS_DATA_TYPE_CMD) { msg->parser = redis_parse_req; } else { msg_put(msg); msg_free(msg); return NULL; } msg->kind = kind; } else { msg->parser = redis_parse_rsp; } msg->data = listCreate(); if (msg->data == NULL) { msg_put(msg); msg_free(msg); return NULL; } if (request) { msg->request = 1; } else { msg->request = 0; } msg->fragment = redis_fragment; msg->reply = redis_reply; msg->pre_coalesce = redis_pre_coalesce; msg->post_coalesce = redis_post_coalesce; msg->resp_check = redis_response_check; log_debug(LOG_VVERB, "get msg %p id %"PRIu64" request %d", msg, msg->id, msg->request); return msg; }
static void *rtsp_conversation_thread_func(void *pconn) { // SIGUSR1 is used to interrupt this thread if blocked for read sigset_t set; sigemptyset(&set); sigaddset(&set, SIGUSR1); pthread_sigmask(SIG_UNBLOCK, &set, NULL); rtsp_conn_info *conn = pconn; rtsp_message *req, *resp; char *hdr, *auth_nonce = NULL; while ((req = rtsp_read_request(conn->fd))) { resp = msg_init(); resp->respcode = 400; apple_challenge(conn->fd, req, resp); hdr = msg_get_header(req, "CSeq"); if (hdr) msg_add_header(resp, "CSeq", hdr); msg_add_header(resp, "Audio-Jack-Status", "connected; type=analog"); if (rtsp_auth(&auth_nonce, req, resp)) goto respond; struct method_handler *mh; for (mh=method_handlers; mh->method; mh++) { if (!strcmp(mh->method, req->method)) { mh->handler(conn, req, resp); break; } } respond: msg_write_response(conn->fd, resp); msg_free(req); msg_free(resp); } debug(1, "closing RTSP connection\n"); if (conn->fd > 0) close(conn->fd); if (rtsp_playing()) { rtp_shutdown(); debug(1, "stop player\n"); player_stop(); debug(1, "player stoped\n"); please_shutdown = 0; pthread_mutex_unlock(&playing_mutex); } if (auth_nonce) free(auth_nonce); conn->running = 0; debug(2, "terminating RTSP thread\n"); return NULL; }
void* fetch_thread(void* prm) { msg_queue_t* q = prm; char name[0x100]; msg_t* m; while(!terminate) { sleep(1); if(!(m = msg_queue_fetch_wait(q, 1))) { printf("msg_queue_errno() = %s\n", msg_queue_errno2str(msg_queue_errno())); continue; } /* safety copying string */ strncpy(name, m->payload, sizeof(name) - 1); name[sizeof(name) - 1] = 0; puts(name); msg_free(m); } return(NULL); }
void msg_release(struct message *msg) { assert(msg->refcount > 0); if (--msg->refcount > 0) return; msg_free(msg); }
/** * send a message to the ShMM * */ void bmc_make_request(unsigned char netfn, unsigned char cmd, unsigned char *data, unsigned char datalen) { ipmbMSG_t *request; if (!(request = msg_malloc())) { uart_printf("ERR: %s: Not enough memory for request msg.\n", __func__); return; } request->rsSA = 0x20; request->rqSA = global_data.bmc_ipmb_addr; request->rsLUN = event_receiver_lun; request->rqSeq = get_seq_counter(); request->rqLUN = 0; request->orig_channel = MSG_CHANNEL_BMC; request->dest_channel = MSG_CHANNEL_IPMB0; request->cmd = cmd; request->netFN = netfn; request->data_len = datalen; memcpy(request->data, data, datalen); if (xQueueSend(msg_hub_rx_queue, &request, QUEUE_BLOCK_10) != pdPASS) { uart_printf("ERR: %s: msg_hub_rx_queue full\n", __func__); mon_queues |= MON_QUEUE_MSG_HUB_RX; msg_free(request); } }
/** * iucvtty_tx_termenv() - Send terminal environment variable * @dest: File descriptor to output data * @dflt: TERM environment string ('\0' terminated) * * Copy terminal environment variable to destination @dest. */ int iucvtty_tx_termenv(int dest, char *dflt) { struct iucvtty_msg *msg; char *term = getenv("TERM"); size_t len; int rc; if (term == NULL && dflt != NULL) term = dflt; len = 0; if (term != NULL) len = 1 + strlen(term); /* Note: The server console tool waits for terminal environment * information: the message is sent even if it is empty */ msg = msg_alloc(MSG_TYPE_TERMENV, len); if (msg == NULL) return -1; msg_cpy_from(msg, term, len); rc = iucvtty_write_msg(dest, msg); msg_free(msg); return rc; }
// send the sync complete message errlHndl_t AttributeSync::sendSyncCompleteMessage( ) { TARG_INF("sending sync complete message"); errlHndl_t l_err = NULL; msg_t * msg = msg_allocate(); // initialize msg buffer memset( msg, 0, sizeof(msg_t) ); msg->type = ATTR_SYNC_COMPLETE_TO_FSP; ATTR_SYNC_ADD_PAGE_COUNT( iv_total_pages, msg->data[0] ); l_err = sendMboxMessage( SYNCHRONOUS, msg ); if( l_err == NULL ) { // see if there was an error on the other end ATTR_SYNC_RC return_code = ATTR_SYNC_GET_RC( msg->data[0] ); if ( return_code ) { TARG_ERR("Attribute sync failed with return code: 0x%x", return_code ); TARG_ERR("Failed syncing iv_total_pages: 0x%x from iv_section_to_sync: 0x%x", iv_total_pages,iv_section_to_sync ); /*@ * @errortype * @moduleid TARG_MOD_ATTR_SYNC * @reasoncode TARG_RC_ATTR_SYNC_TO_FSP_FAIL * @userdata1 return code from FSP attribute sync * @userdata2[0:31] page count for this section * @userdata2[31:63] section ID of for section being sync'd * * @devdesc The attribute synchronization code on the * FSP side was unable to complete the sync * operation successfully. * * @custdesc A problem occurred during the IPL of the * system: Attributes were not fully * syncronized between the host firmware and * service processor. * */ l_err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE, TARG_MOD_ATTR_SYNC, TARG_RC_ATTR_SYNC_TO_FSP_FAIL, return_code, TWO_UINT32_TO_UINT64( iv_total_pages,iv_section_to_sync)); } } // for a syncronous message we need to free the message msg_free( msg ); return l_err; }
static int adc_msg_grow(struct adc_message* msg, size_t size) { char* buf; size_t newsize = 0; if (!msg) return 0; if (msg->capacity > size) return 1; /* Make sure we align our data */ newsize = size; newsize += 2; /* termination */ newsize += (newsize % sizeof(size_t)); /* alignment padding */ buf = msg_malloc_zero(newsize); if (!buf) return 0; if (msg->cache) { memcpy(buf, msg->cache, msg->length); msg_free(msg->cache); } msg->cache = buf; msg->capacity = newsize; return 1; }
int wlan_tx(txfifo_t *tx_fifo, msg_q_t *msg_q, int cnt) { int tx_cnt, i, ret; tx_msg_t *msg; tx_cnt = 0; for (i = 0; i < cnt; i++) { msg = msg_get(msg_q); if (NULL == msg) { break; } ret = tx_fifo_in(tx_fifo, msg); if (TX_FIFO_FULL == ret) { ret = TX_FIFO_FULL; break; } trans_up(); if (HOST_SC2331_CMD == msg->hdr.type) { if ((msg->slice[0].len > 0) && (NULL != msg->slice[0].data)) kfree(msg->slice[0].data); } else if (HOST_SC2331_PKT == msg->hdr.type) { if ((NULL != msg->p)) dev_kfree_skb((struct sk_buff *)(msg->p)); } else { } memset((unsigned char *)msg, 0, sizeof(tx_msg_t)); msg_free(msg_q, msg); tx_cnt++; } return tx_cnt ? tx_cnt : ret; }
int main(int argc, char ** argv) { int num_src_drivers = 10; int num_target_drivers = 32; if (argc != 4) usage(); { char * src_path = argv[1] ; char * target_path = argv[2] ; char * dir = argv[3] ; util_make_path( target_path ); if (util_same_file( src_path , target_path)) { fprintf(stderr,"The two directories:%s and %s point to the same location \n" , src_path , target_path ); exit(1); } { char * src_case = util_alloc_sprintf("%s/%s" , src_path , dir ); char * target_case = util_alloc_sprintf("%s/%s" , target_path , dir ); msg_type * msg = msg_alloc("Copying from: " , false); msg_show( msg ); migrate_file(src_case , num_src_drivers , target_case , num_target_drivers , "ANALYZED" , 32 , msg); migrate_file(src_case , num_src_drivers , target_case , num_target_drivers , "FORECAST" , 32 , msg); migrate_file(src_case , num_src_drivers , target_case , num_target_drivers , "PARAMETER" , 32 , msg); migrate_file(src_case , num_src_drivers , target_case , num_target_drivers , "STATIC" , 32 , msg); copy_index( src_case , target_case ); free( src_case); free( target_case ); msg_free( msg , true ); } } }
// send a request to FSP to sync to Hostboot errlHndl_t AttributeSync::sendSyncToHBRequestMessage() { TARG_INF( ENTER_MRK "AttributeSync::sendSyncToHBRequestMessage" ); errlHndl_t l_err = NULL; // allocate message buffer // buffer will be initialized to zero by msg_allocate() msg_t * l_pMsg = msg_allocate(); l_pMsg->type = ATTR_SYNC_REQUEST_TO_HB; ATTR_SYNC_ADD_SECTION_ID( iv_section_to_sync, l_pMsg->data[0] ); l_err = sendMboxMessage( SYNCHRONOUS, l_pMsg ); if( l_err == NULL ) { // see if there was an error on the other end ATTR_SYNC_RC return_code = ATTR_SYNC_GET_RC( l_pMsg->data[0] ); if ( return_code ) { TARG_ERR( "rc 0x%x received from FSP for Sync to HB request", return_code ); /*@ * @errortype * @moduleid TARG_MOD_ATTR_SYNC * @reasoncode TARG_RC_ATTR_SYNC_REQUEST_TO_HB_FAIL * @userdata1 return code from FSP * @userdata2 section to sync * @devdesc The attribute synchronization code on the * FSP side was unable to fulfill the sync to * HostBoot request. */ l_err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE, TARG_MOD_ATTR_SYNC, TARG_RC_ATTR_SYNC_REQUEST_TO_HB_FAIL, return_code, iv_section_to_sync); } } else { TARG_ERR( "Failed to send request to FSP to sync section type %u " "to Hostboot.", iv_section_to_sync ); } // for a syncronous message we need to free the message msg_free( l_pMsg ); l_pMsg = NULL; TARG_INF( EXIT_MRK "AttributeSync::sendSyncToHBRequestMessage" ); return l_err; }
void misfit_ensemble_initialize( misfit_ensemble_type * misfit_ensemble , const ensemble_config_type * ensemble_config , const enkf_obs_type * enkf_obs , enkf_fs_type * fs , int ens_size , int history_length, bool force_init) { if (force_init || !misfit_ensemble->initialized) { misfit_ensemble_clear( misfit_ensemble ); msg_type * msg = msg_alloc("Evaluating misfit for observation: " , false); double ** chi2_work = __2d_malloc( history_length + 1 , ens_size ); bool_vector_type * iens_valid = bool_vector_alloc( ens_size , true ); hash_iter_type * obs_iter = enkf_obs_alloc_iter( enkf_obs ); const char * obs_key = hash_iter_get_next_key( obs_iter ); misfit_ensemble->history_length = history_length; misfit_ensemble_set_ens_size( misfit_ensemble , ens_size ); msg_show( msg ); while (obs_key != NULL) { obs_vector_type * obs_vector = enkf_obs_get_vector( enkf_obs , obs_key ); msg_update( msg , obs_key ); bool_vector_reset( iens_valid ); bool_vector_iset( iens_valid , ens_size - 1 , true ); obs_vector_ensemble_chi2( obs_vector , fs , iens_valid , 0 , misfit_ensemble->history_length, 0 , ens_size , chi2_work); /** Internalizing the results from the chi2_work table into the misfit structure. */ for (int iens = 0; iens < ens_size; iens++) { misfit_member_type * node = misfit_ensemble_iget_member( misfit_ensemble , iens ); if (bool_vector_iget( iens_valid , iens)) misfit_member_update( node , obs_key , misfit_ensemble->history_length , iens , (const double **) chi2_work); } obs_key = hash_iter_get_next_key( obs_iter ); } bool_vector_free( iens_valid ); msg_free(msg , true ); hash_iter_free( obs_iter ); __2d_free( chi2_work , misfit_ensemble->history_length + 1); misfit_ensemble->initialized = true; } }
static int msg_handle_line(rtsp_message **pmsg, char *line) { rtsp_message *msg = *pmsg; if (!msg) { msg = msg_init(); *pmsg = msg; char *sp, *p; debug(1, "received request: %s\n", line); p = strtok_r(line, " ", &sp); if (!p) goto fail; strncpy(msg->method, p, sizeof(msg->method)-1); p = strtok_r(NULL, " ", &sp); if (!p) goto fail; p = strtok_r(NULL, " ", &sp); if (!p) goto fail; if (strcmp(p, "RTSP/1.0")) goto fail; return -1; } if (strlen(line)) { char *p; p = strstr(line, ": "); if (!p) { warn("bad header: >>%s<<", line); goto fail; } *p = 0; p += 2; msg_add_header(msg, line, p); debug(2, " %s: %s\n", line, p); return -1; } else { char *cl = msg_get_header(msg, "Content-Length"); if (cl) return atoi(cl); else return 0; } fail: *pmsg = NULL; msg_free(msg); return 0; }
void* consoleDaemon(void* unused) { // Detach and register daemon with shutdown path. task_detach(); INITSERVICE::registerShutdownEvent(g_msgq, SYNC, INITSERVICE::CONSOLE_PRIORITY); // Create a default output UART device if there isn't already one. // - Some devices are registered via the CONSOLE_UART_DEFINE_DEVICE // macro and therefore don't need this. if (NULL == Uart::g_device) { Uart::g_device = new Uart(); Uart::g_device->initialize(); } while(1) { msg_t* msg = msg_wait(g_msgq); switch (msg->type) { case DISPLAY: { if (NULL != msg->extra_data) { char timestamp[11]; sprintf(timestamp, "%3d.%05d|", msg->data[0], // 5 Digits worth of ns. (msg->data[1]*100000)/NS_PER_SEC); _display(timestamp); _display( static_cast<const char*>(msg->extra_data)); free(msg->extra_data); } msg_free(msg); break; } case SYNC: { msg_respond(g_msgq, msg); break; } } } return NULL; }
/** * iucvtty_tx_error() - Send an error code * @dest: Destination * @errCode: Error code */ int iucvtty_tx_error(int dest, uint32_t errCode) { struct iucvtty_msg *msg; int rc; msg = msg_alloc(MSG_TYPE_ERROR, sizeof(errCode)); if (msg == NULL) return -1; msg_cpy_from(msg, &errCode, sizeof(errCode)); rc = iucvtty_write_msg(dest, msg); msg_free(msg); return rc; }
/** * iucvtty_tx_winsize() - Send terminal window size information. * @dest: Destination * @from: Terminal file descriptor to request winsize * * Sends the terminal window size from terminal file descriptor * @from to the destination @dest. * If the window size is not retrieved, the routine will not fail. * The routine fails if there is a problem sending the window size * to @dest. The return codes are specified by iucvtty_write_msg(). */ int iucvtty_tx_winsize(int dest, int from) { int rc; struct iucvtty_msg *msg = msg_alloc(MSG_TYPE_WINSIZE, sizeof(struct winsize)); if (msg == NULL) return -1; rc = 0; if (ioctl(from, TIOCGWINSZ, msg->data) > -1) rc = iucvtty_write_msg(dest, msg); msg_free(msg); return rc; }
// send the sync complete message errlHndl_t AttributeSync::sendSyncCompleteMessage( ) { TRACFCOMP(g_trac_targeting, "sending sync complete message"); errlHndl_t l_err = NULL; msg_t * msg = msg_allocate(); // initialize msg buffer memset( msg, 0, sizeof(msg_t) ); msg->type = ATTR_SYNC_COMPLETE_TO_FSP; ATTR_SYNC_ADD_PAGE_COUNT( iv_total_pages, msg->data[0] ); l_err = sendMboxMessage( SYNCHRONOUS, msg ); if( l_err == NULL ) { // see if there was an error on the other end ATTR_SYNC_RC return_code = ATTR_SYNC_GET_RC( msg->data[0] ); if ( return_code ) { TRACFCOMP(g_trac_targeting, "return code: 0x%x", return_code ); /*@ * @errortype * @moduleid TARG_MOD_ATTR_SYNC * @reasoncode TARG_RC_ATTR_SYNC_TO_FSP_FAIL * @userdata1 return code from FSP attribute sync * @userdata2 section ID of for section being sync'd * * @devdesc The Attribute synchronization code on the * FSP side was unable to complete the sync * operation successfully. */ l_err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE, TARG_MOD_ATTR_SYNC, TARG_RC_ATTR_SYNC_TO_FSP_FAIL, return_code, (uint64_t)iv_section_to_sync); } } // for a syncronous message we need to free the message msg_free( msg ); return l_err; }
/////////////////////////////////////////////////////////////////////////////// // ErrlManager::sendErrLogToFSP() /////////////////////////////////////////////////////////////////////////////// void ErrlManager::sendErrLogToFSP ( errlHndl_t& io_err ) { msg_t *msg = NULL; TRACFCOMP( g_trac_errl, ENTER_MRK"ErrlManager::sendErrLogToFSP" ); do { //Create a mailbox message to send to FSP msg = msg_allocate(); msg->type = ERRLOG_SEND_TO_FSP_TYPE; uint32_t l_msgSize = io_err->flattenedSize(); //Data[0] will be hostboot error log ID so Hostboot can //keep track of the error log when FSP responses back. msg->data[0] = io_err->eid(); msg->data[1] = l_msgSize; void * temp_buff = MBOX::allocate( l_msgSize ); io_err->flatten ( temp_buff, l_msgSize ); msg->extra_data = temp_buff; TRACDCOMP( g_trac_errl, INFO_MRK"Send msg to FSP for errlogId %.8x", io_err->eid() ); errlHndl_t l_err = MBOX::send( MBOX::FSP_ERROR_MSGQ, msg ); if( !l_err ) { // clear this - we're done with the message; // the receiver will free the storage when it's done msg = NULL; } else { TRACFCOMP(g_trac_errl, ERR_MRK"Failed sending error log to FSP"); //Free the extra data due to the error MBOX::deallocate( msg->extra_data ); msg_free( msg ); msg = NULL; delete l_err; l_err = NULL; } } while (0); TRACFCOMP( g_trac_errl, EXIT_MRK"ErrlManager::sendErrLogToFSP" ); } // sendErrLogToFSP
//@todo: RTC 119832 void IpmiSEL::execute(void) { //Mark as an independent daemon so if it crashes we terminate. task_detach(); // Register shutdown events with init service. // Done at the "end" of shutdown processesing. // This will flush out any IPMI messages which were sent as // part of the shutdown processing. We chose MBOX priority // as we don't want to accidentally get this message after // interrupt processing has stopped in case we need intr to // finish flushing the pipe. INITSERVICE::registerShutdownEvent(iv_msgQ, IPMISEL::MSG_STATE_SHUTDOWN, INITSERVICE::MBOX_PRIORITY); barrier_wait(&iv_sync_start); while(true) { msg_t* msg = msg_wait(iv_msgQ); const IPMISEL::msg_type msg_type = static_cast<IPMISEL::msg_type>(msg->type); // Invert the "default" by checking here. This allows the compiler // to warn us if the enum has an unhadled case but still catch // runtime errors where msg_type is set out of bounds. assert(msg_type <= IPMISEL::MSG_LAST_TYPE, "msg_type %d not handled", msg_type); switch(msg_type) { case IPMISEL::MSG_SEND_ESEL: IPMISEL::process_esel(msg); //done with msg msg_free(msg); break; case IPMISEL::MSG_STATE_SHUTDOWN: IPMI_TRAC(INFO_MRK "ipmisel shutdown event"); //Respond that we are done shutting down. msg_respond(iv_msgQ, msg); break; } } // while(1) IPMI_TRAC(EXIT_MRK "message loop"); return; } // execute
errlHndl_t Service::stop() { ATTN_SLOW("shutting down..."); mutex_lock(&iv_mutex); tid_t intrTask = iv_intrTask; tid_t prdTask = iv_prdTask; msg_q_t q = iv_intrTaskQ; iv_intrTask = 0; iv_prdTask = 0; mutex_unlock(&iv_mutex); if(intrTask) { errlHndl_t err = configureInterrupts(q, DOWN); if(err) { errlCommit(err, ATTN_COMP_ID); } msg_t * shutdownMsg = msg_allocate(); shutdownMsg->type = SHUTDOWN; msg_sendrecv(q, shutdownMsg); msg_free(shutdownMsg); task_wait_tid(intrTask, 0, 0); msg_q_destroy(q); } if(prdTask) { sync_cond_signal(&iv_cond); task_wait_tid(prdTask, 0, 0); } ATTN_SLOW("..shutdown complete"); return 0; }
int main(int argc , char ** argv) { install_SIGNALS(); if (argc < 4) usage(); { const char * src_mount = argv[1]; const char * target_mount = argv[2]; if (block_fs_is_mount(src_mount)) { const char * pattern = NULL; int iarg; for (iarg = 3; iarg < argc; iarg++) { if (argv[iarg][0] == '-') { /** OK - this is an option .. */ } else pattern = argv[iarg]; } { block_fs_type * src_fs = block_fs_mount(src_mount , 1 , 0 , 1 , 0 , false , true ); block_fs_type * target_fs = block_fs_mount(target_mount , 1 , 0 , 1 , 0 , false , false ); vector_type * files = block_fs_alloc_filelist( src_fs , pattern , NO_SORT , false ); buffer_type * buffer = buffer_alloc( 1024 ); { int i; msg_type * msg = msg_alloc("Copying :" , false); msg_show( msg ); for (i=0; i < vector_get_size( files ); i++) { const user_file_node_type * node = vector_iget_const( files , i ); const char * filename = user_file_node_get_filename( node ); msg_update( msg , filename ); block_fs_fread_realloc_buffer( src_fs , filename , buffer ); block_fs_fwrite_buffer( target_fs , filename , buffer ); } msg_free( msg , true ); } buffer_free( buffer ); vector_free( files ); block_fs_close( target_fs , true); block_fs_close( src_fs , false ); } } else fprintf(stderr,"The files:%s/%s does not seem to be a block_fs mount files.\n" , src_mount , target_mount); } }
static int wlan_tx_msg_q_free(wlan_vif_t *vif) { int q_id, num, i; msg_q_t *msg_q; tx_msg_t *msg; for (q_id = 0; q_id < 2; q_id++) { msg_q = &(vif->msg_q[q_id]); num = msg_num(msg_q); for (i = 0; i < num; i++) { msg = msg_get(msg_q); if (NULL == msg) break; msg_free(msg_q, msg); } msg_q_free(msg_q); } tx_fifo_free(&(vif->txfifo)); return OK; }
void Daemon::sendExtractBuffer(void* i_buffer, size_t i_size) { // Send buffer message. // We don't need to check for mailbox attributes or readiness // because we should only be sending this message if we were // requested to by the SP. msg_t* msg = msg_allocate(); msg->type = DaemonIf::TRACE_BUFFER; msg->data[1] = i_size; msg->extra_data = i_buffer; errlHndl_t l_errl = MBOX::send(MBOX::FSP_TRACE_MSGQ, msg); if (l_errl) { errlCommit(l_errl, TRACE_COMP_ID); MBOX::deallocate(i_buffer); msg_free(msg); } }
/** * iucvtty_rx_termenv() - Receive terminal environment variable * @fd: File descriptor to read data from * @buf: Buffer to store the terminal environment variable * @len: Size of buffer @buf */ int iucvtty_rx_termenv(int fd, void *buf, size_t len) { int rc; size_t skip; struct iucvtty_msg *msg = msg_alloc(MSG_TYPE_TERMENV, len); if (msg == NULL) return -1; skip = 0; rc = iucvtty_read_msg(fd, msg, msg_size(msg), &skip); iucvtty_skip_msg_residual(fd, &skip); if (!rc) { if (msg->datalen == 0) memset(buf, 0, min(1, len)); else msg_cpy_to(msg, buf, len); } msg_free(msg); return rc; }
message_t * msg_unpack(uint8_t * packed, uint32_t size) { uint32_t i = 0; uint8_t * pos = packed; message_t * newmsg = NULL; tlv_t * cur = NULL; uint16_t id = 0, length = 0, type = 0; int ret = 0; if ((NULL == packed) || (0 == size)) { return NULL; } if (MSG_MAGIC != ntohl(GET32(pos))) { return NULL; } ADVANCE32(pos); newmsg = msg_init(ntohl(GET32(pos))); if (NULL == newmsg) { return NULL; } ADVANCE32(pos); for (i = 0; i < (newmsg->capacity) && (pos - packed < size); i++) { id = ntohs(GET16(pos)); ADVANCE16(pos); type = ntohs(GET16(pos)); ADVANCE16(pos); length = ntohs(GET16(pos)); ADVANCE16(pos); cur = MSG_TLV(newmsg, i); ret = unpack_item(type, id, pos, length, cur); if (0 != ret) { msg_free(newmsg); return NULL; } pos += length; } newmsg->nitems = newmsg->capacity; return newmsg; }
void msg_free(message_t * msg) { uint32_t i = 0; tlv_t * cur = NULL; for (i = 0; i < msg->nitems; i++) { cur = MSG_TLV(msg, i); if (NULL == cur->value) { continue; } if (TLV_TYPE_MSG == cur->type) { msg_free((message_t *)(cur->value)); } else { free(cur->value); } } memset(msg, 0, sizeof(message_t) + msg->capacity * sizeof(tlv_t)); free(msg); }
void cm_init_power_status(unsigned char ipmbaddr) { ipmbMSG_t *message; /* allocate free message from global buffer */ if (!(message = msg_malloc())) { DEBUG_PRINTF((DEBUG_UART, "ERR: %s: not enough memory for CM Request\n", __func__)); return; /* discard */ } message->rsSA = ipmbaddr; message->cmd = CMD_GET_POWER_CHANNEL_STATUS; message->netFN = NETFN_PICMG_RQ; message->rsLUN = 0x00; message->rqSA = global_data.bmc_ipmb_addr; message->rqSeq = get_seq_counter(); message->rqLUN = 0; message->data_len = 3; message->data[0] = PICMG_IDENTIFIER; message->data[1] = 1; /* start at channel 1 */ message->data[2] = 16; /* 2 MCH, 2 CU and 12 AMC slots */ message->orig_channel = MSG_CHANNEL_CM; message->dest_channel = MSG_CHANNEL_IPMB0; /* forward request to msg_hub_rx_queue */ if (xQueueSend(msg_hub_rx_queue, &message, QUEUE_BLOCK_10) != pdPASS) { ERROR_PRINTF((DEBUG_UART, "ERR: %s: msg_hub_rx_queue full\n", __func__)); /* set error flag */ mon_queues |= MON_QUEUE_MSG_HUB_RX; /* purge response */ msg_free(message); } }
void* put_thread(void* prm) { msg_queue_t* q = prm; const char* name; msg_t* m; while(!terminate) { sleep(1); /* getting random name */ name = names[rand() % ARRAY_COUNT(names)]; if(!(m = msg_create(name, strlen(name) + 1))) continue; if(msg_queue_put(q, m)) { printf("msg_queue_errno() = %s\n", msg_queue_errno2str(msg_queue_errno())); msg_free(m); sleep(10); } } return(NULL); }