2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: amlogroll.c,v 1.7 2005/09/20 21:32:26 jrjackson Exp $
30 * rename a live log file to the datestamped name.
40 void handle_start P((void));
50 unsigned long malloc_hist_1, malloc_size_1;
51 unsigned long malloc_hist_2, malloc_size_2;
52 char my_cwd[STR_SIZE];
56 set_pname("amlogroll");
58 malloc_size_1 = malloc_inuse(&malloc_hist_1);
62 erroutput_type = ERR_INTERACTIVE;
64 if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) {
65 error("cannot determine current working directory");
69 config_dir = stralloc2(my_cwd, "/");
70 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
71 config_name = stralloc(config_name + 1);
74 config_name = stralloc(argv[1]);
75 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
80 /* read configuration files */
82 conffile = stralloc2(config_dir, CONFFILE_NAME);
83 if(read_conffile(conffile)) {
84 error("errors processing config file \"%s\"", conffile);
88 conf_logdir = getconf_str(CNF_LOGDIR);
89 if (*conf_logdir == '/') {
90 conf_logdir = stralloc(conf_logdir);
92 conf_logdir = stralloc2(config_dir, conf_logdir);
94 logfname = vstralloc(conf_logdir, "/", "log", NULL);
97 if((logfile = fopen(logfname, "r")) == NULL) {
98 error("could not open log %s: %s", logfname, strerror(errno));
102 erroutput_type |= ERR_AMANDALOG;
103 set_logerror(logerror);
105 while(get_logline(logfile)) {
106 if(curlog == L_START) {
108 if(datestamp != NULL) {
115 log_rename(datestamp);
121 malloc_size_2 = malloc_inuse(&malloc_hist_2);
123 if(malloc_size_1 != malloc_size_2) {
124 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
132 static int started = 0;
140 skip_whitespace(s, ch);
142 if(ch == '\0' || strncmp(s - 1, sc, sizeof(sc)-1) != 0) {
143 return; /* ignore bogus line */
148 skip_whitespace(s, ch);
153 skip_non_whitespace(s, ch);
155 datestamp = newstralloc(datestamp, fp);