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
34 #include "amrecover.h"
35 #include "fileheader.h"
44 typedef struct EXTRACT_LIST_ITEM {
47 struct EXTRACT_LIST_ITEM *next;
51 typedef struct EXTRACT_LIST {
52 char *date; /* date tape created */
53 int level; /* level of dump */
54 char *tape; /* tape label */
55 off_t fileno; /* fileno on tape */
56 EXTRACT_LIST_ITEM *files; /* files to get off tape */
58 struct EXTRACT_LIST *next;
65 char *dump_device_name = NULL;
67 extern char *localhost;
69 /* global pid storage for interrupt handler */
70 pid_t extract_restore_child_pid = -1;
72 static EXTRACT_LIST *extract_list = NULL;
73 static int tape_control_sock = -1;
74 static int tape_data_sock = -1;
77 unsigned short samba_extract_method = SAMBA_TAR;
78 #endif /* SAMBA_CLIENT */
80 #define READ_TIMEOUT 240*60
82 EXTRACT_LIST *first_tape_list(void);
83 EXTRACT_LIST *next_tape_list(EXTRACT_LIST *list);
84 int is_extract_list_nonempty(void);
85 int length_of_tape_list(EXTRACT_LIST *tape_list);
86 void add_file(char *path, char *regex);
87 void add_glob(char *glob);
88 void add_regex(char *regex);
89 void clear_extract_list(void);
90 void clean_tape_list(EXTRACT_LIST *tape_list);
91 void clean_extract_list(void);
92 void delete_file(char *path, char *regex);
93 void delete_glob(char *glob);
94 void delete_regex(char *regex);
95 void delete_tape_list(EXTRACT_LIST *tape_list);
96 void display_extract_list(char *file);
97 void extract_files(void);
98 void read_file_header(char *buffer,
102 void writer_intermediary(int ctl_fd, int data_fd, EXTRACT_LIST *elist);
103 void writer_intermediary(int ctl_fd, int data_fd, EXTRACT_LIST *elist);
105 static int add_extract_item(DIR_ITEM *ditem);
106 static int delete_extract_item(DIR_ITEM *ditem);
107 static int extract_files_setup(char *label, off_t fsf);
108 static int okay_to_continue(int allow_tape,
111 static int okay_to_continue(int, int, int);
112 static ssize_t read_buffer(int datafd,
116 static void clear_tape_list(EXTRACT_LIST *tape_list);
117 static void extract_files_child(int in_fd, EXTRACT_LIST *elist);
118 static void send_to_tape_server(int tss, char *cmd);
122 * Function: ssize_t read_buffer(datafd, buffer, buflen, timeout_s)
125 * read data from input file desciptor waiting up to timeout_s
126 * seconds before returning data.
129 * datafd - File descriptor to read from.
130 * buffer - Buffer to read into.
131 * buflen - Maximum number of bytes to read into buffer.
132 * timeout_s - Seconds to wait before returning what was already read.
135 * >0 - Number of data bytes in buffer.
137 * -1 - errno == ETIMEDOUT if no data available in specified time.
138 * errno == ENFILE if datafd is invalid.
139 * otherwise errno is set by select or read..
151 struct timeval timeout;
156 if(datafd < 0 || datafd >= (int)FD_SETSIZE) {
157 errno = EMFILE; /* out of range */
162 spaceleft = (ssize_t)buflen;
166 FD_SET(datafd, &readset);
167 timeout.tv_sec = timeout_s;
169 nfound = select(datafd+1, &readset, NULL, NULL, &timeout);
171 /* Select returned an error. */
172 fprintf(stderr,"select error: %s\n", strerror(errno));
178 /* Select timed out. */
179 if (timeout_s != 0) {
180 /* Not polling: a real read timeout */
181 fprintf(stderr,"timeout waiting for restore\n");
182 fprintf(stderr,"increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n");
189 if(!FD_ISSET(datafd, &readset))
192 /* Select says data is available, so read it. */
193 size = read(datafd, dataptr, (size_t)spaceleft);
195 if ((errno == EINTR) || (errno == EAGAIN)) {
198 if (errno != EPIPE) {
199 fprintf(stderr, "read_buffer: read error - %s",
207 } while ((size > 0) && (spaceleft > 0));
209 return ((((ssize_t)buflen-spaceleft) > 0) ? ((ssize_t)buflen-spaceleft) : size);
214 first_tape_list(void)
221 /*@keep@*/ EXTRACT_LIST *list)
230 EXTRACT_LIST * tape_list)
232 EXTRACT_LIST_ITEM *this, *next;
235 this = tape_list->files;
243 tape_list->files = NULL;
247 /* remove a tape list from the extract list, clearing the tape list
248 beforehand if necessary */
251 EXTRACT_LIST * tape_list)
253 EXTRACT_LIST *this, *prev;
255 if (tape_list == NULL)
258 /* is it first on the list? */
259 if (tape_list == extract_list)
261 extract_list = tape_list->next;
262 clear_tape_list(tape_list);
263 amfree(tape_list->date);
264 amfree(tape_list->tape);
269 /* so not first on list - find it and delete */
271 this = extract_list->next;
274 if (this == tape_list)
276 prev->next = tape_list->next;
277 clear_tape_list(tape_list);
278 amfree(tape_list->date);
279 amfree(tape_list->tape);
290 /* return the number of files on a tape's list */
293 EXTRACT_LIST * tape_list)
295 EXTRACT_LIST_ITEM *fn;
299 for (fn = tape_list->files; fn != NULL; fn = fn->next)
307 clear_extract_list(void)
309 while (extract_list != NULL)
310 delete_tape_list(extract_list);
316 EXTRACT_LIST *tape_list)
318 EXTRACT_LIST_ITEM *fn1, *pfn1, *ofn1;
319 EXTRACT_LIST_ITEM *fn2, *pfn2, *ofn2;
324 fn1 = tape_list->files;
325 while (fn1 != NULL) {
330 while (fn2 != NULL && remove_fn1 == 0) {
332 if(strcmp(fn1->path, fn2->path) == 0) {
334 } else if (strncmp(fn1->path, fn2->path, strlen(fn1->path)) == 0 &&
335 ((strlen(fn2->path) > strlen(fn1->path) &&
336 fn2->path[strlen(fn1->path)] == '/') ||
337 (fn1->path[strlen(fn1->path)-1] == '/'))) {
339 } else if (strncmp(fn2->path, fn1->path, strlen(fn2->path)) == 0 &&
340 ((strlen(fn1->path) > strlen(fn2->path) &&
341 fn1->path[strlen(fn2->path)] == '/') ||
342 (fn2->path[strlen(fn2->path)-1] == '/'))) {
348 dbprintf(("removing path %s, it is included in %s\n",
349 fn2->path, fn1->path));
355 } else if (remove_fn1 == 0) {
361 if(remove_fn1 != 0) {
362 /* fn2->path is always valid */
363 /*@i@*/ dbprintf(("removing path %s, it is included in %s\n",
364 /*@i@*/ fn1->path, fn2->path));
369 amfree(tape_list->files);
370 tape_list->files = fn1;
384 clean_extract_list(void)
388 for (this = extract_list; this != NULL; this = this->next)
389 clean_tape_list(this);
393 /* returns -1 if error */
394 /* returns 0 on succes */
395 /* returns 1 if already added */
400 EXTRACT_LIST *this, *this1;
401 EXTRACT_LIST_ITEM *that, *curr;
402 char *ditem_path = NULL;
404 ditem_path = stralloc(ditem->path);
405 clean_pathname(ditem_path);
407 for (this = extract_list; this != NULL; this = this->next)
409 /* see if this is the list for the tape */
410 if (this->level == ditem->level && strcmp(this->tape, ditem->tape) == 0)
412 /* yes, so add to list */
416 if (strcmp(curr->path, ditem_path) == 0) {
422 that = (EXTRACT_LIST_ITEM *)alloc(sizeof(EXTRACT_LIST_ITEM));
423 that->path = stralloc(ditem_path);
424 that->next = this->files;
425 this->files = that; /* add at front since easiest */
431 /* so this is the first time we have seen this tape */
432 this = (EXTRACT_LIST *)alloc(sizeof(EXTRACT_LIST));
433 this->tape = stralloc(ditem->tape);
434 this->level = ditem->level;
435 this->fileno = ditem->fileno;
436 this->date = stralloc(ditem->date);
437 that = (EXTRACT_LIST_ITEM *)alloc(sizeof(EXTRACT_LIST_ITEM));
438 that->path = stralloc(ditem_path);
442 /* add this in date increasing order */
443 /* because restore must be done in this order */
444 /* add at begining */
445 if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
447 this->next = extract_list;
452 for (this1 = extract_list; this1->next != NULL; this1 = this1->next)
454 /* add in the middle */
455 if(strcmp(this->date,this1->next->date) < 0)
457 this->next = this1->next;
471 /* returns -1 if error */
472 /* returns 0 on deletion */
473 /* returns 1 if not there */
479 EXTRACT_LIST_ITEM *that, *prev;
480 char *ditem_path = NULL;
482 ditem_path = stralloc(ditem->path);
483 clean_pathname(ditem_path);
485 for (this = extract_list; this != NULL; this = this->next)
487 /* see if this is the list for the tape */
488 if (this->level == ditem->level && strcmp(this->tape, ditem->tape) == 0)
490 /* yes, so find file on list */
492 if (strcmp(that->path, ditem_path) == 0)
495 this->files = that->next;
498 /* if list empty delete it */
499 if (this->files == NULL)
500 delete_tape_list(this);
508 if (strcmp(that->path, ditem_path) == 0)
510 prev->next = that->next;
535 char *uqglob = unquote_string(glob);
537 regex = glob_to_regex(uqglob);
538 dbprintf(("add_glob (%s) -> %s\n", uqglob, regex));
539 if ((s = validate_regexp(regex)) != NULL) {
540 printf("%s is not a valid shell wildcard pattern: ", glob);
544 * glob_to_regex() anchors the beginning of the pattern with ^,
545 * but we will be tacking it onto the end of the current directory
546 * in add_file, so strip that off. Also, it anchors the end with
547 * $, but we need to match an optional trailing /, so tack that on
550 regex_path = stralloc(regex + 1);
551 regex_path[strlen(regex_path) - 1] = '\0';
552 strappend(regex_path, "[/]*$");
553 add_file(uqglob, regex_path);
565 char *uqregex = unquote_string(regex);
567 if ((s = validate_regexp(uqregex)) != NULL) {
568 printf("%s is not a valid regular expression: ", regex);
571 add_file(uqregex, regex);
580 DIR_ITEM *ditem, lditem;
581 char *path_on_disk = NULL;
582 char *path_on_disk_slash = NULL;
587 char *dir, *dir_undo, dir_undo_ch = '\0';
588 char *ditem_path = NULL;
591 char *s, *fp, *quoted;
596 if (disk_path == NULL) {
597 printf("Must select directory before adding files\n");
600 memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
602 dbprintf(("add_file: Looking for \"%s\"\n", regex));
604 if(strcmp(regex, "/[/]*$") == 0) { /* "/" behave like "." */
607 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 = stralloc2("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);
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()) {
707 if(strncmp(l, sc, sizeof(sc)-1) != 0) {
708 err = "bad reply: not 201-";
712 s = l + sizeof(sc)-1;
715 skip_whitespace(s, ch);
717 err = "bad reply: missing date field";
721 skip_non_whitespace(s, ch);
723 lditem.date = newstralloc(lditem.date, fp);
726 skip_whitespace(s, ch);
727 if(ch == '\0' || sscanf(s - 1, "%d", &lditem.level) != 1) {
728 err = "bad reply: cannot parse level field";
733 skip_whitespace(s, ch);
735 err = "bad reply: missing tape field";
739 skip_non_whitespace(s, ch);
741 lditem.tape = newstralloc(lditem.tape, fp);
744 if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
745 skip_whitespace(s, ch);
746 if(ch == '\0' || sscanf(s - 1, OFF_T_FMT,
747 (OFF_T_FMT_TYPE *)&lditem.fileno) != 1) {
748 err = "bad reply: cannot parse fileno field";
754 skip_whitespace(s, ch);
756 err = "bad reply: missing directory field";
760 skip_quoted_string(s, ch);
762 dir_undo_ch = *dir_undo;
765 switch(add_extract_item(&lditem)) {
767 printf("System error\n");
768 dbprintf(("add_file: (Failed) System error\n"));
772 quoted = quote_string(lditem.path);
773 printf("Added dir %s at date %s\n",
774 quoted, lditem.date);
775 dbprintf(("add_file: (Successful) Added dir %s at date %s\n",
776 quoted, lditem.date));
785 if(!server_happy()) {
792 } else if(added == 0) {
793 quoted = quote_string(ditem_path);
794 printf("dir %s already added\n", quoted);
795 dbprintf(("add_file: dir %s already added\n", quoted));
799 else /* It is a file */
801 switch(add_extract_item(ditem)) {
803 printf("System error\n");
804 dbprintf(("add_file: (Failed) System error\n"));
808 quoted = quote_string(ditem->path);
809 printf("Added file %s\n", quoted);
810 dbprintf(("add_file: (Successful) Added %s\n", quoted));
815 quoted = quote_string(ditem->path);
816 printf("File %s already added\n", quoted);
817 dbprintf(("add_file: file %s already added\n", quoted));
827 amfree(path_on_disk);
828 amfree(path_on_disk_slash);
831 quoted = quote_string(path);
832 printf("File %s doesn't exist in directory\n", quoted);
833 dbprintf(("add_file: (Failed) File %s doesn't exist in directory\n",
847 char *uqglob = unquote_string(glob);
849 regex = glob_to_regex(uqglob);
850 dbprintf(("delete_glob (%s) -> %s\n", uqglob, regex));
851 if ((s = validate_regexp(regex)) != NULL) {
852 printf("\"%s\" is not a valid shell wildcard pattern: ", glob);
856 * glob_to_regex() anchors the beginning of the pattern with ^,
857 * but we will be tacking it onto the end of the current directory
858 * in add_file, so strip that off. Also, it anchors the end with
859 * $, but we need to match an optional trailing /, so tack that on
862 regex_path = stralloc(regex + 1);
863 regex_path[strlen(regex_path) - 1] = '\0';
864 strappend(regex_path, "[/]*$");
865 delete_file(uqglob, regex_path);
877 char *uqregex = unquote_string(regex);
879 if ((s = validate_regexp(regex)) != NULL) {
880 printf("\"%s\" is not a valid regular expression: ", regex);
883 delete_file(uqregex, uqregex);
893 DIR_ITEM *ditem, lditem;
894 char *path_on_disk = NULL;
895 char *path_on_disk_slash = NULL;
901 char *tape, *tape_undo, tape_undo_ch = '\0';
902 char *dir_undo, dir_undo_ch = '\0';
905 char *ditem_path = NULL;
913 if (disk_path == NULL) {
914 printf("Must select directory before deleting files\n");
917 memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
919 dbprintf(("delete_file: Looking for \"%s\"\n", path));
921 if (strcmp(regex, "[^/]*[/]*$") == 0) {
922 /* Looking for * find everything but single . */
923 regex = "([^/.]|\\.[^/]+|[^/.][^/]*)[/]*$";
925 /* remove "/" at end of path */
926 j = (ssize_t)(strlen(regex) - 1);
927 while(j >= 0 && regex[j] == '/') regex[j--] = '\0';
930 /* convert path (assumed in cwd) to one on disk */
931 if (strcmp(disk_path, "/") == 0) {
933 if (strcmp(regex, "/[/]*$") == 0) {
934 /* We want "/" to match the directory itself: "/." */
935 path_on_disk = stralloc("/\\.[/]*$");
937 /* No mods needed if already starts with '/' */
938 path_on_disk = stralloc(regex);
942 path_on_disk = stralloc2("/", regex);
945 char *clean_disk_path = clean_regex(disk_path);
946 path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
947 amfree(clean_disk_path);
950 path_on_disk_slash = stralloc2(path_on_disk, "/");
952 dbprintf(("delete_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n",
953 regex, path_on_disk));
955 for (ditem=get_dir_list(); ditem!=NULL; ditem=get_next_dir_item(ditem))
957 quoted = quote_string(ditem->path);
958 dbprintf(("delete_file: Pondering ditem->path=%s\n", quoted));
960 if (match(path_on_disk, ditem->path)
961 || match(path_on_disk_slash, ditem->path))
964 j = (ssize_t)strlen(ditem->path);
965 if((j > 0 && ditem->path[j-1] == '/')
966 || (j > 1 && ditem->path[j-2] == '/' && ditem->path[j-1] == '.'))
967 { /* It is a directory */
968 ditem_path = newstralloc(ditem_path, ditem->path);
969 clean_pathname(ditem_path);
971 cmd = stralloc2("ORLD ", ditem_path);
972 if(send_command(cmd) == -1) {
975 amfree(path_on_disk);
976 amfree(path_on_disk_slash);
981 if ((i = get_reply_line()) == -1) {
983 amfree(path_on_disk);
984 amfree(path_on_disk_slash);
987 if(i==0) /* assume something wrong */
990 amfree(path_on_disk);
991 amfree(path_on_disk_slash);
997 lditem.path = newstralloc(lditem.path, ditem->path);
999 tape_undo = dir_undo = NULL;
1000 /* skip the last line -- duplicate of the preamble */
1001 while ((i = get_reply_line()) != 0)
1005 amfree(path_on_disk);
1006 amfree(path_on_disk_slash);
1011 if(tape_undo) *tape_undo = tape_undo_ch;
1012 if(dir_undo) *dir_undo = dir_undo_ch;
1013 tape_undo = dir_undo = NULL;
1014 cmd = stralloc(l); /* save for the error report */
1016 continue; /* throw the rest of the lines away */
1019 if (!server_happy()) {
1024 if(strncmp(l, sc, sizeof(sc)-1) != 0) {
1025 err = "bad reply: not 201-";
1028 s = l + sizeof(sc)-1;
1031 skip_whitespace(s, ch);
1033 err = "bad reply: missing date field";
1037 skip_non_whitespace(s, ch);
1040 skip_whitespace(s, ch);
1041 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
1042 err = "bad reply: cannot parse level field";
1045 skip_integer(s, ch);
1047 skip_whitespace(s, ch);
1049 err = "bad reply: missing tape field";
1053 skip_non_whitespace(s, ch);
1055 tape_undo_ch = *tape_undo;
1058 if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
1059 skip_whitespace(s, ch);
1060 if(ch == '\0' || sscanf(s - 1, OFF_T_FMT,
1061 (OFF_T_FMT_TYPE *)&fileno) != 1) {
1062 err = "bad reply: cannot parse fileno field";
1065 skip_integer(s, ch);
1068 skip_whitespace(s, ch);
1070 err = "bad reply: missing directory field";
1073 skip_non_whitespace(s, ch);
1075 dir_undo_ch = *dir_undo;
1078 lditem.date = newstralloc(lditem.date, date);
1080 lditem.tape = newstralloc(lditem.tape, tape);
1081 switch(delete_extract_item(&lditem)) {
1083 printf("System error\n");
1084 dbprintf(("delete_file: (Failed) System error\n"));
1087 printf("Deleted dir %s at date %s\n", ditem_path, date);
1088 dbprintf(("delete_file: (Successful) Deleted dir %s at date %s\n",
1096 if(!server_happy()) {
1103 } else if(deleted == 0) {
1104 printf("Warning - dir '%s' not on tape list\n",
1106 dbprintf(("delete_file: dir '%s' not on tape list\n",
1112 switch(delete_extract_item(ditem)) {
1114 printf("System error\n");
1115 dbprintf(("delete_file: (Failed) System error\n"));
1118 printf("Deleted %s\n", ditem->path);
1119 dbprintf(("delete_file: (Successful) Deleted %s\n",
1123 printf("Warning - file '%s' not on tape list\n",
1125 dbprintf(("delete_file: file '%s' not on tape list\n",
1134 amfree(path_on_disk);
1135 amfree(path_on_disk_slash);
1138 printf("File %s doesn't exist in directory\n", path);
1139 dbprintf(("delete_file: (Failed) File %s doesn't exist in directory\n",
1145 /* print extract list into file. If NULL ptr passed print to screen */
1147 display_extract_list(
1151 EXTRACT_LIST_ITEM *that;
1154 char *pager_command;
1159 if ((pager = getenv("PAGER")) == NULL)
1164 * Set up the pager command so if the pager is terminated, we do
1165 * not get a SIGPIPE back.
1167 pager_command = stralloc2(pager, " ; /bin/cat > /dev/null");
1168 if ((fp = popen(pager_command, "w")) == NULL)
1170 printf("Warning - can't pipe through %s\n", pager);
1173 amfree(pager_command);
1177 uqfile = unquote_string(file);
1178 if ((fp = fopen(uqfile, "w")) == NULL)
1180 printf("Can't open file %s to print extract list into\n", file);
1187 for (this = extract_list; this != NULL; this = this->next)
1189 fprintf(fp, "TAPE %s LEVEL %d DATE %s\n",
1190 this->tape, this->level, this->date);
1191 for (that = this->files; that != NULL; that = that->next)
1192 fprintf(fp, "\t%s\n", that->path);
1198 printf("Extract list written to file %s\n", file);
1204 /* returns 0 if extract list empty and 1 if it isn't */
1206 is_extract_list_nonempty(void)
1208 return (extract_list != NULL);
1212 /* prints continue prompt and waits for response,
1213 returns 0 if don't, non-0 if do */
1230 prompt = "New tape device [?]: ";
1231 } else if (allow_tape && allow_skip) {
1232 prompt = "Continue [?/Y/n/s/t]? ";
1233 } else if (allow_tape && !allow_skip) {
1234 prompt = "Continue [?/Y/n/t]? ";
1235 } else if (allow_retry) {
1236 prompt = "Continue [?/Y/n/r]? ";
1238 prompt = "Continue [?/Y/n]? ";
1240 fputs(prompt, stdout);
1241 fflush(stdout); fflush(stderr);
1243 if ((line = agets(stdin)) == NULL) {
1254 while ((ch = *s++) != '\0' && isspace(ch)) {
1255 (void)ch; /* Quiet empty loop body warning */
1259 printf("Enter a new device ([host:]device) or \"default\"\n");
1261 printf("Enter \"y\"es to continue, \"n\"o to stop");
1263 printf(", \"s\"kip this tape");
1266 printf(" or \"r\"etry this tape");
1269 printf(" or \"t\"ape to change tape drives");
1273 } else if (get_tape) {
1276 } else if (ch == '\0' || ch == 'Y' || ch == 'y') {
1278 } else if (allow_tape && (ch == 'T' || ch == 't')) {
1280 } else if (ch == 'N' || ch == 'n') {
1282 } else if (allow_retry && (ch == 'R' || ch == 'r')) {
1284 } else if (allow_skip && (ch == 'S' || ch == 's')) {
1295 send_to_tape_server(
1299 char *msg = stralloc2(cmd, "\r\n");
1301 if (fullwrite(tss, msg, strlen(msg)) < 0)
1303 error("Error writing to tape server");
1310 /* start up connection to tape server and set commands to initiate
1311 transfer of dump image.
1312 Return tape server socket on success, -1 on error. */
1314 extract_files_setup(
1319 in_port_t my_port, my_data_port;
1320 char *disk_regex = NULL;
1321 char *host_regex = NULL;
1322 char *service_name = NULL;
1324 char *clean_datestamp, *ch, *ch1;
1325 char *our_feature_string = NULL;
1328 service_name = stralloc2("amidxtape", SERVICE_SUFFIX);
1330 /* get tape server details */
1331 if ((sp = getservbyname(service_name, "tcp")) == NULL)
1333 printf("%s/tcp unknown protocol - config error?\n", service_name);
1334 amfree(service_name);
1337 amfree(service_name);
1338 seteuid(0); /* it either works ... */
1340 tape_control_sock = stream_client_privileged(tape_server_name,
1341 (in_port_t)ntohs((in_port_t)sp->s_port),
1346 if (tape_control_sock < 0)
1348 printf("cannot connect to %s: %s\n", tape_server_name, strerror(errno));
1351 if (my_port >= IPPORT_RESERVED) {
1352 aclose(tape_control_sock);
1353 printf("did not get a reserved port: %u\n", (unsigned)my_port);
1358 seteuid(getuid()); /* put it back */
1360 /* do the security thing */
1361 line = get_security();
1362 send_to_tape_server(tape_control_sock, line);
1363 memset(line, '\0', strlen(line));
1366 disk_regex = alloc(strlen(disk_name) * 2 + 3);
1371 /* we want to force amrestore to only match disk_name exactly */
1374 /* We need to escape some characters first... NT compatibilty crap */
1375 for (; *ch != 0; ch++, ch1++) {
1376 switch (*ch) { /* done this way in case there are more */
1379 /* no break; we do want to fall through... */
1385 /* we want to force amrestore to only match disk_name exactly */
1390 host_regex = alloc(strlen(dump_hostname) * 2 + 3);
1395 /* we want to force amrestore to only match dump_hostname exactly */
1398 /* We need to escape some characters first... NT compatibilty crap */
1399 for (; *ch != 0; ch++, ch1++) {
1400 switch (*ch) { /* done this way in case there are more */
1403 /* no break; we do want to fall through... */
1409 /* we want to force amrestore to only match dump_hostname exactly */
1414 clean_datestamp = stralloc(dump_datestamp);
1415 for(ch=ch1=clean_datestamp;*ch1 != '\0';ch1++) {
1423 /* push our feature list off to the tape server */
1424 /* XXX assumes that index server and tape server are equivalent, ew */
1425 if(am_has_feature(indexsrv_features, fe_amidxtaped_exchange_features)){
1426 char buffer[32768] = "\0";
1428 our_feature_string = am_feature_to_string(our_features);
1429 tt = newstralloc2(tt, "FEATURES=", our_feature_string);
1430 send_to_tape_server(tape_control_sock, tt);
1431 if (read(tape_control_sock, buffer, sizeof(buffer)) <= 0) {
1432 error("Could not read features from control socket\n");
1435 tapesrv_features = am_string_to_feature(buffer);
1436 amfree(our_feature_string);
1440 if(am_has_feature(indexsrv_features, fe_amidxtaped_header) &&
1441 am_has_feature(indexsrv_features, fe_amidxtaped_device) &&
1442 am_has_feature(indexsrv_features, fe_amidxtaped_host) &&
1443 am_has_feature(indexsrv_features, fe_amidxtaped_disk) &&
1444 am_has_feature(indexsrv_features, fe_amidxtaped_datestamp)) {
1446 if(am_has_feature(indexsrv_features, fe_amidxtaped_config)) {
1447 tt = newstralloc2(tt, "CONFIG=", config);
1448 send_to_tape_server(tape_control_sock, tt);
1450 if(am_has_feature(indexsrv_features, fe_amidxtaped_label) &&
1451 label && label[0] != '/') {
1452 tt = newstralloc2(tt,"LABEL=",label);
1453 send_to_tape_server(tape_control_sock, tt);
1455 if(am_has_feature(indexsrv_features, fe_amidxtaped_fsf)) {
1457 snprintf(v_fsf, 99, OFF_T_FMT, (OFF_T_FMT_TYPE)fsf);
1458 tt = newstralloc2(tt, "FSF=",v_fsf);
1459 send_to_tape_server(tape_control_sock, tt);
1461 send_to_tape_server(tape_control_sock, "HEADER");
1462 tt = newstralloc2(tt, "DEVICE=", dump_device_name);
1463 send_to_tape_server(tape_control_sock, tt);
1464 tt = newstralloc2(tt, "HOST=", host_regex);
1465 send_to_tape_server(tape_control_sock, tt);
1466 tt = newstralloc2(tt, "DISK=", disk_regex);
1467 send_to_tape_server(tape_control_sock, tt);
1468 tt = newstralloc2(tt, "DATESTAMP=", clean_datestamp);
1469 send_to_tape_server(tape_control_sock, tt);
1470 send_to_tape_server(tape_control_sock, "END");
1473 else if(am_has_feature(indexsrv_features, fe_amidxtaped_nargs)) {
1474 /* send to the tape server what tape file we want */
1483 send_to_tape_server(tape_control_sock, "6");
1484 send_to_tape_server(tape_control_sock, "-h");
1485 send_to_tape_server(tape_control_sock, "-p");
1486 send_to_tape_server(tape_control_sock, dump_device_name);
1487 send_to_tape_server(tape_control_sock, host_regex);
1488 send_to_tape_server(tape_control_sock, disk_regex);
1489 send_to_tape_server(tape_control_sock, clean_datestamp);
1491 dbprintf(("Started amidxtaped with arguments \"6 -h -p %s %s %s %s\"\n",
1492 dump_device_name, host_regex, disk_regex, clean_datestamp));
1496 * split-restoring amidxtaped versions will expect to set up a data
1497 * connection for dumpfile data, distinct from the socket we're already
1498 * using for control data
1501 if(am_has_feature(tapesrv_features, fe_recover_splits)){
1503 in_port_t data_port = (in_port_t)-1;
1506 nread = read(tape_control_sock, buffer, sizeof(buffer));
1509 error("Could not read from control socket: %s\n",
1514 buffer[nread] = '\0';
1515 if (sscanf(buffer, "CONNECT %hu\n",
1516 (unsigned short *)&data_port) != 1) {
1517 error("Recieved invalid port number message from control socket: %s\n",
1522 tape_data_sock = stream_client_privileged(server_name,
1528 if(tape_data_sock == -1){
1529 error("Unable to make data connection to server: %s\n",
1534 amfree(our_feature_string);
1536 line = get_security();
1538 send_to_tape_server(tape_data_sock, line);
1539 memset(line, '\0', strlen(line));
1545 amfree(clean_datestamp);
1547 return tape_control_sock;
1552 * Reads the first block of a tape file.
1564 bytes_read = read_buffer(tapedev, buffer, buflen, READ_TIMEOUT);
1565 if(bytes_read < 0) {
1566 error("error reading header (%s), check amidxtaped.*.debug on server",
1571 if((size_t)bytes_read < buflen) {
1572 fprintf(stderr, "%s: short block %d byte%s\n",
1573 get_pname(), (int)bytes_read, (bytes_read == 1) ? "" : "s");
1574 print_header(stdout, file);
1575 error("Can't read file header");
1579 /* bytes_read == buflen */
1580 parse_file_header(buffer, file, (size_t)bytes_read);
1593 extract_files_child(
1595 EXTRACT_LIST * elist)
1598 int extra_params = 0;
1600 char **restore_args = NULL;
1602 EXTRACT_LIST_ITEM *fn;
1603 enum dumptypes dumptype = IS_UNKNOWN;
1604 char buffer[DISK_BLOCK_BYTES];
1608 int passwd_field = -1;
1610 char *domain = NULL, *smbpass = NULL;
1613 /* code executed by child to do extraction */
1616 /* make in_fd be our stdin */
1617 if (dup2(in_fd, STDIN_FILENO) == -1)
1619 error("dup2 failed in extract_files_child: %s", strerror(errno));
1623 /* read the file header */
1625 read_file_header(buffer, &file, sizeof(buffer), STDIN_FILENO);
1627 if(file.type != F_DUMPFILE) {
1628 print_header(stdout, &file);
1629 error("bad header");
1633 if (file.program != NULL) {
1635 if (strcmp(file.program, GNUTAR) == 0)
1636 dumptype = IS_GNUTAR;
1639 if (dumptype == IS_UNKNOWN) {
1640 len_program = strlen(file.program);
1641 if(len_program >= 3 &&
1642 strcmp(&file.program[len_program-3],"tar") == 0)
1647 if (dumptype == IS_UNKNOWN && strcmp(file.program, SAMBA_CLIENT) ==0) {
1648 if (samba_extract_method == SAMBA_TAR)
1649 dumptype = IS_SAMBA_TAR;
1651 dumptype = IS_SAMBA;
1656 /* form the arguments to restore */
1657 files_off_tape = length_of_tape_list(elist);
1676 #if defined(XFSDUMP)
1677 if (strcmp(file.program, XFSDUMP) == 0) {
1678 extra_params = 4 + files_off_tape;
1688 restore_args = (char **)alloc((size_t)((extra_params + files_off_tape + 1)
1693 restore_args[j++] = stralloc("smbclient");
1694 smbpass = findpass(file.disk, &domain);
1696 restore_args[j++] = stralloc(file.disk);
1698 restore_args[j++] = stralloc("-U");
1699 restore_args[j++] = smbpass;
1701 restore_args[j++] = stralloc("-W");
1702 restore_args[j++] = stralloc(domain);
1707 restore_args[j++] = stralloc("-d0");
1708 restore_args[j++] = stralloc("-Tx");
1709 restore_args[j++] = stralloc("-"); /* data on stdin */
1714 restore_args[j++] = stralloc("tar");
1715 restore_args[j++] = stralloc("--numeric-owner");
1716 restore_args[j++] = stralloc("-xpGvf");
1717 restore_args[j++] = stralloc("-"); /* data on stdin */
1720 restore_args[j++] = stralloc("tar");
1721 restore_args[j++] = stralloc("-xpvf");
1722 restore_args[j++] = stralloc("-"); /* data on stdin */
1726 restore_args[j++] = stralloc("restore");
1728 restore_args[j++] = stralloc("-xB");
1730 #if defined(XFSDUMP)
1731 if (strcmp(file.program, XFSDUMP) == 0) {
1732 restore_args[j++] = stralloc("-v");
1733 restore_args[j++] = stralloc("silent");
1737 if (strcmp(file.program, VDUMP) == 0) {
1738 restore_args[j++] = stralloc("xf");
1739 restore_args[j++] = stralloc("-"); /* data on stdin */
1743 restore_args[j++] = stralloc("xbf");
1744 restore_args[j++] = stralloc("2"); /* read in units of 1K */
1745 restore_args[j++] = stralloc("-"); /* data on stdin */
1750 for (i = 0, fn = elist->files; i < files_off_tape; i++, fn = fn->next)
1757 if (strcmp(fn->path, "/") == 0)
1758 restore_args[j++] = stralloc(".");
1760 restore_args[j++] = stralloc2(".", fn->path);
1764 #if defined(XFSDUMP)
1765 if (strcmp(file.program, XFSDUMP) == 0) {
1767 * xfsrestore needs a -s option before each file to be
1768 * restored, and also wants them to be relative paths.
1770 restore_args[j++] = stralloc("-s");
1771 restore_args[j++] = stralloc(fn->path + 1);
1775 restore_args[j++] = stralloc(fn->path);
1779 #if defined(XFSDUMP)
1780 if (strcmp(file.program, XFSDUMP) == 0) {
1781 restore_args[j++] = stralloc("-");
1782 restore_args[j++] = stralloc(".");
1785 restore_args[j] = NULL;
1790 cmd = stralloc(SAMBA_CLIENT);
1793 /* fall through to ... */
1799 fprintf(stderr, "warning: GNUTAR program not available.\n");
1800 cmd = stralloc("tar");
1802 cmd = stralloc(GNUTAR);
1809 if (strcmp(file.program, DUMP) == 0) {
1810 cmd = stralloc(RESTORE);
1814 if (strcmp(file.program, VDUMP) == 0) {
1815 cmd = stralloc(VRESTORE);
1819 if (strcmp(file.program, VXDUMP) == 0) {
1820 cmd = stralloc(VXRESTORE);
1823 #if defined(XFSDUMP)
1824 if (strcmp(file.program, XFSDUMP) == 0) {
1825 cmd = stralloc(XFSRESTORE);
1829 fprintf(stderr, "warning: restore program for %s not available.\n",
1831 cmd = stralloc("restore");
1835 dbprintf(("Exec'ing %s with arguments:\n", cmd));
1836 for (i = 0; i < j; i++) {
1837 if( i == passwd_field)
1838 dbprintf(("\tXXXXX\n"));
1840 dbprintf(("\t%s\n", restore_args[i]));
1842 (void)execv(cmd, restore_args);
1843 /* only get here if exec failed */
1845 for (i = 0; i < j; i++) {
1846 amfree(restore_args[i]);
1848 amfree(restore_args);
1850 perror("amrecover couldn't exec");
1851 fprintf(stderr, " problem executing %s\n", cmd);
1859 * Interpose something between the process writing out the dump (writing it to
1860 * some extraction program, really) and the socket from which we're reading, so
1861 * that we can do things like prompt for human interaction for multiple tapes.
1864 writer_intermediary(
1867 EXTRACT_LIST * elist)
1871 char buffer[DISK_BLOCK_BYTES];
1873 amwait_t extractor_status;
1875 SELECT_ARG_TYPE readset, selectset;
1876 struct timeval timeout;
1879 * If there's no distinct data channel (such as if we're talking to an
1880 * older server), don't bother doing anything complicated. Just run the
1884 extract_files_child(ctl_fd, elist);
1888 if(pipe(child_pipe) == -1) {
1889 error("extract_list - error setting up pipe to extractor: %s\n",
1894 /* okay, ready to extract. fork a child to do the actual work */
1895 if ((pid = fork()) == 0) {
1896 /* this is the child process */
1897 /* never gets out of this clause */
1898 aclose(child_pipe[1]);
1899 extract_files_child(child_pipe[0], elist);
1903 /* This is the parent */
1905 error("writer_intermediary - error forking child");
1909 aclose(child_pipe[0]);
1911 if(data_fd > ctl_fd) max_fd = data_fd+1;
1912 else max_fd = ctl_fd+1;
1914 FD_SET(data_fd, &readset);
1915 FD_SET(ctl_fd, &readset);
1918 timeout.tv_sec = READ_TIMEOUT;
1919 timeout.tv_usec = 0;
1920 FD_COPY(&readset, &selectset);
1922 nfound = select(max_fd, &selectset, NULL, NULL,
1925 fprintf(stderr,"select error: %s\n", strerror(errno));
1929 if (nfound == 0) { /* timeout */
1930 fprintf(stderr, "timeout waiting %d seconds for restore\n",
1932 fprintf(stderr, "increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n");
1936 if(FD_ISSET(ctl_fd, &selectset)) {
1937 bytes_read = read(ctl_fd, buffer, sizeof(buffer)-1);
1938 switch(bytes_read) {
1940 if ((errno != EINTR) && (errno != EAGAIN)) {
1941 if (errno != EPIPE) {
1942 fprintf(stderr,"writer ctl fd read error: %s",
1945 FD_CLR(ctl_fd, &readset);
1950 FD_CLR(ctl_fd, &readset);
1954 char desired_tape[MAX_TAPE_LABEL_BUF];
1956 buffer[bytes_read] = '\0';
1957 /* if prompted for a tape, relay said prompt to the user */
1958 if(sscanf(buffer, "FEEDME %132s\n", desired_tape) == 1) {
1962 printf("Please insert tape %s. Continue? [Y|n]: ",
1966 input = agets(stdin); /* strips \n */
1967 if (strcasecmp("", input) == 0||
1968 strcasecmp("y", input) == 0||
1969 strcasecmp("yes", input) == 0) {
1970 send_to_tape_server(tape_control_sock, "OK");
1972 } else if (strcasecmp("n", input) == 0||
1973 strcasecmp("no", input) == 0) {
1974 send_to_tape_server(tape_control_sock, "ERROR");
1976 We are the middle process, so just die. */
1982 fprintf(stderr, "Strange message from tape server: %s", buffer);
1989 /* now read some dump data */
1990 if(FD_ISSET(data_fd, &selectset)) {
1991 bytes_read = read(data_fd, buffer, sizeof(buffer)-1);
1992 switch(bytes_read) {
1994 if ((errno != EINTR) && (errno != EAGAIN)) {
1995 if (errno != EPIPE) {
1996 fprintf(stderr,"writer data fd read error: %s",
1999 FD_CLR(data_fd, &readset);
2004 FD_CLR(data_fd, &readset);
2009 * spit what we got from the server to the child
2010 * process handling actual dumpfile extraction
2012 if(fullwrite(child_pipe[1], buffer, (size_t)bytes_read) < 0) {
2013 if(errno == EPIPE) {
2014 error("%s: pipe data reader has quit: %s\n",
2015 get_pname(), strerror(errno));
2018 error("Write error to extract child: %s\n",
2025 } while(FD_ISSET(ctl_fd, &readset) || FD_ISSET(data_fd, &readset));
2027 aclose(child_pipe[1]);
2029 waitpid(pid, &extractor_status, 0);
2030 if(WEXITSTATUS(extractor_status) != 0){
2031 int ret = WEXITSTATUS(extractor_status);
2032 if(ret == 255) ret = -1;
2033 error("Extractor child exited with status %d\n", ret);
2040 /* exec restore to do the actual restoration */
2042 /* does the actual extraction of files */
2044 * The original design had the dump image being returned exactly as it
2045 * appears on the tape, and this routine getting from the index server
2046 * whether or not it is compressed, on the assumption that the tape
2047 * server may not know how to uncompress it. But
2048 * - Amrestore can't do that. It returns either compressed or uncompressed
2049 * (always). Amrestore assumes it can uncompress files. It is thus a good
2050 * idea to run the tape server on a machine with gzip.
2051 * - The information about compression in the disklist is really only
2052 * for future dumps. It is possible to change compression on a drive
2053 * so the information in the disklist may not necessarily relate to
2054 * the dump image on the tape.
2055 * Consequently the design was changed to assuming that amrestore can
2056 * uncompress any dump image and have it return an uncompressed file
2062 EXTRACT_LIST *elist;
2064 amwait_t child_stat;
2069 tapelist_t *tlist = NULL;
2071 if (!is_extract_list_nonempty())
2073 printf("Extract list empty - No files to extract!\n");
2077 clean_extract_list();
2079 /* get tape device name from index server if none specified */
2080 if (tape_server_name == NULL) {
2081 tape_server_name = newstralloc(tape_server_name, server_name);
2083 if (tape_device_name == NULL) {
2084 if (send_command("TAPE") == -1)
2086 if (get_reply_line() == -1)
2089 if (!server_happy())
2094 /* skip reply number */
2095 tape_device_name = newstralloc(tape_device_name, l+4);
2098 if (strcmp(tape_device_name, "/dev/null") == 0)
2100 printf("amrecover: warning: using %s as the tape device will not work\n",
2105 for (elist = first_tape_list(); elist != NULL; elist = next_tape_list(elist))
2106 if(elist->tape[0]!='/') {
2108 printf("\nExtracting files using tape drive %s on host %s.\n",
2109 tape_device_name, tape_server_name);
2110 printf("The following tapes are needed:");
2115 tlist = unmarshal_tapelist_str(elist->tape);
2116 for( ; tlist != NULL; tlist = tlist->next)
2117 printf(" %s", tlist->label);
2122 for (elist = first_tape_list(); elist != NULL; elist = next_tape_list(elist))
2124 if(elist->tape[0]=='/') {
2126 printf("\nExtracting files from holding disk on host %s.\n",
2128 printf("The following files are needed:");
2133 tlist = unmarshal_tapelist_str(elist->tape);
2134 for( ; tlist != NULL; tlist = tlist->next)
2135 printf(" %s", tlist->label);
2142 if (getcwd(buf, sizeof(buf)) == NULL) {
2143 perror("extract_list: Current working directory unavailable");
2147 printf("Restoring files into directory %s\n", buf);
2149 if (samba_extract_method == SAMBA_SMBCLIENT)
2150 printf("(unless it is a Samba backup, that will go through to the SMB server)\n");
2152 if (!okay_to_continue(0,0,0))
2156 while ((elist = first_tape_list()) != NULL)
2158 if(elist->tape[0]=='/') {
2159 dump_device_name = newstralloc(dump_device_name, elist->tape);
2160 printf("Extracting from file ");
2161 tlist = unmarshal_tapelist_str(dump_device_name);
2162 for( ; tlist != NULL; tlist = tlist->next)
2163 printf(" %s", tlist->label);
2168 printf("Extracting files using tape drive %s on host %s.\n",
2169 tape_device_name, tape_server_name);
2170 tlist = unmarshal_tapelist_str(elist->tape);
2171 printf("Load tape %s now\n", tlist->label);
2173 otc = okay_to_continue(1,1,0);
2176 else if (otc == SKIP_TAPE) {
2177 delete_tape_list(elist); /* skip this tape */
2180 dump_device_name = newstralloc(dump_device_name, tape_device_name);
2182 dump_datestamp = newstralloc(dump_datestamp, elist->date);
2184 /* connect to the tape handler daemon on the tape drive server */
2185 if ((tape_control_sock = extract_files_setup(elist->tape, elist->fileno)) == -1)
2187 fprintf(stderr, "amrecover - can't talk to tape server\n");
2191 /* okay, ready to extract. fork a child to do the actual work */
2192 if ((pid = fork()) == 0)
2194 /* this is the child process */
2195 /* never gets out of this clause */
2196 writer_intermediary(tape_control_sock, tape_data_sock, elist);
2199 /* this is the parent */
2202 perror("extract_list - error forking child");
2203 aclose(tape_control_sock);
2207 /* store the child pid globally so that it can be killed on intr */
2208 extract_restore_child_pid = pid;
2210 /* wait for the child process to finish */
2211 if ((pid = waitpid(-1, &child_stat, 0)) == (pid_t)-1)
2213 perror("extract_list - error waiting for child");
2217 if(tape_data_sock != -1) {
2218 aclose(tape_data_sock);
2221 if (pid == extract_restore_child_pid)
2223 extract_restore_child_pid = -1;
2227 fprintf(stderr, "extract list - unknown child terminated?\n");
2230 if ((WIFEXITED(child_stat) != 0) && (WEXITSTATUS(child_stat) != 0))
2233 "extract_list - child returned non-zero status: %d\n",
2234 WEXITSTATUS(child_stat));
2235 otc = okay_to_continue(0,0,1);
2240 delete_tape_list(elist); /* tape failed so delete from list */
2244 delete_tape_list(elist); /* tape done so delete from list */