* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: extract_list.c,v 1.6.2.1 2006/11/08 17:11:39 martinea Exp $
+ * $Id$
*
* implements the "extract" command in amrecover
*/
#include "amanda.h"
-#include "version.h"
+#include "match.h"
+#include "conffile.h"
#include "amrecover.h"
#include "fileheader.h"
#include "dgram.h"
nfound = select(datafd+1, &readset, NULL, NULL, &timeout);
if(nfound < 0 ) {
/* Select returned an error. */
- fprintf(stderr,"select error: %s\n", strerror(errno));
+ g_fprintf(stderr,_("select error: %s\n"), strerror(errno));
size = -1;
break;
}
/* Select timed out. */
if (timeout_s != 0) {
/* Not polling: a real read timeout */
- fprintf(stderr,"timeout waiting for restore\n");
- fprintf(stderr,"increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n");
+ g_fprintf(stderr,_("timeout waiting for restore\n"));
+ g_fprintf(stderr,_("increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n"));
}
errno = ETIMEDOUT;
size = -1;
continue;
}
if (errno != EPIPE) {
- fprintf(stderr, "read_buffer: read error - %s",
+ g_fprintf(stderr, _("read_buffer: read error - %s"),
strerror(errno));
break;
}
EXTRACT_LIST * tape_list)
{
EXTRACT_LIST_ITEM *this, *next;
-
+
this = tape_list->files;
while (this != NULL)
}
if (remove_fn2) {
- dbprintf(("removing path %s, it is included in %s\n",
- fn2->path, fn1->path));
+ dbprintf(_("removing path %s, it is included in %s\n"),
+ fn2->path, fn1->path);
ofn2 = fn2;
fn2 = fn2->next;
amfree(ofn2->path);
if(remove_fn1 != 0) {
/* fn2->path is always valid */
- /*@i@*/ dbprintf(("removing path %s, it is included in %s\n",
- /*@i@*/ fn1->path, fn2->path));
+ /*@i@*/ dbprintf(_("removing path %s, it is included in %s\n"),
+ /*@i@*/ fn1->path, fn2->path);
ofn1 = fn1;
fn1 = fn1->next;
amfree(ofn1->path);
/* add this in date increasing order */
/* because restore must be done in this order */
/* add at begining */
- if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
+ if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
{
this->next = extract_list;
extract_list = this;
char *uqglob = unquote_string(glob);
regex = glob_to_regex(uqglob);
- dbprintf(("add_glob (%s) -> %s\n", uqglob, regex));
+ dbprintf(_("add_glob (%s) -> %s\n"), uqglob, regex);
if ((s = validate_regexp(regex)) != NULL) {
- printf("%s is not a valid shell wildcard pattern: ", glob);
+ g_printf(_("%s is not a valid shell wildcard pattern: "), glob);
puts(s);
} else {
/*
char *uqregex = unquote_string(regex);
if ((s = validate_regexp(uqregex)) != NULL) {
- printf("%s is not a valid regular expression: ", regex);
+ g_printf(_("%s is not a valid regular expression: "), regex);
puts(s);
} else {
add_file(uqregex, regex);
char *err = NULL;
int i;
ssize_t j;
- char *dir, *dir_undo, dir_undo_ch = '\0';
+ char *dir_undo, dir_undo_ch = '\0';
char *ditem_path = NULL;
char *l = NULL;
int added;
int dir_entries;
if (disk_path == NULL) {
- printf("Must select directory before adding files\n");
+ g_printf(_("Must select directory before adding files\n"));
return;
}
memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
- dbprintf(("add_file: Looking for \"%s\"\n", regex));
+ dbprintf(_("add_file: Looking for \"%s\"\n"), regex);
if(strcmp(regex, "/[/]*$") == 0) { /* "/" behave like "." */
regex = "\\.[/]*$";
path_on_disk = stralloc2("/", regex);
}
} else {
- char *clean_disk_path = clean_regex(disk_path);
+ char *clean_disk_path = clean_regex(disk_path, 0);
path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
amfree(clean_disk_path);
}
path_on_disk_slash = stralloc2(path_on_disk, "/");
- dbprintf(("add_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n",
- regex, path_on_disk));
+ dbprintf(_("add_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n"),
+ regex, path_on_disk);
found_one = 0;
dir_entries = 0;
{
dir_entries++;
quoted = quote_string(ditem->path);
- dbprintf(("add_file: Pondering ditem->path=%s\n", quoted));
+ dbprintf(_("add_file: Pondering ditem->path=%s\n"), quoted);
amfree(quoted);
if (match(path_on_disk, ditem->path)
|| match(path_on_disk_slash, ditem->path))
ditem_path = newstralloc(ditem_path, ditem->path);
clean_pathname(ditem_path);
- cmd = stralloc2("ORLD ", ditem_path);
+ cmd = newstralloc2(cmd, "ORLD ", ditem_path);
if(send_command(cmd) == -1) {
amfree(cmd);
amfree(ditem_path);
amfree(path_on_disk);
amfree(path_on_disk_slash);
l = reply_line();
- printf("%s\n", l);
+ g_printf(_("%s\n"), l);
return;
}
dir_undo = NULL;
puts(l);
continue;
}
-#define sc "201-"
- if(strncmp(l, sc, sizeof(sc)-1) != 0) {
- err = "bad reply: not 201-";
+
+ s = l;
+ if(strncmp_const_skip(l, "201-", s, ch) != 0) {
+ err = _("bad reply: not 201-");
continue;
}
- s = l + sizeof(sc)-1;
ch = *s++;
-#undef sc
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing date field";
+ err = _("bad reply: missing date field");
continue;
}
fp = s-1;
skip_whitespace(s, ch);
if(ch == '\0' || sscanf(s - 1, "%d", &lditem.level) != 1) {
- err = "bad reply: cannot parse level field";
+ err = _("bad reply: cannot parse level field");
continue;
}
skip_integer(s, ch);
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing tape field";
+ err = _("bad reply: missing tape field");
continue;
}
fp = s-1;
s[-1] = (char)ch;
if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
+ long long fileno_ = (long long)0;
skip_whitespace(s, ch);
- if(ch == '\0' || sscanf(s - 1, OFF_T_FMT,
- (OFF_T_FMT_TYPE *)&lditem.fileno) != 1) {
- err = "bad reply: cannot parse fileno field";
+ if(ch == '\0' ||
+ sscanf(s - 1, "%lld", &fileno_) != 1) {
+ err = _("bad reply: cannot parse fileno field");
continue;
}
+ lditem.fileno = (off_t)fileno_;
skip_integer(s, ch);
}
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing directory field";
+ err = _("bad reply: missing directory field");
continue;
}
- dir = s - 1;
skip_quoted_string(s, ch);
dir_undo = s - 1;
dir_undo_ch = *dir_undo;
switch(add_extract_item(&lditem)) {
case -1:
- printf("System error\n");
- dbprintf(("add_file: (Failed) System error\n"));
+ g_printf(_("System error\n"));
+ dbprintf(_("add_file: (Failed) System error\n"));
break;
case 0:
quoted = quote_string(lditem.path);
- printf("Added dir %s at date %s\n",
+ g_printf(_("Added dir %s at date %s\n"),
quoted, lditem.date);
- dbprintf(("add_file: (Successful) Added dir %s at date %s\n",
- quoted, lditem.date));
+ dbprintf(_("add_file: (Successful) Added dir %s at date %s\n"),
+ quoted, lditem.date);
amfree(quoted);
added=1;
break;
puts(cmd);
} else if(added == 0) {
quoted = quote_string(ditem_path);
- printf("dir %s already added\n", quoted);
- dbprintf(("add_file: dir %s already added\n", quoted));
+ g_printf(_("dir %s already added\n"), quoted);
+ dbprintf(_("add_file: dir %s already added\n"), quoted);
amfree(quoted);
}
}
{
switch(add_extract_item(ditem)) {
case -1:
- printf("System error\n");
- dbprintf(("add_file: (Failed) System error\n"));
+ g_printf(_("System error\n"));
+ dbprintf(_("add_file: (Failed) System error\n"));
break;
case 0:
quoted = quote_string(ditem->path);
- printf("Added file %s\n", quoted);
- dbprintf(("add_file: (Successful) Added %s\n", quoted));
+ g_printf(_("Added file %s\n"), quoted);
+ dbprintf(_("add_file: (Successful) Added %s\n"), quoted);
amfree(quoted);
break;
case 1:
quoted = quote_string(ditem->path);
- printf("File %s already added\n", quoted);
- dbprintf(("add_file: file %s already added\n", quoted));
+ g_printf(_("File %s already added\n"), quoted);
+ dbprintf(_("add_file: file %s already added\n"), quoted);
amfree(quoted);
break;
}
if(! found_one) {
quoted = quote_string(path);
- printf("File %s doesn't exist in directory\n", quoted);
- dbprintf(("add_file: (Failed) File %s doesn't exist in directory\n",
- quoted));
+ g_printf(_("File %s doesn't exist in directory\n"), quoted);
+ dbprintf(_("add_file: (Failed) File %s doesn't exist in directory\n"),
+ quoted);
amfree(quoted);
}
}
char *uqglob = unquote_string(glob);
regex = glob_to_regex(uqglob);
- dbprintf(("delete_glob (%s) -> %s\n", uqglob, regex));
+ dbprintf(_("delete_glob (%s) -> %s\n"), uqglob, regex);
if ((s = validate_regexp(regex)) != NULL) {
- printf("\"%s\" is not a valid shell wildcard pattern: ", glob);
+ g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
puts(s);
} else {
/*
char *uqregex = unquote_string(regex);
if ((s = validate_regexp(regex)) != NULL) {
- printf("\"%s\" is not a valid regular expression: ", regex);
+ g_printf(_("\"%s\" is not a valid regular expression: "), regex);
puts(s);
} else {
delete_file(uqregex, uqregex);
char *tape, *tape_undo, tape_undo_ch = '\0';
char *dir_undo, dir_undo_ch = '\0';
int level = 0;
- off_t fileno;
char *ditem_path = NULL;
char *l = NULL;
int deleted;
char *quoted;
if (disk_path == NULL) {
- printf("Must select directory before deleting files\n");
+ g_printf(_("Must select directory before deleting files\n"));
return;
}
memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */
- dbprintf(("delete_file: Looking for \"%s\"\n", path));
+ dbprintf(_("delete_file: Looking for \"%s\"\n"), path);
if (strcmp(regex, "[^/]*[/]*$") == 0) {
/* Looking for * find everything but single . */
path_on_disk = stralloc2("/", regex);
}
} else {
- char *clean_disk_path = clean_regex(disk_path);
+ char *clean_disk_path = clean_regex(disk_path, 0);
path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
amfree(clean_disk_path);
}
path_on_disk_slash = stralloc2(path_on_disk, "/");
- dbprintf(("delete_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n",
- regex, path_on_disk));
+ dbprintf(_("delete_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n"),
+ regex, path_on_disk);
found_one = 0;
for (ditem=get_dir_list(); ditem!=NULL; ditem=get_next_dir_item(ditem))
{
quoted = quote_string(ditem->path);
- dbprintf(("delete_file: Pondering ditem->path=%s\n", quoted));
+ dbprintf(_("delete_file: Pondering ditem->path=%s\n"), quoted);
amfree(quoted);
if (match(path_on_disk, ditem->path)
|| match(path_on_disk_slash, ditem->path))
ditem_path = newstralloc(ditem_path, ditem->path);
clean_pathname(ditem_path);
- cmd = stralloc2("ORLD ", ditem_path);
+ cmd = newstralloc2(cmd, "ORLD ", ditem_path);
if(send_command(cmd) == -1) {
amfree(cmd);
amfree(ditem_path);
amfree(path_on_disk);
amfree(path_on_disk_slash);
l = reply_line();
- printf("%s\n", l);
+ g_printf("%s\n", l);
return;
}
deleted=0;
puts(l);
continue;
}
-#define sc "201-"
- if(strncmp(l, sc, sizeof(sc)-1) != 0) {
- err = "bad reply: not 201-";
+
+ s = l;
+ if(strncmp_const_skip(l, "201-", s, ch) != 0) {
+ err = _("bad reply: not 201-");
continue;
}
- s = l + sizeof(sc)-1;
ch = *s++;
-#undef sc
+
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing date field";
+ err = _("bad reply: missing date field");
continue;
}
date = s - 1;
skip_whitespace(s, ch);
if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
- err = "bad reply: cannot parse level field";
+ err = _("bad reply: cannot parse level field");
continue;
}
skip_integer(s, ch);
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing tape field";
+ err = _("bad reply: missing tape field");
continue;
}
tape = s - 1;
*tape_undo = '\0';
if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) {
+ long long fileno_ = (long long)0;
skip_whitespace(s, ch);
- if(ch == '\0' || sscanf(s - 1, OFF_T_FMT,
- (OFF_T_FMT_TYPE *)&fileno) != 1) {
- err = "bad reply: cannot parse fileno field";
+ if(ch == '\0' ||
+ sscanf(s - 1, "%lld", &fileno_) != 1) {
+ err = _("bad reply: cannot parse fileno field");
continue;
}
skip_integer(s, ch);
skip_whitespace(s, ch);
if(ch == '\0') {
- err = "bad reply: missing directory field";
+ err = _("bad reply: missing directory field");
continue;
}
skip_non_whitespace(s, ch);
lditem.tape = newstralloc(lditem.tape, tape);
switch(delete_extract_item(&lditem)) {
case -1:
- printf("System error\n");
- dbprintf(("delete_file: (Failed) System error\n"));
+ g_printf(_("System error\n"));
+ dbprintf(_("delete_file: (Failed) System error\n"));
break;
case 0:
- printf("Deleted dir %s at date %s\n", ditem_path, date);
- dbprintf(("delete_file: (Successful) Deleted dir %s at date %s\n",
- ditem_path, date));
+ g_printf(_("Deleted dir %s at date %s\n"), ditem_path, date);
+ dbprintf(_("delete_file: (Successful) Deleted dir %s at date %s\n"),
+ ditem_path, date);
deleted=1;
break;
case 1:
if (cmd)
puts(cmd);
} else if(deleted == 0) {
- printf("Warning - dir '%s' not on tape list\n",
+ g_printf(_("Warning - dir '%s' not on tape list\n"),
ditem_path);
- dbprintf(("delete_file: dir '%s' not on tape list\n",
- ditem_path));
+ dbprintf(_("delete_file: dir '%s' not on tape list\n"),
+ ditem_path);
}
}
else
{
switch(delete_extract_item(ditem)) {
case -1:
- printf("System error\n");
- dbprintf(("delete_file: (Failed) System error\n"));
+ g_printf(_("System error\n"));
+ dbprintf(_("delete_file: (Failed) System error\n"));
break;
case 0:
- printf("Deleted %s\n", ditem->path);
- dbprintf(("delete_file: (Successful) Deleted %s\n",
- ditem->path));
+ g_printf(_("Deleted %s\n"), ditem->path);
+ dbprintf(_("delete_file: (Successful) Deleted %s\n"),
+ ditem->path);
break;
case 1:
- printf("Warning - file '%s' not on tape list\n",
+ g_printf(_("Warning - file '%s' not on tape list\n"),
ditem->path);
- dbprintf(("delete_file: file '%s' not on tape list\n",
- ditem->path));
+ dbprintf(_("delete_file: file '%s' not on tape list\n"),
+ ditem->path);
break;
}
}
amfree(path_on_disk_slash);
if(! found_one) {
- printf("File %s doesn't exist in directory\n", path);
- dbprintf(("delete_file: (Failed) File %s doesn't exist in directory\n",
- path));
+ g_printf(_("File %s doesn't exist in directory\n"), path);
+ dbprintf(_("delete_file: (Failed) File %s doesn't exist in directory\n"),
+ path);
}
}
pager_command = stralloc2(pager, " ; /bin/cat > /dev/null");
if ((fp = popen(pager_command, "w")) == NULL)
{
- printf("Warning - can't pipe through %s\n", pager);
+ g_printf(_("Warning - can't pipe through %s\n"), pager);
fp = stdout;
}
amfree(pager_command);
uqfile = unquote_string(file);
if ((fp = fopen(uqfile, "w")) == NULL)
{
- printf("Can't open file %s to print extract list into\n", file);
+ g_printf(_("Can't open file %s to print extract list into\n"), file);
amfree(uqfile);
return;
}
for (this = extract_list; this != NULL; this = this->next)
{
- fprintf(fp, "TAPE %s LEVEL %d DATE %s\n",
+ g_fprintf(fp, _("TAPE %s LEVEL %d DATE %s\n"),
this->tape, this->level, this->date);
for (that = this->files; that != NULL; that = that->next)
- fprintf(fp, "\t%s\n", that->path);
+ g_fprintf(fp, "\t%s\n", that->path);
}
if (file == NULL) {
apclose(fp);
} else {
- printf("Extract list written to file %s\n", file);
+ g_printf(_("Extract list written to file %s\n"), file);
afclose(fp);
}
}
get_tape = 0;
while (ret < 0) {
if (get_tape) {
- prompt = "New tape device [?]: ";
+ prompt = _("New tape device [?]: ");
} else if (allow_tape && allow_skip) {
- prompt = "Continue [?/Y/n/s/t]? ";
+ prompt = _("Continue [?/Y/n/s/t]? ");
} else if (allow_tape && !allow_skip) {
- prompt = "Continue [?/Y/n/t]? ";
+ prompt = _("Continue [?/Y/n/t]? ");
} else if (allow_retry) {
- prompt = "Continue [?/Y/n/r]? ";
+ prompt = _("Continue [?/Y/n/r]? ");
} else {
- prompt = "Continue [?/Y/n]? ";
+ prompt = _("Continue [?/Y/n]? ");
}
fputs(prompt, stdout);
fflush(stdout); fflush(stderr);
break;
}
s = line;
- while ((ch = *s++) != '\0' && isspace(ch)) {
+ while ((ch = *s++) != '\0' && g_ascii_isspace(ch)) {
(void)ch; /* Quiet empty loop body warning */
}
if (ch == '?') {
if (get_tape) {
- printf("Enter a new device ([host:]device) or \"default\"\n");
+ g_printf(_("Enter a new device ([host:]device) or \"default\"\n"));
} else {
- printf("Enter \"y\"es to continue, \"n\"o to stop");
+ g_printf(_("Enter \"y\"es to continue, \"n\"o to stop"));
if(allow_skip) {
- printf(", \"s\"kip this tape");
+ g_printf(_(", \"s\"kip this tape"));
}
if(allow_retry) {
- printf(" or \"r\"etry this tape");
+ g_printf(_(" or \"r\"etry this tape"));
}
if (allow_tape) {
- printf(" or \"t\"ape to change tape drives");
+ g_printf(_(" or \"t\"ape to change tape drives"));
}
putchar('\n');
}
{
char *msg = stralloc2(cmd, "\r\n");
- if (fullwrite(tss, msg, strlen(msg)) < 0)
+ if (full_write(tss, msg, strlen(msg)) < strlen(msg))
{
- error("Error writing to tape server");
+ error(_("Error writing to tape server: %s"), strerror(errno));
/*NOTREACHED*/
}
amfree(msg);
/* get tape server details */
if ((sp = getservbyname(service_name, "tcp")) == NULL)
{
- printf("%s/tcp unknown protocol - config error?\n", service_name);
+ g_printf(_("%s/tcp unknown protocol - config error?\n"), service_name);
amfree(service_name);
return -1;
}
0);
if (tape_control_sock < 0)
{
- printf("cannot connect to %s: %s\n", tape_server_name, strerror(errno));
+ g_printf(_("cannot connect to %s: %s\n"), tape_server_name, strerror(errno));
return -1;
}
if (my_port >= IPPORT_RESERVED) {
aclose(tape_control_sock);
- printf("did not get a reserved port: %u\n", (unsigned)my_port);
+ g_printf(_("did not get a reserved port: %u\n"), (unsigned)my_port);
return -1;
}
tt = newstralloc2(tt, "FEATURES=", our_feature_string);
send_to_tape_server(tape_control_sock, tt);
if (read(tape_control_sock, buffer, sizeof(buffer)) <= 0) {
- error("Could not read features from control socket\n");
+ error(_("Could not read features from control socket\n"));
/*NOTREACHED*/
}
tapesrv_features = am_string_to_feature(buffer);
}
if(am_has_feature(indexsrv_features, fe_amidxtaped_fsf)) {
char v_fsf[100];
- snprintf(v_fsf, 99, OFF_T_FMT, (OFF_T_FMT_TYPE)fsf);
+ g_snprintf(v_fsf, 99, "%lld", (long long)fsf);
tt = newstralloc2(tt, "FSF=",v_fsf);
send_to_tape_server(tape_control_sock, tt);
}
send_to_tape_server(tape_control_sock, disk_regex);
send_to_tape_server(tape_control_sock, clean_datestamp);
- dbprintf(("Started amidxtaped with arguments \"6 -h -p %s %s %s %s\"\n",
- dump_device_name, host_regex, disk_regex, clean_datestamp));
+ dbprintf(_("Started amidxtaped with arguments \"6 -h -p %s %s %s %s\"\n"),
+ dump_device_name, host_regex, disk_regex, clean_datestamp);
}
/*
nread = read(tape_control_sock, buffer, sizeof(buffer));
if (nread <= 0) {
- error("Could not read from control socket: %s\n",
+ error(_("Could not read from control socket: %s\n"),
strerror(errno));
/*NOTREACHED*/
}
buffer[nread] = '\0';
if (sscanf(buffer, "CONNECT %hu\n",
(unsigned short *)&data_port) != 1) {
- error("Recieved invalid port number message from control socket: %s\n",
+ error(_("Recieved invalid port number message from control socket: %s\n"),
buffer);
/*NOTREACHED*/
}
&my_data_port,
0);
if(tape_data_sock == -1){
- error("Unable to make data connection to server: %s\n",
+ error(_("Unable to make data connection to server: %s\n"),
strerror(errno));
/*NOTREACHED*/
}
amfree(our_feature_string);
-
+
line = get_security();
send_to_tape_server(tape_data_sock, line);
bytes_read = read_buffer(tapedev, buffer, buflen, READ_TIMEOUT);
if(bytes_read < 0) {
- error("error reading header (%s), check amidxtaped.*.debug on server",
+ error(_("error reading header (%s), check amidxtaped.*.debug on server"),
strerror(errno));
/*NOTREACHED*/
}
if((size_t)bytes_read < buflen) {
- fprintf(stderr, "%s: short block %d byte%s\n",
- get_pname(), (int)bytes_read, (bytes_read == 1) ? "" : "s");
+ g_fprintf(stderr, plural(_("%s: short block %d byte\n"),
+ _("%s: short block %d bytes\n"), bytes_read),
+ get_pname(), (int)bytes_read);
print_header(stdout, file);
- error("Can't read file header");
+ error(_("Can't read file header"));
/*NOTREACHED*/
}
EXTRACT_LIST * elist)
{
int save_errno;
- int extra_params = 0;
- int i,j=0;
- char **restore_args = NULL;
+ int i;
+ guint j;
+ GPtrArray *argv_ptr = g_ptr_array_new();
int files_off_tape;
EXTRACT_LIST_ITEM *fn;
enum dumptypes dumptype = IS_UNKNOWN;
dumpfile_t file;
size_t len_program;
char *cmd = NULL;
- int passwd_field = -1;
+ guint passwd_field = 999999999;
#ifdef SAMBA_CLIENT
char *domain = NULL, *smbpass = NULL;
#endif
/* make in_fd be our stdin */
if (dup2(in_fd, STDIN_FILENO) == -1)
{
- error("dup2 failed in extract_files_child: %s", strerror(errno));
+ error(_("dup2 failed in extract_files_child: %s"), strerror(errno));
/*NOTREACHED*/
}
if(file.type != F_DUMPFILE) {
print_header(stdout, &file);
- error("bad header");
+ error(_("bad header"));
/*NOTREACHED*/
}
/* form the arguments to restore */
files_off_tape = length_of_tape_list(elist);
- switch (dumptype) {
- case IS_SAMBA:
-#ifdef SAMBA_CLIENT
- extra_params = 10;
- break;
-#endif
- case IS_TAR:
- case IS_GNUTAR:
- extra_params = 4;
- break;
- case IS_SAMBA_TAR:
- extra_params = 3;
- break;
- case IS_UNKNOWN:
- case IS_DUMP:
-#ifdef AIX_BACKUP
- extra_params = 2;
-#else
-#if defined(XFSDUMP)
- if (strcmp(file.program, XFSDUMP) == 0) {
- extra_params = 4 + files_off_tape;
- } else
-#endif
- {
- extra_params = 4;
- }
-#endif
- break;
- }
-
- restore_args = (char **)alloc((size_t)((extra_params + files_off_tape + 1)
- * sizeof(char *)));
switch(dumptype) {
case IS_SAMBA:
#ifdef SAMBA_CLIENT
- restore_args[j++] = stralloc("smbclient");
- smbpass = findpass(file.disk, &domain);
- if (smbpass) {
- restore_args[j++] = stralloc(file.disk);
- passwd_field=j;
- restore_args[j++] = stralloc("-U");
- restore_args[j++] = smbpass;
- if (domain) {
- restore_args[j++] = stralloc("-W");
- restore_args[j++] = stralloc(domain);
- } else
- extra_params -= 2;
- } else
- extra_params -= 6;
- restore_args[j++] = stralloc("-d0");
- restore_args[j++] = stralloc("-Tx");
- restore_args[j++] = stralloc("-"); /* data on stdin */
- break;
+ g_ptr_array_add(argv_ptr, stralloc("smbclient"));
+ smbpass = findpass(file.disk, &domain);
+ if (smbpass) {
+ g_ptr_array_add(argv_ptr, stralloc(file.disk));
+ g_ptr_array_add(argv_ptr, stralloc("-U"));
+ passwd_field = argv_ptr->len;
+ g_ptr_array_add(argv_ptr, stralloc(smbpass));
+ if (domain) {
+ g_ptr_array_add(argv_ptr, stralloc("-W"));
+ g_ptr_array_add(argv_ptr, stralloc(domain));
+ }
+ }
+ g_ptr_array_add(argv_ptr, stralloc("-d0"));
+ g_ptr_array_add(argv_ptr, stralloc("-Tx"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
+ break;
#endif
case IS_TAR:
case IS_GNUTAR:
- restore_args[j++] = stralloc("tar");
- restore_args[j++] = stralloc("--numeric-owner");
- restore_args[j++] = stralloc("-xpGvf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("tar"));
+ g_ptr_array_add(argv_ptr, stralloc("--numeric-owner"));
+ g_ptr_array_add(argv_ptr, stralloc("-xpGvf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
break;
case IS_SAMBA_TAR:
- restore_args[j++] = stralloc("tar");
- restore_args[j++] = stralloc("-xpvf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("tar"));
+ g_ptr_array_add(argv_ptr, stralloc("-xpvf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
break;
case IS_UNKNOWN:
case IS_DUMP:
- restore_args[j++] = stralloc("restore");
+ g_ptr_array_add(argv_ptr, stralloc("restore"));
#ifdef AIX_BACKUP
- restore_args[j++] = stralloc("-xB");
+ g_ptr_array_add(argv_ptr, stralloc("-xB"));
#else
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- restore_args[j++] = stralloc("-v");
- restore_args[j++] = stralloc("silent");
+ g_ptr_array_add(argv_ptr, stralloc("-v"));
+ g_ptr_array_add(argv_ptr, stralloc("silent"));
} else
#endif
#if defined(VDUMP)
if (strcmp(file.program, VDUMP) == 0) {
- restore_args[j++] = stralloc("xf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("xf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
} else
#endif
{
- restore_args[j++] = stralloc("xbf");
- restore_args[j++] = stralloc("2"); /* read in units of 1K */
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("xbf"));
+ g_ptr_array_add(argv_ptr, stralloc("2")); /* read in units of 1K */
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
}
#endif
}
-
+
for (i = 0, fn = elist->files; i < files_off_tape; i++, fn = fn->next)
{
switch (dumptype) {
- case IS_TAR:
- case IS_GNUTAR:
- case IS_SAMBA_TAR:
- case IS_SAMBA:
+ case IS_TAR:
+ case IS_GNUTAR:
+ case IS_SAMBA_TAR:
+ case IS_SAMBA:
if (strcmp(fn->path, "/") == 0)
- restore_args[j++] = stralloc(".");
+ g_ptr_array_add(argv_ptr, stralloc("."));
else
- restore_args[j++] = stralloc2(".", fn->path);
+ g_ptr_array_add(argv_ptr, stralloc2(".", fn->path));
break;
case IS_UNKNOWN:
case IS_DUMP:
* xfsrestore needs a -s option before each file to be
* restored, and also wants them to be relative paths.
*/
- restore_args[j++] = stralloc("-s");
- restore_args[j++] = stralloc(fn->path + 1);
+ g_ptr_array_add(argv_ptr, stralloc("-s"));
+ g_ptr_array_add(argv_ptr, stralloc(fn->path + 1));
} else
#endif
{
- restore_args[j++] = stralloc(fn->path);
+ g_ptr_array_add(argv_ptr, stralloc(fn->path));
}
- }
+ }
}
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- restore_args[j++] = stralloc("-");
- restore_args[j++] = stralloc(".");
+ g_ptr_array_add(argv_ptr, stralloc("-"));
+ g_ptr_array_add(argv_ptr, stralloc("."));
}
#endif
- restore_args[j] = NULL;
+ g_ptr_array_add(argv_ptr, NULL);
switch (dumptype) {
case IS_SAMBA:
#ifdef SAMBA_CLIENT
- cmd = stralloc(SAMBA_CLIENT);
- break;
+ cmd = stralloc(SAMBA_CLIENT);
+ break;
#else
/* fall through to ... */
#endif
case IS_GNUTAR:
case IS_SAMBA_TAR:
#ifndef GNUTAR
- fprintf(stderr, "warning: GNUTAR program not available.\n");
+ g_fprintf(stderr, _("warning: GNUTAR program not available.\n"));
cmd = stralloc("tar");
#else
cmd = stralloc(GNUTAR);
#endif
- break;
+ break;
case IS_UNKNOWN:
case IS_DUMP:
cmd = NULL;
#if defined(DUMP)
if (strcmp(file.program, DUMP) == 0) {
- cmd = stralloc(RESTORE);
+ cmd = stralloc(RESTORE);
}
#endif
#if defined(VDUMP)
if (strcmp(file.program, VDUMP) == 0) {
- cmd = stralloc(VRESTORE);
+ cmd = stralloc(VRESTORE);
}
#endif
#if defined(VXDUMP)
if (strcmp(file.program, VXDUMP) == 0) {
- cmd = stralloc(VXRESTORE);
+ cmd = stralloc(VXRESTORE);
}
#endif
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- cmd = stralloc(XFSRESTORE);
+ cmd = stralloc(XFSRESTORE);
}
#endif
if (cmd == NULL) {
- fprintf(stderr, "warning: restore program for %s not available.\n",
+ g_fprintf(stderr, _("warning: restore program for %s not available.\n"),
file.program);
cmd = stralloc("restore");
}
}
if (cmd) {
- dbprintf(("Exec'ing %s with arguments:\n", cmd));
- for (i = 0; i < j; i++) {
- if( i == passwd_field)
- dbprintf(("\tXXXXX\n"));
+ dbprintf(_("Exec'ing %s with arguments:\n"), cmd);
+ for (j = 0; j < argv_ptr->len - 1; j++) {
+ if( j == passwd_field)
+ dbprintf("\tXXXXX\n");
else
- dbprintf(("\t%s\n", restore_args[i]));
+ dbprintf("\t%s\n", (char *)g_ptr_array_index(argv_ptr, j));
}
- (void)execv(cmd, restore_args);
+ safe_fd(-1, 0);
+ (void)execv(cmd, (char **)argv_ptr->pdata);
/* only get here if exec failed */
save_errno = errno;
- for (i = 0; i < j; i++) {
- amfree(restore_args[i]);
- }
- amfree(restore_args);
+ g_ptr_array_free_full(argv_ptr);
errno = save_errno;
- perror("amrecover couldn't exec");
- fprintf(stderr, " problem executing %s\n", cmd);
+ perror(_("amrecover couldn't exec"));
+ g_fprintf(stderr, _(" problem executing %s\n"), cmd);
amfree(cmd);
}
exit(1);
int child_pipe[2];
pid_t pid;
char buffer[DISK_BLOCK_BYTES];
- ssize_t bytes_read;
+ size_t bytes_read;
amwait_t extractor_status;
int max_fd, nfound;
SELECT_ARG_TYPE readset, selectset;
}
if(pipe(child_pipe) == -1) {
- error("extract_list - error setting up pipe to extractor: %s\n",
+ error(_("extract_list - error setting up pipe to extractor: %s\n"),
strerror(errno));
/*NOTREACHED*/
}
/* This is the parent */
if (pid == -1) {
- error("writer_intermediary - error forking child");
+ error(_("writer_intermediary - error forking child"));
/*NOTREACHED*/
}
timeout.tv_sec = READ_TIMEOUT;
timeout.tv_usec = 0;
FD_COPY(&readset, &selectset);
-
+
nfound = select(max_fd, &selectset, NULL, NULL,
&timeout);
if(nfound < 0) {
- fprintf(stderr,"select error: %s\n", strerror(errno));
+ g_fprintf(stderr,_("select error: %s\n"), strerror(errno));
break;
}
-
+
if (nfound == 0) { /* timeout */
- fprintf(stderr, "timeout waiting %d seconds for restore\n",
+ g_fprintf(stderr, _("timeout waiting %d seconds for restore\n"),
READ_TIMEOUT);
- fprintf(stderr, "increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n");
+ g_fprintf(stderr, _("increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n"));
break;
}
-
+
if(FD_ISSET(ctl_fd, &selectset)) {
bytes_read = read(ctl_fd, buffer, sizeof(buffer)-1);
switch(bytes_read) {
case -1:
if ((errno != EINTR) && (errno != EAGAIN)) {
if (errno != EPIPE) {
- fprintf(stderr,"writer ctl fd read error: %s",
+ g_fprintf(stderr,_("writer ctl fd read error: %s"),
strerror(errno));
}
FD_CLR(ctl_fd, &readset);
}
break;
-
+
case 0:
FD_CLR(ctl_fd, &readset);
break;
-
+
default: {
char desired_tape[MAX_TAPE_LABEL_BUF];
-
+
buffer[bytes_read] = '\0';
/* if prompted for a tape, relay said prompt to the user */
if(sscanf(buffer, "FEEDME %132s\n", desired_tape) == 1) {
int done = 0;
while (!done) {
char *input = NULL;
- printf("Please insert tape %s. Continue? [Y|n]: ",
+ g_printf(_("Please insert tape %s. Continue? [Y|n]: "),
desired_tape);
fflush(stdout);
-
+
input = agets(stdin); /* strips \n */
- if (strcasecmp("", input) == 0||
- strcasecmp("y", input) == 0||
+ if (strcasecmp("", input) == 0||
+ strcasecmp("y", input) == 0||
strcasecmp("yes", input) == 0) {
send_to_tape_server(tape_control_sock, "OK");
done = 1;
- } else if (strcasecmp("n", input) == 0||
+ } else if (strcasecmp("n", input) == 0||
strcasecmp("no", input) == 0) {
send_to_tape_server(tape_control_sock, "ERROR");
/* Abort!
amfree(input);
}
} else {
- fprintf(stderr, "Strange message from tape server: %s", buffer);
+ g_fprintf(stderr, _("Strange message from tape server: %s"), buffer);
break;
- }
+ }
}
}
}
case -1:
if ((errno != EINTR) && (errno != EAGAIN)) {
if (errno != EPIPE) {
- fprintf(stderr,"writer data fd read error: %s",
+ g_fprintf(stderr,_("writer data fd read error: %s"),
strerror(errno));
}
FD_CLR(data_fd, &readset);
}
break;
-
+
case 0:
FD_CLR(data_fd, &readset);
break;
-
+
default:
/*
* spit what we got from the server to the child
* process handling actual dumpfile extraction
*/
- if(fullwrite(child_pipe[1], buffer, (size_t)bytes_read) < 0) {
+ if(full_write(child_pipe[1], buffer, bytes_read) < bytes_read) {
if(errno == EPIPE) {
- error("%s: pipe data reader has quit: %s\n",
- get_pname(), strerror(errno));
+ error(_("pipe data reader has quit: %s\n"),
+ strerror(errno));
/* NOTREACHED */
}
- error("Write error to extract child: %s\n",
+ error(_("Write error to extract child: %s\n"),
strerror(errno));
/* NOTREACHED */
}
if(WEXITSTATUS(extractor_status) != 0){
int ret = WEXITSTATUS(extractor_status);
if(ret == 255) ret = -1;
- error("Extractor child exited with status %d\n", ret);
+ error(_("Extractor child exited with status %d\n"), ret);
/*NOTREACHED*/
}
if (!is_extract_list_nonempty())
{
- printf("Extract list empty - No files to extract!\n");
+ g_printf(_("Extract list empty - No files to extract!\n"));
return;
}
l = reply_line();
if (!server_happy())
{
- printf("%s\n", l);
+ g_printf("%s\n", l);
exit(1);
}
/* skip reply number */
if (strcmp(tape_device_name, "/dev/null") == 0)
{
- printf("amrecover: warning: using %s as the tape device will not work\n",
+ g_printf(_("amrecover: warning: using %s as the tape device will not work\n"),
tape_device_name);
}
for (elist = first_tape_list(); elist != NULL; elist = next_tape_list(elist))
if(elist->tape[0]!='/') {
if(first) {
- printf("\nExtracting files using tape drive %s on host %s.\n",
+ g_printf(_("\nExtracting files using tape drive %s on host %s.\n"),
tape_device_name, tape_server_name);
- printf("The following tapes are needed:");
+ g_printf(_("The following tapes are needed:"));
first=0;
}
else
- printf(" ");
- tlist = unmarshal_tapelist_str(elist->tape);
+ g_printf(" ");
+ tlist = unmarshal_tapelist_str(elist->tape);
for( ; tlist != NULL; tlist = tlist->next)
- printf(" %s", tlist->label);
- printf("\n");
+ g_printf(" %s", tlist->label);
+ g_printf("\n");
amfree(tlist);
}
first=1;
{
if(elist->tape[0]=='/') {
if(first) {
- printf("\nExtracting files from holding disk on host %s.\n",
+ g_printf(_("\nExtracting files from holding disk on host %s.\n"),
tape_server_name);
- printf("The following files are needed:");
+ g_printf(_("The following files are needed:"));
first=0;
}
else
- printf(" ");
- tlist = unmarshal_tapelist_str(elist->tape);
+ g_printf(" ");
+ tlist = unmarshal_tapelist_str(elist->tape);
for( ; tlist != NULL; tlist = tlist->next)
- printf(" %s", tlist->label);
- printf("\n");
+ g_printf(" %s", tlist->label);
+ g_printf("\n");
amfree(tlist);
}
}
- printf("\n");
+ g_printf("\n");
if (getcwd(buf, sizeof(buf)) == NULL) {
- perror("extract_list: Current working directory unavailable");
+ perror(_("extract_list: Cannot determine current working directory"));
exit(1);
}
- printf("Restoring files into directory %s\n", buf);
+ g_printf(_("Restoring files into directory %s\n"), buf);
#ifdef SAMBA_CLIENT
if (samba_extract_method == SAMBA_SMBCLIENT)
- printf("(unless it is a Samba backup, that will go through to the SMB server)\n");
+ g_printf(_("(unless it is a Samba backup, that will go through to the SMB server)\n"));
#endif
if (!okay_to_continue(0,0,0))
return;
- printf("\n");
+ g_printf("\n");
while ((elist = first_tape_list()) != NULL)
{
if(elist->tape[0]=='/') {
dump_device_name = newstralloc(dump_device_name, elist->tape);
- printf("Extracting from file ");
- tlist = unmarshal_tapelist_str(dump_device_name);
+ g_printf(_("Extracting from file "));
+ tlist = unmarshal_tapelist_str(dump_device_name);
for( ; tlist != NULL; tlist = tlist->next)
- printf(" %s", tlist->label);
- printf("\n");
+ g_printf(" %s", tlist->label);
+ g_printf("\n");
amfree(tlist);
}
else {
- printf("Extracting files using tape drive %s on host %s.\n",
+ g_printf(_("Extracting files using tape drive %s on host %s.\n"),
tape_device_name, tape_server_name);
- tlist = unmarshal_tapelist_str(elist->tape);
- printf("Load tape %s now\n", tlist->label);
+ tlist = unmarshal_tapelist_str(elist->tape);
+ g_printf(_("Load tape %s now\n"), tlist->label);
amfree(tlist);
otc = okay_to_continue(1,1,0);
if (otc == 0)
/* connect to the tape handler daemon on the tape drive server */
if ((tape_control_sock = extract_files_setup(elist->tape, elist->fileno)) == -1)
{
- fprintf(stderr, "amrecover - can't talk to tape server\n");
+ g_fprintf(stderr, _("amrecover - can't talk to tape server\n"));
return;
}
/* this is the parent */
if (pid == -1)
{
- perror("extract_list - error forking child");
+ perror(_("extract_list - error forking child"));
aclose(tape_control_sock);
exit(1);
}
/* wait for the child process to finish */
if ((pid = waitpid(-1, &child_stat, 0)) == (pid_t)-1)
{
- perror("extract_list - error waiting for child");
+ perror(_("extract_list - error waiting for child"));
exit(1);
}
}
else
{
- fprintf(stderr, "extract list - unknown child terminated?\n");
+ g_fprintf(stderr, _("extract list - unknown child terminated?\n"));
exit(1);
}
if ((WIFEXITED(child_stat) != 0) && (WEXITSTATUS(child_stat) != 0))
{
- fprintf(stderr,
- "extract_list - child returned non-zero status: %d\n",
+ g_fprintf(stderr,
+ _("extract_list - child returned non-zero status: %d\n"),
WEXITSTATUS(child_stat));
otc = okay_to_continue(0,0,1);
if(otc == 0)