#ifndef lint
static const char rcsid[] =
- "$Id: tape.c,v 1.11 2000/01/21 10:17:41 stelian Exp $";
+ "$Id: tape.c,v 1.18 2000/03/11 15:29:01 stelian Exp $";
#endif /* not lint */
#ifdef __linux__
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
+#include <compaterr.h>
#ifdef __STDC__
#include <stdlib.h>
#include <string.h>
extern char *host;
char *nexttape;
extern pid_t rshpid;
+int eot_code = 1;
static ssize_t atomic_read __P((int, void *, size_t));
static ssize_t atomic_write __P((int, const void *, size_t));
static void flushtape __P((void));
static void killall __P((void));
static void rollforward __P((void));
+static int system_command __P((const char *, const char *, int));
/*
* Concurrent dump mods (Caltech) - disk block reading and tape writing
#else
(void) time((time_t *) &tnow);
#endif
+ if (blockswritten > tapesize)
+ tapesize = blockswritten;
deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing))
/ blockswritten * tapesize;
(void)snprintf(msgbuf, sizeof(msgbuf),
timeest();
}
-void
+/*
+ * Executes the command in a shell.
+ * Returns -1 if an error occured, the exit status of
+ * the command on success.
+ */
+int system_command(const char *command, const char *device, int volnum) {
+ int pid, status;
+ char commandstr[4096];
+
+ pid = fork();
+ if (pid == -1) {
+ perror(" DUMP: unable to fork");
+ return -1;
+ }
+ if (pid == 0) {
+ setuid(getuid());
+ setgid(getgid());
+ snprintf(commandstr, sizeof(commandstr), "%s %s %d", command, device, volnum);
+ commandstr[sizeof(commandstr) - 1] = '\0';
+ execl("/bin/sh", "sh", "-c", commandstr, NULL);
+ perror(" DUMP: unable to execute shell");
+ exit(-1);
+ }
+ do {
+ if (waitpid(pid, &status, 0) == -1) {
+ if (errno != EINTR) {
+ perror(" DUMP: waitpid error");
+ return -1;
+ }
+ } else {
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
+ else
+ return -1;
+ }
+ } while(1);
+}
+
+time_t
trewind(void)
{
int f;
while (wait((int *)NULL) >= 0) /* wait for any signals from slaves */
/* void */;
- if (pipeout)
- return;
+ if (!pipeout) {
- msg("Closing %s\n", tape);
+ msg("Closing %s\n", tape);
#ifdef RDUMP
- if (host) {
- rmtclose();
- while (rmtopen(tape, 0) < 0)
- sleep(10);
- rmtclose();
- return;
- }
+ if (host) {
+ rmtclose();
+ while (rmtopen(tape, 0) < 0)
+ sleep(10);
+ rmtclose();
+ }
+ else
#endif
- (void) close(tapefd);
- while ((f = open(tape, 0)) < 0)
- sleep (10);
- (void) close(f);
+ {
+ (void) close(tapefd);
+ while ((f = open(tape, 0)) < 0)
+ sleep (10);
+ (void) close(f);
+ }
+ eot_code = 1;
+ if (eot_script) {
+ msg("Launching %s\n", eot_script);
+ eot_code = system_command(eot_script, tape, tapeno);
+ }
+ if (eot_code != 0 && eot_code != 1) {
+ msg("Dump aborted by the end of tape script\n");
+ dumpabort(0);
+ }
+ }
+ return do_stats();
}
+
void
close_rewind(void)
{
- trewind();
- (void)do_stats();
- if (nexttape || Mflag)
+ (void)trewind();
+ if (nexttape || Mflag || (eot_code == 0) )
return;
if (!nogripe) {
msg("Change Volumes: Mount volume #%d\n", tapeno+1);
*/
tapeno++; /* current tape sequence */
if (Mflag) {
- snprintf(tape, NAME_MAX, "%s%03d", tapeprefix, tapeno);
- tape[NAME_MAX - 1] = '\0';
+ snprintf(tape, MAXPATHLEN, "%s%03d", tapeprefix, tapeno);
+ tape[MAXPATHLEN - 1] = '\0';
msg("Dumping volume %d on %s\n", tapeno, tape);
}
else if (nexttape || strchr(tapeprefix, ',')) {
nexttape = p + 1;
} else
nexttape = NULL;
- strncpy(tape, tapeprefix, NAME_MAX);
- tape[NAME_MAX - 1] = '\0';
+ strncpy(tape, tapeprefix, MAXPATHLEN);
+ tape[MAXPATHLEN - 1] = '\0';
msg("Dumping volume %d on %s\n", tapeno, tape);
}
#ifdef RDUMP
- while ((tapefd = (host ? rmtopen(tape, 2) :
- pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
+ while ((tapefd = (host ? rmtopen(tape, 2) : pipeout ?
+ fileno(stdout) :
+ open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
#else
- while ((tapefd = (pipeout ? 1 :
+ while ((tapefd = (pipeout ? fileno(stdout) :
open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
#endif
{