void abort_message(const char *format, ...) { va_list vargs; char emessage[1024]; if (dpsTimer || nomessageflag) { closeFiles(); close_error(1); /* 1 arg means fail/abort */ exit(1); } va_start(vargs, format); vfprintf(stdout,format,vargs); va_end(vargs); if ( *(format+(strlen(format)-1)) != '\n') fprintf(stdout,"\n"); if (!erroropen) { if (P_getstring(GLOBAL, "userdir", errorpath, 1, MAXPATHL) >= 0) { strcat(errorpath,"/psg.error"); if ( (errorfile=fopen(errorpath,"w+")) ) erroropen = 1; } } if (erroropen) { va_start(vargs, format); vfprintf(errorfile,format,vargs); va_end(vargs); fprintf(errorfile,"P.S.G. Aborted....\n"); fprintf(stdout,"P.S.G. Aborted....\n"); } va_start(vargs, format); vsprintf(emessage,format,vargs); va_end(vargs); closeFiles(); if (newacq) { while (emessage[strlen(emessage)-1] == '\n') emessage[strlen(emessage)-1] = '\0'; vnmremsg(emessage); if (!acqiflag && !dps_flag) release_console(); } close_error(1); /* 1 arg means fail/abort */ exit(1); }
void write_directory_file (void) { FILE *fp = listed_incremental_stream; char buf[UINTMAX_STRSIZE_BOUND]; char *s; if (! fp) return; if (fseeko (fp, 0L, SEEK_SET) != 0) seek_error (listed_incremental_option); if (sys_truncate (fileno (fp)) != 0) truncate_error (listed_incremental_option); fprintf (fp, "%s-%s-%d\n", PACKAGE_NAME, PACKAGE_VERSION, TAR_INCREMENTAL_VERSION); s = (TYPE_SIGNED (time_t) ? imaxtostr (start_time.tv_sec, buf) : umaxtostr (start_time.tv_sec, buf)); fwrite (s, strlen (s) + 1, 1, fp); s = umaxtostr (start_time.tv_nsec, buf); fwrite (s, strlen (s) + 1, 1, fp); if (! ferror (fp) && directory_table) hash_do_for_each (directory_table, write_directory_file_entry, fp); if (ferror (fp)) write_error (listed_incremental_option); if (fclose (fp) != 0) close_error (listed_incremental_option); }
void close_fake_pipes(void) { FILE_NODE *p = file_list; char xbuff[100]; /* close input pipes first to free descriptors for children */ while (p) { if (p->type == PIPE_IN) { FINclose((FIN *) p->ptr); unlink(tmp_file_name(p->pid, xbuff)); } p = p->link; } /* doit again */ p = file_list; while (p) { if (p->type == PIPE_OUT) { if (fclose(p->ptr) != 0) { close_error(p); } close_fake_outpipe(p->name->str, p->pid); } p = p->link; } }
void close_out_pipes(void) { FILE_NODE *p = file_list; FILE_NODE *q = 0; while (p) { if (IS_OUTPUT(p->type)) { if (fclose((FILE *) p->ptr) != 0) { /* if another error occurs we do not want to be called for the same file again */ if (q != 0) q->link = p->link; else file_list = p->link; close_error(p); } else if (p->type == PIPE_OUT) { wait_for(p->pid); } } q = p; p = p->link; } }
static int new_error(enum severity_e severity, const struct file_list_s *flist, linepos_t epoint) { struct error_s *err; size_t line_len; int dupl; dupl = close_error(); switch (severity) { case SV_NOTDEFGNOTE: case SV_NOTDEFLNOTE: case SV_DOUBLENOTE: if (dupl) return 1; line_len = 0; break; default: line_len = ((epoint->line == lpoint.line) && in_macro()) ? (strlen((char *)pline) + 1) : 0; break; } error_list.header_pos = (error_list.len + 7) & ~7; if (error_list.header_pos + sizeof(struct error_s) + line_len > error_list.max) { error_list.max += (sizeof(struct error_s) > 0x200) ? sizeof(struct error_s) : 0x200; error_list.data = (uint8_t *)realloc(error_list.data, error_list.max); if (!error_list.data) {fputs("Out of memory error\n", stderr);exit(1);} } error_list.len = error_list.header_pos + sizeof(struct error_s) + line_len; err = (struct error_s *)&error_list.data[error_list.header_pos]; err->severity = severity; err->error_len = 0; err->line_len = line_len; err->file_list = flist; err->epoint = *epoint; if (line_len) memcpy(&error_list.data[error_list.header_pos + sizeof(struct error_s)], pline, line_len); return 0; }
void psg_abort(int error) { closeFiles(); if (dpsTimer) { close_error(1); /* 1 arg means failure/abort */ exit(1); } text_error("P.S.G. Aborted."); if (newacq) { if (!acqiflag && !dps_flag) release_console(); } close_error(1); /* 1 arg means failure/abort */ exit(error); }
void close_diag (char const *name) { if (ignore_failed_read_option) close_warn (name); else close_error (name); }
/* Catenate file FILE_NAME to the archive without creating a header for it. It had better be a tar file or the archive is screwed. */ static void append_file (char *file_name) { int handle = open (file_name, O_RDONLY | O_BINARY); struct stat stat_data; if (handle < 0) { open_error (file_name); return; } if (fstat (handle, &stat_data) != 0) stat_error (file_name); else { off_t bytes_left = stat_data.st_size; while (bytes_left > 0) { union block *start = find_next_block (); size_t buffer_size = available_space_after (start); size_t status; char buf[UINTMAX_STRSIZE_BOUND]; if (bytes_left < buffer_size) { buffer_size = bytes_left; status = buffer_size % BLOCKSIZE; if (status) memset (start->buffer + bytes_left, 0, BLOCKSIZE - status); } status = safe_read (handle, start->buffer, buffer_size); if (status == SAFE_READ_ERROR) read_fatal_details (file_name, stat_data.st_size - bytes_left, buffer_size); if (status == 0) FATAL_ERROR ((0, 0, ngettext ("%s: File shrank by %s byte", "%s: File shrank by %s bytes", bytes_left), quotearg_colon (file_name), STRINGIFY_BIGINT (bytes_left, buf))); bytes_left -= status; set_next_block_after (start + (status - 1) / BLOCKSIZE); } } if (close (handle) != 0) close_error (file_name); }
/* ** cleanup: ** ** free all memory, close all files, etc. */ void cleanup( void ) { /* close file */ if ( outfile && (outfile!=stdout) ) fclose( outfile ); close_error(); /* release lists */ del_dllist( defent ); del_dllist( deftag ); del_dllist( cltags ); del_dllist( macros ); del_dllist( vars ); #if 0 /* todo: remove this */ del_dllist( macarg ); #endif /* misc. work */ ufreestr( outfilename ); ufreestr( rel_destdir ); ufreestr( last_anchor ); }
int file_close(STRING * sval) { FILE_NODE *p; FILE_NODE *q = 0; /* trails p */ FILE_NODE *hold; char *name = sval->str; int retval = -1; p = file_list; while (p) { if (strcmp(name, p->name->str) == 0) { /* found */ /* Remove it from the list first because we might be called again if an error occurs leading to an infinite loop. Note that we don't have to consider the list corruption caused by a recursive call because it will never return. */ if (q == 0) file_list = p->link; else q->link = p->link; switch (p->type) { case F_TRUNC: case F_APPEND: if (fclose((FILE *) p->ptr) != 0) { close_error(p); } retval = 0; break; case PIPE_OUT: if (fclose((FILE *) p->ptr) != 0) { close_error(p); } #ifdef HAVE_REAL_PIPES retval = wait_for(p->pid); #endif #ifdef HAVE_FAKE_PIPES retval = close_fake_outpipe(p->name->str, p->pid); #endif break; case F_IN: FINclose((FIN *) p->ptr); retval = 0; break; case PIPE_IN: FINclose((FIN *) p->ptr); #ifdef HAVE_REAL_PIPES retval = wait_for(p->pid); #endif #ifdef HAVE_FAKE_PIPES { char xbuff[100]; unlink(tmp_file_name(p->pid, xbuff)); retval = p->inpipe_exit; } #endif break; } hold = p; p = p->link; free_filenode(hold); } else { q = p; p = p->link; } } return retval; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Test error API. * * Programmer: Raymond Lu * July 10, 2003 * *------------------------------------------------------------------------- */ int main(void) { hid_t file, fapl; hid_t estack_id; char filename[1024]; const char *FUNC_main = "main"; HDfprintf(stderr, " This program tests the Error API. There're supposed to be some error messages\n"); /* Initialize errors */ if(init_error() < 0) TEST_ERROR; fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; /* Test error stack */ if(error_stack() < 0) { /* Push an error onto error stack */ if(H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK, "Error stack test failed") < 0) TEST_ERROR; /* Delete an error from the top of error stack */ H5Epop(ERR_STACK, 1); /* Make sure we can use other class's major or minor errors. */ H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS2, ERR_MAJ_TEST, ERR_MIN_ERRSTACK, "Error stack test failed"); /* Print out the errors on stack */ dump_error(ERR_STACK); /* Empty error stack */ H5Eclear2(ERR_STACK); /* Close error stack */ H5Eclose_stack(ERR_STACK); } /* end if */ /* Test error API */ if(test_error(file) < 0) { H5Epush(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE, "Error test failed, %s", "it's wrong"); estack_id = H5Eget_current_stack(); H5Eprint2(estack_id, stderr); H5Eclose_stack(estack_id); } /* end if */ /* Test pushing a very long error description */ if(test_long_desc() < 0) TEST_ERROR; /* Test creating a new error stack */ if(test_create() < 0) TEST_ERROR; /* Test copying a new error stack */ if(test_copy() < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Close error information */ if(close_error() < 0) TEST_ERROR; /* Test error message during data reading when filter isn't registered * Use default FAPL to avoid some VFD drivers by the check-vfd test because * the test file was pre-generated. */ h5_fixname(DATAFILE, H5P_DEFAULT, filename, sizeof filename); if(test_filter_error(filename) < 0) TEST_ERROR; h5_clean_files(FILENAME, fapl); HDfprintf(stderr, "\nAll error API tests passed.\n"); return 0; error: HDfprintf(stderr, "\n***** ERROR TEST FAILED (real problem)! *****\n"); return 1; }
int main(int argc, char* argv[]) { char* path_to_config; char* path_to_errors; int is_batch_mode; int key = 0; int list_scr = 0; struct process_list* proc_list; screen_t* screen = NULL; int screen_num = 0; int q; int paranoia_level; /* Check OS to make sure we can run. */ paranoia_level = check(); init_options(&options); options.paranoia_level = paranoia_level; path_to_config = get_path_to_config(argc, argv); path_to_errors = get_path_to_error(argc, argv); is_batch_mode = get_batch_mode(argc, argv); init_errors(is_batch_mode, path_to_errors); q = read_config(path_to_config, &options); if (q == 0) { debug_printf("Config file successfully parsed.\n"); options.config_file = 1; } else debug_printf("Could not parse config file.\n"); /* Parse command line arguments. */ parse_command_line(argc, argv, &options, &list_scr, &screen_num); /* Add default screens */ if (options.default_screen == 1) init_screen(); /* Remove unused but declared counters */ tamp_counters(); if (list_scr) { list_screens(); delete_screens(); exit(0); } if (options.spawn_pos) { /* monitor only spawned process */ int child = spawn(argv + options.spawn_pos); options.only_pid = child; options.idle = 1; } do { if (screen_num >= 0) screen = get_screen(screen_num); else screen = get_screen_by_name(argv[-screen_num]); if (!screen) { fprintf(stderr, "No such screen.\n"); exit(EXIT_FAILURE); } /* initialize the list of processes, and then run */ proc_list = init_proc_list(); if (options.spawn_pos) { options.spawn_pos = 0; /* do this only once */ new_processes(proc_list, screen, &options); start_child(); } if (options.batch) { batch_mode(proc_list, screen); key = 'q'; } #ifdef HAVE_LIBCURSES else { key = live_mode(proc_list, screen); if ((key == '+') || (key == KEY_RIGHT)) { screen_num = (screen_num + 1) % get_num_screens(); active_col = 0; done_proc_list(proc_list); free(header); } if ((key == '-') || (key == KEY_LEFT)) { int n = get_num_screens(); screen_num = (screen_num + n - 1) % n; active_col = 0; done_proc_list(proc_list); free(header); } if ((key == 'u') || (key == 'K') || (key == 'p')) { done_proc_list(proc_list); } } #endif } while (key != 'q'); /* done, free memory (makes valgrind happy) */ close_error(); delete_screens(); done_proc_list(proc_list); free_options(&options); return 0; }