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.14 2006/07/25 18:27:57 martinea Exp $
30 * rename a live log file to the datestamped name.
40 void handle_start(void);
41 int main(int argc, char **argv);
43 int main(int argc, char **argv)
49 unsigned long malloc_hist_1, malloc_size_1;
50 unsigned long malloc_hist_2, malloc_size_2;
51 char my_cwd[STR_SIZE];
52 int new_argc, my_argc;
53 char **new_argv, **my_argv;
57 set_pname("amlogroll");
59 dbopen(DBG_SUBDIR_SERVER);
61 malloc_size_1 = malloc_inuse(&malloc_hist_1);
65 erroutput_type = ERR_INTERACTIVE;
67 if (getcwd(my_cwd, SIZEOF(my_cwd)) == NULL) {
68 error("cannot determine current working directory");
72 parse_server_conf(argc, argv, &new_argc, &new_argv);
77 config_dir = stralloc2(my_cwd, "/");
78 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
79 config_name = stralloc(config_name + 1);
82 config_name = stralloc(my_argv[1]);
83 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
88 /* read configuration files */
90 conffile = stralloc2(config_dir, CONFFILE_NAME);
91 if(read_conffile(conffile)) {
92 error("errors processing config file \"%s\"", conffile);
97 dbrename(config_name, DBG_SUBDIR_SERVER);
99 report_bad_conf_arg();
101 conf_logdir = getconf_str(CNF_LOGDIR);
102 if (*conf_logdir == '/') {
103 conf_logdir = stralloc(conf_logdir);
105 conf_logdir = stralloc2(config_dir, conf_logdir);
107 logfname = vstralloc(conf_logdir, "/", "log", NULL);
110 if((logfile = fopen(logfname, "r")) == NULL) {
111 error("could not open log %s: %s", logfname, strerror(errno));
116 erroutput_type |= ERR_AMANDALOG;
117 set_logerror(logerror);
119 while(get_logline(logfile)) {
120 if(curlog == L_START) {
122 if(datestamp != NULL) {
129 log_rename(datestamp);
134 free_new_argv(new_argc, new_argv);
135 free_server_config();
137 malloc_size_2 = malloc_inuse(&malloc_hist_2);
139 if(malloc_size_1 != malloc_size_2) {
140 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
148 void handle_start(void)
150 static int started = 0;
158 skip_whitespace(s, ch);
160 if(ch == '\0' || strncmp(s - 1, sc, SIZEOF(sc)-1) != 0) {
161 return; /* ignore bogus line */
166 skip_whitespace(s, ch);
171 skip_non_whitespace(s, ch);
173 datestamp = newstralloc(datestamp, fp);