#include "conffile.h"
#include "libscsi.h"
#include "scsi-defs.h"
+int Tape_Ready1 ( char *tapedev , int wait);
char *tapestatfile = NULL;
int get_current_slot(char *count_file);
void put_current_slot(char *count_file,int slot);
void usage(char *argv[]);
-void parse_args(int argc, char *argv[],command *rval);
int get_relative_target(int fd,int nslots,char *parameter,int loaded,
char *changer_file,int slot_offset,int maxslot);
int is_positive_number(char *tmp);
changer_t * chg,
size_t number_of_config)
{
- int i;
+ size_t i;
memset(chg, 0, SIZEOF(*chg));
chg->number_of_configs = number_of_config;
chg->eject = 1;
chg->sleep = 0;
chg->cleanmax = 0;
- chg->device = NULL
+ chg->device = NULL;
chg->conf = alloc(SIZEOF(config_t) * number_of_config);
for (i=0; i < number_of_config; i++){
chg->conf[i].drivenum = 0;
{
int i;
- dbprintf(("Number of configurations: %d\n", chg->number_of_configs));
- dbprintf(("Tapes need eject: %s\n", (chg->eject>0 ? "Yes" : "No")));
- dbprintf(("Tapes need sleep: %d seconds\n", chg->sleep));
- dbprintf(("Cleancycles : %d\n", chg->cleanmax));
- dbprintf(("Changerdevice : %s\n", chg->device));
+ dbprintf(_("Number of configurations: %d\n"), chg->number_of_configs);
+ dbprintf(_("Tapes need eject: %s\n"), (chg->eject>0 ? _("Yes") : _("No")));
+ dbprintf(_("Tapes need sleep: %lld seconds\n"), (long long)chg->sleep);
+ dbprintf(_("Clean cycles : %d\n"), chg->cleanmax);
+ dbprintf(_("Changer device : %s\n"), chg->device);
for (i = 0; i < chg->number_of_configs; i++){
- dbprintf(("Tapeconfig Nr: %d\n", i));
- dbprintf((" Drivenumber : %d\n", chg->conf[i].drivenum));
- dbprintf((" Startslot : %d\n", chg->conf[i].start));
- dbprintf((" Endslot : %d\n", chg->conf[i].end));
- dbprintf((" Cleanslot : %d\n", chg->conf[i].cleanslot));
+ dbprintf(_("Tape config Nr: %d\n"), i);
+ dbprintf(_(" Drive number : %d\n"), chg->conf[i].drivenum);
+ dbprintf(_(" Start slot : %d\n"), chg->conf[i].start);
+ dbprintf(_(" End slot : %d\n"), chg->conf[i].end);
+ dbprintf(_(" Clean slot : %d\n"), chg->conf[i].cleanslot);
if (chg->conf[i].device != NULL)
- dbprintf((" Devicename : %s\n", chg->conf[i].device));
+ dbprintf(_(" Device name : %s\n"), chg->conf[i].device);
else
- dbprintf((" Devicename : none\n"));
+ dbprintf(_(" Device name : none\n"));
if (chg->conf[i].scsitapedev != NULL)
- dbprintf((" SCSITapedev : %s\n", chg->conf[i].scsitapedev));
+ dbprintf(_(" SCSI Tape dev : %s\n"), chg->conf[i].scsitapedev);
else
- dbprintf((" SCSITapedev : none\n"));
+ dbprintf(_(" SCSI Tape dev : none\n"));
if (chg->conf[i].tapestatfile != NULL)
- dbprintf((" statfile : %s\n", chg->conf[i].tapestatfile));
+ dbprintf(_(" stat file : %s\n"), chg->conf[i].tapestatfile);
else
- dbprintf((" statfile : none\n"));
+ dbprintf(_(" stat file : none\n"));
if (chg->conf[i].slotfile != NULL)
- dbprintf((" Slotfile : %s\n", chg->conf[i].slotfile));
+ dbprintf(_(" Slot file : %s\n"), chg->conf[i].slotfile);
else
- dbprintf((" Slotfile : none\n"));
+ dbprintf(_(" Slot file : none\n"));
if (chg->conf[i].cleanfile != NULL)
- dbprintf((" Cleanfile : %s\n", chg->conf[i].cleanfile));
+ dbprintf(_(" Clean file : %s\n"), chg->conf[i].cleanfile);
else
- dbprintf((" Cleanfile : none\n"));
+ dbprintf(_(" Clean file : none\n"));
if (chg->conf[i].timefile != NULL)
- dbprintf((" Usagecount : %s\n", chg->conf[i].timefile));
+ dbprintf(_(" Usage count : %s\n"), chg->conf[i].timefile);
else
- dbprintf((" Usagecount : none\n"));
+ dbprintf(_(" Usage count : none\n"));
}
}
size_t numconf;
FILE *file;
int init_flag = 0;
- int drivenum=0;
+ size_t drivenum=0;
char *linebuffer;
int token;
char *value;
init_flag=1;
}
switch (token){
- case NUMDRIVE: if (atoi(value) != numconf)
- fprintf(stderr,"Error: number_drives at wrong place, should be "\
- "first in file\n");
+ case NUMDRIVE: if ((size_t)atoi(value) != numconf)
+ g_fprintf(stderr,_("Error: number_drives at wrong place, should be "
+ "first in file\n"));
break;
case EJECT:
chg->eject = atoi(value);
case DRIVE:
drivenum = atoi(value);
if(drivenum >= numconf){
- fprintf(stderr,"Error: drive must be less than number_drives\n");
+ g_fprintf(stderr,_("Error: drive must be less than number_drives\n"));
}
break;
case DRIVENUM:
if (drivenum < numconf){
chg->conf[drivenum].drivenum = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " drivenum ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " drivenum ignored\n"));
}
break;
case START:
if (drivenum < numconf){
chg->conf[drivenum].start = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " startuse ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " startuse ignored\n"));
}
break;
case END:
if (drivenum < numconf){
chg->conf[drivenum].end = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " enduse ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " enduse ignored\n"));
}
break;
case CLEAN:
if (drivenum < numconf){
chg->conf[drivenum].cleanslot = atoi(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " cleanslot ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " cleanslot ignored\n"));
}
break;
case DEVICE:
if (drivenum < numconf){
chg->conf[drivenum].device = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " device ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " device ignored\n"));
}
break;
case STATFILE:
if (drivenum < numconf){
chg->conf[drivenum].slotfile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " slotfile ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " slotfile ignored\n"));
}
break;
case CLEANFILE:
if (drivenum < numconf){
chg->conf[drivenum].cleanfile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " cleanfile ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " cleanfile ignored\n"));
}
break;
case USAGECOUNT:
if (drivenum < numconf){
chg->conf[drivenum].timefile = stralloc(value);
} else {
- fprintf(stderr,"Error: drive is not less than number_drives"\
- " usagecount ignored\n");
+ g_fprintf(stderr,_("Error: drive is not less than number_drives"
+ " usagecount ignored\n"));
}
break;
default:
- fprintf(stderr,"Error: Unknown token\n");
+ g_fprintf(stderr,_("Error: Unknown token\n"));
break;
}
}
FILE *inf;
int retval;
if ((inf=fopen(count_file,"r")) == NULL) {
- fprintf(stderr, "%s: unable to open current slot file (%s)\n",
+ g_fprintf(stderr, _("%s: unable to open current slot file (%s)\n"),
get_pname(), count_file);
return 0;
}
if (fscanf(inf, "%d", &retval) != 1) {
- fprintf(stderr, "%s: unable to read current slot file (%s)\n",
+ g_fprintf(stderr, _("%s: unable to read current slot file (%s)\n"),
get_pname(), count_file);
retval = 0;
}
FILE *inf;
if ((inf=fopen(count_file,"w")) == NULL) {
- fprintf(stderr, "%s: unable to open current slot file (%s)\n",
+ g_fprintf(stderr, _("%s: unable to open current slot file (%s)\n"),
get_pname(), count_file);
exit(2);
}
- fprintf(inf, "%d\n", slot);
+ g_fprintf(inf, "%d\n", slot);
fclose(inf);
}
} command;
+void parse_args(int argc, char *argv[], command *rval);
+
/* major command line args */
#define COMCOUNT 5
#define COM_SLOT 0
void usage(char *argv[])
{
int cnt;
- printf("%s: Usage error.\n", argv[0]);
+ g_printf(_("%s: Usage error.\n"), argv[0]);
for (cnt=0; cnt < COMCOUNT; cnt++){
- printf(" %s %s",argv[0],argdefs[cnt].str);
+ g_printf(" %s %s",argv[0],argdefs[cnt].str);
if (argdefs[cnt].takesparam)
- printf(" <param>\n");
+ g_printf(_(" <param>\n"));
else
- printf("\n");
+ g_printf("\n");
}
exit(2);
}
return maxslot;
default:
- printf("<none> no slot `%s'\n",parameter);
+ g_printf(_("<none> no slot `%s'\n"),parameter);
close(fd);
exit(2);
/*NOTREACHED*/
char * usagetime)
{
int counter;
+ char *mailer;
if (cleancart == -1 ){
return;
}
+ mailer = getconf_str(CNF_MAILER);
+
/* Now we should increment the counter */
if (cnt_file != NULL){
counter = get_current_slot(cnt_file);
char *mail_cmd;
FILE *mailf;
int mail_pipe_opened = 1;
- if(getconf_seen(CNF_MAILTO) && strlen(getconf_str(CNF_MAILTO)) > 0 &&
- validate_mailto(getconf_str(CNF_MAILTO))) {
- mail_cmd = vstralloc(MAILER,
- " -s", " \"", "AMANDA PROBLEM: PLEASE FIX", "\"",
- " ", getconf_str(CNF_MAILTO),
- NULL);
- if((mailf = popen(mail_cmd, "w")) == NULL){
- printf("Mail failed\n");
- error("could not open pipe to \"%s\": %s",
- mail_cmd, strerror(errno));
- /*NOTREACHED*/
- }
+ if (mailer && *mailer != '\0') {
+ if (getconf_seen(CNF_MAILTO) && strlen(getconf_str(CNF_MAILTO)) > 0 &&
+ validate_mailto(getconf_str(CNF_MAILTO))) {
+ mail_cmd = vstralloc(mailer,
+ " -s", " \"", _("AMANDA PROBLEM: PLEASE FIX"), "\"",
+ " ", getconf_str(CNF_MAILTO),
+ NULL);
+ if ((mailf = popen(mail_cmd, "w")) == NULL) {
+ g_printf(_("Mail failed\n"));
+ error(_("could not open pipe to \"%s\": %s"),
+ mail_cmd, strerror(errno));
+ /*NOTREACHED*/
+ }
+ } else {
+ mail_pipe_opened = 0;
+ mailf = stderr;
+ g_fprintf(mailf, _("\nNo mail recipient specified, output redirected to stderr"));
+ }
+ } else {
+ mail_pipe_opened = 0;
+ mailf = stderr;
+ g_fprintf(mailf, _("\nNo mailer specified; output redirected to stderr"));
}
- else{
- mail_pipe_opened = 0;
- mailf = stderr;
- fprintf(mailf, "\nNo mail recipient specified, output redirected to stderr");
- }
-
- fprintf(mailf,"\nThe usage count of your cleaning tape in slot %d",
+ g_fprintf(mailf, _("\nThe usage count of your cleaning tape in slot %d"),
cleancart);
- fprintf(mailf,"\nis more than %d. (cleanmax)",maxclean);
- fprintf(mailf,"\nTapedrive %s needs to be cleaned",tapedev);
- fprintf(mailf,"\nPlease insert a new cleaning tape and reset");
- fprintf(mailf,"\nthe countingfile %s",cnt_file);
+ g_fprintf(mailf,_("\nis more than %d. (cleanmax)"),maxclean);
+ g_fprintf(mailf,_("\nTapedrive %s needs to be cleaned"),tapedev);
+ g_fprintf(mailf,_("\nPlease insert a new cleaning tape and reset"));
+ g_fprintf(mailf,_("\nthe countingfile %s"),cnt_file);
if(mail_pipe_opened == 1 && pclose(mailf) != 0) {
- error("mail command failed: %s", mail_cmd);
+ error(_("mail command failed: %s"), mail_cmd);
/*NOTREACHED*/
}
int
main(
int argc,
- char * argv[])
+ char ** argv)
{
int loaded;
int target = -1;
char *changer_file = NULL;
char *scsitapedevice = NULL;
+ /*
+ * Configure program for internationalization:
+ * 1) Only set the message locale for now.
+ * 2) Set textdomain for all amanda related programs to "amanda"
+ * We don't want to be forced to support dozens of message catalogs.
+ */
+ setlocale(LC_MESSAGES, "C");
+ textdomain("amanda");
+
set_pname("chg-scsi");
/* Don't die when child closes pipe */
parse_args(argc,argv,&com);
changer = alloc(SIZEOF(changer_t));
- if(read_conffile(CONFFILE_NAME)) {
- fprintf(stderr, "%s: could not find config file \"%s\"",
- changer_dev, conffile);
- exit(1);
+ config_init(CONFIG_INIT_USE_CWD, NULL);
+
+ if (config_errors(NULL) >= CFGERR_WARNINGS) {
+ config_print_errors();
+ if (config_errors(NULL) >= CFGERR_ERRORS) {
+ g_critical(_("errors processing config file"));
+ }
}
- changer_dev = getconf_str(CNF_CHNGRDEV);
- changer_file = getconf_str(CNF_CHNGRFILE);
+ changer_dev = getconf_str(CNF_CHANGERDEV);
+ changer_file = getconf_str(CNF_CHANGERFILE);
tape_device = getconf_str(CNF_TAPEDEV);
/* Get the configuration parameters */
"changer_dev", changer->conf[confnum].changerident);
if (fd == -1) {
int localerr = errno;
- fprintf(stderr, "%s: open: %s: %s\n", get_pname(),
+ g_fprintf(stderr, _("%s: open: %s: %s\n"), get_pname(),
changer_dev, strerror(localerr));
- printf("%s open: %s: %s\n", "<none>", changer_dev, strerror(localerr));
- dbprintf(("%s: open: %s: %s\n", get_pname(),
- changer_dev, strerror(localerr)));
+ g_printf(_("%s open: %s: %s\n"), "<none>", changer_dev, strerror(localerr));
+ dbprintf(_("open: %s: %s\n"), changer_dev, strerror(localerr));
return 2;
}
"changer_dev", changer->conf[confnum].changerident);
if (fd == -1) {
int localerr = errno;
- fprintf(stderr, "%s: open: %s: %s\n", get_pname(),
+ g_fprintf(stderr, _("%s: open: %s: %s\n"), get_pname(),
changer_dev, strerror(localerr));
- printf("%s open: %s: %s\n", "<none>", changer_dev, strerror(localerr));
- dbprintf(("%s: open: %s: %s\n", get_pname(),
- changer_dev, strerror(localerr)));
+ g_printf(_("%s open: %s: %s\n"), _("<none>"), changer_dev, strerror(localerr));
+ dbprintf(_("open: %s: %s\n"), changer_dev, strerror(localerr));
return 2;
}
slotcnt = get_slot_count(fd);
drivecnt = get_drive_count(fd);
if (drive_num > drivecnt) {
- printf("%s drive number error (%d > %d)\n", "<none>",
+ g_printf(_("%s drive number error (%d > %d)\n"), _("<none>"),
drive_num, drivecnt);
- fprintf(stderr, "%s: requested drive number (%d) greater than "
- "number of supported drives (%d)\n", get_pname(),
+ g_fprintf(stderr, _("%s: requested drive number (%d) greater than "
+ "number of supported drives (%d)\n"), get_pname(),
drive_num, drivecnt);
- dbprintf(("%s: requested drive number (%d) greater than "
- "number of supported drives (%d)\n", get_pname(),
- drive_num, drivecnt));
+ dbprintf(_("requested drive number (%d) greater than "
+ "number of supported drives (%d)\n"), drive_num, drivecnt);
CloseDevice("", fd);
return 2;
}
case COM_SLOT: /* slot changing command */
if (is_positive_number(com.parameter)) {
if ((target = atoi(com.parameter))>=use_slots) {
- printf("<none> no slot `%d'\n",target);
+ g_printf(_("<none> no slot `%d'\n"),target);
close(fd);
endstatus = 2;
break;
put_current_slot(changer_file, target);
}
if (!loaded && isempty(fd, target)) {
- printf("%d slot %d is empty\n",target-slot_offset,
+ g_printf(_("%d slot %d is empty\n"),target-slot_offset,
target-slot_offset);
close(fd);
endstatus = 1;
}
if (!loaded)
if (load(fd, drive_num, target) != 0) {
- printf("%d slot %d move failed\n",target-slot_offset,
+ g_printf(_("%d slot %d move failed\n"),target-slot_offset,
target-slot_offset);
close(fd);
endstatus = 2;
break;
}
if (need_sleep)
- Tape_Ready(scsitapedevice, need_sleep);
- printf("%d %s\n", target-slot_offset, tape_device);
+ Tape_Ready1(scsitapedevice, need_sleep);
+ g_printf(_("%d %s\n"), target-slot_offset, tape_device);
break;
case COM_INFO:
if (changer_file != NULL)
{
- printf("%d ", get_current_slot(changer_file)-slot_offset);
+ g_printf("%d ", get_current_slot(changer_file)-slot_offset);
} else {
- printf("%d ", GetCurrentSlot(fd, drive_num)-slot_offset);
+ g_printf("%d ", GetCurrentSlot(fd, drive_num)-slot_offset);
}
- printf("%d 1\n", use_slots);
+ g_printf("%d 1\n", use_slots);
break;
case COM_RESET:
}
if (isempty(fd, slot_offset)) {
- printf("0 slot 0 is empty\n");
+ g_printf(_("0 slot 0 is empty\n"));
close(fd);
endstatus = 1;
break;
}
if (load(fd, drive_num, slot_offset) != 0) {
- printf("%d slot %d move failed\n",slot_offset,
+ g_printf(_("%d slot %d move failed\n"),slot_offset,
slot_offset);
close(fd);
endstatus = 2;
put_current_slot(changer_file, slot_offset);
}
if (need_sleep)
- Tape_Ready(scsitapedevice, need_sleep);
+ Tape_Ready1(scsitapedevice, need_sleep);
if (changer_file != NULL)
{
- printf("%d %s\n", get_current_slot(changer_file), tape_device);
+ g_printf("%d %s\n", get_current_slot(changer_file), tape_device);
} else {
- printf("%d %s\n", GetCurrentSlot(fd, drive_num), tape_device);
+ g_printf("%d %s\n", GetCurrentSlot(fd, drive_num), tape_device);
}
break;
if (ask_clean(scsitapedevice))
clean_tape(fd,tape_device,clean_file,drive_num,clean_slot,
maxclean,time_file);
- printf("%d %s\n", target, tape_device);
+ g_printf("%d %s\n", target, tape_device);
} else {
- printf("%d %s\n", target, "drive was not loaded");
+ g_printf(_("%d drive was not loaded\n"), target);
endstatus = 1;
}
break;
}
clean_tape(fd,tape_device,clean_file,drive_num,clean_slot,
maxclean,time_file);
- printf("%s cleaned\n", tape_device);
+ g_printf(_("%s cleaned\n"), tape_device);
break;
};