Line | |
---|
1 | #include "NvEventLog.h" |
---|
2 | #include "config.h" |
---|
3 | #include <stdio.h> |
---|
4 | #include <assert.h> |
---|
5 | #include <sys/time.h> |
---|
6 | #include <sys/types.h> |
---|
7 | #include <unistd.h> |
---|
8 | #include <fcntl.h> |
---|
9 | #include <stdlib.h> |
---|
10 | #include <string.h> |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | #ifdef XINETD |
---|
15 | FILE* xinetd_log; |
---|
16 | #endif |
---|
17 | |
---|
18 | FILE* event_log; |
---|
19 | double cur_time; //in seconds |
---|
20 | |
---|
21 | #ifdef XINETD |
---|
22 | void NvInitService() |
---|
23 | { |
---|
24 | const char* user = getenv("USER"); |
---|
25 | char* logName = NULL; |
---|
26 | int logNameLen = 0; |
---|
27 | extern int debug_flag; |
---|
28 | |
---|
29 | if (user == NULL) { |
---|
30 | logNameLen = 20+1; |
---|
31 | logName = (char*) calloc(logNameLen,sizeof(char)); |
---|
32 | strncpy(logName,"/tmp/nanovis_log.txt",logNameLen); |
---|
33 | } |
---|
34 | else { |
---|
35 | logNameLen = 17+1+strlen(user); |
---|
36 | logName = (char*) calloc(logNameLen,sizeof(char)); |
---|
37 | strncpy(logName,"/tmp/nanovis_log_",logNameLen); |
---|
38 | strncat(logName,user,strlen(user)); |
---|
39 | } |
---|
40 | |
---|
41 | if (!debug_flag) { |
---|
42 | //open log and map stderr to log file |
---|
43 | xinetd_log = fopen(logName, "w"); |
---|
44 | close(2); |
---|
45 | dup2(fileno(xinetd_log), 2); |
---|
46 | dup2(2,1); |
---|
47 | //flush junk |
---|
48 | fflush(stdout); |
---|
49 | fflush(stderr); |
---|
50 | } |
---|
51 | |
---|
52 | // clean up malloc'd memory |
---|
53 | if (logName != NULL) { |
---|
54 | free(logName); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | void NvExitService() |
---|
59 | { |
---|
60 | //close log file |
---|
61 | fclose(xinetd_log); |
---|
62 | } |
---|
63 | #endif |
---|
64 | |
---|
65 | void NvInitEventLog() |
---|
66 | { |
---|
67 | event_log = fopen("event.txt", "w"); |
---|
68 | assert(event_log!=0); |
---|
69 | |
---|
70 | struct timeval time; |
---|
71 | gettimeofday(&time, NULL); |
---|
72 | cur_time = time.tv_sec*1000. + time.tv_usec/1000.; |
---|
73 | } |
---|
74 | |
---|
75 | void NvExitEventLog() |
---|
76 | { |
---|
77 | fclose(event_log); |
---|
78 | } |
---|
79 | |
---|
80 | double NvGetTimeInterval() |
---|
81 | { |
---|
82 | struct timeval time; |
---|
83 | gettimeofday(&time, NULL); |
---|
84 | double new_time = time.tv_sec*1000. + time.tv_usec/1000.; |
---|
85 | |
---|
86 | double interval = new_time - cur_time; |
---|
87 | cur_time = new_time; |
---|
88 | return interval; |
---|
89 | } |
---|
90 | |
---|
Note: See
TracBrowser
for help on using the repository browser.