projects
/
debian
/
amanda
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Imported Upstream version 2.5.1p3
[debian/amanda]
/
server-src
/
amlabel.c
diff --git
a/server-src/amlabel.c
b/server-src/amlabel.c
index b7bdc4ca04bfd00f805a306c409418ff385f1af6..b04dcff2732460737404b2c7e831dcc6c8ec90ad 100644
(file)
--- a/
server-src/amlabel.c
+++ b/
server-src/amlabel.c
@@
-24,7
+24,7
@@
* file named AUTHORS, in the root directory of this distribution.
*/
/*
* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amlabel.c,v 1.
43 2006/01/14 04:37:19 paddy_s
Exp $
+ * $Id: amlabel.c,v 1.
53.2.2 2007/02/06 14:07:44 martinea
Exp $
*
* write an Amanda label on a tape
*/
*
* write an Amanda label on a tape
*/
@@
-40,20
+40,21
@@
/* local functions */
/* local functions */
-int main
P((int, char **)
);
-void usage
P((char *argv0)
);
+int main
(int argc, char **argv
);
+void usage
(void
);
-void
usage(argv0)
-char *argv0;
+void
+usage(void)
{
{
- fprintf(stderr, "Usage: %s [-f] <conf> <label> [slot <slot-number>]\n",
-
argv0
);
+ fprintf(stderr, "Usage: %s [-f] <conf> <label> [slot <slot-number>]
[-o configoption]*
\n",
+
get_pname()
);
exit(1);
}
exit(1);
}
-int main(argc, argv)
- int argc;
- char **argv;
+int
+main(
+ int argc,
+ char ** argv)
{
char *conffile;
char *conf_tapelist;
{
char *conffile;
char *conf_tapelist;
@@
-70,14
+71,15
@@
int main(argc, argv)
#endif /* HAVE_LINUX_ZFTAPE_H */
int have_changer;
int force, tape_ok;
#endif /* HAVE_LINUX_ZFTAPE_H */
int have_changer;
int force, tape_ok;
- tape_t *tp;
tapetype_t *tape;
tapetype_t *tape;
-
long
tt_blocksize_kb;
+
size_t
tt_blocksize_kb;
int slotcommand;
uid_t uid_me;
uid_t uid_dumpuser;
char *dumpuser;
struct passwd *pw;
int slotcommand;
uid_t uid_me;
uid_t uid_dumpuser;
char *dumpuser;
struct passwd *pw;
+ int new_argc;
+ char **new_argv;
#ifdef HAVE_LIBVTBLC
int vtbl_no = -1;
#ifdef HAVE_LIBVTBLC
int vtbl_no = -1;
@@
-91,6
+93,8
@@
int main(argc, argv)
set_pname("amlabel");
set_pname("amlabel");
+ dbopen(DBG_SUBDIR_SERVER);
+
/* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
/* Don't die when child closes pipe */
signal(SIGPIPE, SIG_IGN);
@@
-98,20
+102,22
@@
int main(argc, argv)
erroutput_type = ERR_INTERACTIVE;
erroutput_type = ERR_INTERACTIVE;
- if(argc > 1 && strcmp(argv[1],"-f") == 0)
+ parse_server_conf(argc, argv, &new_argc, &new_argv);
+
+ if(new_argc > 1 && strcmp(new_argv[1],"-f") == 0)
force=1;
else force=0;
force=1;
else force=0;
- if(
argc != 3+force &&
argc != 5+force)
- usage(
argv[0]
);
+ if(
new_argc != 3+force && new_
argc != 5+force)
+ usage();
- config_name = argv[1+force];
- label = argv[2+force];
+ config_name =
new_
argv[1+force];
+ label =
new_
argv[2+force];
- if(argc == 5+force) {
- if(strcmp(argv[3+force], "slot"))
- usage(
argv[0]
);
- slotstr = argv[4+force];
+ if(
new_
argc == 5+force) {
+ if(strcmp(
new_
argv[3+force], "slot"))
+ usage();
+ slotstr =
new_
argv[4+force];
slotcommand = 1;
} else {
slotstr = "current";
slotcommand = 1;
} else {
slotstr = "current";
@@
-122,8
+128,13
@@
int main(argc, argv)
conffile = stralloc2(config_dir, CONFFILE_NAME);
if (read_conffile(conffile)) {
error("errors processing config file \"%s\"", conffile);
conffile = stralloc2(config_dir, CONFFILE_NAME);
if (read_conffile(conffile)) {
error("errors processing config file \"%s\"", conffile);
+ /*NOTREACHED*/
}
}
+ dbrename(config_name, DBG_SUBDIR_SERVER);
+
+ report_bad_conf_arg();
+
conf_tapelist = getconf_str(CNF_TAPELIST);
if (*conf_tapelist == '/') {
conf_tapelist = stralloc(conf_tapelist);
conf_tapelist = getconf_str(CNF_TAPELIST);
if (*conf_tapelist == '/') {
conf_tapelist = stralloc(conf_tapelist);
@@
-132,6
+143,7
@@
int main(argc, argv)
}
if (read_tapelist(conf_tapelist)) {
error("could not load tapelist \"%s\"", conf_tapelist);
}
if (read_tapelist(conf_tapelist)) {
error("could not load tapelist \"%s\"", conf_tapelist);
+ /*NOTREACHED*/
}
uid_me = getuid();
}
uid_me = getuid();
@@
-140,47
+152,58
@@
int main(argc, argv)
if ((pw = getpwnam(dumpuser)) == NULL) {
error("cannot look up dump user \"%s\"", dumpuser);
if ((pw = getpwnam(dumpuser)) == NULL) {
error("cannot look up dump user \"%s\"", dumpuser);
- /*
NOTREACHED
*/
+ /*
NOTREACHED
*/
}
uid_dumpuser = pw->pw_uid;
if ((pw = getpwuid(uid_me)) == NULL) {
error("cannot look up my own uid %ld", (long)uid_me);
}
uid_dumpuser = pw->pw_uid;
if ((pw = getpwuid(uid_me)) == NULL) {
error("cannot look up my own uid %ld", (long)uid_me);
- /*
NOTREACHED
*/
+ /*
NOTREACHED
*/
}
if (uid_me != uid_dumpuser) {
error("running as user \"%s\" instead of \"%s\"",
pw->pw_name, dumpuser);
}
if (uid_me != uid_dumpuser) {
error("running as user \"%s\" instead of \"%s\"",
pw->pw_name, dumpuser);
- /*
NOTREACHED
*/
+ /*
NOTREACHED
*/
}
labelstr = getconf_str(CNF_LABELSTR);
}
labelstr = getconf_str(CNF_LABELSTR);
- if(!match(labelstr, label))
+ if(!match(labelstr, label))
{
error("label %s doesn't match labelstr \"%s\"", label, labelstr);
error("label %s doesn't match labelstr \"%s\"", label, labelstr);
+ /*NOTREACHED*/
+ }
- if((
tp =
lookup_tapelabel(label))!=NULL) {
- if(!force)
+ if((lookup_tapelabel(label))!=NULL) {
+ if(!force)
{
error("label %s already on a tape\n",label);
error("label %s already on a tape\n",label);
+ /*NOTREACHED*/
+ }
}
tape = lookup_tapetype(getconf_str(CNF_TAPETYPE));
}
tape = lookup_tapetype(getconf_str(CNF_TAPETYPE));
- tt_blocksize_kb =
tape->blocksize
;
+ tt_blocksize_kb =
(size_t)tapetype_get_blocksize(tape)
;
if((have_changer = changer_init()) == 0) {
if(slotcommand) {
fprintf(stderr,
"%s: no tpchanger specified in \"%s\", so slot command invalid\n",
if((have_changer = changer_init()) == 0) {
if(slotcommand) {
fprintf(stderr,
"%s: no tpchanger specified in \"%s\", so slot command invalid\n",
- argv[0], conffile);
- usage(argv[0]);
+ new_argv[0], conffile);
+ usage();
+ }
+ tapename = getconf_str(CNF_TAPEDEV);
+ if (tapename == NULL) {
+ error("No tapedev specified");
+ } else {
+ tapename = stralloc(tapename);
}
}
- tapename = stralloc(getconf_str(CNF_TAPEDEV));
#ifdef HAVE_LIBVTBLC
rawtapedev = stralloc(getconf_str(CNF_RAWTAPEDEV));
#endif /* HAVE_LIBVTBLC */
} else if(have_changer != 1) {
error("changer initialization failed: %s", strerror(errno));
#ifdef HAVE_LIBVTBLC
rawtapedev = stralloc(getconf_str(CNF_RAWTAPEDEV));
#endif /* HAVE_LIBVTBLC */
} else if(have_changer != 1) {
error("changer initialization failed: %s", strerror(errno));
+ /*NOTREACHED*/
} else {
if(changer_loadslot(slotstr, &outslot, &tapename)) {
error("could not load slot \"%s\": %s", slotstr, changer_resultstr);
} else {
if(changer_loadslot(slotstr, &outslot, &tapename)) {
error("could not load slot \"%s\": %s", slotstr, changer_resultstr);
+ /*NOTREACHED*/
}
printf("labeling tape in slot %s (%s):\n", outslot, tapename);
}
printf("labeling tape in slot %s (%s):\n", outslot, tapename);
@@
-194,6
+217,7
@@
int main(argc, argv)
(errno == EACCES) ? "tape is write-protected"
: strerror(errno));
error(errstr);
(errno == EACCES) ? "tape is write-protected"
: strerror(errno));
error(errstr);
+ /*NOTREACHED*/
}
}
#endif /* HAVE_LINUX_ZFTAPE_H */
}
}
#endif /* HAVE_LINUX_ZFTAPE_H */
@@
-205,6
+229,7
@@
int main(argc, argv)
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
+ /*NOTREACHED*/
}
}
else
}
}
else
@@
-212,6
+237,7
@@
int main(argc, argv)
if((errstr = tape_rewind(tapename)) != NULL) {
putchar('\n');
error(errstr);
if((errstr = tape_rewind(tapename)) != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
tape_ok=1;
}
tape_ok=1;
@@
-230,7
+256,7
@@
int main(argc, argv)
tape_ok=0;
}
else {
tape_ok=0;
}
else {
- if((
tp =
lookup_tapelabel(oldlabel)) != NULL) {
+ if((lookup_tapelabel(oldlabel)) != NULL) {
printf(", tape is active");
if(!force)
tape_ok=0;
printf(", tape is active");
if(!force)
tape_ok=0;
@@
-248,6
+274,7
@@
int main(argc, argv)
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
+ /*NOTREACHED*/
}
}
else
}
}
else
@@
-255,6
+282,7
@@
int main(argc, argv)
if((errstr = tape_rewind(tapename)) != NULL) {
putchar('\n');
error(errstr);
if((errstr = tape_rewind(tapename)) != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
if(tape_ok) {
}
if(tape_ok) {
@@
-262,51
+290,60
@@
int main(argc, argv)
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
- errstr = tapefd_wrlabel(fd, "X", label, tt_blocksize_kb * 1024);
+ errstr = tapefd_wrlabel(fd, "X", label,
+ (tt_blocksize_kb * 1024));
if(errstr != NULL) {
putchar('\n');
error(errstr);
if(errstr != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
}
else
#endif /* HAVE_LINUX_ZFTAPE_H */
}
}
else
#endif /* HAVE_LINUX_ZFTAPE_H */
- errstr = tape_wrlabel(tapename, "X", label, tt_blocksize_kb * 1024);
+ errstr = tape_wrlabel(tapename, "X", label,
+ (tt_blocksize_kb * 1024));
if(errstr != NULL) {
putchar('\n');
error(errstr);
if(errstr != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
}
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
- tapefd_weof(fd, 1);
+ tapefd_weof(fd,
(off_t)
1);
}
#endif /* HAVE_LINUX_ZFTAPE_H */
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
}
#endif /* HAVE_LINUX_ZFTAPE_H */
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
- errstr = tapefd_wrendmark(fd, "X", tt_blocksize_kb * 1024);
+ errstr = tapefd_wrendmark(fd, "X",
+ (tt_blocksize_kb * 1024));
if(errstr != NULL) {
putchar('\n');
error(errstr);
if(errstr != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
}
else
#endif /* HAVE_LINUX_ZFTAPE_H */
}
}
else
#endif /* HAVE_LINUX_ZFTAPE_H */
- errstr = tape_wrendmark(tapename, "X", tt_blocksize_kb * 1024);
+ errstr = tape_wrendmark(tapename, "X",
+ (tt_blocksize_kb * 1024));
if(errstr != NULL) {
putchar('\n');
error(errstr);
if(errstr != NULL) {
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
}
#ifdef HAVE_LINUX_ZFTAPE_H
if (isa_zftape) {
- tapefd_weof(fd, 1);
+ tapefd_weof(fd,
(off_t)
1);
printf(",\nrewinding"); fflush(stdout);
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
printf(",\nrewinding"); fflush(stdout);
if(tapefd_rewind(fd) == -1) {
putchar('\n');
error(strerror(errno));
+ /*NOTREACHED*/
}
close(fd);
#ifdef HAVE_LIBVTBLC
}
close(fd);
#ifdef HAVE_LIBVTBLC
@@
-323,6
+360,7
@@
int main(argc, argv)
}
putchar('\n');
error(errstr);
}
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
/* read volume table */
if ((num_volumes = read_vtbl(fd, volumes, vtbl_buffer,
}
/* read volume table */
if ((num_volumes = read_vtbl(fd, volumes, vtbl_buffer,
@@
-331,6
+369,7
@@
int main(argc, argv)
"reading volume table: ", strerror(errno));
putchar('\n');
error(errstr);
"reading volume table: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
/* set date and volume label for first entry */
vtbl_no = 0;
}
/* set date and volume label for first entry */
vtbl_no = 0;
@@
-340,12
+379,14
@@
int main(argc, argv)
"setting date for entry 1: ", strerror(errno));
putchar('\n');
error(errstr);
"setting date for entry 1: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
if(set_label(label, volumes, num_volumes, vtbl_no)){
errstr = newstralloc2(errstr,
"setting label for entry 1: ", strerror(errno));
putchar('\n');
error(errstr);
}
if(set_label(label, volumes, num_volumes, vtbl_no)){
errstr = newstralloc2(errstr,
"setting label for entry 1: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
/* set date and volume label for last entry */
vtbl_no = 1;
}
/* set date and volume label for last entry */
vtbl_no = 1;
@@
-355,12
+396,14
@@
int main(argc, argv)
"setting date for entry 2: ", strerror(errno));
putchar('\n');
error(errstr);
"setting date for entry 2: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
if(set_label("AMANDA Tape End", volumes, num_volumes, vtbl_no)){
errstr = newstralloc2(errstr,
"setting label for entry 2: ", strerror(errno));
putchar('\n');
error(errstr);
}
if(set_label("AMANDA Tape End", volumes, num_volumes, vtbl_no)){
errstr = newstralloc2(errstr,
"setting label for entry 2: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
/* write volume table back */
if (write_vtbl(fd, volumes, vtbl_buffer, num_volumes, first_seg,
}
/* write volume table back */
if (write_vtbl(fd, volumes, vtbl_buffer, num_volumes, first_seg,
@@
-369,6
+412,7
@@
int main(argc, argv)
"writing volume table: ", strerror(errno));
putchar('\n');
error(errstr);
"writing volume table: ", strerror(errno));
putchar('\n');
error(errstr);
+ /*NOTREACHED*/
}
close(fd);
#endif /* HAVE_LIBVTBLC */
}
close(fd);
#endif /* HAVE_LIBVTBLC */
@@
-380,10
+424,13
@@
int main(argc, argv)
if((errstr = tape_rdlabel(tapename, &olddatestamp, &oldlabel)) != NULL) {
putchar('\n');
if((errstr = tape_rdlabel(tapename, &olddatestamp, &oldlabel)) != NULL) {
putchar('\n');
- if (strcmp(errstr, "not an amanda tape") != 0)
+ if (strcmp(errstr, "not an amanda tape") != 0)
{
error(errstr);
error(errstr);
+ /*NOTREACHED*/
+ }
error("no label found, are you sure %s is non-rewinding?",
tapename);
error("no label found, are you sure %s is non-rewinding?",
tapename);
+ /*NOTREACHED*/
}
if (strcmp("X", olddatestamp) != 0 ||
}
if (strcmp("X", olddatestamp) != 0 ||
@@
-392,6
+439,7
@@
int main(argc, argv)
putchar('\n');
error("read label %s back, timestamp %s (expected X), what now?",
oldlabel, olddatestamp);
putchar('\n');
error("read label %s back, timestamp %s (expected X), what now?",
oldlabel, olddatestamp);
+ /*NOTREACHED*/
}
amfree(oldlabel);
amfree(olddatestamp);
}
amfree(oldlabel);
amfree(olddatestamp);
@@
-402,32
+450,37
@@
int main(argc, argv)
conf_tapelist_old = stralloc2(conf_tapelist, ".amlabel");
if(write_tapelist(conf_tapelist_old)) {
error("couldn't write tapelist: %s", strerror(errno));
conf_tapelist_old = stralloc2(conf_tapelist, ".amlabel");
if(write_tapelist(conf_tapelist_old)) {
error("couldn't write tapelist: %s", strerror(errno));
+ /*NOTREACHED*/
}
amfree(conf_tapelist_old);
/* XXX add cur_tape number to tape list structure */
remove_tapelabel(label);
}
amfree(conf_tapelist_old);
/* XXX add cur_tape number to tape list structure */
remove_tapelabel(label);
- add_tapelabel(
0
, label);
+ add_tapelabel(
"0"
, label);
if(write_tapelist(conf_tapelist)) {
error("couldn't write tapelist: %s", strerror(errno));
if(write_tapelist(conf_tapelist)) {
error("couldn't write tapelist: %s", strerror(errno));
+ /*NOTREACHED*/
}
}
- } /* write tape list */
-
if
(have_changer) {
- /* Now we try to inform the changer, about the new label */
- /* changer_label(outslot,label); */
- }
+
if
(have_changer) {
+ changer_label(outslot, label);
+ }
+ }
/* write tape list */
printf(", done.\n");
} else {
printf("\ntape not labeled\n");
}
printf(", done.\n");
} else {
printf("\ntape not labeled\n");
}
+ clear_tapelist();
+ free_new_argv(new_argc, new_argv);
+ free_server_config();
amfree(outslot);
amfree(tapename);
amfree(conffile);
amfree(conf_tapelist);
amfree(config_dir);
config_name=NULL;
amfree(outslot);
amfree(tapename);
amfree(conffile);
amfree(conf_tapelist);
amfree(config_dir);
config_name=NULL;
+ dbclose();
malloc_size_2 = malloc_inuse(&malloc_hist_2);
malloc_size_2 = malloc_inuse(&malloc_hist_2);