X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famlogroll.c;h=dd38d2195dd9fc25baca3caa7e8dda5f92404eb2;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=728ee3a3bff796eb23cd457608f669242d9177c3;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/server-src/amlogroll.c b/server-src/amlogroll.c index 728ee3a..dd38d21 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.1.2.1.4.1.2.3 2003/10/27 17:55:39 martinea Exp $ + * $Id: amlogroll.c,v 1.14 2006/07/25 18:27:57 martinea Exp $ * * rename a live log file to the datestamped name. */ @@ -33,83 +33,76 @@ #include "amanda.h" #include "conffile.h" #include "logfile.h" -#include "version.h" 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; - int fd; - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; - char my_cwd[STR_SIZE]; - - for(fd = 3; fd < FD_SETSIZE; fd++) { - /* - * Make sure nobody spoofs us with a lot of extra open files - * that would cause an open we do to get a very high file - * descriptor, which in turn might be used as an index into - * an array (e.g. an fd_set). - */ - close(fd); - } + config_overrides_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); + + add_amanda_log_handler(amanda_log_stderr); /* Process options */ - - erroutput_type = ERR_INTERACTIVE; + cfg_ovr = extract_commandline_config_overrides(&argc, &argv); - if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) { - error("cannot determine current working directory"); + 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 */ + + set_config_overrides(cfg_ovr); + config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt); + + 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); - erroutput_type |= ERR_AMANDALOG; - set_logerror(logerror); + add_amanda_log_handler(amanda_log_trace_log); while(get_logline(logfile)) { if(curlog == L_START) { @@ -124,19 +117,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; @@ -147,13 +134,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; @@ -162,7 +146,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; }