void remove_list(t_dlist *dlist) { t_list *next; free_tables(dlist->env); free_tables(dlist->path); while (dlist->start != NULL) { next = pop_list_start(dlist); free(next->name); free(next->params); free(next); } free(dlist); }
int gp_filter_tables_init(gp_filter_tables *self, const gp_pixmap *pixmap) { unsigned int i; const gp_pixel_type_desc *desc; GP_DEBUG(2, "Allocating tables for pixel %s", gp_pixel_type_name(pixmap->pixel_type)); for (i = 0; i < GP_PIXELTYPE_MAX_CHANNELS; i++) self->table[i] = NULL; desc = gp_pixel_desc(pixmap->pixel_type); for (i = 0; i < desc->numchannels; i++) { self->table[i] = create_table(&desc->channels[i]); if (!self->table[i]) { free_tables(self); return 1; } } self->free_table = 0; return 0; }
/* funcao responsavel pela montagem do arquivo. Une todos processos. */ void mount(char* fileFrom, char* fileTo) { set_table s_table; label_table l_table = build_labels(fileFrom, &s_table); print_file(fileFrom, fileTo, l_table, s_table); free_tables(s_table, l_table); }
int GP_FilterTablesInit(GP_FilterTables *self, const GP_Context *ctx) { unsigned int i; const GP_PixelTypeDescription *desc; GP_DEBUG(2, "Allocating tables for pixel %s", GP_PixelTypeName(ctx->pixel_type)); for (i = 0; i < GP_PIXELTYPE_MAX_CHANNELS; i++) self->table[i] = NULL; desc = GP_PixelTypeDesc(ctx->pixel_type); for (i = 0; i < desc->numchannels; i++) { self->table[i] = create_table(&desc->channels[i]); if (!self->table[i]) { free_tables(self); return 1; } } self->free_table = 0; return 0; }
/** Free the memory occupied by a league. @param league The pointer to the league we free. */ void free_league(League *league) { #ifdef DEBUG printf("free_league\n"); #endif free_gchar_ptr(league->name); free_gchar_ptr(league->short_name); free_gchar_ptr(league->symbol); free_gchar_ptr(league->sid); free_gchar_array(&league->skip_weeks_with); if(league->teams != NULL) free_teams_array(&league->teams, FALSE); free_joined_leagues(&league->joined_leagues); free_prom_rel(&league->prom_rel); free_g_array(&league->teams); free_tables(&league->tables); free_new_tables(&league->new_tables); free_g_array(&league->fixtures); free_g_array(&league->rr_breaks); free_g_array(&league->week_breaks); free_g_array(&league->two_match_weeks[0]); free_g_array(&league->two_match_weeks[1]); free_league_stats(&league->stats); }
void free_cup_round(CupRound *cup_round) { #ifdef DEBUG printf("free_cup_round\n"); #endif gint j; g_free(cup_round->name); free_g_array(&cup_round->two_match_weeks[0]); free_g_array(&cup_round->two_match_weeks[1]); for(j = 0; j < cup_round->waits->len; j++) g_free(g_array_index(cup_round->waits, CupRoundWait, j).cup_sid); free_g_array(&cup_round->waits); if(cup_round->round_robin_number_of_groups > 0) { free_tables(&cup_round->tables); for(j=0; j<cup_round->choose_teams->len; j++) free_cup_choose_team( &g_array_index(cup_round->choose_teams, CupChooseTeam, j)); free_g_array(&cup_round->choose_teams); free_teams_array(&cup_round->teams, FALSE); g_ptr_array_free(cup_round->team_ptrs, TRUE); } }
void gp_filter_tables_free(gp_filter_tables *self) { GP_DEBUG(1, "Freeing point filter and tables (%p)", self); free_tables(self); if (self->free_table) { GP_DEBUG(2, "Freeing table itself"); free(self); } }
void GP_FilterTablesFree(GP_FilterTables *self) { GP_DEBUG(1, "Freeing point filter and tables (%p)", self); free_tables(self); if (self->free_table) { GP_DEBUG(2, "Freeing table itself"); free(self); } }
void free_storage (void) { GModule module; g_hash_table_destroy (ht_agent_keys); g_hash_table_destroy (ht_agent_vals); g_hash_table_destroy (ht_hostnames); g_hash_table_destroy (ht_unique_keys); for (module = 0; module < TOTAL_MODULES; ++module) { free_tables (ht_storage[module].metrics); } }
void free_storage (void) { GModule module; tc_db_close (ht_agent_keys, get_dbname (DB_AGENT_KEYS, -1)); tc_db_close (ht_agent_vals, get_dbname (DB_AGENT_VALS, -1)); tc_db_close (ht_general_stats, get_dbname (DB_GEN_STATS, -1)); tc_db_close (ht_hostnames, get_dbname (DB_HOSTNAMES, -1)); tc_db_close (ht_unique_keys, get_dbname (DB_UNIQUE_KEYS, -1)); for (module = 0; module < TOTAL_MODULES; ++module) { free_tables (ht_storage[module].metrics, module); } }
void Solution::free() { if (mono_coefs != NULL) { delete [] mono_coefs; mono_coefs = NULL; } if (elem_orders != NULL) { delete [] elem_orders; elem_orders = NULL; } if (dxdy_buffer != NULL) { delete [] dxdy_buffer; dxdy_buffer = NULL; } for (int i = 0; i < num_components; i++) if (elem_coefs[i] != NULL) { delete [] elem_coefs[i]; elem_coefs[i] = NULL; } if (own_mesh && mesh != NULL) { delete mesh; own_mesh = false; } e_last = NULL; free_tables(); }
int main(int argc, char *argv[]) { int status = 0, c; size_t i; static const struct option long_opts[] = { { "all", 0, 0, 'a' }, { "help", 0, 0, 'h' }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((c = getopt_long(argc, argv, "ahvVL:U:", long_opts, NULL)) != -1) { switch (c) { case 'a': /* all */ ++all; break; case 'h': /* help */ usage(stdout); break; case 'v': /* be chatty */ ++verbose; break; case 'V': /* version */ printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'L': add_label(optarg); break; case 'U': add_uuid(optarg); break; case '?': default: usage(stderr); } } argv += optind; if (!all && !numof_labels() && !numof_uuids() && *argv == NULL) usage(stderr); mnt_init_debug(0); mntcache = mnt_new_cache(); for (i = 0; i < numof_labels(); i++) status |= swapoff_by("LABEL", get_label(i), !QUIET); for (i = 0; i < numof_uuids(); i++) status |= swapoff_by("UUID", get_uuid(i), !QUIET); while (*argv != NULL) status |= do_swapoff(*argv++, !QUIET, !CANONIC); if (all) status |= swapoff_all(); free_tables(); mnt_unref_cache(mntcache); return status; }
int main(int argc, char **argv) { extern int optind; extern char *optarg; int c, err_flag = 0; char *ext; #ifdef SGDEBUG char logfilename_buffer[_MAX_PATH]; #ifdef WIN32 DWORD tmpPathLen; #endif /* WIN32 */ #endif /* SGDEBUG */ #ifdef SGDEBUG #ifdef WIN32 tmpPathLen = GetTempPath(_MAX_PATH, logfilename_buffer); if (logfilename_buffer[tmpPathLen - 1] != '\\') strcat(logfilename_buffer, "\\"); #else /* !WIN32 */ strcpy(logfilename_buffer, "/tmp/"); #endif /* WIN32 */ strcat(logfilename_buffer, sg_getlogin()); strcat(logfilename_buffer, "-"); strcat(logfilename_buffer, logfilename); if (!log_open(logfilename_buffer)) { /* open failed */ fatal(1, "%s: cannot write to %s\n", progname, logfilename_buffer); } #endif /* SGDEBUG */ while ((c = getopt(argc, argv, OPTS)) != EOF) { switch (c) { case 'h': opt_h = 1; break; case 'q': opt_q = 1; break; case 'v': opt_v = 1; break; case 'g': opt_g = 1; break; case 'a': opt_a = 1; break; case 'e': opt_e = optarg; if (opt_e[0] == '.') opt_e++; break; case 'r': opt_r = 1; break; case 'i': opt_i = 1; break; case 'c': if (opt_d) err_flag = 1; opt_c = 1; break; case 'd': if (opt_c) err_flag = 1; opt_d = 1; break; case 'b': if (opt_f || opt_s || opt_n) err_flag = 1; opt_b = 1; break; case 'f': if (opt_b || opt_s || opt_n) err_flag = 1; opt_f = 1; break; case 's': if (opt_f || opt_b || opt_n) err_flag = 1; opt_s = 1; break; case 'n': if (opt_f || opt_s || opt_b) err_flag = 1; opt_n = 1; break; default: err_flag = 1; } } if (opt_h || opt_v || err_flag) { inform_user("%s version %s (build %d).\n", progname, progver, revision()); if (opt_h || err_flag) fatal(err_flag, usage, progname); else fatal(0, "%s\n%s", copyright, version_info); } if (!(opt_b || opt_f || opt_s || opt_n)) opt_b = 1; /* done setting options */ if (argc == optind) { /* read from stdin and stdout */ outfile = stdout; fprintf(outfile, "/* %s: reading from stdin */\n", progname); using_stdio = 1; inPath = "stdin"; outPath = strdup("stdout"); opt_q = 1; /* force quiet mode */ log_printf("initting...\n"); init_tables(); scan_and_generate(stdin); log_printf("freeing memory...\n"); free_tables(); } else { inform_user("%s version %s (build %d).\n", progname, progver, revision()); /* each bloody file from the command line */ while (optind < argc) { FILE *infile; log_printf("working on %s\n", argv[optind]); /* open for read */ infile = fopen(argv[optind], "r"); if (infile == NULL) { /* open failed */ fatal(1, "%s: cannot open %s\n", progname, argv[optind]); } inPath = basename(argv[optind]); outPath = (char *)malloc(strlen(inPath) + strlen(opt_e) + 2); strcpy(outPath, inPath); /* tie off .h, .hh, .hpp, or .hxx extension */ if (((ext = strrchr(outPath, '.')) != NULL) && (((strlen(ext) == 2) && ((ext[1] == 'H') || (ext[1] == 'h'))) || (((strlen(ext) == 3) && ((ext[1] == 'H') || (ext[1] == 'h')) && ((ext[2] == 'H') || (ext[2] == 'h')))) || ((strlen(ext) == 4) && ((ext[1] == 'H') || (ext[1] == 'h')) && ((((ext[2] == 'P') || (ext[2] == 'p')) && ((ext[3] == 'P') || (ext[3] == 'p'))) || (((ext[2] == 'X') || (ext[2] == 'x')) && ((ext[3] == 'X') || (ext[3] == 'x'))))))) *ext = '\0'; assert(opt_e[0] != '.'); strcat(outPath, "."); strcat(outPath, opt_e); log_printf("initting...\n"); init_tables(); scan_existing_skeleton(); scan_and_generate(infile); log_printf("freeing memory...\n"); free_tables(); clear_skeleton_queue(); fclose(infile); optind++; } } #ifdef SGDEBUG log_flush(); log_close(); #endif /* SGDEBUG */ return 0; }
int main (int argc, char *argv[]) # endif { int column_num; long field_len; int line_num; char *msg_name; int save_statement_number = 0; # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) double end_time; double start_time; /* char time[20]; */ double total_cpu_time; struct rusage ru; # else # if !defined(_HOST_OS_UNICOS) long end_clock; # endif float end_time; float start_time; float total_cpu_time; # endif # if defined(_HOST_OS_UNICOS) && defined(_DEBUG) lowmem_check(); # endif # if defined(_TARGET32) && defined(_DEBUG) setbuf(stdout, NULL); setbuf(stderr, NULL); # endif # if defined(_HOST_OS_UNICOS) /* Lots of start up - ignore first call. See the comment block that */ /* precedes procedure cif_summary_rec in fecif.c for a discussion of the */ /* timing methods used by the different platforms. */ SECOND(&start_time); /* M_LOWFIT will eventually be in malloc.h. */ /* When it is remove this definition. */ # define M_LOWFIT 0107 /* Use lowest-fit algorithm for allocation. */ mallopt(M_LOWFIT, 1); # elif defined(_HOST_OS_MAX) /* Use clock() on MPP's (in particular T3E's) because at the time this */ /* change was made, neither SECOND() nor SECONDR() worked on T3E's. */ /* LRR 4 Mar 1997 */ clock(); start_time = 0; /* M_LOWFIT will eventually be in malloc.h. */ /* When it is remove this definition. */ # define M_LOWFIT 0107 /* Use lowest-fit algorithm for allocation. */ mallopt(M_LOWFIT, 1); # elif defined(_HOST_OS_SOLARIS) /* clock() is only semi-useful on a Sun because it rolls over in just over */ /* 2147 seconds (about 36 minutes). So on a Sun, we use clock() and */ /* time() both. If elapsed time <= 2147 seconds, the accounting info will */ /* show milliseconds (from clock()), else it will show seconds (because */ /* that is the accuracy of time()). This resolution should be good enough */ /* for a compilation exceeding 36 minutes. */ start_time = (float) time(NULL); clock(); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) getrusage (RUSAGE_SELF, &ru); start_time = (double) ru.ru_utime.tv_sec + (double) ru.ru_utime.tv_usec * 1e-6 + (double) ru.ru_stime.tv_sec + (double) ru.ru_stime.tv_usec * 1e-6; # else start_time = 0; # endif comp_phase = Pass1_Parsing; stmt_start_line = 1; /* Set in case mem problems */ init_compiler(argc, argv); /* init and process cmd line */ if (on_off_flags.preprocess_only) { goto PREPROCESS_ONLY_SKIP; } stmt_start_line = 0; while (LA_CH_CLASS != Ch_Class_EOF) { comp_phase = Pass1_Parsing; num_prog_unit_errors = 0; /* Accum errs for pgm unit */ OUTPUT_PASS_HEADER(Syntax_Pass); if (save_statement_number != 0) { statement_number = save_statement_number; } parse_prog_unit(); save_statement_number = statement_number; if (LA_CH_CLASS == Ch_Class_EOF) { issue_deferred_msgs(); } /* get current field length and save largest value */ field_len = (long) sbrk(0); # if defined(_HOST_OS_MAX) field_len &= (1 << 32) - 1; # endif if (field_len > max_field_len) { /* Max set in init_compiler */ max_field_len = field_len; /* Track max usage */ } PRINT_IR_TBL; /* If -u ir and DEBUG compiler, print ir. */ OUTPUT_PASS_HEADER(Semantics_Pass); semantics_pass_driver(); /* PASS 2 */ if (SCP_IN_ERR(curr_scp_idx)) { some_scp_in_err = TRUE; } PRINT_ALL_SYM_TBLS; /* If debug print -u options */ PRINT_FORTRAN_OUT; /* Print ir in a fortran format */ line_num = SH_GLB_LINE(SCP_LAST_SH_IDX(curr_scp_idx)); column_num = SH_COL_NUM(SCP_LAST_SH_IDX(curr_scp_idx)); if (num_prog_unit_errors == 0) { if (opt_flags.inline_lvl > Inline_Lvl_0) { comp_phase = Inlining; inline_processing(SCP_FIRST_SH_IDX(curr_scp_idx)); PRINT_IR_TBL3; } } insert_global_directives = TRUE; comp_phase = Pdg_Conversion; if (dump_flags.preinline) { /* Do not do a full compile */ if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module || ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Function || ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Subroutine) { curr_scp_idx = MAIN_SCP_IDX; #ifdef KEY /* Bug 3477 */ if (create_mod_info_file()) { /* Creates a name for the file. */ create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ } #else create_mod_info_file(); /* Creates a name for the file. */ create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ #endif /* KEY Bug 3477 */ free_tables(); /* Frees the tables. */ } } else { #ifdef KEY /* Bug 3477 */ int do_output_file = FALSE; #endif /* KEY Bug 3477 */ if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module) { #ifdef KEY /* Bug 3477 */ do_output_file = create_mod_info_file(); /* Creates a name for the file. */ #else create_mod_info_file(); /* Creates a name for the file. */ #endif /* KEY Bug 3477 */ } if (num_prog_unit_errors == 0 && (binary_output || assembly_output)) { cvrt_to_pdg(compiler_gen_date); } else if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module) { if (!SCP_IN_ERR(MAIN_SCP_IDX)) { curr_scp_idx = MAIN_SCP_IDX; #ifdef KEY /* Bug 3477 */ if (do_output_file) { create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ } #else create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ #endif /* KEY Bug 3477 */ } free_tables(); /* Frees the tables. */ } else { free_tables(); /* Frees the tables. */ } } /* ALERT - At this point, the symbol tables are invalid. */ /* Spit out the End Unit for the current program unit. The End Unit */ /* is needed if the Compiler Information File (CIF) is being produced */ /* and for the buffered message file. */ stmt_start_line = line_num; stmt_start_col = column_num; if (scp_tbl == NULL_IDX) { /* Table has been freed. */ cif_end_unit_rec(program_unit_name); } else { cif_end_unit_rec(AT_OBJ_NAME_PTR(SCP_ATTR_IDX(curr_scp_idx))); } } /* while */ clean_up_module_files(); # ifdef _NAME_SUBSTITUTION_INLINING if (!dump_flags.preinline) # endif terminate_PDGCS(); PRINT_GL_TBL; /* Prints to debug_file ifdef _DEBUG and -u gl */ PRINT_GN_TBL; /* Prints to debug_file ifdef _DEBUG and -u gn */ PREPROCESS_ONLY_SKIP: # if defined(_HOST_OS_UNICOS) SECOND(&end_time); # elif defined(_HOST_OS_MAX) end_clock = clock(); end_time = 0; # elif defined(_HOST_OS_SOLARIS) end_time = (float) time(NULL); end_clock = clock(); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) getrusage(RUSAGE_SELF, &ru); end_time = (double) ru.ru_utime.tv_sec + (double) ru.ru_utime.tv_usec * 1e-6 + (double) ru.ru_stime.tv_sec + (double) ru.ru_stime.tv_usec * 1e-6; # else end_time = 0; # endif total_cpu_time = end_time - start_time; if (cif_need_unit_rec && cif_first_pgm_unit) { /* Catastrophic errors, like a free source form program was compiled */ /* in fixed source form mode, so no Unit record was output. Output */ /* enough records to keep libcif tools happy. This routine needs to be */ /* called whether or not a CIF is being written because the buffered */ /* message file also must have the correct format. */ cif_fake_a_unit(); } /* CAUTION: The following code assumes that non-Cray platforms measure */ /* memory usage in terms of bytes and that there are 4 bytes per word. */ cif_summary_rec(release_level, compiler_gen_date, compiler_gen_time, total_cpu_time, # if defined(_HOST_OS_UNICOS) (long) 0, (some_scp_in_err) ? -3 : max_field_len); # elif defined(_HOST_OS_MAX) end_clock, (some_scp_in_err) ? -3 : max_field_len); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) (long) 0, (some_scp_in_err) ? -3 : max_field_len/4); # else /* defined(_HOST_OS_SOLARIS) */ end_clock, (some_scp_in_err) ? -3 : max_field_len/4); # endif /* Output compilation summary info if the -V option was specified on the */ /* command line. Also, issue the summary information if any messages were */ /* actually issued. */ if (cmd_line_flags.verify_option || num_errors > 0 || num_warnings > 0 || num_cautions > 0 || num_notes > 0 || num_comments > 0 || num_ansi > 0 || (num_optz_msgs > 0 && opt_flags.msgs)) { print_buffered_messages(); print_id_line(); /* Output the summary lines. The compilation time is in seconds. */ /* CAUTION: The following non-Cray code assumes a 32-bit word. */ # if defined(_HOST_OS_UNICOS) PRINTMSG (0, 104, Log_Summary, 0, (double) total_cpu_time); msg_name = "cf90"; # elif defined(_HOST_OS_MAX) PRINTMSG (0, 104, Log_Summary, 0, (double) end_clock/1000000.0); msg_name = "cf90"; # elif defined(_HOST_OS_LINUX) msg_name = PSC_NAME_PREFIX "f95"; # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) /* IRIX cannot handle the int to float change necessary to get the */ /* time printed correctly, so we'll convert it to a character string */ /* and use a different message. */ /* */ /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ /* sprintf(time, "%-1.2f", (double) total_cpu_time); PRINTMSG (0, 1310, Log_Summary, 0, time); */ msg_name = "cf90"; # elif defined(_HOST_OS_SOLARIS) PRINTMSG (0, 104, Log_Summary, 0, (total_cpu_time <= 2147.0) ? (float) end_clock/1000000.0 : (float) total_cpu_time); msg_name = "cf90"; # endif /* Maximum field length (maximum amount of memory used) in words */ /* (decimal). */ /* CAUTION: Non-Cray platforms are assumed to measure memory usage in */ /* bytes and we assume 4 bytes per word. */ # if defined(_HOST_OS_UNICOS) PRINTMSG (0, 105, Log_Summary, 0, max_field_len); # elif ! (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ PRINTMSG (0, 105, Log_Summary, 0, max_field_len/4); # endif /* Number of source lines compiled. */ # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) && !defined(_TARGET_SV2) PRINTMSG (0, 1401, Log_Summary, 0, --curr_glb_line); # else PRINTMSG (0, 106, Log_Summary, 0, --curr_glb_line); # endif /* Number of messages issued. */ # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) && !defined(_TARGET_SV2) PRINTMSG (0, 1403, Log_Summary, 0, num_errors, num_warnings, (opt_flags.msgs == 0) ? (num_cautions + num_notes + num_comments) : (num_cautions + num_notes + num_comments + num_optz_msgs), num_ansi); # else PRINTMSG (0, 107, Log_Summary, 0, num_errors, num_warnings, (opt_flags.msgs == 0) ? (num_cautions + num_notes + num_comments) : (num_cautions + num_notes + num_comments + num_optz_msgs), num_ansi); /* Code: in words; data: in words. */ /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ # if !defined(_TARGET_SV2) /* Prints blank for sv2 right now. */ PRINTMSG (0, 108, Log_Summary, 0, code_size, data_size); # endif # endif if (num_errors > 0 || num_warnings > 0 || num_cautions > 0 || num_notes > 0 || num_comments > 0 || num_ansi > 0 || (num_optz_msgs > 0 && opt_flags.msgs)) { PRINTMSG (0, 1636, Log_Summary, 0, msg_name, msg_name); } } /* End of summary printing. */ # ifdef _DEBUG /* Get memory usage reports for these global tables. */ final_src_input(); MEM_REPORT(file_path_tbl); MEM_REPORT(global_attr_tbl); MEM_REPORT(global_bounds_tbl); MEM_REPORT(global_line_tbl); MEM_REPORT(global_name_tbl); MEM_REPORT(global_type_tbl); MEM_REPORT(str_pool); # endif exit_compiler ((num_errors == 0) ? RC_OKAY : RC_USER_ERROR); } /* main */
/** * \param[in] argc argument count * \param[in] argv argument array * \return 0 on success, 1 on error * * \attention In daemon mode, it finishes immediately. */ int main(int argc, char** argv) { AppArgs::Init(); if (!( AppArgs::AddOption("about", '?', AAT_NO_VALUE, false) && AppArgs::AddOption("help", 'h', AAT_NO_VALUE, false) && AppArgs::AddOption("foreground", 'n', AAT_NO_VALUE, false) && AppArgs::AddOption("kill", 'k', AAT_NO_VALUE, false) && AppArgs::AddOption("config", 'f', AAT_MANDATORY_VALUE, false) && AppArgs::AddOption("version", 'V', AAT_NO_VALUE, false))) { fprintf(stderr, "error while initializing application"); return 1; } AppArgs::Parse(argc, argv); if (AppArgs::ExistsOption("help")) { fprintf(stderr, "%s\n", INCROND_HELP); return 0; } if (AppArgs::ExistsOption("about")) { fprintf(stderr, "%s\n", INCROND_DESCRIPTION); return 0; } if (AppArgs::ExistsOption("version")) { fprintf(stderr, "%s\n", INCROND_VERSION); return 0; } IncronCfg::Init(); std::string cfg; if (!AppArgs::GetOption("config", cfg)) cfg = INCRON_CONFIG; IncronCfg::Load(cfg); std::string lckdir; IncronCfg::GetValue("lockfile_dir", lckdir); std::string lckfile; IncronCfg::GetValue("lockfile_name", lckfile); AppInstance app(lckfile, lckdir); if (AppArgs::ExistsOption("kill")) { fprintf(stderr, "attempting to terminate a running instance of incrond...\n"); if (app.Terminate()) { fprintf(stderr, "the instance notified, going down\n"); return 0; } else { fprintf(stderr, "error - incrond probably not running\n"); return 1; } } if (AppArgs::ExistsOption("foreground")) g_daemon = false; openlog(INCROND_NAME, INCRON_LOG_OPTS, INCRON_LOG_FACIL); syslog(LOG_NOTICE, "starting service (version %s, built on %s %s)", INCRON_VERSION, __DATE__, __TIME__); AppArgs::Destroy(); int ret = 0; std::string sysBase; std::string userBase; if (!IncronCfg::GetValue("system_table_dir", sysBase)) throw InotifyException("configuration is corrupted", EINVAL); if (access(sysBase.c_str(), R_OK) != 0) { syslog(LOG_CRIT, "cannot read directory for system tables (%s): (%i) %s", sysBase.c_str(), errno, strerror(errno)); if (!g_daemon) fprintf(stderr, "cannot read directory for system tables (%s): (%i) %s", sysBase.c_str(), errno, strerror(errno)); ret = 1; goto error; } if (!IncronCfg::GetValue("user_table_dir", userBase)) throw InotifyException("configuration is corrupted", EINVAL); if (access(userBase.c_str(), R_OK) != 0) { syslog(LOG_CRIT, "cannot read directory for user tables (%s): (%i) %s", userBase.c_str(), errno, strerror(errno)); if (!g_daemon) fprintf(stderr, "cannot read directory for user tables (%s): (%i) %s", userBase.c_str(), errno, strerror(errno)); ret = 1; goto error; } try { if (g_daemon) if (daemon(0, 0) == -1) { syslog(LOG_CRIT, "daemonizing failed: (%i) %s", errno, strerror(errno)); fprintf(stderr, "daemonizing failed: (%i) %s\n", errno, strerror(errno)); ret = 1; goto error; } try { if (!app.Lock()) { syslog(LOG_CRIT, "another instance of incrond already running"); if (!g_daemon) fprintf(stderr, "another instance of incrond already running\n"); ret = 1; goto error; } } catch (AppInstException e) { syslog(LOG_CRIT, "instance lookup failed: (%i) %s", e.GetErrorNumber(), strerror(e.GetErrorNumber())); if (!g_daemon) fprintf(stderr, "instance lookup failed: (%i) %s\n", e.GetErrorNumber(), strerror(e.GetErrorNumber())); ret = 1; goto error; } prepare_pipe(); Inotify in; in.SetNonBlock(true); in.SetCloseOnExec(true); uint32_t wm = IN_CREATE | IN_CLOSE_WRITE | IN_DELETE | IN_MOVE | IN_DELETE_SELF | IN_UNMOUNT; InotifyWatch stw(sysBase, wm); in.Add(stw); InotifyWatch utw(userBase, wm); in.Add(utw); EventDispatcher ed(g_cldPipe[0], &in, &stw, &utw); try { load_tables(&ed); } catch (InotifyException e) { int err = e.GetErrorNumber(); syslog(LOG_CRIT, "%s: (%i) %s", e.GetMessage().c_str(), err, strerror(err)); ret = 1; goto error; } ed.Rebuild(); // not too efficient, but simple signal(SIGTERM, on_signal); signal(SIGINT, on_signal); signal(SIGCHLD, on_signal); syslog(LOG_NOTICE, "ready to process filesystem events"); while (!g_fFinish) { int res = poll(ed.GetPollData(), ed.GetSize(), -1); if (res > 0) { if (ed.ProcessEvents()) UserTable::FinishDone(); } else if (res < 0) { switch (errno) { case EINTR: // syscall interrupted - continue polling break; case EAGAIN: // not enough resources - wait a moment and try again syslog(LOG_WARNING, "polling failed due to resource shortage, retrying later..."); sleep(POLL_EAGAIN_WAIT); break; default: throw InotifyException("polling failed", errno, NULL); } } } free_tables(&ed); if (g_cldPipe[0] != -1) close(g_cldPipe[0]); if (g_cldPipe[1] != -1) close(g_cldPipe[1]); } catch (InotifyException e) { int err = e.GetErrorNumber(); syslog(LOG_CRIT, "*** unhandled exception occurred ***"); syslog(LOG_CRIT, " %s", e.GetMessage().c_str()); syslog(LOG_CRIT, " error: (%i) %s", err, strerror(err)); ret = 1; } error: syslog(LOG_NOTICE, "stopping service"); closelog(); return ret; }
static grub_err_t grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; struct grub_acpi_rsdp_v10 *rsdp; struct efiemu_acpi_table *cur, *t; int i, mmapregion; int numoftables; /* Default values if no RSDP is found. */ rev1 = 1; rev2 = 3; facs_addr = 0; playground = playground_ptr = 0; playground_size = 0; rsdp = (struct grub_acpi_rsdp_v10 *) grub_machine_acpi_get_rsdpv2 (); if (! rsdp) rsdp = grub_machine_acpi_get_rsdpv1 (); if (rsdp) { grub_uint32_t *entry_ptr; char *exclude = 0; char *load_only = 0; char *ptr; /* RSDT consists of header and an array of 32-bit pointers. */ struct grub_acpi_table_header *rsdt; exclude = state[0].set ? grub_strdup (state[0].arg) : 0; if (exclude) { for (ptr = exclude; *ptr; ptr++) *ptr = grub_tolower (*ptr); } load_only = state[1].set ? grub_strdup (state[1].arg) : 0; if (load_only) { for (ptr = load_only; *ptr; ptr++) *ptr = grub_tolower (*ptr); } /* Set revision variables to replicate the same version as host. */ rev1 = ! rsdp->revision; rev2 = rsdp->revision; rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr; /* Load host tables. */ for (entry_ptr = (grub_uint32_t *) (rsdt + 1); entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt) + rsdt->length); entry_ptr++) { char signature[5]; struct efiemu_acpi_table *table; struct grub_acpi_table_header *curtable = (struct grub_acpi_table_header *) (grub_addr_t) *entry_ptr; signature[4] = 0; for (i = 0; i < 4;i++) signature[i] = grub_tolower (curtable->signature[i]); /* If it's FADT it contains addresses of DSDT and FACS. */ if (grub_strcmp (signature, "facp") == 0) { struct grub_acpi_table_header *dsdt; struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable; /* Set root header variables to the same values as FADT by default. */ grub_memcpy (&root_oemid, &(fadt->hdr.oemid), sizeof (root_oemid)); grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable), sizeof (root_oemtable)); root_oemrev = fadt->hdr.oemrev; grub_memcpy (&root_creator_id, &(fadt->hdr.creator_id), sizeof (root_creator_id)); root_creator_rev = fadt->hdr.creator_rev; /* Load DSDT if not excluded. */ dsdt = (struct grub_acpi_table_header *) (grub_addr_t) fadt->dsdt_addr; if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt")) && (! load_only || grub_strword (load_only, "dsdt")) && dsdt->length >= sizeof (*dsdt)) { dsdt_size = dsdt->length; table_dsdt = grub_malloc (dsdt->length); if (! table_dsdt) { free_tables (); grub_free (exclude); grub_free (load_only); return grub_errno; } grub_memcpy (table_dsdt, dsdt, dsdt->length); } /* Save FACS address. FACS shouldn't be overridden. */ facs_addr = fadt->facs_addr; } /* Skip excluded tables. */ if (exclude && grub_strword (exclude, signature)) continue; if (load_only && ! grub_strword (load_only, signature)) continue; /* Sanity check. */ if (curtable->length < sizeof (*curtable)) continue; table = (struct efiemu_acpi_table *) grub_malloc (sizeof (struct efiemu_acpi_table)); if (! table) { free_tables (); grub_free (exclude); grub_free (load_only); return grub_errno; } table->size = curtable->length; table->addr = grub_malloc (table->size); playground_size += table->size; if (! table->addr) { free_tables (); return grub_errno; } table->next = acpi_tables; acpi_tables = table; grub_memcpy (table->addr, curtable, table->size); } grub_free (exclude); grub_free (load_only); } /* Does user specify versions to generate? */ if (state[2].set || state[3].set) { rev1 = state[2].set; if (state[3].set) rev2 = rev2 ? : 2; else
PyMODINIT_FUNC cleanupkeybindings(void) { free_tables(); }