* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amlabel.c,v 1.18.2.15.4.3.2.4 2003/01/01 23:28:53 martinea Exp $
+ * $Id: amlabel.c,v 1.43 2006/01/14 04:37:19 paddy_s Exp $
*
* write an Amanda label on a tape
*/
/* local functions */
+int main P((int, char **));
void usage P((char *argv0));
void usage(argv0)
char *conf_tapelist_old;
unsigned long malloc_hist_1, malloc_size_1;
unsigned long malloc_hist_2, malloc_size_2;
- int fd;
+#ifdef HAVE_LINUX_ZFTAPE_H
+ int fd = -1;
+ int isa_zftape;
+#endif /* HAVE_LINUX_ZFTAPE_H */
int have_changer;
int force, tape_ok;
tape_t *tp;
int first_seg, last_seg;
#endif /* HAVE_LIBVTBLC */
- for(fd = 3; fd < FD_SETSIZE; fd++) {
- /*
- * Make sure nobody spoofs us with a lot of extra open files
- * that would cause an open we do to get a very high file
- * descriptor, which in turn might be used as an index into
- * an array (e.g. an fd_set).
- */
- close(fd);
- }
-
+ safe_fd(-1, 0);
safe_cd();
set_pname("amlabel");
- dbopen();
+
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
malloc_size_1 = malloc_inuse(&malloc_hist_1);
if (read_conffile(conffile)) {
error("errors processing config file \"%s\"", conffile);
}
+
conf_tapelist = getconf_str(CNF_TAPELIST);
if (*conf_tapelist == '/') {
conf_tapelist = stralloc(conf_tapelist);
}
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ isa_zftape = is_zftape(tapename);
+ if (isa_zftape) {
if((fd = tape_open(tapename, O_WRONLY)) == -1) {
errstr = newstralloc2(errstr, "amlabel: ",
(errno == EACCES) ? "tape is write-protected"
printf("rewinding"); fflush(stdout);
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
printf("rewinding"); fflush(stdout);
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
printf(", writing label %s", label); fflush(stdout);
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
errstr = tapefd_wrlabel(fd, "X", label, tt_blocksize_kb * 1024);
if(errstr != NULL) {
putchar('\n');
}
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
tapefd_weof(fd, 1);
}
#endif /* HAVE_LINUX_ZFTAPE_H */
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
errstr = tapefd_wrendmark(fd, "X", tt_blocksize_kb * 1024);
if(errstr != NULL) {
putchar('\n');
}
#ifdef HAVE_LINUX_ZFTAPE_H
- if (is_zftape(tapename) == 1){
+ if (isa_zftape) {
tapefd_weof(fd, 1);
printf(",\nrewinding"); fflush(stdout);
} /* write tape list */
if(have_changer) {
- /* Now we try to inform the changer, about the new label */
- changer_label(outslot,label);
+ /* Now we try to inform the changer, about the new label */
+ /* changer_label(outslot,label); */
}
printf(", done.\n");
} else {
malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
}
- dbclose();
return 0;
}