static void log_current_data(void) { response_t *r; ecu_data_t *ep; unsigned int i; if (!global_logfp) return; log_timestamp("D"); fprintf(global_logfp, "MODE 1 DATA\n"); for (i=0, ep=ecu_info; i<ecu_count; i++, ep++) { for (r = ep->mode1_data; r < &ep->mode1_data[ARRAY_SIZE(ep->mode1_data)]; r++) { log_response((int)i, r); } } log_timestamp("D"); fprintf(global_logfp, "MODE 2 DATA\n"); for (i=0, ep=ecu_info; i<ecu_count; i++, ep++) { for (r = ep->mode2_data; r < &ep->mode2_data[ARRAY_SIZE(ep->mode2_data)]; r++) { log_response((int)i, r); } } }
//adds an entry to the directory structure int Add_to_Directory(char* Filename, int inodeNumber) { int fileExist = Search_Directory(Filename); Inode curNode = Inode_Read(inodeNumber); //if file does not exist and inode is not in use if ((fileExist == -1) && (curNode.Inode_Number == -1)) { //create directory entry and claim inode strcpy(Directory_Structure[inodeNumber].Filename, Filename); Directory_Structure[inodeNumber].Inode_Number = inodeNumber; Inode_List[inodeNumber].Inode_Number = inodeNumber; FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Directory\t\t\t Write\n"); fclose(File); return 1; } FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Directory\t\t\t Read\n"); fclose(File); return 0; //file already exists or inode is already initialized }
static void log_heading(struct log_entry *entry, enum log_major major, enum log_minor minor) { log_timestamp(entry); log_major_minor(entry); }
//copies the corresponding inode to the inode list int Inode_Write(int inodeNumber, Inode inode) { if ((inodeNumber < 0) || (inodeNumber > 127)) {return 0;} if (inode.Inode_Number != -1) { FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); if (inodeNumber < 10) fprintf(File,"Inode %d\t\t\t\t Write\n", inodeNumber); else fprintf(File,"Inode %d\t\t\t Write\n", inodeNumber); fclose(File); } Inode_List[inodeNumber].Inode_Number = inode.Inode_Number; Inode_List[inodeNumber].User_Id = inode.User_Id; Inode_List[inodeNumber].Group_Id = inode.Group_Id; Inode_List[inodeNumber].File_Size = inode.File_Size; Inode_List[inodeNumber].Start_Block = inode.Start_Block; Inode_List[inodeNumber].End_Block = inode.End_Block; Inode_List[inodeNumber].Flag = inode.Flag; return 1; }
void launch_thread(jobtype ptype, pkgstate* state, pkg_exec* item, pkgdata* data) { char* arr[2]; create_script(ptype, state, item, data); log_timestamp(1); log_putspace(1); if(ptype == JT_DOWNLOAD) { log_puts(1, SPL("downloading ")); } else log_puts(1, SPL("building ")); log_put(1, VARIS(item->name), VARISL("("), VARIS(item->scripts.filename), VARISL(") -> "), VARIS(item->scripts.stdoutfn), NULL); arr[0] = item->scripts.filename->ptr; arr[1] = NULL; posix_spawn_file_actions_init(&item->fa); posix_spawn_file_actions_addclose(&item->fa, 0); posix_spawn_file_actions_addclose(&item->fa, 1); posix_spawn_file_actions_addclose(&item->fa, 2); posix_spawn_file_actions_addopen(&item->fa, 0, "/dev/null", O_RDONLY, 0); posix_spawn_file_actions_addopen(&item->fa, 1, item->scripts.stdoutfn->ptr, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); posix_spawn_file_actions_adddup2(&item->fa, 1, 2); int ret = posix_spawnp(&item->pid, arr[0], &item->fa, NULL, arr, environ); if(ret == -1) { log_perror("posix_spawn"); die(SPL("")); } }
//initializes filesystem int Initialize_Filesystem(char* log_filename) { //Creating log file Log_Filename = log_filename; FILE *File = fopen(Log_Filename,"w"); log_timestamp(File); fprintf(File, "Filesystem Initialized\n"); fclose(File); Count = 0; Inode newNode; int i; for (i=0; i<128; i++) { newNode.Inode_Number = -1; Inode_Write(i,newNode); } Super_block supBlock; supBlock.next_free_block = 0; supBlock.next_free_inode = 0; Superblock_Write(supBlock); return 0; }
void logv(enum plugin_log_type type, const char *prefix, const char *fmt, va_list ap) { assert(fmt); FILE *out = (logger.file ? logger.file : stderr); if (out != stderr && out != stdout) log_timestamp(out); switch (type) { case PLOG_WARN: fprintf(out, "(WARN) "); break; case PLOG_ERROR: fprintf(out, "(ERROR) "); break; default: break; } if (prefix) fprintf(out, "%s: ", prefix); vfprintf(out, fmt, ap); fprintf(out, "\n"); fflush(out); }
//returns the superblock structure Super_block Superblock_Read(void) { FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Superblock\t\t\t Read\n"); fclose(File); return Superblock; }
//copies the given superblock info into the superblock int Superblock_Write(Super_block supBlock) { FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Superblock\t\t\t Write\n"); fclose(File); Superblock.next_free_inode = supBlock.next_free_inode; Superblock.next_free_block = supBlock.next_free_block; return 0; }
Logger::Logger() { log_path = "log.txt"; mode = DEBUG; //cambiar para cambiar el default. en la version final el default deberia ser ERROR mode_symbols[0] = "D.\t"; mode_symbols[1] = "W.\t"; mode_symbols[2] = "E.\t"; mode_symbols[3] = "I.\t"; mode_symbols[4] = "T.\t"; log_timestamp(); }
static int cmd_log(int argc, char **argv) { char autofilename[20]=""; char *file; struct stat buf; time_t now; int i; file=autofilename; if (global_logfp != NULL) { printf("Already logging\n"); return CMD_FAILED; } /* Turn on logging */ if (argc > 1) { file = argv[1]; //if a file name was specified, use that } else { //else, generate an auto log file for (i = 0; i <= 100; i++) { sprintf(autofilename,"log.%02d",i); if (stat(file, &buf) == -1 && errno == ENOENT) break; } if (i == 100) { printf("Can't create log.%d; remember to clean old auto log files\n",i); return CMD_FAILED; } } global_logfp = fopen(file, "a"); //add to end of log or create file if (global_logfp == NULL) { printf("Failed to create log file %s\n", file); return CMD_FAILED; } now = time(NULL); //reset stopwatch: unsigned long t1; t1=diag_os_chronoms(0); (void) diag_os_chronoms(t1); fprintf(global_logfp, "%s\n", LOG_FORMAT); log_timestamp("#"); fprintf(global_logfp, "logging started at %s", asctime(localtime(&now))); printf("Logging to file %s\n", file); return CMD_OK; }
static void log_command(int argc, char **argv) { int i; if (!global_logfp) return; log_timestamp(">"); for (i = 0; i < argc; i++) fprintf(global_logfp, " %s", argv[i]); fprintf(global_logfp, "\n"); }
void log_error(const char *format, ...) { va_list ap, ap2; log_timestamp(); va_start(ap, format); va_copy(ap2, ap); if(logfile) { vfprintf(logfile, format, ap); fprintf(logfile, "\n"); } vfprintf(stderr, format, ap2); fprintf(stderr, "\n"); va_end(ap); va_end(ap2); }
int log_core(struct log *log, int priority, const char *format, va_list ap) { int l = 0; assert(priority < 8 && priority >= 0); if (priority <= log->priority) { l = log_timestamp(log); l += fprintf(log->fp, "%s ", pristr[priority].info); l += vfprintf(log->fp, format, ap); } return l; }
void hashpipe_info(const char *name, const char *msg, ...) { char timestamp[256]; log_timestamp(timestamp); fprintf(stderr, "%s : ", timestamp); fprintf(stderr, "Info (%s)", name); if(msg) { va_list ap; va_start(ap, msg); fprintf(stderr, ": "); vfprintf(stderr, msg, ap); va_end(ap); } fprintf(stderr, "\n"); fflush(stderr); }
//search through the directory for the given filename //returns the inode number of the file int Search_Directory(char* filename) { FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Directory\t\t\t Read\n"); fclose(File); int i; for (i=0; i<128; i++) { if (strcmp(filename, Directory_Structure[i].Filename) == 0) {return Directory_Structure[i].Inode_Number;} } return -1; //file does not exist }
void log_info(const char *format, ...) { va_list ap, ap2; log_timestamp(); va_start(ap, format); va_copy(ap2, ap); if(logfile) { vfprintf(logfile, format, ap); fprintf(logfile, "\n"); } vfprintf(stdout, format, ap2); fprintf(stdout, "\n"); fflush(stdout); va_end(ap); va_end(ap2); }
void log_msg(const char *format, ...) { va_list ap; if (log_stream == NULL) return; log_timestamp(); log_conn(); va_start(ap, format); vfprintf(log_stream, format, ap); va_end(ap); putc('\n', log_stream); }
//reads from specified block into character string //returns number of bytes read int Block_Read(int blockNumber, int numBytes, char* charString) { if ((blockNumber < 0) || (blockNumber > 8191)) {return 0;} //invalid block number if ((numBytes < 1) || (numBytes > 512)) {return 0;} //invalid number of bytes FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Disk Block %d\t\t Read\n", blockNumber); fclose(File); char* curBlock = Disk_Blocks[blockNumber]; if (copyString(charString, curBlock, numBytes) != numBytes) {return 0;} //string copy was not successful return numBytes; }
/* For now just put it all to stderr. * Maybe do something clever like a stack in the future? */ void hashpipe_error(const char *name, const char *msg, ...) { char timestamp[256]; log_timestamp(timestamp); fprintf(stderr, "%s : ", timestamp); fprintf(stderr, "Error (%s)", name); if(msg) { va_list ap; va_start(ap, msg); fprintf(stderr, ": "); vfprintf(stderr, msg, ap); va_end(ap); } if(errno) { fprintf(stderr, " [%s]", strerror(errno)); } fprintf(stderr, "\n"); fflush(stderr); }
void log_error(const char *format, ...) { va_list ap; int error; if (log_stream == NULL) return; error = errno; log_timestamp(); log_conn(); va_start(ap, format); vfprintf(log_stream, format, ap); va_end(ap); fprintf(log_stream, ": %s", strerror(error)); putc('\n', log_stream); }
static int process (jack_nframes_t nframes, void *arg) { int chn; size_t i; jack_thread_info_t *info = (jack_thread_info_t *) arg; /* Do nothing until we're ready to begin. */ if ((!info->can_process) || (!info->can_capture)) return 0; if (!logged_timestamp) log_timestamp(); for (chn = 0; chn < nports; chn++) in[chn] = jack_port_get_buffer (ports[chn], nframes); /* Sndfile requires interleaved data. It is simpler here to * just queue interleaved samples to a single ringbuffer. */ for (i = 0; i < nframes; i++) { for (chn = 0; chn < nports; chn++) { if (jack_ringbuffer_write (rb, (void *) (in[chn]+i), sample_size) < sample_size) warn_about_overrun(info); } } /* Tell the disk thread there is work to do. If it is already * running, the lock will not be available. We can't wait * here in the process() thread, but we don't need to signal * in that case, because the disk thread will read all the * data queued before waiting again. */ if (pthread_mutex_trylock (&disk_thread_lock) == 0) { pthread_cond_signal (&data_ready); pthread_mutex_unlock (&disk_thread_lock); } return 0; }
void memory_print_stats(sb_stat_t type) { double seconds; const double megabyte = 1024.0 * 1024.0; switch (type) { case SB_STAT_INTERMEDIATE: SB_THREAD_MUTEX_LOCK(); seconds = NS2SEC(sb_timer_split(&sb_globals.exec_timer)); log_timestamp(LOG_NOTICE, &sb_globals.exec_timer, "%4.2f MB/sec,", (double)(total_bytes - last_bytes) / megabyte / seconds); last_bytes = total_bytes; SB_THREAD_MUTEX_UNLOCK(); break; case SB_STAT_CUMULATIVE: seconds = NS2SEC(sb_timer_split(&sb_globals.cumulative_timer1)); log_text(LOG_NOTICE, "Operations performed: %d (%8.2f ops/sec)\n", total_ops, total_ops / seconds); if (memory_oper != SB_MEM_OP_NONE) log_text(LOG_NOTICE, "%4.2f MB transferred (%4.2f MB/sec)\n", total_bytes / megabyte, total_bytes / megabyte / seconds); total_ops = 0; total_bytes = 0; /* So that intermediate stats are calculated from the current moment rather than from the previous intermediate report */ if (sb_timer_initialized(&sb_globals.exec_timer)) sb_timer_split(&sb_globals.exec_timer); break; } }
//returns the inode structure for the corresponding inode number Inode Inode_Read(int inodeNumber) { FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); if (inodeNumber < 10) fprintf(File,"Inode %d\t\t\t\t Read\n", inodeNumber); else fprintf(File,"Inode %d\t\t\t Read\n", inodeNumber); fclose(File); int i; for (i=0; i<128; i++) { if (Directory_Structure[i].Inode_Number == inodeNumber) {return Inode_List[inodeNumber];} } //inode is not a valid file. Return inode with number = -1 Inode emptyNode; emptyNode.Inode_Number = -1; return emptyNode; }
//writes the given string to the desired block (max of 512 bytes) //returns number of bytes written int Block_Write(int blockNumber, int number_of_bytes, char* charString) { if ((blockNumber < 0) || (blockNumber > 8191)) {return 0;} //invalid block number if (number_of_bytes > 512) {return 0;} //trying to write too many bytes FILE *File = fopen(Log_Filename,"a"); log_timestamp(File); fprintf(File,"Disk Block %d\t\t Write\n", blockNumber); fclose(File); //allocate memory for block Disk_Blocks[blockNumber] = (char*) malloc(512); if (Disk_Blocks[blockNumber] == NULL) {return 0;} char* curBlock = Disk_Blocks[blockNumber]; if (copyString(curBlock, charString, number_of_bytes) != number_of_bytes) {return 0;} return number_of_bytes; }