/* Forward declarations */
+static void QuietExit(int) AFS_NORETURN;
+static void SalvageShowLog(void);
static int IsVnodeOrphaned(struct SalvInfo *salvinfo, VnodeId vnode);
static int AskVolumeSummary(struct SalvInfo *salvinfo,
VolumeId singleVolumeNumber);
} else {
int fd;
- ShowLog = 0;
+ ShowLog = 0; /* Child processes do not display. */
for (fd = 0; fd < 16; fd++)
close(fd);
open(OS_DIRSEP, 0);
if (!canfork || debug || Fork() == 0) {
SalvageFileSys1(partP, singleVolumeNumber);
if (canfork && !debug) {
- ShowLog = 0;
- Exit(0);
+ QuietExit(0);
}
} else
Wait("SalvageFileSys");
goto error;
}
if (canfork && !debug) {
- ShowLog = 0;
- Exit(0);
+ QuietExit(0);
}
} else {
if (Wait("Inode summary") == -1) {
IH_RELEASE(salvinfo->VGLinkH);
if (canfork && !debug) {
- ShowLog = 0;
- Exit(0);
+ QuietExit(0);
}
}
return f;
}
-void
-Exit(int code)
+static void
+QuietExit(int code)
{
- if (ShowLog)
- showlog();
-
#ifdef AFS_DEMAND_ATTACH_FS
if (programType == salvageServer) {
/* release all volume locks before closing down our SYNC channels.
#endif
}
+void
+Exit(int code)
+{
+ SalvageShowLog();
+ QuietExit(code);
+}
+
+
int
Wait(char *prog)
{
void
CheckLogFile(char * log_path)
{
- char oldSlvgLog[AFSDIR_PATH_MAX];
+ char *oldSlvgLog;
#ifndef AFS_NT40_ENV
if (useSyslog) {
- ShowLog = 0;
return;
}
#endif
- strcpy(oldSlvgLog, log_path);
- strcat(oldSlvgLog, ".old");
if (!logFile) {
- rk_rename(log_path, oldSlvgLog);
+ if (asprintf(&oldSlvgLog, "%s.old", log_path) >= 0) {
+ rk_rename(log_path, oldSlvgLog);
+ free(oldSlvgLog);
+ }
logFile = afs_fopen(log_path, "a");
if (!logFile) { /* still nothing, use stdout */
logFile = stdout;
- ShowLog = 0;
}
#ifndef AFS_NAMEI_ENV
AFS_DEBUG_IOPS_LOG(logFile);
void
TimeStampLogFile(char * log_path)
{
- char stampSlvgLog[AFSDIR_PATH_MAX];
+ char *stampSlvgLog;
struct tm *lt;
time_t now;
now = time(0);
lt = localtime(&now);
- snprintf(stampSlvgLog, sizeof stampSlvgLog,
- "%s.%04d-%02d-%02d.%02d:%02d:%02d", log_path,
- lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour,
- lt->tm_min, lt->tm_sec);
-
- /* try to link the logfile to a timestamped filename */
- /* if it fails, oh well, nothing we can do */
- if (link(log_path, stampSlvgLog))
- ; /* oh well */
+ if (asprintf(&stampSlvgLog,
+ "%s.%04d-%02d-%02d.%02d:%02d:%02d", log_path,
+ lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour,
+ lt->tm_min, lt->tm_sec) >= 0) {
+ /* try to link the logfile to a timestamped filename */
+ /* if it fails, oh well, nothing we can do */
+ if (link(log_path, stampSlvgLog))
+ ; /* oh well */
+ free(stampSlvgLog);
+ }
}
#endif
-void
-showlog(void)
+static void
+SalvageShowLog(void)
{
char line[256];
+ if (ShowLog == 0 || logFile == stdout || logFile == stderr) {
+ return;
+ }
+
#ifndef AFS_NT40_ENV
if (useSyslog) {
printf("Can't show log since using syslog.\n");
if (logFile) {
fprintf(logFile, "%s", tmp);
fflush(logFile);
- if (ShowLog)
- showlog();
+ SalvageShowLog();
}
if (debug)
abort();
- Exit(1);
+ QuietExit(1);
}
char *
nt_SetupPartitionSalvage(void *datap, int len)
{
childJob_t *jobp = (childJob_t *) datap;
- char logname[AFSDIR_PATH_MAX];
+ char *logname;
if (len != sizeof(childJob_t))
return -1;
myjob = *jobp;
/* Open logFile */
- (void)sprintf(logname, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH,
- myjob.cj_number);
+ if (asprintf(&logname, "%s.%d", AFSDIR_SERVER_SLVGLOG_FILEPATH,
+ myjob.cj_number) < 0)
+ return -1;
logFile = afs_fopen(logname, "w");
+ free(logname);
if (!logFile)
logFile = stdout;