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 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amstar.c 8888 2007-10-02 13:40:42Z martineau $
29 * send estimated backup sizes using dump
34 * STAR-PATH (default STAR)
42 * INCLUDE-LIST (for restore only)
50 #include "pipespawn.h"
51 #include "amfeatures.h"
52 #include "amandates.h"
56 #include "client_util.h"
59 #include "sendbackup.h"
61 int debug_application = 1;
62 #define application_debug(i, ...) do { \
63 if ((i) <= debug_application) { \
64 dbprintf(__VA_ARGS__); \
68 static amregex_t init_re_table[] = {
69 /* tar prints the size in bytes */
70 AM_SIZE_RE("star: [0-9][0-9]* blocks", 10240, 1),
71 AM_NORMAL_RE("^could not open conf file"),
72 AM_NORMAL_RE("^Type of this level "),
73 AM_NORMAL_RE("^Date of this level "),
74 AM_NORMAL_RE("^Date of last level "),
75 AM_NORMAL_RE("^Dump record level "),
76 AM_NORMAL_RE("^Throughput"),
77 AM_NORMAL_RE("^.*is sparse$"),
79 #ifdef IGNORE_TAR_ERRORS
80 AM_NORMAL_RE("^.*shrunk*$"),
81 AM_NORMAL_RE("^.*changed size.*$"),
82 AM_NORMAL_RE("^.*Cannot listxattr for.*$"),
83 AM_NORMAL_RE("^.Cannot: stat .*$"),
84 AM_NORMAL_RE("^.Missing links .*$"),
85 AM_NORMAL_RE("^.Cannot get xattr.*$"),
86 AM_NORMAL_RE("^.Cannot.*acl.*$"),
89 AM_NORMAL_RE("^star: dumped [0-9][0-9]* (tar )?files"),
90 AM_NORMAL_RE("^.*The following problems occurred during .* processing.*$"),
91 AM_NORMAL_RE("^.*Processed all possible files, despite earlier errors.*$"),
92 AM_NORMAL_RE("^.*not written due to problems during backup.*$"),
94 AM_STRANGE_RE("^Perform a level 0 dump first.*$"),
96 /* catch-all: DMP_STRANGE is returned for all other lines */
99 static amregex_t *re_table;
101 /* local functions */
102 int main(int argc, char **argv);
104 typedef struct application_argument_s {
111 GSList *command_options;
115 } application_argument_t;
117 enum { CMD_ESTIMATE, CMD_BACKUP };
119 static void amstar_support(application_argument_t *argument);
120 static void amstar_selfcheck(application_argument_t *argument);
121 static void amstar_estimate(application_argument_t *argument);
122 static void amstar_backup(application_argument_t *argument);
123 static void amstar_restore(application_argument_t *argument);
124 static void amstar_validate(application_argument_t *argument);
125 static GPtrArray *amstar_build_argv(application_argument_t *argument,
128 static int check_device(application_argument_t *argument);
130 static char *star_path;
131 static char *star_tardumps;
132 static int star_dle_tardumps;
133 static int star_onefilesystem;
134 static int star_sparse;
136 static char *star_directory;
137 static GSList *normal_message = NULL;
138 static GSList *ignore_message = NULL;
139 static GSList *strange_message = NULL;
141 static struct option long_options[] = {
142 {"config" , 1, NULL, 1},
143 {"host" , 1, NULL, 2},
144 {"disk" , 1, NULL, 3},
145 {"device" , 1, NULL, 4},
146 {"level" , 1, NULL, 5},
147 {"index" , 1, NULL, 6},
148 {"message" , 1, NULL, 7},
149 {"collection" , 0, NULL, 8},
150 {"record" , 0, NULL, 9},
151 {"star-path" , 1, NULL, 10},
152 {"star-tardump" , 1, NULL, 11},
153 {"star-dle-tardump", 1, NULL, 12},
154 {"one-file-system" , 1, NULL, 13},
155 {"sparse" , 1, NULL, 14},
156 {"calcsize" , 0, NULL, 15},
157 {"normal" , 1, NULL, 16},
158 {"ignore" , 1, NULL, 17},
159 {"strange" , 1, NULL, 18},
160 {"include-list" , 1, NULL, 19},
161 {"exclude-list" , 1, NULL, 20},
162 {"directory" , 1, NULL, 21},
163 {"command-options" , 1, NULL, 22},
164 {"exclude-file" , 1, NULL, 23},
165 {"acl" , 1, NULL, 24},
177 application_argument_t argument;
184 star_tardumps = "/etc/tardumps";
185 star_dle_tardumps = 0;
186 star_onefilesystem = 1;
189 star_directory = NULL;
194 * Configure program for internationalization:
195 * 1) Only set the message locale for now.
196 * 2) Set textdomain for all amanda related programs to "amanda"
197 * We don't want to be forced to support dozens of message catalogs.
199 setlocale(LC_MESSAGES, "C");
200 textdomain("amanda");
203 printf("ERROR no command given to amstar\n");
204 error(_("No command given to amstar"));
207 /* drop root privileges */
208 if (!set_root_privs(0)) {
209 if (strcmp(argv[1], "selfcheck") == 0) {
210 printf("ERROR amstar must be run setuid root\n");
212 error(_("amstar must be run setuid root"));
219 /* Don't die when child closes pipe */
220 signal(SIGPIPE, SIG_IGN);
222 #if defined(USE_DBMALLOC)
223 malloc_size_1 = malloc_inuse(&malloc_hist_1);
226 add_amanda_log_handler(amanda_log_stderr);
227 add_amanda_log_handler(amanda_log_syslog);
228 dbopen(DBG_SUBDIR_CLIENT);
230 dbprintf(_("version %s\n"), VERSION);
232 config_init(CONFIG_INIT_CLIENT, NULL);
234 //check_running_as(RUNNING_AS_DUMPUSER_PREFERRED);
236 //RUNNING_AS_CLIENT_LOGIN from selfcheck, sendsize, sendbackup
241 argument.config = NULL;
242 argument.host = NULL;
243 argument.message = 0;
244 argument.collection = 0;
245 argument.calcsize = 0;
246 argument.level = NULL;
247 argument.command_options = NULL;
248 init_dle(&argument.dle);
252 int option_index = 0;
253 c = getopt_long (argc, argv, "", long_options, &option_index);
258 case 1: argument.config = stralloc(optarg);
260 case 2: argument.host = stralloc(optarg);
262 case 3: argument.dle.disk = stralloc(optarg);
264 case 4: argument.dle.device = stralloc(optarg);
266 case 5: argument.level = g_slist_append(argument.level,
267 GINT_TO_POINTER(atoi(optarg)));
269 case 6: argument.dle.create_index = 1;
271 case 7: argument.message = 1;
273 case 8: argument.collection = 1;
275 case 9: argument.dle.record = 1;
277 case 10: star_path = stralloc(optarg);
279 case 11: star_tardumps = stralloc(optarg);
281 case 12: if (optarg && strcasecmp(optarg, "NO") == 0)
282 star_dle_tardumps = 0;
283 else if (optarg && strcasecmp(optarg, "YES") == 0)
284 star_dle_tardumps = 1;
285 else if (strcasecmp(command, "selfcheck") == 0)
286 printf(_("ERROR [%s: bad STAR-DLE-TARDUMP property value (%s)]\n"), get_pname(), optarg);
288 case 13: if (optarg && strcasecmp(optarg, "YES") != 0) {
289 /* This option is required to be YES */
290 /* star_onefilesystem = 0; */
293 case 14: if (optarg && strcasecmp(optarg, "NO") == 0)
295 else if (optarg && strcasecmp(optarg, "YES") == 0)
297 else if (strcasecmp(command, "selfcheck") == 0)
298 printf(_("ERROR [%s: bad SPARSE property value (%s)]\n"), get_pname(), optarg);
300 case 15: argument.calcsize = 1;
304 g_slist_append(normal_message, optarg);
308 g_slist_append(ignore_message, optarg);
312 g_slist_append(strange_message, optarg);
315 argument.dle.include_list =
316 append_sl(argument.dle.include_list, optarg);
319 argument.dle.exclude_list =
320 append_sl(argument.dle.exclude_list, optarg);
323 star_directory = stralloc(optarg);
325 case 22: argument.command_options =
326 g_slist_append(argument.command_options,
329 argument.dle.exclude_file =
330 append_sl(argument.dle.exclude_file, optarg);
332 case 24: if (optarg && strcasecmp(optarg, "NO") == 0)
334 else if (optarg && strcasecmp(optarg, "YES") == 0)
336 else if (strcasecmp(command, "selfcheck") == 0)
337 printf(_("ERROR [%s: bad ACL property value (%s)]\n"), get_pname(), optarg);
345 if (!argument.dle.disk && argument.dle.device)
346 argument.dle.disk = stralloc(argument.dle.device);
347 if (!argument.dle.device && argument.dle.disk)
348 argument.dle.device = stralloc(argument.dle.disk);
350 argument.argc = argc - optind;
351 argument.argv = argv + optind;
353 if (argument.config) {
354 /* overlay this configuration on the existing (nameless) configuration */
355 config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
357 dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
361 if (config_errors(NULL) >= CFGERR_ERRORS) {
362 g_critical(_("errors processing config file"));
365 re_table = build_re_table(init_re_table, normal_message, ignore_message,
368 if (strcmp(command, "support") == 0) {
369 amstar_support(&argument);
370 } else if (strcmp(command, "selfcheck") == 0) {
371 amstar_selfcheck(&argument);
372 } else if (strcmp(command, "estimate") == 0) {
373 amstar_estimate(&argument);
374 } else if (strcmp(command, "backup") == 0) {
375 amstar_backup(&argument);
376 } else if (strcmp(command, "restore") == 0) {
377 amstar_restore(&argument);
378 } else if (strcmp(command, "validate") == 0) {
379 amstar_validate(&argument);
381 fprintf(stderr, "Unknown command `%s'.\n", command);
389 application_argument_t *argument)
392 fprintf(stdout, "CONFIG YES\n");
393 fprintf(stdout, "HOST YES\n");
394 fprintf(stdout, "DISK YES\n");
395 fprintf(stdout, "MAX-LEVEL 9\n");
396 fprintf(stdout, "INDEX-LINE YES\n");
397 fprintf(stdout, "INDEX-XML NO\n");
398 fprintf(stdout, "MESSAGE-LINE YES\n");
399 fprintf(stdout, "MESSAGE-XML NO\n");
400 fprintf(stdout, "RECORD YES\n");
401 fprintf(stdout, "INCLUDE-FILE NO\n");
402 fprintf(stdout, "INCLUDE-LIST YES\n");
403 fprintf(stdout, "EXCLUDE-FILE YES\n");
404 fprintf(stdout, "EXCLUDE-LIST YES\n");
405 fprintf(stdout, "COLLECTION NO\n");
406 fprintf(stdout, "MULTI-ESTIMATE YES\n");
407 fprintf(stdout, "CALCSIZE YES\n");
408 fprintf(stdout, "CLIENT-ESTIMATE YES\n");
413 application_argument_t *argument)
415 fprintf(stdout, "OK amstar\n");
416 if (argument->dle.disk) {
417 char *qdisk = quote_string(argument->dle.disk);
418 fprintf(stdout, "OK %s\n", qdisk);
421 if (argument->dle.device) {
422 char *qdevice = quote_string(argument->dle.device);
423 fprintf(stdout, "OK %s\n", qdevice);
426 if (star_directory) {
427 char *qdirectory = quote_string(star_directory);
428 fprintf(stdout, "OK %s\n", qdirectory);
432 if (argument->dle.include_list &&
433 argument->dle.include_list->nb_element >= 0) {
434 fprintf(stdout, "ERROR include-list not supported for backup\n");
438 fprintf(stdout, "ERROR STAR-PATH not defined\n");
440 check_file(star_path, X_OK);
443 if (argument->calcsize) {
444 char *calcsize = vstralloc(amlibexecdir, "/", "calcsize", NULL);
445 check_file(calcsize, X_OK);
446 check_suid(calcsize);
451 char *amandates_file;
452 amandates_file = getconf_str(CNF_AMANDATES);
453 check_file(amandates_file, R_OK|W_OK);
457 if (argument->dle.device) {
458 check_dir(argument->dle.device, R_OK);
465 application_argument_t *argument)
471 FILE *dumpout = NULL;
477 amwait_t wait_status;
482 GSList *levels = NULL;
484 if (!argument->level) {
485 fprintf(stderr, "ERROR No level argument\n");
486 error(_("No level argument"));
488 if (!argument->dle.disk) {
489 fprintf(stderr, "ERROR No disk argument\n");
490 error(_("No disk argument"));
492 if (!argument->dle.device) {
493 fprintf(stderr, "ERROR No device argument\n");
494 error(_("No device argument"));
497 if (argument->dle.include_list &&
498 argument->dle.include_list->nb_element >= 0) {
499 fprintf(stderr, "ERROR include-list not supported for backup\n");
502 if (check_device(argument) == 0) {
506 qdisk = quote_string(argument->dle.disk);
507 if (argument->calcsize) {
510 if (star_directory) {
511 dirname = star_directory;
513 dirname = argument->dle.device;
515 run_calcsize(argument->config, "STAR", argument->dle.disk, dirname,
516 argument->level, NULL, NULL);
521 errmsg = vstrallocf(_("STAR-PATH not defined"));
524 cmd = stralloc(star_path);
526 start_time = curclock();
528 for (levels = argument->level; levels != NULL; levels = levels->next) {
529 level = GPOINTER_TO_INT(levels->data);
530 argv_ptr = amstar_build_argv(argument, level, CMD_ESTIMATE);
532 if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
533 errmsg = vstrallocf(_("Cannot access /dev/null : %s"),
538 starpid = pipespawnv(cmd, STDERR_PIPE, 1,
539 &nullfd, &nullfd, &pipefd,
540 (char **)argv_ptr->pdata);
542 dumpout = fdopen(pipefd,"r");
544 errmsg = vstrallocf(_("Can't fdopen: %s"), strerror(errno));
549 while (size < 0 && (fgets(line, sizeof(line), dumpout)) != NULL) {
550 if (line[strlen(line)-1] == '\n') /* remove trailling \n */
551 line[strlen(line)-1] = '\0';
554 dbprintf("%s\n", line);
555 /* check for size match */
557 for(rp = re_table; rp->regex != NULL; rp++) {
558 if(match(rp->regex, line)) {
559 if (rp->typ == DMP_SIZE) {
560 size = ((the_num(line, rp->field)*rp->scale+1023.0)/1024.0);
562 size = 1.0; /* found on NeXT -- sigh */
570 while ((fgets(line, sizeof(line), dumpout)) != NULL) {
571 dbprintf("%s", line);
575 dbprintf(_("estimate time for %s level %d: %s\n"),
578 walltime_str(timessub(curclock(), start_time)));
579 if(size == (off_t)-1) {
580 errmsg = vstrallocf(_("no size line match in %s output"),
582 dbprintf(_("%s for %s\n"), errmsg, qdisk);
584 } else if(size == (off_t)0 && argument->level == 0) {
585 dbprintf(_("possible %s problem -- is \"%s\" really empty?\n"),
586 cmd, argument->dle.disk);
589 dbprintf(_("estimate size for %s level %d: %lld KB\n"),
594 kill(-starpid, SIGTERM);
596 dbprintf(_("waiting for %s \"%s\" child\n"), cmd, qdisk);
597 waitpid(starpid, &wait_status, 0);
598 if (WIFSIGNALED(wait_status)) {
599 errmsg = vstrallocf(_("%s terminated with signal %d: see %s"),
600 cmd, WTERMSIG(wait_status), dbfn());
601 } else if (WIFEXITED(wait_status)) {
602 if (WEXITSTATUS(wait_status) != 0) {
603 errmsg = vstrallocf(_("%s exited with status %d: see %s"),
604 cmd, WEXITSTATUS(wait_status), dbfn());
609 errmsg = vstrallocf(_("%s got bad exit: see %s"), cmd, dbfn());
611 dbprintf(_("after %s %s wait\n"), cmd, qdisk);
613 g_ptr_array_free_full(argv_ptr);
618 fprintf(stdout, "%d %lld 1\n", level, (long long)size);
625 dbprintf("%s\n", errmsg);
626 qerrmsg = quote_string(errmsg);
628 dbprintf("%s", errmsg);
629 fprintf(stdout, "ERROR %s\n", qerrmsg);
637 application_argument_t *argument)
644 off_t dump_size = -1;
654 FILE *indexstream = NULL;
660 regex_t regex_special;
661 regex_t regex_symbolic;
664 mesgstream = fdopen(mesgf, "w");
666 error(_("error mesgstream(%d): %s\n"), mesgf, strerror(errno));
669 if (!argument->level) {
670 fprintf(mesgstream, "? No level argument\n");
671 error(_("No level argument"));
673 if (!argument->dle.disk) {
674 fprintf(mesgstream, "? No disk argument\n");
675 error(_("No disk argument"));
677 if (!argument->dle.device) {
678 fprintf(mesgstream, "? No device argument\n");
679 error(_("No device argument"));
682 if (argument->dle.include_list &&
683 argument->dle.include_list->nb_element >= 0) {
684 fprintf(mesgstream, "? include-list not supported for backup\n");
687 level = GPOINTER_TO_INT(argument->level->data);
689 qdisk = quote_string(argument->dle.disk);
691 argv_ptr = amstar_build_argv(argument, level, CMD_BACKUP);
693 cmd = stralloc(star_path);
695 starpid = pipespawnv(cmd, STDIN_PIPE|STDERR_PIPE, 1,
696 &dumpin, &dataf, &outf, (char **)argv_ptr->pdata);
698 g_ptr_array_free_full(argv_ptr);
699 /* close the write ends of the pipes */
702 if (argument->dle.create_index) {
703 indexstream = fdopen(indexf, "w");
705 error(_("error indexstream(%d): %s\n"), indexf, strerror(errno));
708 outstream = fdopen(outf, "r");
710 error(_("error outstream(%d): %s\n"), outf, strerror(errno));
713 regcomp(®ex_root, "^a \\.\\/ directory$", REG_EXTENDED|REG_NEWLINE);
714 regcomp(®ex_dir, "^a (.*) directory$", REG_EXTENDED|REG_NEWLINE);
715 regcomp(®ex_file, "^a (.*) (.*) bytes", REG_EXTENDED|REG_NEWLINE);
716 regcomp(®ex_special, "^a (.*) special", REG_EXTENDED|REG_NEWLINE);
717 regcomp(®ex_symbolic, "^a (.*) symbolic", REG_EXTENDED|REG_NEWLINE);
718 regcomp(®ex_hard, "^a (.*) link to", REG_EXTENDED|REG_NEWLINE);
720 while ((fgets(line, sizeof(line), outstream)) != NULL) {
721 regmatch_t regmatch[3];
723 if (line[strlen(line)-1] == '\n') /* remove trailling \n */
724 line[strlen(line)-1] = '\0';
726 if (regexec(®ex_root, line, 1, regmatch, 0) == 0) {
727 if (argument->dle.create_index)
728 fprintf(indexstream, "%s\n", "/");
732 if (regexec(®ex_dir, line, 3, regmatch, 0) == 0) {
733 if (argument->dle.create_index && regmatch[1].rm_so == 2) {
734 line[regmatch[1].rm_eo+1]='\0';
735 fprintf(indexstream, "/%s\n", &line[regmatch[1].rm_so]);
740 if (regexec(®ex_file, line, 3, regmatch, 0) == 0 ||
741 regexec(®ex_special, line, 3, regmatch, 0) == 0 ||
742 regexec(®ex_symbolic, line, 3, regmatch, 0) == 0 ||
743 regexec(®ex_hard, line, 3, regmatch, 0) == 0) {
744 if (argument->dle.create_index && regmatch[1].rm_so == 2) {
745 line[regmatch[1].rm_eo]='\0';
746 fprintf(indexstream, "/%s\n", &line[regmatch[1].rm_so]);
751 for (rp = re_table; rp->regex != NULL; rp++) {
752 if (match(rp->regex, line)) {
756 if (rp->typ == DMP_SIZE) {
757 dump_size = (off_t)((the_num(line, rp->field)* rp->scale+1023.0)/1024.0);
783 dbprintf("%3d: %7s(%c): %s\n", rp->srcline, type, startchr, line);
784 fprintf(mesgstream,"%c %s\n", startchr, line);
787 regfree(®ex_root);
789 regfree(®ex_file);
790 regfree(®ex_special);
791 regfree(®ex_symbolic);
792 regfree(®ex_hard);
794 dbprintf(_("gnutar: %s: pid %ld\n"), cmd, (long)starpid);
796 dbprintf("sendbackup: size %lld\n", (long long)dump_size);
797 fprintf(mesgstream, "sendbackup: size %lld\n", (long long)dump_size);
798 dbprintf("sendbackup: end\n");
799 fprintf(mesgstream, "sendbackup: end\n");
802 if (argument->dle.create_index)
811 application_argument_t *argument)
814 GPtrArray *argv_ptr = g_ptr_array_new();
820 error(_("STAR-PATH not defined"));
823 cmd = stralloc(star_path);
825 g_ptr_array_add(argv_ptr, stralloc(star_path));
826 if (star_directory) {
827 struct stat stat_buf;
828 if(stat(star_directory, &stat_buf) != 0) {
829 fprintf(stderr,"can not stat directory %s: %s\n", star_directory, strerror(errno));
832 if (!S_ISDIR(stat_buf.st_mode)) {
833 fprintf(stderr,"%s is not a directory\n", star_directory);
836 if (access(star_directory, W_OK) != 0 ) {
837 fprintf(stderr, "Can't write to %s: %s\n", star_directory, strerror(errno));
841 g_ptr_array_add(argv_ptr, stralloc("-C"));
842 g_ptr_array_add(argv_ptr, stralloc(star_directory));
844 g_ptr_array_add(argv_ptr, stralloc("-x"));
845 g_ptr_array_add(argv_ptr, stralloc("-v"));
846 g_ptr_array_add(argv_ptr, stralloc("-xattr"));
847 g_ptr_array_add(argv_ptr, stralloc("-acl"));
848 g_ptr_array_add(argv_ptr, stralloc("errctl=WARN|SAMEFILE|SETTIME|DIFF|SETACL|SETXATTR|SETMODE|BADACL *"));
849 g_ptr_array_add(argv_ptr, stralloc("-no-fifo"));
850 g_ptr_array_add(argv_ptr, stralloc("-f"));
851 g_ptr_array_add(argv_ptr, stralloc("-"));
853 if (argument->dle.exclude_list &&
854 argument->dle.exclude_list->nb_element == 1) {
855 g_ptr_array_add(argv_ptr, stralloc("-exclude-from"));
856 g_ptr_array_add(argv_ptr,
857 stralloc(argument->dle.exclude_list->first->name));
860 if (argument->dle.include_list &&
861 argument->dle.include_list->nb_element == 1) {
862 FILE *include_list = fopen(argument->dle.include_list->first->name, "r");
863 char line[2*PATH_MAX+2];
864 while (fgets(line, 2*PATH_MAX, include_list)) {
865 line[strlen(line)-1] = '\0'; /* remove '\n' */
866 if (strncmp(line, "./", 2) == 0)
867 g_ptr_array_add(argv_ptr, stralloc(line+2)); /* remove ./ */
868 else if (strcmp(line, ".") != 0)
869 g_ptr_array_add(argv_ptr, stralloc(line));
871 fclose(include_list);
873 for (j=1; j< argument->argc; j++) {
874 if (strncmp(argument->argv[j], "./", 2) == 0)
875 g_ptr_array_add(argv_ptr, stralloc(argument->argv[j]+2));/*remove ./ */
876 else if (strcmp(argument->argv[j], ".") != 0)
877 g_ptr_array_add(argv_ptr, stralloc(argument->argv[j]));
879 g_ptr_array_add(argv_ptr, NULL);
881 debug_executing(argv_ptr);
884 execve(cmd, (char **)argv_ptr->pdata, env);
886 error(_("error [exec %s: %s]"), cmd, e);
892 application_argument_t *argument G_GNUC_UNUSED)
895 GPtrArray *argv_ptr = g_ptr_array_new();
901 dbprintf("STAR-PATH not set; Piping to /dev/null\n");
902 fprintf(stderr,"STAR-PATH not set; Piping to /dev/null\n");
906 cmd = stralloc(star_path);
908 g_ptr_array_add(argv_ptr, stralloc(star_path));
909 g_ptr_array_add(argv_ptr, stralloc("-t"));
910 g_ptr_array_add(argv_ptr, stralloc("-f"));
911 g_ptr_array_add(argv_ptr, stralloc("-"));
912 g_ptr_array_add(argv_ptr, NULL);
914 debug_executing(argv_ptr);
916 execve(cmd, (char **)argv_ptr->pdata, env);
918 dbprintf("failed to execute %s: %s; Piping to /dev/null\n", cmd, e);
919 fprintf(stderr,"failed to execute %s: %s; Piping to /dev/null\n", cmd, e);
921 while (read(0, buf, 32768) > 0) {
926 static GPtrArray *amstar_build_argv(
927 application_argument_t *argument,
933 char levelstr[NUM_STR_SIZE+7];
934 GPtrArray *argv_ptr = g_ptr_array_new();
939 if (star_directory) {
940 dirname = star_directory;
942 dirname = argument->dle.device;
944 fsname = vstralloc("fs-name=", dirname, NULL);
945 for (s = fsname; *s != '\0'; s++) {
946 if (iscntrl((int)*s))
949 snprintf(levelstr, SIZEOF(levelstr), "-level=%d", level);
951 if (star_dle_tardumps) {
952 char *sdisk = sanitise_filename(argument->dle.disk);
953 tardumpfile = vstralloc(star_tardumps, sdisk, NULL);
956 tardumpfile = stralloc(star_tardumps);
959 g_ptr_array_add(argv_ptr, stralloc(star_path));
961 g_ptr_array_add(argv_ptr, stralloc("-c"));
962 g_ptr_array_add(argv_ptr, stralloc("-f"));
963 if (command == CMD_ESTIMATE) {
964 g_ptr_array_add(argv_ptr, stralloc("/dev/null"));
966 g_ptr_array_add(argv_ptr, stralloc("-"));
968 g_ptr_array_add(argv_ptr, stralloc("-C"));
970 #if defined(__CYGWIN__)
972 char tmppath[PATH_MAX];
974 cygwin_conv_to_full_posix_path(dirname, tmppath);
975 g_ptr_array_add(argv_ptr, stralloc(tmppath));
978 g_ptr_array_add(argv_ptr, stralloc(dirname));
980 g_ptr_array_add(argv_ptr, stralloc(fsname));
981 if (star_onefilesystem)
982 g_ptr_array_add(argv_ptr, stralloc("-xdev"));
983 g_ptr_array_add(argv_ptr, stralloc("-link-dirs"));
984 g_ptr_array_add(argv_ptr, stralloc(levelstr));
985 g_ptr_array_add(argv_ptr, stralloc2("tardumps=", tardumpfile));
986 if (command == CMD_BACKUP)
987 g_ptr_array_add(argv_ptr, stralloc("-wtardumps"));
989 g_ptr_array_add(argv_ptr, stralloc("-xattr"));
991 g_ptr_array_add(argv_ptr, stralloc("-acl"));
992 g_ptr_array_add(argv_ptr, stralloc("H=exustar"));
993 g_ptr_array_add(argv_ptr, stralloc("errctl=WARN|SAMEFILE|DIFF|GROW|SHRINK|SPECIALFILE|GETXATTR|BADACL *"));
995 g_ptr_array_add(argv_ptr, stralloc("-sparse"));
996 g_ptr_array_add(argv_ptr, stralloc("-dodesc"));
998 for (copt = argument->command_options; copt != NULL; copt = copt->next) {
999 g_ptr_array_add(argv_ptr, stralloc((char *)copt->data));
1002 if (command == CMD_BACKUP && argument->dle.create_index)
1003 g_ptr_array_add(argv_ptr, stralloc("-v"));
1005 if ((argument->dle.exclude_file &&
1006 argument->dle.exclude_file->nb_element >= 1) ||
1007 (argument->dle.exclude_list &&
1008 argument->dle.exclude_list->nb_element >= 1)) {
1009 g_ptr_array_add(argv_ptr, stralloc("-match-tree"));
1010 g_ptr_array_add(argv_ptr, stralloc("-not"));
1012 if (argument->dle.exclude_file &&
1013 argument->dle.exclude_file->nb_element >= 1) {
1015 for (excl = argument->dle.exclude_file->first; excl != NULL;
1016 excl = excl->next) {
1018 if (strcmp(excl->name, "./") == 0) {
1019 ex = g_strdup_printf("pat=%s", excl->name+2);
1021 ex = g_strdup_printf("pat=%s", excl->name);
1023 g_ptr_array_add(argv_ptr, ex);
1026 if (argument->dle.exclude_list &&
1027 argument->dle.exclude_list->nb_element >= 1) {
1029 for (excl = argument->dle.exclude_list->first; excl != NULL;
1030 excl = excl->next) {
1031 char *exclname = fixup_relative(excl->name, argument->dle.device);
1034 if ((exclude = fopen(exclname, "r")) != NULL) {
1035 while ((aexc = agets(exclude)) != NULL) {
1036 if (aexc[0] != '\0') {
1038 if (strcmp(aexc, "./") == 0) {
1039 ex = g_strdup_printf("pat=%s", aexc+2);
1041 ex = g_strdup_printf("pat=%s", aexc);
1043 g_ptr_array_add(argv_ptr, ex);
1053 g_ptr_array_add(argv_ptr, stralloc("."));
1055 g_ptr_array_add(argv_ptr, NULL);
1057 amfree(tardumpfile);
1065 application_argument_t *argument)
1068 struct stat stat_buf;
1070 qdevice = quote_string(argument->dle.device);
1072 if(!stat(argument->dle.device, &stat_buf)) {
1073 if (!S_ISDIR(stat_buf.st_mode)) {
1075 g_fprintf(stderr, _("ERROR %s is not a directory\n"), qdevice);
1081 g_fprintf(stderr, _("ERROR can not stat %s: %s\n"), qdevice,
1086 if (access(argument->dle.device, R_OK|X_OK) == -1) {
1088 g_fprintf(stderr, _("ERROR can not access %s: %s\n"),
1089 argument->dle.device, strerror(errno));