* Authors: the Amanda Development Team. Its members are listed in a
* file named AUTHORS, in the root directory of this distribution.
*/
-/* $Id: amidxtaped.c,v 1.73 2006/07/25 19:06:46 martinea Exp $
+/* $Id: amidxtaped.c,v 1.73.2.1 2006/09/27 12:04:09 martinea Exp $
*
* This daemon extracts a dump image off a tape for amrecover and
* returns it over the network. It basically, reads a number of
static g_option_t *g_options = NULL;
static int ctlfdin, ctlfdout, datafdout;
static char *amandad_auth = NULL;
+static FILE *cmdin, *cmdout;
-static char *get_client_line(void);
+static char *get_client_line(FILE *in);
static void check_security_buffer(char *);
static char *get_client_line_fd(int);
/* get a line from client - line terminated by \r\n */
static char *
-get_client_line(void)
+get_client_line(FILE *in)
{
static char *line = NULL;
char *part = NULL;
amfree(line);
while(1) {
- if((part = agets(stdin)) == NULL) {
+ if((part = agets(in)) == NULL) {
if(errno != 0) {
dbprintf(("%s: read error: %s\n",
debug_prefix_time(NULL), strerror(errno)));
char *their_feature_string = NULL;
rst_flags_t *rst_flags;
int use_changer = 0;
- FILE *prompt_stream = NULL;
int re_end;
char *re_config = NULL;
char *conf_tapetype;
/* do the security thing */
amfree(buf);
- buf = stralloc(get_client_line());
+ fflush(stdout);
+ cmdout = stdout;
+ cmdin = stdin;
+ buf = stralloc(get_client_line(cmdin));
check_security_buffer(buf);
}
else {
printf("CONNECT CTL %d DATA %d\n", DATA_FD_OFFSET, DATA_FD_OFFSET+1);
printf("\n");
fflush(stdout);
- fflush(stdin);
- if ((dup2(ctlfdout, fileno(stdout)) < 0)
- || (dup2(ctlfdin, fileno(stdin)) < 0)) {
- error("amandad: Failed to setup stdin or stdout");
+ fclose(stdin);
+ fclose(stdout);
+ cmdout = fdopen(ctlfdout, "a");
+ if (!cmdout) {
+ error("amidxtaped: Can't fdopen(ctlfdout): %s", strerror(errno));
+ /*NOTREACHED*/
+ }
+ cmdin = fdopen(ctlfdin, "r");
+ if (!cmdin) {
+ error("amidxtaped: Can't fdopen(ctlfdin): %s", strerror(errno));
/*NOTREACHED*/
}
}
for (re_end = 0; re_end == 0; ) {
amfree(buf);
- buf = stralloc(get_client_line());
+ buf = stralloc(get_client_line(cmdin));
if(strncmp(buf, "LABEL=", 6) == 0) {
tapes = unmarshal_tapelist_str(buf+6);
}
amfree(their_feature_string);
our_feature_string = am_feature_to_string(our_features);
if(from_amandad == 1)
- printf("FEATURES=%s\r\n", our_feature_string);
+ fprintf(cmdout,"FEATURES=%s\r\n", our_feature_string);
else
- printf("%s", our_feature_string);
- fflush(stdout);
+ fprintf(cmdout,"%s", our_feature_string);
+ fflush(cmdout);
amfree(our_feature_string);
}
else if(strncmp(buf, "DEVICE=", 7) == 0) {
if(am_has_feature(their_features, fe_recover_splits)) {
if(from_amandad == 1) {
rst_flags->pipe_to_fd = datafdout;
- prompt_stream = stdout;
}
else {
int data_fd;
check_security_buffer(buf);
rst_flags->pipe_to_fd = data_fd;
- prompt_stream = stdout;
}
}
else {
rst_flags->pipe_to_fd = fileno(stdout);
- prompt_stream = stderr;
+ cmdout = stderr;
}
dbprintf(("%s: Sending output to file descriptor %d\n",
get_pname(), rst_flags->pipe_to_fd));
(use_changer || (rst_flags->alt_tapedev &&
strcmp(rst_flags->alt_tapedev,
getconf_str(CNF_TAPEDEV)) == 0) ) ) {
- send_message(prompt_stream, rst_flags, their_features,
+ send_message(cmdout, rst_flags, their_features,
"%s exists: amdump or amflush is already running, "
"or you must run amcleanup",
rst_conf_logfile);
if (check_rst_flags(rst_flags) == -1) {
if (rst_flags->pipe_to_fd != -1)
aclose(rst_flags->pipe_to_fd);
- send_message(prompt_stream, rst_flags, their_features,
+ send_message(cmdout, rst_flags, their_features,
"restore flags are crazy");
exit(1);
}
/* actual restoration */
- search_tapes(prompt_stream, use_changer, tapes, match_list, rst_flags,
+ search_tapes(cmdout, cmdin, use_changer, tapes, match_list, rst_flags,
their_features);
dbprintf(("%s: Restoration finished\n", debug_prefix_time(NULL)));