3 * Copyright (c) 1992-2001 by Mike Gleason.
13 /* Saves their session in a ~/.ncftp/trace file.
14 * This is nice for me when I need to diagnose problems.
17 FILE *gTraceFile
= NULL
;
21 extern FTPLibraryInfo gLib
;
22 extern FTPConnectionInfo gConn
;
23 extern char gVersion
[], gOS
[];
24 extern char gOurDirectoryPath
[];
30 Trace(const int level
, const char *const fmt
, ...)
36 if ((gDebug
>= level
) || (level
> 8)) {
39 (void) vsnprintf(buf
, sizeof(buf
) - 1, fmt
, ap
);
40 buf
[sizeof(buf
) - 1] = '\0';
42 (void) vsprintf(buf
, fmt
, ap
);
46 (void) time(&gTraceTime
);
47 ltp
= localtime(&gTraceTime
);
48 if ((gTraceFile
!= NULL
) && (ltp
!= NULL
)) {
49 (void) fprintf(gTraceFile
, "%02d:%02d:%02d %s",
57 (void) fprintf(stdout
, "%s", buf
);
66 ErrorHook(const FTPCIPtr
UNUSED(cipUnused
), char *msg
)
68 LIBNCFTP_USE_VAR(cipUnused
); /* shut up gcc */
70 /* Will also get Trace'd. */
71 (void) fprintf(stdout
, "%s", msg
);
78 DebugHook(const FTPCIPtr
UNUSED(cipUnused
), char *msg
)
80 LIBNCFTP_USE_VAR(cipUnused
); /* shut up gcc */
99 gConn
.debugLogProc
= DebugHook
;
100 gConn
.debugLog
= NULL
;
101 gConn
.errLogProc
= ErrorHook
;
116 #if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
120 if (gOurDirectoryPath
[0] == '\0')
121 return; /* Don't create in root directory. */
123 (void) sprintf(tName
, "trace.%u", (unsigned int) (pid
= getpid()));
124 (void) OurDirectoryPath(pathName
, sizeof(pathName
), tName
);
126 fp
= fopen(pathName
, FOPEN_WRITE_TEXT
);
128 (void) chmod(pathName
, 00600);
130 (void) setvbuf(fp
, gTraceLBuf
, _IOLBF
, sizeof(gTraceLBuf
));
131 #endif /* HAVE_SETVBUF */
132 /* Opened the trace file. */
133 (void) time(&gTraceTime
);
134 (void) fprintf(fp
, "SESSION STARTED at: %s", ctime(&gTraceTime
));
135 (void) fprintf(fp
, " Program Version: %s\n", gVersion
+ 5);
136 (void) fprintf(fp
, " Library Version: %s\n", gLibNcFTPVersion
+ 5);
137 (void) fprintf(fp
, " Process ID: %u\n", pid
);
139 (void) fprintf(fp
, " Platform: %s\n", gOS
);
140 #if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
141 if (uname(&u
) == 0) {
142 (void) fprintf(fp
, " Uname: %.63s|%.63s|%.63s|%.63s|%.63s\r\n", u
.sysname
, u
.nodename
, u
.release
, u
.version
, u
.machine
);
145 FTPInitializeOurHostName(&gLib
);
146 (void) fprintf(fp
, " Hostname: %s (rc=%d)\n", gLib
.ourHostName
, gLib
.hresult
);
147 cp
= (const char *) getenv("TERM");
150 (void) fprintf(fp
, " Terminal: %s\n", cp
);
165 if ((gOurDirectoryPath
[0] == '\0') || (gTraceFile
== NULL
))
168 (void) sprintf(tName
, "trace.%u", (unsigned int) getpid());
169 (void) OurDirectoryPath(pathName
, sizeof(pathName
), tName
);
170 (void) OurDirectoryPath(pathName2
, sizeof(pathName2
), kTraceFileName
);
172 (void) time(&gTraceTime
);
173 (void) fprintf(gTraceFile
, "SESSION ENDED at: %s", ctime(&gTraceTime
));
174 (void) fclose(gTraceFile
);
176 (void) unlink(pathName2
);
177 (void) rename(pathName
, pathName2
);