void input_manager::save() { write_to_file( FILENAMES["user_keybindings"], [&]( std::ostream & data_file ) { JsonOut jsout( data_file, true ); jsout.start_array(); for( t_action_contexts::const_iterator a = action_contexts.begin(); a != action_contexts.end(); ++a ) { const t_actions &actions = a->second; for( const auto &action : actions ) { const t_input_event_list &events = action.second.input_events; jsout.start_object(); jsout.member( "id", action.first ); jsout.member( "category", a->first ); bool is_user_created = action.second.is_user_created; if( is_user_created ) { jsout.member( "is_user_created", is_user_created ); } jsout.member( "bindings" ); jsout.start_array(); for( const auto &event : events ) { jsout.start_object(); switch( event.type ) { case CATA_INPUT_KEYBOARD: jsout.member( "input_method", "keyboard" ); break; case CATA_INPUT_GAMEPAD: jsout.member( "input_method", "gamepad" ); break; case CATA_INPUT_MOUSE: jsout.member( "input_method", "mouse" ); break; default: throw std::runtime_error( "unknown input_event_t" ); } jsout.member( "key" ); jsout.start_array(); for( size_t i = 0; i < event.sequence.size(); i++ ) { jsout.write( get_keyname( event.sequence[i], event.type, true ) ); } jsout.end_array(); jsout.end_object(); } jsout.end_array(); jsout.end_object(); } } jsout.end_array(); }, _( "key bindings configuration" ) ); }
int main() { int fd = 0; if ( -1 == (fd = open("test.log",O_APPEND | O_CREAT | O_RDWR ,0777)) ) { perror("open file failed."); } char * str = "teststring\n"; write_to_file(str,fd); return 0; }
int main(int argc, char *argv[]) { int ret; char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX]; char *mygroup_p, *script_pid_p, *test_num_p, *chunk_size_p; char *num_chunks_p; struct sigaction newaction1, newaction2, oldaction1, oldaction2; /* Capture variables from the script environment */ test_num_p = getenv("TEST_NUM"); mygroup_p = getenv("MYGROUP"); script_pid_p = getenv("SCRIPT_PID"); chunk_size_p = getenv("CHUNK_SIZE"); num_chunks_p = getenv("NUM_CHUNKS"); if (test_num_p != NULL && mygroup_p != NULL && script_pid_p != NULL && chunk_size_p != NULL && num_chunks_p != NULL) { scriptpid = atoi(script_pid_p); test_num = atoi(test_num_p); chunk_size = atoi(chunk_size_p); num_of_chunks = atoi(num_chunks_p); sprintf(mygroup,"%s", mygroup_p); } else { tst_brkm(TBROK, cleanup, "invalid parameters recieved from script\n"); } /* XXX (garrcoop): this section really needs error handling. */ /* Signal handling for SIGUSR1 recieved from script */ sigemptyset(&newaction1.sa_mask); newaction1.sa_handler = signal_handler_sigusr1; newaction1.sa_flags=0; sigaction(SIGUSR1, &newaction1, &oldaction1); /* Signal handling for SIGUSR2 recieved from script */ sigemptyset(&newaction2.sa_mask); newaction2.sa_handler = signal_handler_sigusr2; newaction2.sa_flags = 0; sigaction(SIGUSR2, &newaction2, &oldaction2); sprintf(mytaskfile, "%s", mygroup); strcat (mytaskfile,"/tasks"); /* Assign the task to it's group */ write_to_file (mytaskfile, "a", getpid()); /* Assign the task to it's group*/ ret = allocate_memory(); /*should i check ret?*/ cleanup(); tst_exit(); }
static void update_t_low(u32 t_low) { char buf[SIZE]; #ifdef DEBUG LOGD("update_t_low (%ld)\n", t_low); #endif sprintf(buf, "%ld\n", convert_hotspot_temp_to_omap_sensor_temp(OMAP_CPU, t_low)); write_to_file( config_file.omaptemp_file_paths[OMAP_CPU_THRESHOLD_LOW_PATH], buf); current_t_low = t_low; }
/* * The goal of this function is to update the setting of monitoring * rate only if this is required to avoid useless SYSFS accesses. */ static void update_omap_rate(u32 rate) { char buf[SIZE]; if (update_rate != rate) { sprintf(buf, "%ld\n", rate); write_to_file( config_file.omaptemp_file_paths[OMAP_CPU_UPDATE_RATE_PATH], buf); update_rate = rate; } }
int set_cpu_params(char *governor, char *min_freq, char *max_freq) { if (write_to_file(SYS_CGOV_C0, governor) != 0) return -1; if (write_to_file(SYS_CMAX_C0, max_freq) != 0) return -1; if (write_to_file(SYS_CMIN_C0, min_freq) != 0) return -1; write_to_file(SYS_CGOV_C1, governor); write_to_file(SYS_CMAX_C1, max_freq); write_to_file(SYS_CMIN_C1, min_freq); char buf[255]; buf[0] = 0; strcat(buf, "Setting CPU Params: Governor="); my_trim(governor); strcat(buf, governor); strcat(buf, " min_freq="); my_trim(min_freq); strcat(buf, min_freq); strcat(buf, " max_freq="); my_trim(max_freq); strcat(buf, max_freq); __android_log_write(ANDROID_LOG_INFO, APPNAME, buf); return 0; }
bool mod_manager::set_default_mods(const t_mod_list &mods) { default_mods = mods; return write_to_file( FILENAMES["mods-user-default"], [&]( std::ostream &fout ) { JsonOut json( fout, true ); // pretty-print json.start_object(); json.member("type", "MOD_INFO"); json.member("ident", "user:default"); json.member("dependencies"); json.write(mods); json.end_object(); }, _( "list of default mods" ) ); }
void file_cache_destroy(file_cache *cache){ while(cache){ if(cache->pin && cache->dirty){ // Search through each cache to check for dirty buffer. write_to_file(cache); #ifdef DEBUG printf("\n Successfully written to file %s \n",cache->filename); fflush(stdout); #endif /* DEBUG */ } strcpy(cache->buf,""); /*make the cache buffer empty for the nondirty node */ cache = cache->next; } }
static void fhopen_file(int num, struct fhb_handle *handle) { int fd; fd = fhb_fhopen(handle, O_RDWR); if (fd < 0) err(1, "open"); if (write_file) write_to_file(fd, write_file); close(fd); }
/** * closes a flow described by fd * if send_reply is non-zero, a response is sent to client's mapi stub, * (send_reply=0 is used for local clean-ups) */ static void cmd_close_flow(int fd, int pid, int sock, int send_reply) { struct flow *f; struct client *cl; struct mapiipcbuf buf; long file_size; f=(struct flow*)flist_get(flowlist, fd); if (f) { /* to avoid reading memory after it's freed */ int tmpfd = f->fd; /* prevent closing flows of other processes */ if (pid != f->id) { DEBUG_CMD(Debug_Message( "Proc %d tried to close flow %d, which belongs to proc %d", pid, f->fd, f->id)); report_error(MAPI_INVALID_FLOW, pid, sock); return; } cleanup_flow(f); while(__sync_lock_test_and_set(&clientlist_lock,1)); cl = flist_get(clientlist, pid); f = (struct flow *) flist_remove(cl->flowlist, fd); cl->numflows--; clientlist_lock = 0; //send an ACK that flow closed if (send_reply) { buf.mtype = pid; buf.cmd = CLOSE_FLOW_ACK; buf.fd = tmpfd; mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock); if (log_to_file) { file_size = acquire_write_lock(log_fd_info); write_to_file(log_fd_info, "MAPID: flow %d was closed at ", buf.fd); write_date(log_fd_info); write_newline(log_fd_info, "\n"); release_write_lock(log_fd_info, file_size); } if (log_to_syslog) log_message("flow %d was closed", buf.fd); } } else { report_error(MAPI_INVALID_FLOW, pid, sock); } }
/* * Enable the scsi disk for dumping * Return: 0 - ok * != 0 - error */ static int enable_zfcp_device(void) { char command[1024], file[1024]; struct stat s; /* device */ if (read_file(IPL_DEVNO, g.dump_devno, sizeof(g.dump_devno))) return -1; sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/online", g.dump_devno); if (write_to_file(file, "1\n")) return -1; /* wwpn */ if (read_file(IPL_WWPN, g.dump_wwpn, sizeof(g.dump_wwpn))) return -1; sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/port_add", g.dump_devno); /* The port_add attribute has been removed in recent kernels */ if (stat(file, &s) == 0) { sprintf(command, "%s\n", g.dump_wwpn); if (write_to_file(file, command)) return -1; } /* lun */ if (read_file(IPL_LUN, g.dump_lun, sizeof(g.dump_lun))) return -1; sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/%s/unit_add", g.dump_devno, g.dump_wwpn); sprintf(command, "%s\n", g.dump_lun); if (write_to_file(file, command)) return -1; /* bootprog */ read_file("/sys/firmware/ipl/bootprog", g.dump_bootprog, sizeof(g.dump_bootprog)); return 0; }
TEST_F(PNGReaderTest, ReadFile) { static constexpr unsigned int VALID_WIDTH = 2; static constexpr unsigned int VALID_HEIGHT = 2; static constexpr Color VALID_COLORS[VALID_HEIGHT][VALID_WIDTH] = {{Color::red(), Color::yellow()}, {Color::green(), Color::blue()}}; ScopedTempDir temp_dir; const std::string valid_path = temp_dir.path() / "valid.png"; write_to_file(valid_path, png_data()); Image image = PNGReader().read_file(valid_path); ASSERT_EQ(VALID_WIDTH, image.width()); ASSERT_EQ(VALID_HEIGHT, image.height()); for (unsigned int y = 0; y < VALID_HEIGHT; y++) { for (unsigned int x = 0; x < VALID_WIDTH; x++) { Color valid_color = VALID_COLORS[y][x]; Color color = image.read_pixel(x, y); EXPECT_NEAR(valid_color.r(), color.r(), 1e-100); EXPECT_NEAR(valid_color.g(), color.g(), 1e-100); EXPECT_NEAR(valid_color.b(), color.b(), 1e-100); } } const std::string corrupt_path = temp_dir.path() / "corrupt.png"; write_to_file(corrupt_path, corrupt_png_data()); EXPECT_THROW(PNGReader().read_file(corrupt_path), PNGReader::Exception); const std::string short_path = temp_dir.path() / "short.png"; write_to_file(short_path, short_png_data()); EXPECT_THROW(PNGReader().read_file(short_path), PNGReader::Exception); EXPECT_THROW(PNGReader().read_file(temp_dir.path() / "does_not_exist.png"), PNGReader::Exception); }
void ProtobufFileOutputService::execute() { bool wrote = false; for (auto& sensor : sensors_) { for (int i = 0; sensor->protobuf_file_fifo_is_empty() == false && i < MAX_READINGS_PER_STEP; i++) { wrote = true; write_to_file(sensor); } } if (!wrote) { std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); } }
int main(void) { I16 card, err; setbuf( stdout, NULL ); printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9812 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name); getch(); if ((card=Register_Card (PCI_9812, 0)) <0 ) { printf("Register_Card error=%d\n", card); exit(1); } err = AI_9812_Config(card, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH0, P9812_TRGSLP_POS, P9812_AD2_GT_PCI|P9812_CLKSRC_INT, 0x80, 0); if (err!=0) { printf("AI_9812_Config error=%d", err); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); exit(1); } mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); free( ai_buf ); Release_Card(card); exit(1); } printf(" %ld data trnasfered !\n", read_count ); Release_Card(card); if( write_to_file( (U16*)ai_buf, channel+1 ) ) printf("\n\nThe input data is already stored in file '%s'.\n", file_name); // show_channel_data( (U16*)ai_buf, channel+1 ); plot_channel_data(); free( ai_buf ); printf("\nPress ENTER to exit the program. "); //getch(); //putchar('\n'); return 0; }
void signal_handler(int sig_no) { BOOLEAN HalfReady; HalfReady=0; DI_AsyncMultiBufferNextReady(card, &HalfReady, &viewidx[j%10000]); switch(viewidx[j%10000]) { case 0: write_to_file( in_buf ); break; case 1: write_to_file( in_buf2 ); break; } DI_AsyncDblBufferTransfer(card, NULL); //notify the buffer have handled DI_AsyncDblBufferOverrun(card, 0, &sts); if(sts==1) { t++; DI_AsyncDblBufferOverrun(card, 1, &sts); } printf("\roverrun:%d cb:%d", t, j); j++; }
static rc_t print_edge( struct rna_splice_log * sl, INSDC_coord_zero pos, bool const reverse_complement, bool const add_newline ) { rc_t rc; INSDC_coord_len from_ref_obj, to_read; uint8_t buffer[ EDGE_LEN + 1 ]; INSDC_coord_zero rd_pos = 0; uint32_t pre_len = PRE_POST_LEN; uint32_t post_len = PRE_POST_LEN; if ( pos >= PRE_POST_LEN ) rd_pos = ( pos - PRE_POST_LEN ); /* in the rare case the delete is at the very beginning of the alignment */ else pre_len = pos; /* rd_pos is still 0, what we want*/ to_read = pre_len + post_len + 2; rc = ReferenceObj_Read( sl->ref_obj, rd_pos, to_read, buffer, &from_ref_obj ); if ( rc == 0 ) { uint8_t complement[ EDGE_LEN + 1 ]; uint8_t to_write[ EDGE_LEN + 5 ]; uint8_t * ref_bytes = buffer; if ( from_ref_obj < to_read ) post_len -= ( to_read - from_ref_obj ); if ( reverse_complement ) { copy_read_and_reverse_complement( complement, buffer, from_ref_obj ); ref_bytes = complement; } memmove( to_write, ref_bytes, pre_len ); to_write[ pre_len ] = '\t'; to_write[ pre_len + 1 ] = ref_bytes[ pre_len ]; to_write[ pre_len + 2 ] = ref_bytes[ pre_len + 1 ]; to_write[ pre_len + 3 ] = '\t'; memmove( &( to_write[ pre_len + 4 ] ), &( ref_bytes[ pre_len + 2 ] ), post_len ); if ( add_newline ) to_write[ pre_len + post_len + 4 ] = '\n'; else to_write[ pre_len + post_len + 4 ] = '\t'; rc = write_to_file( sl, to_write, pre_len + post_len + 5 ); } return rc; }
void write_app(int fd, const XdgApp *value) { if (value->groups && value->groups->owner == value) { write(fd, value, sizeof(XdgApp)); write(fd, value->groups, sizeof(XdgAppGroups)); write_to_file(fd, &value->groups->tree, write_app_key, (WriteValue)write_app_group, NULL); } else { XdgApp empty; memset(&empty, 0, sizeof(XdgApp)); write(fd, &empty, sizeof(XdgApp)); } }
/* Write the file header to a dump file. Returns TRUE on success, FALSE on failure. Sets "*err" to an error code, or 0 for a short write, on failure*/ gboolean libpcap_write_file_header(FILE* pfile, int linktype, int snaplen, gboolean ts_nsecs, guint64 *bytes_written, int *err) { struct pcap_hdr file_hdr; file_hdr.magic = ts_nsecs ? PCAP_NSEC_MAGIC : PCAP_MAGIC; /* current "libpcap" format is 2.4 */ file_hdr.version_major = 2; file_hdr.version_minor = 4; file_hdr.thiszone = 0; /* XXX - current offset? */ file_hdr.sigfigs = 0; /* unknown, but also apparently unused */ file_hdr.snaplen = snaplen; file_hdr.network = linktype; return write_to_file(pfile, (const guint8*)&file_hdr, sizeof(file_hdr), bytes_written, err); }
void flush_one(disk_stream *inflight, unsigned long superp) { if(inflight->compressed) { zlib_stream_flush(inflight, superp); } else { unsigned long disk_buffer_pos = inflight->disk_pos[superp]; unsigned long disk_page_offset = disk_buffer_pos % DISK_PAGE_SIZE; if(disk_page_offset > 0) { write_to_file(inflight->superp_fd[superp], inflight->disk_pages[superp], DISK_PAGE_SIZE); } } }
size_t pack_ramdisk_directory(byte_p ramdisk_cpio_data){ int i; names = calloc(256, sizeof(names)); for(i = 0; i < 256; i++) { names[i] = (char *)calloc(1024,sizeof(char)); if (names[i] == NULL) { perror("Memory cannot be allocated to arr[]"); } } getcwd(names[0],1024);total++; listdir(option_values.ramdisk_directory_name, 0); qsort(names, total, sizeof(char*), qsort_comparer); chdir(option_values.ramdisk_directory_name); byte_p nextbyte = &ramdisk_cpio_data[0]; byte_p start_header=nextbyte; for(i = 1; i < total; i++) { //fprintf(stderr,"Out:%p %s\n", nextbyte,nextbyte); struct stat sb ; lstat(names[i],&sb); nextbyte = append_cpio_header_to_stream(sb,names[i],start_header); //fprintf(stderr,"names[%d]: %p %s %d\n",i,names[i] ,names[i], strlen(names[i])+4); unsigned filesize = S_ISDIR(sb.st_mode) ? 0 : sb.st_size; unsigned long header_align = (4 - (((nextbyte-start_header)+filesize) % 4)) % 4; fprintf(stderr,"Heade:%d %p %p %d %d\n",nextbyte-start_header, nextbyte,start_header,header_align,sb.st_size); if(S_ISREG(sb.st_mode)){ nextbyte = load_file_easy(names[i],sb.st_size,&nextbyte); }else if(S_ISLNK(sb.st_mode)){ readlink(names[i],nextbyte,PATH_MAX); nextbyte+=filesize; } nextbyte+=header_align; start_header=nextbyte; fprintf(stderr,"names[%d]: %p %s %d\n",i,names[i] ,names[i], strlen(names[i])+4); } struct stat s ; memset(&s, 0, sizeof(s)); nextbyte =append_cpio_header_to_stream(s,CPIO_TRAILER_MAGIC,start_header); nextbyte+=( (4 - (((nextbyte-start_header)) % 4)) % 4); //fprintf(stderr,"done:%p %s %d\n",ramdisk_cpio_data,ramdisk_cpio_data,nextbyte-ramdisk_cpio_data); //fprintf(stderr,"done:%p %s %d\n",nextbyte-100,nextbyte-100,nextbyte-ramdisk_cpio_data); //free(outputstream); chdir(names[0]); write_to_file(ramdisk_cpio_data,nextbyte-&ramdisk_cpio_data[0],"test2.cpio"); free(names); return nextbyte-ramdisk_cpio_data ; }
int main(void) { I16 card, err; setbuf( stdout, NULL ); printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9118 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name); getch(); if ((card=Register_Card (PCI_9118DG, 0)) <0 ) { printf("Register_Card error=%d", card); exit(1); } err = AI_9118_Config(card, P9118_AI_BiPolar|P9118_AI_SingEnded, 0, 0, 0); if (err!=0) { printf("AI_9118_Config error=%d", err); Release_Card(card); exit(1); } err = AI_AsyncDblBufferMode(card, 0); if (err!=0) { printf("AI_DblBufferMode error=%d", err); Release_Card(card); exit(1); } mem_size=read_count*2; ai_buf = (U16*)malloc(mem_size); //err = AI_ContReadChannel(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP); if (err!=0) { printf("AI_ContReadChannel error=%d", err); Release_Card(card); free( ai_buf ); exit(1); } Release_Card(card); if( write_to_file( ai_buf, channel+1 ) ) printf("\n\nThe input data is already stored in file '%s'.\n", file_name); show_channel_data( ai_buf, channel+1 ); free( ai_buf ); printf("\nPress ENTER to exit the program. "); getchar(); return 0; }
void mod_manager::save_mods_list(WORLDPTR world) const { if( world == NULL ) { return; } const std::string path = get_mods_list_file(world); if( world->active_mod_order.empty() ) { // If we were called from load_mods_list to prune the list, // and it's empty now, delete the file. remove_file(path); return; } write_to_file( path, [&]( std::ostream &fout ) { JsonOut json( fout, true ); // pretty-print json.write(world->active_mod_order); }, _( "list of mods" ) ); }
/** * Makes all history items unique and force them to fit the maximum history * size and writes all entries of the different history types to file. */ void history_cleanup(void) { const char *file; GList *list; /* don't cleanup the history file if history max size is 0 */ if (!vb.config.history_max) { return; } for (HistoryType i = HISTORY_FIRST; i < HISTORY_LAST; i++) { file = HIST_FILE(i); list = load(file); write_to_file(list, file); g_list_free_full(list, (GDestroyNotify)free_history); } }
static void open_file(int num) { int fd; char filename[1024]; snprintf(filename, sizeof(filename), "file-%d", num); fd = open(filename, O_RDWR, 0666); if (fd < 0) err(1, "open"); if (write_file) write_to_file(fd, write_file); close(fd); }
LATENT_VAR infer_latent_variables(PATTERN x, LABEL y, STRUCTMODEL *sm, STRUCT_LEARN_PARM *sparm) { /* Complete the latent variable h for labeled examples, i.e., computing argmax_{h} <w,psi(x,y,h)>. */ LATENT_VAR h; // 1. Write input to a file char *filename = "tmpfiles/inf_lat_var"; // Online SVM: Note --- no longer using this code hence replace w by w_iters[0][0] write_to_file(x, y, sm->w_iters[0][0], sparm->max_feature_key, sparm->total_number_rels, filename); // 2. CALL the method InferLatentVarHelper FROM JAVA //printf("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelper tmpfiles/inf_lat_var \n"); system("export LD_LIBRARY_PATH=/usr/lib/lp_solve && java -cp java/bin:java/lib/* javaHelpers.InferLatentVarHelper tmpfiles/inf_lat_var"); // 3. READ the LATENT VAR h from the file tmpfiles/inf_lat_var.latentvar FILE *fp = fopen("tmpfiles/inf_lat_var.latentvar","r"); if (fp==NULL) { printf("Cannot open output file %s!\n", "tmpfiles/inf_lat_var"); exit(1); } int num_mentions; fscanf(fp,"%d\n",&num_mentions); if(num_mentions != x.num_mentions) { printf("Something is wrong .. exiting ..."); exit(1); } h.num_mentions = num_mentions; h.mention_labels = (int*)malloc(sizeof(int)*num_mentions); int i; for(i = 0; i < num_mentions; i ++) { int label; fscanf(fp, "%d\n", &label); h.mention_labels[i] = label; } // CLEANUP fclose(fp); // Delete tmp files created. return(h); }
//// proc processing function assigned to a specific data type in proc_io_init //return 1 if output is available // return 0 if not output static int proc_tuple(void * vinstance, wsdata_t* input_data, ws_doutput_t * dout, int type_index) { dprint("print proc_process_meta"); proc_instance_t * proc = (proc_instance_t*) vinstance; proc->meta_process_cnt++; write_to_file(proc, input_data); if (!proc->act_as_sink) { ws_set_outdata(input_data, proc->outtype_meta[type_index], dout); proc->outcnt++; } return 1; }
static void cmd_delete_offline_device(char *dev, int pid, int sock) { mapidrv *drv; struct mapiipcbuf buf; long file_size; for (drv = drvlist; drv != NULL; drv = drv->next) { if (drv->device != NULL) if (strcmp(dev, drv->device) == 0) { break; } } if (drv == NULL) { DEBUG_CMD(Debug_Message("No device found for %s", dev)); report_error(MAPID_NO_DEVICE, pid, sock); return; } if (drv->offline != 0) { mapidrv_delete_device = get_drv_funct(drv->handle, "mapidrv_delete_device"); mapidrv_delete_device(drv->devid); drv->active=0; } buf.mtype = pid; buf.cmd = DELETE_OFFLINE_DEVICE_ACK; buf.fd = -1; if (log_to_file) { file_size = acquire_write_lock(log_fd_info); write_to_file(log_fd_info, "MAPID: offline device %s was deleted at ", dev); write_date(log_fd_info); write_newline(log_fd_info, "\n"); release_write_lock(log_fd_info, file_size); } if (log_to_syslog) log_message("offline device %s was deleted", dev); DEBUG_CMD(Debug_Message("Deleted offline device %s", dev)); mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock); }
int main(int argc, char *argv[]) { char mytaskfile[FILENAME_MAX]; int test_num; /* Signal handler for tasks for exiting gracefully */ struct sigaction newaction, oldaction; sigemptyset(&newaction.sa_mask); sigaddset(&newaction.sa_mask, SIGUSR1); newaction.sa_handler = &sighandler; sigaction(SIGUSR1, &newaction, &oldaction); if ((argc < 2) || (argc > 3)) { printf("TBROK\t Invalid #args received from script" " The test will run without any cpu load \n"); exit(1); } /* Migrate the task to its group if applicable */ test_num = atoi(argv[1]); if (test_num < 0) { printf("Invalid test number received from script." " Skipping load creation "); exit(1); } if (test_num == 2) { strncpy(mytaskfile, argv[2], FILENAME_MAX); strncat(mytaskfile, "/tasks", FILENAME_MAX - strlen(mytaskfile) - 1); write_to_file(mytaskfile, "a", getpid()); } /* * Need to run some cpu intensive task. Not sure if it is the best * workload I can run? */ double f = 27409.345; /*just a float number for sqrt*/ while (1) f = sqrt(f * f); return 0; }
int bloom_filter_init_on_disk_alt(BloomFilter *bf, uint64_t estimated_elements, float false_positive_rate, char *filepath, HashFunction hash_function) { if(estimated_elements <= 0 || estimated_elements > UINT64_MAX || false_positive_rate <= 0.0 || false_positive_rate >= 1.0) { return BLOOM_FAILURE; } bf->estimated_elements = estimated_elements; bf->false_positive_probability = false_positive_rate; calculate_optimal_hashes(bf); bf->elements_added = 0; FILE *fp; fp = fopen(filepath, "w+b"); if (fp == NULL) { fprintf(stderr, "Can't open file %s!\n", filepath); return BLOOM_FAILURE; } write_to_file(bf, fp, 1); fclose(fp); // slightly ineffecient to redo some of the calculations... return bloom_filter_import_on_disk_alt(bf, filepath, hash_function); }
void create_banish_file(char *str) { saved_player **hash, *sp, *scan; int sum; char *c, name[20]; strncpy(name, str, MAX_NAME - 1); sp = (saved_player *) MALLOC(sizeof(saved_player)); memset((char *) sp, 0, sizeof(saved_player)); strcpy(stack, name); lower_case(stack); strncpy(sp->lower_name, stack, MAX_NAME - 1); sp->saved_email[0]=' '; sp->saved_email[1]=0; sp->rooms = 0; sp->mail_sent = 0; sp->received_list = 0; hash = saved_hash[((int) name[0] - (int) 'a')]; for (sum = 0, c = name; *c; c++) if (isalpha(*c)) sum += (int) (*c) - 'a'; else { log("error", "Tried to banish bad player"); FREE(sp); return; } hash = (hash + (sum % HASH_SIZE)); scan = *hash; while (scan) { hash = &(scan->next); scan = scan->next; } *hash = sp; sp->residency = BANISHD; sp->saved_flags = 0; sp->last_host[0] = 0; sp->last_on = time(0); sp->next = 0; sp->cache = -1; write_to_file(sp); }