2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998, 2000 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: extract_list.c,v 1.6 2006/08/24 01:57:15 paddy_s Exp $
29 * implements the "extract" command in amrecover
35 #include "amrecover.h"
36 #include "fileheader.h"
45 typedef struct EXTRACT_LIST_ITEM {
48 struct EXTRACT_LIST_ITEM *next;
52 typedef struct EXTRACT_LIST {
53 char *date; /* date tape created */
54 int level; /* level of dump */
55 char *tape; /* tape label */
56 off_t fileno; /* fileno on tape */
57 EXTRACT_LIST_ITEM *files; /* files to get off tape */
59 struct EXTRACT_LIST *next;
66 char *dump_device_name = NULL;
68 extern char *localhost;
70 /* global pid storage for interrupt handler */
71 pid_t extract_restore_child_pid = -1;
73 static EXTRACT_LIST *extract_list = NULL;
74 static int tape_control_sock = -1;
75 static int tape_data_sock = -1;
78 unsigned short samba_extract_method = SAMBA_TAR;
79 #endif /* SAMBA_CLIENT */
81 #define READ_TIMEOUT 240*60
83 EXTRACT_LIST *first_tape_list(void);
84 EXTRACT_LIST *next_tape_list(EXTRACT_LIST *list);
85 int is_extract_list_nonempty(void);
86 int length_of_tape_list(EXTRACT_LIST *tape_list);
87 void add_file(char *path, char *regex);
88 void add_glob(char *glob);
89 void add_regex(char *regex);
90 void clear_extract_list(void);
91 void clean_tape_list(EXTRACT_LIST *tape_list);
92 void clean_extract_list(void);
93 void delete_file(char *path, char *regex);
94 void delete_glob(char *glob);
95 void delete_regex(char *regex);
96 void delete_tape_list(EXTRACT_LIST *tape_list);
97 void display_extract_list(char *file);
98 void extract_files(void);
99 void read_file_header(char *buffer,
103 void writer_intermediary(int ctl_fd, int data_fd, EXTRACT_LIST *elist);
104 void writer_intermediary(int ctl_fd, int data_fd, EXTRACT_LIST *elist);
106 static int add_extract_item(DIR_ITEM *ditem);
107 static int delete_extract_item(DIR_ITEM *ditem);
108 static int extract_files_setup(char *label, off_t fsf);
109 static int okay_to_continue(int allow_tape,
112 static int okay_to_continue(int, int, int);
113 static ssize_t read_buffer(int datafd,
117 static void clear_tape_list(EXTRACT_LIST *tape_list);
118 static void extract_files_child(int in_fd, EXTRACT_LIST *elist);
119 static void send_to_tape_server(int tss, char *cmd);
123 * Function: ssize_t read_buffer(datafd, buffer, buflen, timeout_s)
126 * read data from input file desciptor waiting up to timeout_s
127 * seconds before returning data.
130 * datafd - File descriptor to read from.
131 * buffer - Buffer to read into.
132 * buflen - Maximum number of bytes to read into buffer.
133 * timeout_s - Seconds to wait before returning what was already read.
136 * >0 - Number of data bytes in buffer.
138 * -1 - errno == ETIMEDOUT if no data available in specified time.
139 * errno == ENFILE if datafd is invalid.
140 * otherwise errno is set by select or read..
152 struct timeval timeout;
157 if(datafd < 0 || datafd >= (int)FD_SETSIZE) {
158 errno = EMFILE; /* out of range */
163 spaceleft = (ssize_t)buflen;
167 FD_SET(datafd, &readset);
168 timeout.tv_sec = timeout_s;
170 nfound = select(datafd+1, &readset, NULL, NULL, &timeout);
172 /* Select returned an error. */
173 g_fprintf(stderr,_("select error: %s\n"), strerror(errno));
179 /* Select timed out. */
180 if (timeout_s != 0) {
181 /* Not polling: a real read timeout */
182 g_fprintf(stderr,_("timeout waiting for restore\n"));
183 g_fprintf(stderr,_("increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n"));
190 if(!FD_ISSET(datafd, &readset))
193 /* Select says data is available, so read it. */
194 size = read(datafd, dataptr, (size_t)spaceleft);
196 if ((errno == EINTR) || (errno == EAGAIN)) {
199 if (errno != EPIPE) {
200 g_fprintf(stderr, _("read_buffer: read error - %s"),
208 } while ((size > 0) && (spaceleft > 0));
210 return ((((ssize_t)buflen-spaceleft) > 0) ? ((ssize_t)buflen-spaceleft) : size);
215 first_tape_list(void)
222 /*@keep@*/ EXTRACT_LIST *list)
231 EXTRACT_LIST * tape_list)
233 EXTRACT_LIST_ITEM *this, *next;
236 this = tape_list->files;
244 tape_list->files = NULL;
248 /* remove a tape list from the extract list, clearing the tape list
249 beforehand if necessary */
252 EXTRACT_LIST * tape_list)
254 EXTRACT_LIST *this, *prev;
256 if (tape_list == NULL)
259 /* is it first on the list? */
260 if (tape_list == extract_list)
262 extract_list = tape_list->next;
263 clear_tape_list(tape_list);
264 amfree(tape_list->date);
265 amfree(tape_list->tape);
270 /* so not first on list - find it and delete */
272 this = extract_list->next;
275 if (this == tape_list)
277 prev->next = tape_list->next;
278 clear_tape_list(tape_list);
279 amfree(tape_list->date);
280 amfree(tape_list->tape);
291 /* return the number of files on a tape's list */
294 EXTRACT_LIST * tape_list)
296 EXTRACT_LIST_ITEM *fn;
300 for (fn = tape_list->files; fn != NULL; fn = fn->next)
308 clear_extract_list(void)
310 while (extract_list != NULL)
311 delete_tape_list(extract_list);
317 EXTRACT_LIST *tape_list)
319 EXTRACT_LIST_ITEM *fn1, *pfn1, *ofn1;
320 EXTRACT_LIST_ITEM *fn2, *pfn2, *ofn2;
325 fn1 = tape_list->files;
326 while (fn1 != NULL) {
331 while (fn2 != NULL && remove_fn1 == 0) {
333 if(strcmp(fn1->path, fn2->path) == 0) {
335 } else if (strncmp(fn1->path, fn2->path, strlen(fn1->path)) == 0 &&
336 ((strlen(fn2->path) > strlen(fn1->path) &&
337 fn2->path[strlen(fn1->path)] == '/') ||
338 (fn1->path[strlen(fn1->path)-1] == '/'))) {
340 } else if (strncmp(fn2->path, fn1->path, strlen(fn2->path)) == 0 &&
341 ((strlen(fn1->path) > strlen(fn2->path) &&
342 fn1->path[strlen(fn2->path)] == '/') ||
343 (fn2->path[strlen(fn2->path)-1] == '/'))) {
349 dbprintf(_("removing path %s, it is included in %s\n"),
350 fn2->path, fn1->path);
356 } else if (remove_fn1 == 0) {
362 if(remove_fn1 != 0) {
363 /* fn2->path is always valid */
364 /*@i@*/ dbprintf(_("removing path %s, it is included in %s\n"),
365 /*@i@*/ fn1->path, fn2->path);
370 amfree(tape_list->files);
371 tape_list->files = fn1;
385 clean_extract_list(void)
389 for (this = extract_list; this != NULL; this = this->next)
390 clean_tape_list(this);
394 /* returns -1 if error */
395 /* returns 0 on succes */
396 /* returns 1 if already added */
401 EXTRACT_LIST *this, *this1;
402 EXTRACT_LIST_ITEM *that, *curr;
403 char *ditem_path = NULL;
405 ditem_path = stralloc(ditem->path);
406 clean_pathname(ditem_path);
408 for (this = extract_list; this != NULL; this = this->next)
410 /* see if this is the list for the tape */
411 if (this->level == ditem->level && strcmp(this->tape, ditem->tape) == 0)
413 /* yes, so add to list */
417 if (strcmp(curr->path, ditem_path) == 0) {
423 that = (EXTRACT_LIST_ITEM *)alloc(sizeof(EXTRACT_LIST_ITEM));
424 that->path = stralloc(ditem_path);
425 that->next = this->files;
426 this->files = that; /* add at front since easiest */
432 /* so this is the first time we have seen this tape */
433 this = (EXTRACT_LIST *)alloc(sizeof(EXTRACT_LIST));
434 this->tape = stralloc(ditem->tape);
435 this->level = ditem->level;
436 this->fileno = ditem->fileno;
437 this->date = stralloc(ditem->date);
438 that = (EXTRACT_LIST_ITEM *)alloc(sizeof(EXTRACT_LIST_ITEM));
439 that->path = stralloc(ditem_path);
443 /* add this in date increasing order */
444 /* because restore must be done in this order */
445 /* add at begining */
446 if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
448 this->next = extract_list;
453 for (this1 = extract_list; this1->next != NULL; this1 = this1->next)
455 /* add in the middle */
456 if(strcmp(this->date,this1->next->date) < 0)
458 this->next = this1->next;
472 /* returns -1 if error */
473 /* returns 0 on deletion */
474 /* returns 1 if not there */
480 EXTRACT_LIST_ITEM *that, *prev;
481 char *ditem_path = NULL;
483 ditem_path = stralloc(ditem->path);
484 clean_pathname(ditem_path);
486 for (this = extract_list; this != NULL; this = this->next)
488 /* see if this is the list for the tape */
489 if (this->level == ditem->level && strcmp(this->tape, ditem->tape) == 0)
491 /* yes, so find file on list */
493 if (strcmp(that->path, ditem_path) == 0)
496 this->files = that->next;
499 /* if list empty delete it */
500 if (this->files == NULL)
501 delete_tape_list(this);
509 if (strcmp(that->path, ditem_path) == 0)
511 prev->next = that->next;
536 char *uqglob = unquote_string(glob);
538 regex = glob_to_regex(uqglob);
539 dbprintf(_("add_glob (%s) -> %s\n"), uqglob, regex);
540 if ((s = validate_regexp(regex)) != NULL) {
541 g_printf(_("%s is not a valid shell wildcard pattern: "), glob);
545 * glob_to_regex() anchors the beginning of the pattern with ^,
546 * but we will be tacking it onto the end of the current directory
547 * in add_file, so strip that off. Also, it anchors the end with
548 * $, but we need to match an optional trailing /, so tack that on
551 regex_path = stralloc(regex + 1);
552 regex_path[strlen(regex_path) - 1] = '\0';
553 strappend(regex_path, "[/]*$");
554 add_file(uqglob, regex_path);
566 char *uqregex = unquote_string(regex);
568 if ((s = validate_regexp(uqregex)) != NULL) {
569 g_printf(_("%s is not a valid regular expression: "), regex);
572 add_file(uqregex, regex);
581 DIR_ITEM *ditem, lditem;
582 char *path_on_disk = NULL;
583 char *path_on_disk_slash = NULL;
588 char *dir, *dir_undo, dir_undo_ch = '\0';
589 char *ditem_path = NULL;
592 char *s, *fp, *quoted;
597 if (disk_path == NULL) {
598 g_printf(_("Must select directory before adding files\n"));
601 memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
603 dbprintf(_("add_file: Looking for \"%s\"\n"), regex);
605 if(strcmp(regex, "/[/]*$") == 0) { /* "/" behave like "." */
608 else if(strcmp(regex, "[^/]*[/]*$") == 0) { /* "*" */
609 regex = "([^/.]|\\.[^/]+|[^/.][^/]*)[/]*$";
611 /* remove "/" at end of path */
612 j = (ssize_t)(strlen(regex) - 1);
613 while(j >= 0 && regex[j] == '/')
617 /* convert path (assumed in cwd) to one on disk */
618 if (strcmp(disk_path, "/") == 0) {
620 /* No mods needed if already starts with '/' */
621 path_on_disk = stralloc(regex);
624 path_on_disk = stralloc2("/", regex);
627 char *clean_disk_path = clean_regex(disk_path);
628 path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
629 amfree(clean_disk_path);
632 path_on_disk_slash = stralloc2(path_on_disk, "/");
634 dbprintf(_("add_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n"),
635 regex, path_on_disk);
639 for (ditem=get_dir_list(); ditem!=NULL; ditem=get_next_dir_item(ditem))
642 quoted = quote_string(ditem->path);
643 dbprintf(_("add_file: Pondering ditem->path=%s\n"), quoted);
645 if (match(path_on_disk, ditem->path)
646 || match(path_on_disk_slash, ditem->path))
649 j = (ssize_t)strlen(ditem->path);
650 if((j > 0 && ditem->path[j-1] == '/')
651 || (j > 1 && ditem->path[j-2] == '/' && ditem->path[j-1] == '.'))
652 { /* It is a directory */
653 ditem_path = newstralloc(ditem_path, ditem->path);
654 clean_pathname(ditem_path);
656 cmd = newstralloc2(cmd, "ORLD ", ditem_path);
657 if(send_command(cmd) == -1) {
660 amfree(path_on_disk);
661 amfree(path_on_disk_slash);
667 if ((i = get_reply_line()) == -1) {
669 amfree(path_on_disk);
670 amfree(path_on_disk_slash);
673 if(i==0) { /* assume something wrong */
675 amfree(path_on_disk);
676 amfree(path_on_disk_slash);
678 g_printf(_("%s\n"), l);
683 lditem.path = newstralloc(lditem.path, ditem->path);
684 /* skip the last line -- duplicate of the preamble */
686 while ((i = get_reply_line()) != 0) {
689 amfree(path_on_disk);
690 amfree(path_on_disk_slash);
695 if(dir_undo) *dir_undo = dir_undo_ch;
697 cmd = stralloc(l); /* save for error report */
699 continue; /* throw the rest of the lines away */
702 if (!server_happy()) {
708 if(strncmp_const_skip(l, "201-", s, ch) != 0) {
709 err = _("bad reply: not 201-");
714 skip_whitespace(s, ch);
716 err = _("bad reply: missing date field");
720 skip_non_whitespace(s, ch);
722 lditem.date = newstralloc(lditem.date, fp);
725 skip_whitespace(s, ch);
726 if(ch == '\0' || sscanf(s - 1, "%d", &lditem.level) != 1) {
727 err = _("bad reply: cannot parse level field");
732 skip_whitespace(s, ch);
734 err = _("bad reply: missing tape field");
738 skip_non_whitespace(s, ch);
740 lditem.tape = newstralloc(lditem.tape, fp);
743 if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
744 long long fileno_ = (long long)0;
745 skip_whitespace(s, ch);
747 sscanf(s - 1, "%lld", &fileno_) != 1) {
748 err = _("bad reply: cannot parse fileno field");
751 lditem.fileno = (off_t)fileno_;
755 skip_whitespace(s, ch);
757 err = _("bad reply: missing directory field");
761 skip_quoted_string(s, ch);
763 dir_undo_ch = *dir_undo;
766 switch(add_extract_item(&lditem)) {
768 g_printf(_("System error\n"));
769 dbprintf(_("add_file: (Failed) System error\n"));
773 quoted = quote_string(lditem.path);
774 g_printf(_("Added dir %s at date %s\n"),
775 quoted, lditem.date);
776 dbprintf(_("add_file: (Successful) Added dir %s at date %s\n"),
777 quoted, lditem.date);
786 if(!server_happy()) {
793 } else if(added == 0) {
794 quoted = quote_string(ditem_path);
795 g_printf(_("dir %s already added\n"), quoted);
796 dbprintf(_("add_file: dir %s already added\n"), quoted);
800 else /* It is a file */
802 switch(add_extract_item(ditem)) {
804 g_printf(_("System error\n"));
805 dbprintf(_("add_file: (Failed) System error\n"));
809 quoted = quote_string(ditem->path);
810 g_printf(_("Added file %s\n"), quoted);
811 dbprintf(_("add_file: (Successful) Added %s\n"), quoted);
816 quoted = quote_string(ditem->path);
817 g_printf(_("File %s already added\n"), quoted);
818 dbprintf(_("add_file: file %s already added\n"), quoted);
828 amfree(path_on_disk);
829 amfree(path_on_disk_slash);
832 quoted = quote_string(path);
833 g_printf(_("File %s doesn't exist in directory\n"), quoted);
834 dbprintf(_("add_file: (Failed) File %s doesn't exist in directory\n"),
848 char *uqglob = unquote_string(glob);
850 regex = glob_to_regex(uqglob);
851 dbprintf(_("delete_glob (%s) -> %s\n"), uqglob, regex);
852 if ((s = validate_regexp(regex)) != NULL) {
853 g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
857 * glob_to_regex() anchors the beginning of the pattern with ^,
858 * but we will be tacking it onto the end of the current directory
859 * in add_file, so strip that off. Also, it anchors the end with
860 * $, but we need to match an optional trailing /, so tack that on
863 regex_path = stralloc(regex + 1);
864 regex_path[strlen(regex_path) - 1] = '\0';
865 strappend(regex_path, "[/]*$");
866 delete_file(uqglob, regex_path);
878 char *uqregex = unquote_string(regex);
880 if ((s = validate_regexp(regex)) != NULL) {
881 g_printf(_("\"%s\" is not a valid regular expression: "), regex);
884 delete_file(uqregex, uqregex);
894 DIR_ITEM *ditem, lditem;
895 char *path_on_disk = NULL;
896 char *path_on_disk_slash = NULL;
902 char *tape, *tape_undo, tape_undo_ch = '\0';
903 char *dir_undo, dir_undo_ch = '\0';
906 char *ditem_path = NULL;
914 if (disk_path == NULL) {
915 g_printf(_("Must select directory before deleting files\n"));
918 memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
920 dbprintf(_("delete_file: Looking for \"%s\"\n"), path);
922 if (strcmp(regex, "[^/]*[/]*$") == 0) {
923 /* Looking for * find everything but single . */
924 regex = "([^/.]|\\.[^/]+|[^/.][^/]*)[/]*$";
926 /* remove "/" at end of path */
927 j = (ssize_t)(strlen(regex) - 1);
928 while(j >= 0 && regex[j] == '/') regex[j--] = '\0';
931 /* convert path (assumed in cwd) to one on disk */
932 if (strcmp(disk_path, "/") == 0) {
934 if (strcmp(regex, "/[/]*$") == 0) {
935 /* We want "/" to match the directory itself: "/." */
936 path_on_disk = stralloc("/\\.[/]*$");
938 /* No mods needed if already starts with '/' */
939 path_on_disk = stralloc(regex);
943 path_on_disk = stralloc2("/", regex);
946 char *clean_disk_path = clean_regex(disk_path);
947 path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
948 amfree(clean_disk_path);
951 path_on_disk_slash = stralloc2(path_on_disk, "/");
953 dbprintf(_("delete_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n"),
954 regex, path_on_disk);
956 for (ditem=get_dir_list(); ditem!=NULL; ditem=get_next_dir_item(ditem))
958 quoted = quote_string(ditem->path);
959 dbprintf(_("delete_file: Pondering ditem->path=%s\n"), quoted);
961 if (match(path_on_disk, ditem->path)
962 || match(path_on_disk_slash, ditem->path))
965 j = (ssize_t)strlen(ditem->path);
966 if((j > 0 && ditem->path[j-1] == '/')
967 || (j > 1 && ditem->path[j-2] == '/' && ditem->path[j-1] == '.'))
968 { /* It is a directory */
969 ditem_path = newstralloc(ditem_path, ditem->path);
970 clean_pathname(ditem_path);
972 cmd = newstralloc2(cmd, "ORLD ", ditem_path);
973 if(send_command(cmd) == -1) {
976 amfree(path_on_disk);
977 amfree(path_on_disk_slash);
982 if ((i = get_reply_line()) == -1) {
984 amfree(path_on_disk);
985 amfree(path_on_disk_slash);
988 if(i==0) /* assume something wrong */
991 amfree(path_on_disk);
992 amfree(path_on_disk_slash);
998 lditem.path = newstralloc(lditem.path, ditem->path);
1000 tape_undo = dir_undo = NULL;
1001 /* skip the last line -- duplicate of the preamble */
1002 while ((i = get_reply_line()) != 0)
1006 amfree(path_on_disk);
1007 amfree(path_on_disk_slash);
1012 if(tape_undo) *tape_undo = tape_undo_ch;
1013 if(dir_undo) *dir_undo = dir_undo_ch;
1014 tape_undo = dir_undo = NULL;
1015 cmd = stralloc(l); /* save for the error report */
1017 continue; /* throw the rest of the lines away */
1020 if (!server_happy()) {
1026 if(strncmp_const_skip(l, "201-", s, ch) != 0) {
1027 err = _("bad reply: not 201-");
1032 skip_whitespace(s, ch);
1034 err = _("bad reply: missing date field");
1038 skip_non_whitespace(s, ch);
1041 skip_whitespace(s, ch);
1042 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
1043 err = _("bad reply: cannot parse level field");
1046 skip_integer(s, ch);
1048 skip_whitespace(s, ch);
1050 err = _("bad reply: missing tape field");
1054 skip_non_whitespace(s, ch);
1056 tape_undo_ch = *tape_undo;
1059 if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
1060 long long fileno_ = (long long)0;
1061 skip_whitespace(s, ch);
1063 sscanf(s - 1, "%lld", &fileno_) != 1) {
1064 err = _("bad reply: cannot parse fileno field");
1067 fileno = (off_t)fileno_;
1068 skip_integer(s, ch);
1071 skip_whitespace(s, ch);
1073 err = _("bad reply: missing directory field");
1076 skip_non_whitespace(s, ch);
1078 dir_undo_ch = *dir_undo;
1081 lditem.date = newstralloc(lditem.date, date);
1083 lditem.tape = newstralloc(lditem.tape, tape);
1084 switch(delete_extract_item(&lditem)) {
1086 g_printf(_("System error\n"));
1087 dbprintf(_("delete_file: (Failed) System error\n"));
1090 g_printf(_("Deleted dir %s at date %s\n"), ditem_path, date);
1091 dbprintf(_("delete_file: (Successful) Deleted dir %s at date %s\n"),
1099 if(!server_happy()) {
1106 } else if(deleted == 0) {
1107 g_printf(_("Warning - dir '%s' not on tape list\n"),
1109 dbprintf(_("delete_file: dir '%s' not on tape list\n"),
1115 switch(delete_extract_item(ditem)) {
1117 g_printf(_("System error\n"));
1118 dbprintf(_("delete_file: (Failed) System error\n"));
1121 g_printf(_("Deleted %s\n"), ditem->path);
1122 dbprintf(_("delete_file: (Successful) Deleted %s\n"),
1126 g_printf(_("Warning - file '%s' not on tape list\n"),
1128 dbprintf(_("delete_file: file '%s' not on tape list\n"),
1137 amfree(path_on_disk);
1138 amfree(path_on_disk_slash);
1141 g_printf(_("File %s doesn't exist in directory\n"), path);
1142 dbprintf(_("delete_file: (Failed) File %s doesn't exist in directory\n"),
1148 /* print extract list into file. If NULL ptr passed print to screen */
1150 display_extract_list(
1154 EXTRACT_LIST_ITEM *that;
1157 char *pager_command;
1162 if ((pager = getenv("PAGER")) == NULL)
1167 * Set up the pager command so if the pager is terminated, we do
1168 * not get a SIGPIPE back.
1170 pager_command = stralloc2(pager, " ; /bin/cat > /dev/null");
1171 if ((fp = popen(pager_command, "w")) == NULL)
1173 g_printf(_("Warning - can't pipe through %s\n"), pager);
1176 amfree(pager_command);
1180 uqfile = unquote_string(file);
1181 if ((fp = fopen(uqfile, "w")) == NULL)
1183 g_printf(_("Can't open file %s to print extract list into\n"), file);
1190 for (this = extract_list; this != NULL; this = this->next)
1192 g_fprintf(fp, _("TAPE %s LEVEL %d DATE %s\n"),
1193 this->tape, this->level, this->date);
1194 for (that = this->files; that != NULL; that = that->next)
1195 g_fprintf(fp, "\t%s\n", that->path);
1201 g_printf(_("Extract list written to file %s\n"), file);
1207 /* returns 0 if extract list empty and 1 if it isn't */
1209 is_extract_list_nonempty(void)
1211 return (extract_list != NULL);
1215 /* prints continue prompt and waits for response,
1216 returns 0 if don't, non-0 if do */
1233 prompt = _("New tape device [?]: ");
1234 } else if (allow_tape && allow_skip) {
1235 prompt = _("Continue [?/Y/n/s/t]? ");
1236 } else if (allow_tape && !allow_skip) {
1237 prompt = _("Continue [?/Y/n/t]? ");
1238 } else if (allow_retry) {
1239 prompt = _("Continue [?/Y/n/r]? ");
1241 prompt = _("Continue [?/Y/n]? ");
1243 fputs(prompt, stdout);
1244 fflush(stdout); fflush(stderr);
1246 if ((line = agets(stdin)) == NULL) {
1257 while ((ch = *s++) != '\0' && g_ascii_isspace(ch)) {
1258 (void)ch; /* Quiet empty loop body warning */
1262 g_printf(_("Enter a new device ([host:]device) or \"default\"\n"));
1264 g_printf(_("Enter \"y\"es to continue, \"n\"o to stop"));
1266 g_printf(_(", \"s\"kip this tape"));
1269 g_printf(_(" or \"r\"etry this tape"));
1272 g_printf(_(" or \"t\"ape to change tape drives"));
1276 } else if (get_tape) {
1279 } else if (ch == '\0' || ch == 'Y' || ch == 'y') {
1281 } else if (allow_tape && (ch == 'T' || ch == 't')) {
1283 } else if (ch == 'N' || ch == 'n') {
1285 } else if (allow_retry && (ch == 'R' || ch == 'r')) {
1287 } else if (allow_skip && (ch == 'S' || ch == 's')) {
1298 send_to_tape_server(
1302 char *msg = stralloc2(cmd, "\r\n");
1304 if (full_write(tss, msg, strlen(msg)) < strlen(msg))
1306 error(_("Error writing to tape server: %s"), strerror(errno));
1313 /* start up connection to tape server and set commands to initiate
1314 transfer of dump image.
1315 Return tape server socket on success, -1 on error. */
1317 extract_files_setup(
1322 in_port_t my_port, my_data_port;
1323 char *disk_regex = NULL;
1324 char *host_regex = NULL;
1325 char *service_name = NULL;
1327 char *clean_datestamp, *ch, *ch1;
1328 char *our_feature_string = NULL;
1331 service_name = stralloc2("amidxtape", SERVICE_SUFFIX);
1333 /* get tape server details */
1334 if ((sp = getservbyname(service_name, "tcp")) == NULL)
1336 g_printf(_("%s/tcp unknown protocol - config error?\n"), service_name);
1337 amfree(service_name);
1340 amfree(service_name);
1341 seteuid(0); /* it either works ... */
1343 tape_control_sock = stream_client_privileged(tape_server_name,
1344 (in_port_t)ntohs((in_port_t)sp->s_port),
1349 if (tape_control_sock < 0)
1351 g_printf(_("cannot connect to %s: %s\n"), tape_server_name, strerror(errno));
1354 if (my_port >= IPPORT_RESERVED) {
1355 aclose(tape_control_sock);
1356 g_printf(_("did not get a reserved port: %u\n"), (unsigned)my_port);
1361 seteuid(getuid()); /* put it back */
1363 /* do the security thing */
1364 line = get_security();
1365 send_to_tape_server(tape_control_sock, line);
1366 memset(line, '\0', strlen(line));
1369 disk_regex = alloc(strlen(disk_name) * 2 + 3);
1374 /* we want to force amrestore to only match disk_name exactly */
1377 /* We need to escape some characters first... NT compatibilty crap */
1378 for (; *ch != 0; ch++, ch1++) {
1379 switch (*ch) { /* done this way in case there are more */
1382 /* no break; we do want to fall through... */
1388 /* we want to force amrestore to only match disk_name exactly */
1393 host_regex = alloc(strlen(dump_hostname) * 2 + 3);
1398 /* we want to force amrestore to only match dump_hostname exactly */
1401 /* We need to escape some characters first... NT compatibilty crap */
1402 for (; *ch != 0; ch++, ch1++) {
1403 switch (*ch) { /* done this way in case there are more */
1406 /* no break; we do want to fall through... */
1412 /* we want to force amrestore to only match dump_hostname exactly */
1417 clean_datestamp = stralloc(dump_datestamp);
1418 for(ch=ch1=clean_datestamp;*ch1 != '\0';ch1++) {
1426 /* push our feature list off to the tape server */
1427 /* XXX assumes that index server and tape server are equivalent, ew */
1428 if(am_has_feature(indexsrv_features, fe_amidxtaped_exchange_features)){
1429 char buffer[32768] = "\0";
1431 our_feature_string = am_feature_to_string(our_features);
1432 tt = newstralloc2(tt, "FEATURES=", our_feature_string);
1433 send_to_tape_server(tape_control_sock, tt);
1434 if (read(tape_control_sock, buffer, sizeof(buffer)) <= 0) {
1435 error(_("Could not read features from control socket\n"));
1438 tapesrv_features = am_string_to_feature(buffer);
1439 amfree(our_feature_string);
1443 if(am_has_feature(indexsrv_features, fe_amidxtaped_header) &&
1444 am_has_feature(indexsrv_features, fe_amidxtaped_device) &&
1445 am_has_feature(indexsrv_features, fe_amidxtaped_host) &&
1446 am_has_feature(indexsrv_features, fe_amidxtaped_disk) &&
1447 am_has_feature(indexsrv_features, fe_amidxtaped_datestamp)) {
1449 if(am_has_feature(indexsrv_features, fe_amidxtaped_config)) {
1450 tt = newstralloc2(tt, "CONFIG=", config);
1451 send_to_tape_server(tape_control_sock, tt);
1453 if(am_has_feature(indexsrv_features, fe_amidxtaped_label) &&
1454 label && label[0] != '/') {
1455 tt = newstralloc2(tt,"LABEL=",label);
1456 send_to_tape_server(tape_control_sock, tt);
1458 if(am_has_feature(indexsrv_features, fe_amidxtaped_fsf)) {
1460 g_snprintf(v_fsf, 99, "%lld", (long long)fsf);
1461 tt = newstralloc2(tt, "FSF=",v_fsf);
1462 send_to_tape_server(tape_control_sock, tt);
1464 send_to_tape_server(tape_control_sock, "HEADER");
1465 tt = newstralloc2(tt, "DEVICE=", dump_device_name);
1466 send_to_tape_server(tape_control_sock, tt);
1467 tt = newstralloc2(tt, "HOST=", host_regex);
1468 send_to_tape_server(tape_control_sock, tt);
1469 tt = newstralloc2(tt, "DISK=", disk_regex);
1470 send_to_tape_server(tape_control_sock, tt);
1471 tt = newstralloc2(tt, "DATESTAMP=", clean_datestamp);
1472 send_to_tape_server(tape_control_sock, tt);
1473 send_to_tape_server(tape_control_sock, "END");
1476 else if(am_has_feature(indexsrv_features, fe_amidxtaped_nargs)) {
1477 /* send to the tape server what tape file we want */
1486 send_to_tape_server(tape_control_sock, "6");
1487 send_to_tape_server(tape_control_sock, "-h");
1488 send_to_tape_server(tape_control_sock, "-p");
1489 send_to_tape_server(tape_control_sock, dump_device_name);
1490 send_to_tape_server(tape_control_sock, host_regex);
1491 send_to_tape_server(tape_control_sock, disk_regex);
1492 send_to_tape_server(tape_control_sock, clean_datestamp);
1494 dbprintf(_("Started amidxtaped with arguments \"6 -h -p %s %s %s %s\"\n"),
1495 dump_device_name, host_regex, disk_regex, clean_datestamp);
1499 * split-restoring amidxtaped versions will expect to set up a data
1500 * connection for dumpfile data, distinct from the socket we're already
1501 * using for control data
1504 if(am_has_feature(tapesrv_features, fe_recover_splits)){
1506 in_port_t data_port = (in_port_t)-1;
1509 nread = read(tape_control_sock, buffer, sizeof(buffer));
1512 error(_("Could not read from control socket: %s\n"),
1517 buffer[nread] = '\0';
1518 if (sscanf(buffer, "CONNECT %hu\n",
1519 (unsigned short *)&data_port) != 1) {
1520 error(_("Recieved invalid port number message from control socket: %s\n"),
1525 tape_data_sock = stream_client_privileged(server_name,
1531 if(tape_data_sock == -1){
1532 error(_("Unable to make data connection to server: %s\n"),
1537 amfree(our_feature_string);
1539 line = get_security();
1541 send_to_tape_server(tape_data_sock, line);
1542 memset(line, '\0', strlen(line));
1548 amfree(clean_datestamp);
1550 return tape_control_sock;
1555 * Reads the first block of a tape file.
1567 bytes_read = read_buffer(tapedev, buffer, buflen, READ_TIMEOUT);
1568 if(bytes_read < 0) {
1569 error(_("error reading header (%s), check amidxtaped.*.debug on server"),
1574 if((size_t)bytes_read < buflen) {
1575 g_fprintf(stderr, plural(_("%s: short block %d byte\n"),
1576 _("%s: short block %d bytes\n"), bytes_read),
1577 get_pname(), (int)bytes_read);
1578 print_header(stdout, file);
1579 error(_("Can't read file header"));
1583 /* bytes_read == buflen */
1584 parse_file_header(buffer, file, (size_t)bytes_read);
1597 extract_files_child(
1599 EXTRACT_LIST * elist)
1602 int extra_params = 0;
1604 char **restore_args = NULL;
1606 EXTRACT_LIST_ITEM *fn;
1607 enum dumptypes dumptype = IS_UNKNOWN;
1608 char buffer[DISK_BLOCK_BYTES];
1612 int passwd_field = -1;
1614 char *domain = NULL, *smbpass = NULL;
1617 /* code executed by child to do extraction */
1620 /* make in_fd be our stdin */
1621 if (dup2(in_fd, STDIN_FILENO) == -1)
1623 error(_("dup2 failed in extract_files_child: %s"), strerror(errno));
1627 /* read the file header */
1629 read_file_header(buffer, &file, sizeof(buffer), STDIN_FILENO);
1631 if(file.type != F_DUMPFILE) {
1632 print_header(stdout, &file);
1633 error(_("bad header"));
1637 if (file.program != NULL) {
1639 if (strcmp(file.program, GNUTAR) == 0)
1640 dumptype = IS_GNUTAR;
1643 if (dumptype == IS_UNKNOWN) {
1644 len_program = strlen(file.program);
1645 if(len_program >= 3 &&
1646 strcmp(&file.program[len_program-3],"tar") == 0)
1651 if (dumptype == IS_UNKNOWN && strcmp(file.program, SAMBA_CLIENT) ==0) {
1652 if (samba_extract_method == SAMBA_TAR)
1653 dumptype = IS_SAMBA_TAR;
1655 dumptype = IS_SAMBA;
1660 /* form the arguments to restore */
1661 files_off_tape = length_of_tape_list(elist);
1680 #if defined(XFSDUMP)
1681 if (strcmp(file.program, XFSDUMP) == 0) {
1682 extra_params = 4 + files_off_tape;
1692 restore_args = (char **)alloc((size_t)((extra_params + files_off_tape + 1)
1697 restore_args[j++] = stralloc("smbclient");
1698 smbpass = findpass(file.disk, &domain);
1700 restore_args[j++] = stralloc(file.disk);
1702 restore_args[j++] = stralloc("-U");
1703 restore_args[j++] = smbpass;
1705 restore_args[j++] = stralloc("-W");
1706 restore_args[j++] = stralloc(domain);
1711 restore_args[j++] = stralloc("-d0");
1712 restore_args[j++] = stralloc("-Tx");
1713 restore_args[j++] = stralloc("-"); /* data on stdin */
1718 restore_args[j++] = stralloc("tar");
1719 restore_args[j++] = stralloc("--numeric-owner");
1720 restore_args[j++] = stralloc("-xpGvf");
1721 restore_args[j++] = stralloc("-"); /* data on stdin */
1724 restore_args[j++] = stralloc("tar");
1725 restore_args[j++] = stralloc("-xpvf");
1726 restore_args[j++] = stralloc("-"); /* data on stdin */
1730 restore_args[j++] = stralloc("restore");
1732 restore_args[j++] = stralloc("-xB");
1734 #if defined(XFSDUMP)
1735 if (strcmp(file.program, XFSDUMP) == 0) {
1736 restore_args[j++] = stralloc("-v");
1737 restore_args[j++] = stralloc("silent");
1741 if (strcmp(file.program, VDUMP) == 0) {
1742 restore_args[j++] = stralloc("xf");
1743 restore_args[j++] = stralloc("-"); /* data on stdin */
1747 restore_args[j++] = stralloc("xbf");
1748 restore_args[j++] = stralloc("2"); /* read in units of 1K */
1749 restore_args[j++] = stralloc("-"); /* data on stdin */
1754 for (i = 0, fn = elist->files; i < files_off_tape; i++, fn = fn->next)
1761 if (strcmp(fn->path, "/") == 0)
1762 restore_args[j++] = stralloc(".");
1764 restore_args[j++] = stralloc2(".", fn->path);
1768 #if defined(XFSDUMP)
1769 if (strcmp(file.program, XFSDUMP) == 0) {
1771 * xfsrestore needs a -s option before each file to be
1772 * restored, and also wants them to be relative paths.
1774 restore_args[j++] = stralloc("-s");
1775 restore_args[j++] = stralloc(fn->path + 1);
1779 restore_args[j++] = stralloc(fn->path);
1783 #if defined(XFSDUMP)
1784 if (strcmp(file.program, XFSDUMP) == 0) {
1785 restore_args[j++] = stralloc("-");
1786 restore_args[j++] = stralloc(".");
1789 restore_args[j] = NULL;
1794 cmd = stralloc(SAMBA_CLIENT);
1797 /* fall through to ... */
1803 g_fprintf(stderr, _("warning: GNUTAR program not available.\n"));
1804 cmd = stralloc("tar");
1806 cmd = stralloc(GNUTAR);
1813 if (strcmp(file.program, DUMP) == 0) {
1814 cmd = stralloc(RESTORE);
1818 if (strcmp(file.program, VDUMP) == 0) {
1819 cmd = stralloc(VRESTORE);
1823 if (strcmp(file.program, VXDUMP) == 0) {
1824 cmd = stralloc(VXRESTORE);
1827 #if defined(XFSDUMP)
1828 if (strcmp(file.program, XFSDUMP) == 0) {
1829 cmd = stralloc(XFSRESTORE);
1833 g_fprintf(stderr, _("warning: restore program for %s not available.\n"),
1835 cmd = stralloc("restore");
1839 dbprintf(_("Exec'ing %s with arguments:\n"), cmd);
1840 for (i = 0; i < j; i++) {
1841 if( i == passwd_field)
1842 dbprintf("\tXXXXX\n");
1844 dbprintf("\t%s\n", restore_args[i]);
1847 (void)execv(cmd, restore_args);
1848 /* only get here if exec failed */
1850 for (i = 0; i < j; i++) {
1851 amfree(restore_args[i]);
1853 amfree(restore_args);
1855 perror(_("amrecover couldn't exec"));
1856 g_fprintf(stderr, _(" problem executing %s\n"), cmd);
1864 * Interpose something between the process writing out the dump (writing it to
1865 * some extraction program, really) and the socket from which we're reading, so
1866 * that we can do things like prompt for human interaction for multiple tapes.
1869 writer_intermediary(
1872 EXTRACT_LIST * elist)
1876 char buffer[DISK_BLOCK_BYTES];
1878 amwait_t extractor_status;
1880 SELECT_ARG_TYPE readset, selectset;
1881 struct timeval timeout;
1884 * If there's no distinct data channel (such as if we're talking to an
1885 * older server), don't bother doing anything complicated. Just run the
1889 extract_files_child(ctl_fd, elist);
1893 if(pipe(child_pipe) == -1) {
1894 error(_("extract_list - error setting up pipe to extractor: %s\n"),
1899 /* okay, ready to extract. fork a child to do the actual work */
1900 if ((pid = fork()) == 0) {
1901 /* this is the child process */
1902 /* never gets out of this clause */
1903 aclose(child_pipe[1]);
1904 extract_files_child(child_pipe[0], elist);
1908 /* This is the parent */
1910 error(_("writer_intermediary - error forking child"));
1914 aclose(child_pipe[0]);
1916 if(data_fd > ctl_fd) max_fd = data_fd+1;
1917 else max_fd = ctl_fd+1;
1919 FD_SET(data_fd, &readset);
1920 FD_SET(ctl_fd, &readset);
1923 timeout.tv_sec = READ_TIMEOUT;
1924 timeout.tv_usec = 0;
1925 FD_COPY(&readset, &selectset);
1927 nfound = select(max_fd, &selectset, NULL, NULL,
1930 g_fprintf(stderr,_("select error: %s\n"), strerror(errno));
1934 if (nfound == 0) { /* timeout */
1935 g_fprintf(stderr, _("timeout waiting %d seconds for restore\n"),
1937 g_fprintf(stderr, _("increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n"));
1941 if(FD_ISSET(ctl_fd, &selectset)) {
1942 bytes_read = read(ctl_fd, buffer, sizeof(buffer)-1);
1943 switch(bytes_read) {
1945 if ((errno != EINTR) && (errno != EAGAIN)) {
1946 if (errno != EPIPE) {
1947 g_fprintf(stderr,_("writer ctl fd read error: %s"),
1950 FD_CLR(ctl_fd, &readset);
1955 FD_CLR(ctl_fd, &readset);
1959 char desired_tape[MAX_TAPE_LABEL_BUF];
1961 buffer[bytes_read] = '\0';
1962 /* if prompted for a tape, relay said prompt to the user */
1963 if(sscanf(buffer, "FEEDME %132s\n", desired_tape) == 1) {
1967 g_printf(_("Please insert tape %s. Continue? [Y|n]: "),
1971 input = agets(stdin); /* strips \n */
1972 if (strcasecmp("", input) == 0||
1973 strcasecmp("y", input) == 0||
1974 strcasecmp("yes", input) == 0) {
1975 send_to_tape_server(tape_control_sock, "OK");
1977 } else if (strcasecmp("n", input) == 0||
1978 strcasecmp("no", input) == 0) {
1979 send_to_tape_server(tape_control_sock, "ERROR");
1981 We are the middle process, so just die. */
1987 g_fprintf(stderr, _("Strange message from tape server: %s"), buffer);
1994 /* now read some dump data */
1995 if(FD_ISSET(data_fd, &selectset)) {
1996 bytes_read = read(data_fd, buffer, sizeof(buffer)-1);
1997 switch(bytes_read) {
1999 if ((errno != EINTR) && (errno != EAGAIN)) {
2000 if (errno != EPIPE) {
2001 g_fprintf(stderr,_("writer data fd read error: %s"),
2004 FD_CLR(data_fd, &readset);
2009 FD_CLR(data_fd, &readset);
2014 * spit what we got from the server to the child
2015 * process handling actual dumpfile extraction
2017 if(full_write(child_pipe[1], buffer, bytes_read) < bytes_read) {
2018 if(errno == EPIPE) {
2019 error(_("pipe data reader has quit: %s\n"),
2023 error(_("Write error to extract child: %s\n"),
2030 } while(FD_ISSET(ctl_fd, &readset) || FD_ISSET(data_fd, &readset));
2032 aclose(child_pipe[1]);
2034 waitpid(pid, &extractor_status, 0);
2035 if(WEXITSTATUS(extractor_status) != 0){
2036 int ret = WEXITSTATUS(extractor_status);
2037 if(ret == 255) ret = -1;
2038 error(_("Extractor child exited with status %d\n"), ret);
2045 /* exec restore to do the actual restoration */
2047 /* does the actual extraction of files */
2049 * The original design had the dump image being returned exactly as it
2050 * appears on the tape, and this routine getting from the index server
2051 * whether or not it is compressed, on the assumption that the tape
2052 * server may not know how to uncompress it. But
2053 * - Amrestore can't do that. It returns either compressed or uncompressed
2054 * (always). Amrestore assumes it can uncompress files. It is thus a good
2055 * idea to run the tape server on a machine with gzip.
2056 * - The information about compression in the disklist is really only
2057 * for future dumps. It is possible to change compression on a drive
2058 * so the information in the disklist may not necessarily relate to
2059 * the dump image on the tape.
2060 * Consequently the design was changed to assuming that amrestore can
2061 * uncompress any dump image and have it return an uncompressed file
2067 EXTRACT_LIST *elist;
2069 amwait_t child_stat;
2074 tapelist_t *tlist = NULL;
2076 if (!is_extract_list_nonempty())
2078 g_printf(_("Extract list empty - No files to extract!\n"));
2082 clean_extract_list();
2084 /* get tape device name from index server if none specified */
2085 if (tape_server_name == NULL) {
2086 tape_server_name = newstralloc(tape_server_name, server_name);
2088 if (tape_device_name == NULL) {
2089 if (send_command("TAPE") == -1)
2091 if (get_reply_line() == -1)
2094 if (!server_happy())
2096 g_printf("%s\n", l);
2099 /* skip reply number */
2100 tape_device_name = newstralloc(tape_device_name, l+4);
2103 if (strcmp(tape_device_name, "/dev/null") == 0)
2105 g_printf(_("amrecover: warning: using %s as the tape device will not work\n"),
2110 for (elist = first_tape_list(); elist != NULL; elist = next_tape_list(elist))
2111 if(elist->tape[0]!='/') {
2113 g_printf(_("\nExtracting files using tape drive %s on host %s.\n"),
2114 tape_device_name, tape_server_name);
2115 g_printf(_("The following tapes are needed:"));
2120 tlist = unmarshal_tapelist_str(elist->tape);
2121 for( ; tlist != NULL; tlist = tlist->next)
2122 g_printf(" %s", tlist->label);
2127 for (elist = first_tape_list(); elist != NULL; elist = next_tape_list(elist))
2129 if(elist->tape[0]=='/') {
2131 g_printf(_("\nExtracting files from holding disk on host %s.\n"),
2133 g_printf(_("The following files are needed:"));
2138 tlist = unmarshal_tapelist_str(elist->tape);
2139 for( ; tlist != NULL; tlist = tlist->next)
2140 g_printf(" %s", tlist->label);
2147 if (getcwd(buf, sizeof(buf)) == NULL) {
2148 perror(_("extract_list: Cannot determine current working directory"));
2152 g_printf(_("Restoring files into directory %s\n"), buf);
2154 if (samba_extract_method == SAMBA_SMBCLIENT)
2155 g_printf(_("(unless it is a Samba backup, that will go through to the SMB server)\n"));
2157 if (!okay_to_continue(0,0,0))
2161 while ((elist = first_tape_list()) != NULL)
2163 if(elist->tape[0]=='/') {
2164 dump_device_name = newstralloc(dump_device_name, elist->tape);
2165 g_printf(_("Extracting from file "));
2166 tlist = unmarshal_tapelist_str(dump_device_name);
2167 for( ; tlist != NULL; tlist = tlist->next)
2168 g_printf(" %s", tlist->label);
2173 g_printf(_("Extracting files using tape drive %s on host %s.\n"),
2174 tape_device_name, tape_server_name);
2175 tlist = unmarshal_tapelist_str(elist->tape);
2176 g_printf(_("Load tape %s now\n"), tlist->label);
2178 otc = okay_to_continue(1,1,0);
2181 else if (otc == SKIP_TAPE) {
2182 delete_tape_list(elist); /* skip this tape */
2185 dump_device_name = newstralloc(dump_device_name, tape_device_name);
2187 dump_datestamp = newstralloc(dump_datestamp, elist->date);
2189 /* connect to the tape handler daemon on the tape drive server */
2190 if ((tape_control_sock = extract_files_setup(elist->tape, elist->fileno)) == -1)
2192 g_fprintf(stderr, _("amrecover - can't talk to tape server\n"));
2196 /* okay, ready to extract. fork a child to do the actual work */
2197 if ((pid = fork()) == 0)
2199 /* this is the child process */
2200 /* never gets out of this clause */
2201 writer_intermediary(tape_control_sock, tape_data_sock, elist);
2204 /* this is the parent */
2207 perror(_("extract_list - error forking child"));
2208 aclose(tape_control_sock);
2212 /* store the child pid globally so that it can be killed on intr */
2213 extract_restore_child_pid = pid;
2215 /* wait for the child process to finish */
2216 if ((pid = waitpid(-1, &child_stat, 0)) == (pid_t)-1)
2218 perror(_("extract_list - error waiting for child"));
2222 if(tape_data_sock != -1) {
2223 aclose(tape_data_sock);
2226 if (pid == extract_restore_child_pid)
2228 extract_restore_child_pid = -1;
2232 g_fprintf(stderr, _("extract list - unknown child terminated?\n"));
2235 if ((WIFEXITED(child_stat) != 0) && (WEXITSTATUS(child_stat) != 0))
2238 _("extract_list - child returned non-zero status: %d\n"),
2239 WEXITSTATUS(child_stat));
2240 otc = okay_to_continue(0,0,1);
2245 delete_tape_list(elist); /* tape failed so delete from list */
2249 delete_tape_list(elist); /* tape done so delete from list */