* University of Maryland at College Park
*/
/*
- * $Id: selfcheck.c,v 1.40.2.3.4.4.2.22 2003/11/18 18:04:26 martinea Exp $
+ * $Id: selfcheck.c,v 1.40.2.3.4.4.2.22.2.3 2005/09/20 21:31:52 jrjackson Exp $
*
* do self-check and send back any error messages
*/
int need_runtar=0;
int need_gnutar=0;
int need_compress_path=0;
+int need_calcsize=0;
static am_feature_t *our_features = NULL;
static char *our_feature_string = NULL;
/* local functions */
int main P((int argc, char **argv));
-static void check_options P((char *program, char *disk, char *device, option_t *options));
-static void check_disk P((char *program, char *disk, char *amdevice, int level));
+static void check_options P((char *program, char *calcprog, char *disk, char *device, option_t *options));
+static void check_disk P((char *program, char *calcprog, char *disk, char *amdevice, int level));
static void check_overall P((void));
static void check_access P((char *filename, int mode));
static void check_file P((char *filename, int mode));
int level;
char *line = NULL;
char *program = NULL;
+ char *calcprog = NULL;
char *disk = NULL;
char *device = NULL;
char *optstr = NULL;
char *err_extra = NULL;
char *s, *fp;
int ch;
- int fd;
unsigned long malloc_hist_1, malloc_size_1;
unsigned long malloc_hist_2, malloc_size_2;
option_t *options;
/* initialize */
- 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("selfcheck");
skip_non_whitespace(s, ch);
s[-1] = '\0'; /* terminate the program name */
+ if(strncmp(program, "CALCSIZE", 8) == 0) {
+ skip_whitespace(s, ch); /* find program name */
+ if (ch == '\0') {
+ goto err; /* no program */
+ }
+ calcprog = s - 1;
+ skip_non_whitespace(s, ch);
+ s[-1] = '\0';
+ }
+ else {
+ calcprog = NULL;
+ }
+
skip_whitespace(s, ch); /* find disk name */
if (ch == '\0') {
goto err; /* no disk */
skip_non_whitespace(s, ch);
s[-1] = '\0'; /* terminate the options */
options = parse_options(optstr, disk, device, g_options->features, 1);
- check_options(program, disk, device, options);
- check_disk(program, disk, device, level);
+ check_options(program, calcprog, disk, device, options);
+ check_disk(program, calcprog, disk, device, level);
free_sl(options->exclude_file);
free_sl(options->exclude_list);
free_sl(options->include_file);
need_runtar=1;
need_gnutar=1;
need_compress_path=1;
- check_disk(program, disk, device, level);
+ need_calcsize=1;
+ check_disk(program, calcprog, disk, device, level);
} else {
goto err; /* bad syntax */
}
static void
-check_options(program, disk, device, options)
- char *program, *disk, *device;
+check_options(program, calcprog, disk, device, options)
+ char *program, *calcprog, *disk, *device;
option_t *options;
{
- if(strcmp(program,"GNUTAR") == 0) {
+ char *myprogram = program;
+
+ if(strcmp(myprogram,"CALCSIZE") == 0) {
+ int nb_exclude = 0;
+ int nb_include = 0;
+ char *file_exclude = NULL;
+ char *file_include = NULL;
+
+ if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
+ if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
+ if(options->include_file) nb_include += options->include_file->nb_element;
+ if(options->include_list) nb_include += options->include_list->nb_element;
+
+ if(nb_exclude > 0) file_exclude = build_exclude(disk, device, options, 1);
+ if(nb_include > 0) file_include = build_include(disk, device, options, 1);
+
+ amfree(file_exclude);
+ amfree(file_include);
+
+ need_calcsize=1;
+ myprogram = calcprog;
+ }
+
+ if(strcmp(myprogram,"GNUTAR") == 0) {
need_gnutar=1;
if(disk[0] == '/' && disk[1] == '/') {
if(options->exclude_file && options->exclude_file->nb_element > 1) {
need_runtar=1;
}
}
- if(strcmp(program,"DUMP") == 0) {
+
+ if(strcmp(myprogram,"DUMP") == 0) {
if(options->exclude_file && options->exclude_file->nb_element > 0) {
printf("ERROR [DUMP does not support exclude file]\n");
}
need_compress_path=1;
}
-static void check_disk(program, disk, amdevice, level)
-char *program, *disk, *amdevice;
+static void check_disk(program, calcprog, disk, amdevice, level)
+char *program, *calcprog, *disk, *amdevice;
int level;
{
char *device = NULL;
int access_result;
char *access_type;
char *extra_info = NULL;
+ char *myprogram = program;
+
+ if(strcmp(myprogram,"CALCSIZE") == 0) {
+ if(amdevice[0] == '/' && amdevice[1] == '/') {
+ err = vstralloc("Can't use CALCSIZE for samba estimate,",
+ " use CLIENT: ",
+ amdevice,
+ NULL);
+ goto common_exit;
+ }
+ myprogram = calcprog;
+ }
dbprintf(("%s: checking disk %s\n", debug_prefix_time(NULL), disk));
- if (strcmp(program, "GNUTAR") == 0) {
+ if (strcmp(myprogram, "GNUTAR") == 0) {
if(amdevice[0] == '/' && amdevice[1] == '/') {
#ifdef SAMBA_CLIENT
int nullfd, checkerr;
#endif
}
+ if( need_calcsize ) {
+ char *cmd;
+
+ cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL);
+
+ check_file(cmd, X_OK);
+
+ amfree(cmd);
+ }
+
if( need_samba ) {
#ifdef SAMBA_CLIENT
check_file(SAMBA_CLIENT, X_OK);