X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famlogroll.c;h=a20ef36266364f1fbc17ce4a6ff0100a09f258cd;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=35e504d72ae4bdcb86f4aaa8c4280d76fca591ab;hpb=1194fb66aa28d9929c3f2bef3cc6c1c3f40a60a4;p=debian%2Famanda diff --git a/server-src/amlogroll.c b/server-src/amlogroll.c index 35e504d..a20ef36 100644 --- a/server-src/amlogroll.c +++ b/server-src/amlogroll.c @@ -25,7 +25,7 @@ * University of Maryland at College Park */ /* - * $Id: amlogroll.c,v 1.7 2005/09/20 21:32:26 jrjackson Exp $ + * $Id: amlogroll.c,v 1.14 2006/07/25 18:27:57 martinea Exp $ * * rename a live log file to the datestamped name. */ @@ -37,65 +37,69 @@ char *datestamp; -void handle_start P((void)); +void handle_start(void); +int main(int argc, char **argv); -int main(argc, argv) -int argc; -char **argv; +int +main( + int argc, + char ** argv) { - char *conffile; char *logfname; char *conf_logdir; FILE *logfile; - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; - char my_cwd[STR_SIZE]; + config_overwrites_t *cfg_ovr = NULL; + char *cfg_opt = NULL; + + /* + * Configure program for internationalization: + * 1) Only set the message locale for now. + * 2) Set textdomain for all amanda related programs to "amanda" + * We don't want to be forced to support dozens of message catalogs. + */ + setlocale(LC_MESSAGES, "C"); + textdomain("amanda"); safe_fd(-1, 0); set_pname("amlogroll"); - malloc_size_1 = malloc_inuse(&malloc_hist_1); + dbopen(DBG_SUBDIR_SERVER); - /* Process options */ - erroutput_type = ERR_INTERACTIVE; - if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) { - error("cannot determine current working directory"); + /* Process options */ + cfg_ovr = extract_commandline_config_overwrites(&argc, &argv); + + if (argc >= 2) { + cfg_opt = argv[1]; } - if (argc < 2) { - config_dir = stralloc2(my_cwd, "/"); - if ((config_name = strrchr(my_cwd, '/')) != NULL) { - config_name = stralloc(config_name + 1); + /* read configuration files */ + + config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt); + apply_config_overwrites(cfg_ovr); + + if (config_errors(NULL) >= CFGERR_WARNINGS) { + config_print_errors(); + if (config_errors(NULL) >= CFGERR_ERRORS) { + g_critical(_("errors processing config file")); } - } else { - config_name = stralloc(argv[1]); - config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL); } - safe_cd(); + safe_cd(); /* must happen after config_init */ - /* read configuration files */ + check_running_as(RUNNING_AS_DUMPUSER); - conffile = stralloc2(config_dir, CONFFILE_NAME); - if(read_conffile(conffile)) { - error("errors processing config file \"%s\"", conffile); - } - amfree(conffile); + dbrename(get_config_name(), DBG_SUBDIR_SERVER); - conf_logdir = getconf_str(CNF_LOGDIR); - if (*conf_logdir == '/') { - conf_logdir = stralloc(conf_logdir); - } else { - conf_logdir = stralloc2(config_dir, conf_logdir); - } + conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR)); logfname = vstralloc(conf_logdir, "/", "log", NULL); amfree(conf_logdir); if((logfile = fopen(logfname, "r")) == NULL) { - error("could not open log %s: %s", logfname, strerror(errno)); + error(_("could not open log %s: %s"), logfname, strerror(errno)); + /*NOTREACHED*/ } amfree(logfname); @@ -115,19 +119,13 @@ char **argv; log_rename(datestamp); amfree(datestamp); - amfree(config_dir); - amfree(config_name); - malloc_size_2 = malloc_inuse(&malloc_hist_2); - - if(malloc_size_1 != malloc_size_2) { - malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2); - } + dbclose(); return 0; } -void handle_start() +void handle_start(void) { static int started = 0; char *s, *fp; @@ -138,13 +136,10 @@ void handle_start() ch = *s++; skip_whitespace(s, ch); -#define sc "date" - if(ch == '\0' || strncmp(s - 1, sc, sizeof(sc)-1) != 0) { + if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) { return; /* ignore bogus line */ } - s += sizeof(sc)-1; - ch = s[-1]; -#undef sc + skip_whitespace(s, ch); if(ch == '\0') { return; @@ -153,7 +148,7 @@ void handle_start() skip_non_whitespace(s, ch); s[-1] = '\0'; datestamp = newstralloc(datestamp, fp); - s[-1] = ch; + s[-1] = (char)ch; started = 1; }