Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit 3564e43

Browse files
authored
Merge pull request #2 from bocianu/usageLog
Usage log
2 parents 789613c + 77ad8eb commit 3564e43

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

tnfs/tnfsd/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ endif
2626
ifdef DEBUG
2727
EXFLAGS = -g -DDEBUG
2828
endif
29+
30+
ifdef USAGELOG
31+
LOGFLAGS = -DUSAGELOG
32+
endif
2933

30-
CFLAGS=$(FLAGS) $(EXFLAGS)
34+
CFLAGS=$(FLAGS) $(EXFLAGS) $(LOGFLAGS)
3135
OBJS=main.o datagram.o log.o session.o endian.o directory.o errortable.o tnfs_file.o chroot.o fileinfo.o $(EXOBJS)
3236

3337
all: $(OBJS)

tnfs/tnfsd/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ since I'm not sure chrooting is supported under Cygwin.
1616
To make a debug version, use 'make OS=osname DEBUG=yes'. This will add
1717
some extra debugging messages and add the -g flag to the compilation
1818
options.
19+
20+
To output basic usage log on stdout, use 'make OS=osname USAGELOG=yes'.
21+

tnfs/tnfsd/directory.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <stdbool.h>
3535

3636
#include "tnfs.h"
37+
#include "log.h"
3738
#include "config.h"
3839
#include "directory.h"
3940
#include "tnfs_file.h"
@@ -329,6 +330,7 @@ void tnfs_seekdir(Header *hdr, Session *s, unsigned char *databuf, int datasz)
329330
#ifdef DEBUG
330331
fprintf(stderr, "tnfs_seekdir to pos %u\n", pos);
331332
#endif
333+
332334
// We handle this differently depending on whether we've pre-loaded the directory or not
333335
if (s->dhandles[*databuf].entry_list == NULL)
334336
{
@@ -338,6 +340,12 @@ void tnfs_seekdir(Header *hdr, Session *s, unsigned char *databuf, int datasz)
338340
{
339341
s->dhandles[*databuf].current_entry = dirlist_get_node_at_index(s->dhandles[*databuf].entry_list, pos);
340342
}
343+
#ifdef USAGELOG
344+
if (pos == 0) {
345+
USGLOG(hdr, "Path changed to: %s", s->dhandles[*databuf].path);
346+
}
347+
#endif
348+
341349

342350
hdr->status = TNFS_SUCCESS;
343351
tnfs_send(s, hdr, NULL, 0);

tnfs/tnfsd/log.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* */
2626

2727
#include <stdio.h>
28+
#include <time.h>
2829
#include <stdlib.h>
2930
#include <stdarg.h>
3031
#include <sys/types.h>
@@ -56,6 +57,31 @@ void TNFSMSGLOG(Header *hdr, const char *msg, ...)
5657
#endif
5758
}
5859

60+
void USGLOG(Header *hdr, const char *msg, ...)
61+
{
62+
unsigned char *ip = (unsigned char *)&hdr->ipaddr;
63+
char buff[128];
64+
char sdate[20];
65+
struct tm *sTm;
66+
67+
time_t now = time (0);
68+
sTm = gmtime (&now);
69+
70+
strftime (sdate, sizeof(sdate), "%Y-%m-%d %H:%M:%S", sTm);
71+
72+
va_list vargs;
73+
va_start(vargs, msg);
74+
75+
vsnprintf(buff, sizeof(buff), msg, vargs);
76+
va_end(vargs);
77+
78+
fprintf(stderr, "%s|%d.%d.%d.%d|SID=%02x|%s\n", sdate, ip[0], ip[1], ip[2], ip[3], hdr->sid, buff);
79+
80+
#ifdef WIN32
81+
fflush(stderr);
82+
#endif
83+
}
84+
5985
void MSGLOG(in_addr_t ipaddr, const char *msg, ...)
6086
{
6187
unsigned char *ip = (unsigned char *)&ipaddr;

tnfs/tnfsd/log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
void die(const char *msg);
3434

3535
void TNFSMSGLOG(Header *hdr, const char *msg, ...);
36+
void USGLOG(Header *hdr, const char *msg, ...);
3637
void MSGLOG(in_addr_t ipaddr, const char *msg, ...);
3738
void LOG(const char *msg, ...);
3839

tnfs/tnfsd/session.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ int tnfs_mount(Header *hdr, unsigned char *buf, int bufsz)
137137
tnfs_send(s, hdr, repbuf, 4);
138138
#ifdef DEBUG
139139
TNFSMSGLOG(hdr, "Mounted %s OK, SID=%x", s->root, s->sid);
140+
#endif
141+
#ifdef USAGELOG
142+
USGLOG(hdr, "Session started at: %s", s->root);
140143
#endif
141144
}
142145
else
@@ -162,6 +165,9 @@ void tnfs_umount(Header *hdr, Session *s, int sindex)
162165
{
163166
#ifdef DEBUG
164167
TNFSMSGLOG(hdr, "Unmounting");
168+
#endif
169+
#ifdef USAGELOG
170+
USGLOG(hdr, "Unmounting session");
165171
#endif
166172
/* the response must be sent before we deallocate the
167173
* session */

tnfs/tnfsd/tnfs_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ void tnfs_open(Header *hdr, Session *s, unsigned char *buf, int bufsz)
112112
fprintf(stderr, "mode: %o\n", mode);
113113
fprintf(stderr, "open: fd=%d\n", fd);
114114
#endif
115+
#ifdef USAGELOG
116+
USGLOG(hdr, "File mounted: %s", (char *)buf + 4);
117+
#endif
118+
115119
if (fd <= 0)
116120
{
117121
hdr->status = tnfs_error(errno);

0 commit comments

Comments
 (0)