ReactOS 0.4.16-dev-2104-gb84fa49
trace.c
Go to the documentation of this file.
1/* trace.c
2 *
3 * Copyright (c) 1992-2001 by Mike Gleason.
4 * All rights reserved.
5 *
6 */
7
8#include "syshdrs.h"
9
10#include "trace.h"
11#include "util.h"
12
13/* Saves their session in a ~/.ncftp/trace file.
14 * This is nice for me when I need to diagnose problems.
15 */
18char gTraceLBuf[256];
19int gDebug = 0;
20
21extern FTPLibraryInfo gLib;
23extern char gVersion[], gOS[];
24extern char gOurDirectoryPath[];
25
26
27
28/*VARARGS*/
29void
30Trace(const int level, const char *const fmt, ...)
31{
32 va_list ap;
33 char buf[512];
34 struct tm *ltp;
35
36 if ((gDebug >= level) || (level > 8)) {
37 va_start(ap, fmt);
38#ifdef HAVE_VSNPRINTF
39 (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
40 buf[sizeof(buf) - 1] = '\0';
41#else
42 (void) vsprintf(buf, fmt, ap);
43#endif
44 va_end(ap);
45
47 ltp = localtime(&gTraceTime);
48 if ((gTraceFile != NULL) && (ltp != NULL)) {
49 (void) fprintf(gTraceFile , "%02d:%02d:%02d %s",
50 ltp->tm_hour,
51 ltp->tm_min,
52 ltp->tm_sec,
53 buf
54 );
55 }
56 if (gDebug > level) {
57 (void) fprintf(stdout, "%s", buf);
58 }
59 }
60} /* Trace */
61
62
63
64
65void
66ErrorHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
67{
68 LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
69
70 /* Will also get Trace'd. */
71 (void) fprintf(stdout, "%s", msg);
72} /* ErrorHook */
73
74
75
76
77void
78DebugHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
79{
80 LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
81 Trace(0, "%s", msg);
82} /* DebugHook */
83
84
85
86
87void
89{
90 gDebug = i;
91} /* SetDebug */
92
93
94
95
96void
98{
102 gConn.errLog = NULL;
103} /* UseTrace */
104
105
106
107
108void
110{
111 FILE *fp;
112 char pathName[256];
113 char tName[32];
114 int pid;
115 const char *cp;
116#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
117 struct utsname u;
118#endif
119
120 if (gOurDirectoryPath[0] == '\0')
121 return; /* Don't create in root directory. */
122
123 (void) sprintf(tName, "trace.%u", (unsigned int) (pid = getpid()));
124 (void) OurDirectoryPath(pathName, sizeof(pathName), tName);
125
126 fp = fopen(pathName, FOPEN_WRITE_TEXT);
127 if (fp != NULL) {
128 (void) _chmod(pathName, 00600);
129#ifdef HAVE_SETVBUF
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);
138 if (gOS[0] != '\0')
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);
143 }
144#endif /* UNAME */
146 (void) fprintf(fp, " Hostname: %s (rc=%d)\n", gLib.ourHostName, gLib.hresult);
147 cp = (const char *) getenv("TERM");
148 if (cp == NULL)
149 cp = "unknown?";
150 (void) fprintf(fp, " Terminal: %s\n", cp);
151 gTraceFile = fp;
152 }
153} /* OpenTrace */
154
155
156
157
158void
160{
161 char pathName[256];
162 char pathName2[256];
163 char tName[32];
164
165 if ((gOurDirectoryPath[0] == '\0') || (gTraceFile == NULL))
166 return;
167
168 (void) sprintf(tName, "trace.%u", (unsigned int) getpid());
169 (void) OurDirectoryPath(pathName, sizeof(pathName), tName);
170 (void) OurDirectoryPath(pathName2, sizeof(pathName2), kTraceFileName);
171
172 (void) time(&gTraceTime);
173 (void) fprintf(gTraceFile, "SESSION ENDED at: %s", ctime(&gTraceTime));
175
176 (void) unlink(pathName2);
177 (void) rename(pathName, pathName2);
178} /* CloseTrace */
#define kTraceFileName
Definition: trace.h:11
#define msg(x)
Definition: auth_time.c:54
#define UNUSED(x)
Definition: btrfs_drv.h:82
#define NULL
Definition: types.h:112
#define Trace(x)
Definition: inflate.c:42
char *CDECL getenv(const char *name)
Definition: environ.c:227
int CDECL fclose(FILE *file)
Definition: file.c:3757
int CDECL _chmod(const char *path, int flags)
Definition: file.c:1052
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
int CDECL rename(const char *oldpath, const char *newpath)
Definition: file.c:4973
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
int CDECL setvbuf(FILE *file, char *buf, int mode, size_t size)
Definition: file.c:5006
__time32_t time_t
Definition: corecrt.h:228
#define stdout
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl vsprintf(char *, const char *, va_list) __WINE_CRT_PRINTF_ATTR(2
#define _IOLBF
Definition: stdio.h:31
static struct tm * localtime(const time_t *t)
Definition: time.h:121
char * va_list
Definition: vadefs.h:50
GLint level
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define unlink
Definition: syshdrs.h:54
POINT cp
Definition: magnifier.c:59
__u16 ctime
Definition: mkdosfs.c:4
__u16 time
Definition: mkdosfs.c:8
char gLibNcFTPVersion[64]
Definition: ftp.c:11
void SetDebug(int i)
Definition: trace.c:88
FTPConnectionInfo gConn
Definition: main.c:37
FILE * gTraceFile
Definition: trace.c:17
char gOS[]
Definition: trace.c:23
FTPLibraryInfo gLib
Definition: main.c:36
time_t gTraceTime
Definition: trace.c:16
void OpenTrace(void)
Definition: trace.c:109
char gVersion[]
Definition: init.c:22
void ErrorHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
Definition: trace.c:66
int gDebug
Definition: trace.c:19
char gTraceLBuf[256]
Definition: trace.c:18
void DebugHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
Definition: trace.c:78
void UseTrace(void)
Definition: trace.c:97
char gOurDirectoryPath[]
Definition: util.c:17
void CloseTrace(void)
Definition: trace.c:159
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
#define sprintf
Definition: sprintf.c:45
#define FOPEN_WRITE_TEXT
Definition: syshdrs.h:83
void FTPInitializeOurHostName(const FTPLIPtr)
Definition: open.c:63
#define LIBNCFTP_USE_VAR(a)
Definition: ncftp.h:521
FTPLogProc errLogProc
Definition: ncftp.h:148
FILE * debugLog
Definition: ncftp.h:145
FILE * errLog
Definition: ncftp.h:146
FTPLogProc debugLogProc
Definition: ncftp.h:147
int hresult
Definition: ncftp.h:119
char ourHostName[64]
Definition: ncftp.h:118
Definition: dsound.c:943
int tm_hour
Definition: corecrt_wtime.h:14
int tm_sec
Definition: corecrt_wtime.h:12
int tm_min
Definition: corecrt_wtime.h:13
#define vsnprintf
Definition: tif_win32.c:406
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
#define getpid
Definition: wintirpc.h:52