* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amflush.c,v 1.41.2.13.4.6.2.9.2.2 2004/10/20 21:49:26 martinea Exp $
+ * $Id: amflush.c,v 1.80 2006/01/14 04:37:19 paddy_s Exp $
*
* write files from work directory onto tape
*/
void redirect_stderr P((void));
void detach P((void));
void run_dumps P((void));
-
+static int get_letter_from_user P((void));
int main(main_argc, main_argv)
int main_argc;
char *dumpuser;
char **datearg = NULL;
int nb_datearg = 0;
- int fd;
char *conffile;
char *conf_diskfile;
char *conf_tapelist;
char *conf_logfile;
- disklist_t *diskqp;
+ disklist_t diskq;
disk_t *dp;
- pid_t pid, driver_pid, reporter_pid;
+ pid_t pid;
+ pid_t driver_pid, reporter_pid;
amwait_t exitcode;
int opt;
dumpfile_t file;
char date_string[100];
time_t today;
- 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);
- }
-
+ safe_fd(-1, 0);
safe_cd();
set_pname("amflush");
+ /* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
erroutput_type = ERR_INTERACTIVE;
case 's': redirect = 0;
break;
case 'D': if (datearg == NULL)
- datearg = alloc(21*sizeof(char *));
+ datearg = alloc(21*sizeof(char *));
if(nb_datearg == 20) {
fprintf(stderr,"maximum of 20 -D arguments.\n");
exit(1);
}
config_name = main_argv[0];
-
config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
+
conffile = stralloc2(config_dir, CONFFILE_NAME);
- if(read_conffile(conffile)) {
+ if(read_conffile(conffile))
error("errors processing config file \"%s\"", conffile);
- }
amfree(conffile);
+
conf_diskfile = getconf_str(CNF_DISKFILE);
if (*conf_diskfile == '/') {
conf_diskfile = stralloc(conf_diskfile);
} else {
conf_diskfile = stralloc2(config_dir, conf_diskfile);
}
- if((diskqp = read_diskfile(conf_diskfile)) == NULL) {
+ if (read_diskfile(conf_diskfile, &diskq) < 0)
error("could not read disklist file \"%s\"", conf_diskfile);
- }
- match_disklist(diskqp, main_argc-1, main_argv+1);
+ match_disklist(&diskq, main_argc-1, main_argv+1);
amfree(conf_diskfile);
+
conf_tapelist = getconf_str(CNF_TAPELIST);
if (*conf_tapelist == '/') {
conf_tapelist = stralloc(conf_tapelist);
} else {
conf_tapelist = stralloc2(config_dir, conf_tapelist);
}
- if(read_tapelist(conf_tapelist)) {
+ if(read_tapelist(conf_tapelist))
error("could not load tapelist \"%s\"", conf_tapelist);
- }
amfree(conf_tapelist);
datestamp = construct_datestamp(NULL);
conf_logdir = stralloc2(config_dir, conf_logdir);
}
conf_logfile = vstralloc(conf_logdir, "/log", NULL);
- if (access(conf_logfile, F_OK) == 0) {
+ if (access(conf_logfile, F_OK) == 0)
error("%s exists: amdump or amflush is already running, or you must run amcleanup", conf_logfile);
- }
amfree(conf_logfile);
-
+
driver_program = vstralloc(libexecdir, "/", "driver", versionsuffix(),
- NULL);
+ NULL);
reporter_program = vstralloc(sbindir, "/", "amreport", versionsuffix(),
NULL);
logroll_program = vstralloc(libexecdir, "/", "amlogroll", versionsuffix(),
if(!batch) confirm();
- for(dp = diskqp->head; dp != NULL; dp = dp->next) {
+ for(dp = diskq.head; dp != NULL; dp = dp->next) {
if(dp->todo)
log_add(L_DISK, "%s %s", dp->host->hostname, dp->name);
}
/* First, find out the last existing errfile, */
/* to avoid ``infinite'' loops if tapecycle is infinite */
- ap_snprintf(number,100,"%d",days);
+ snprintf(number,100,"%d",days);
errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
while ( days < maxdays && stat(errfilex,&stat_buf)==0) {
days++;
- ap_snprintf(number,100,"%d",days);
+ snprintf(number,100,"%d",days);
errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
}
- ap_snprintf(number,100,"%d",days);
+ snprintf(number,100,"%d",days);
errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
nerrfilex = NULL;
while (days > 1) {
amfree(nerrfilex);
nerrfilex = errfilex;
days--;
- ap_snprintf(number,100,"%d",days);
+ snprintf(number,100,"%d",days);
errfilex = vstralloc(errfile, ".", number, NULL);
if (rename(errfilex, nerrfilex) != 0) {
error("cannot rename \"%s\" to \"%s\": %s",
}
-int get_letter_from_user()
+static int get_letter_from_user()
{
- int r = '\0';
- int ch;
+ int r, ch;
fflush(stdout); fflush(stderr);
while((ch = getchar()) != EOF && ch != '\n' && isspace(ch)) {}