fixup
[lcr.git] / trace.c
diff --git a/trace.c b/trace.c
index 73686ff..0d6c114 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -22,6 +22,8 @@ static const char *spaces = "          ";
  */
 void _start_trace(const char *__file, int __line, int port, struct interface *interface, const char *caller, const char *dialing, int direction, int category, int serial, const char *name)
 {
+       struct timeval current_time;
+
        if (trace.name[0])
                PERROR("trace already started (name=%s) in file %s line %d\n", trace.name, __file, __line);
        memset(&trace, 0, sizeof(struct trace));
@@ -39,8 +41,9 @@ void _start_trace(const char *__file, int __line, int port, struct interface *in
                SCPY(trace.name, name);
        if (!trace.name[0])
                SCPY(trace.name, "<unknown>");
-       trace.sec = now_tv.tv_sec;
-       trace.usec = now_tv.tv_usec;
+       gettimeofday(&current_time, NULL);
+       trace.sec = current_time.tv_sec;
+       trace.usec = current_time.tv_usec;
 }
 
 
@@ -89,7 +92,9 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        char buffer[256];
        time_t ti = trace.sec;
        struct tm *tm;
+#ifdef WITH_MISDN
        struct mISDNport *mISDNport;
+#endif
        int i;
 
        trace_string[0] = '\0'; // always clear string
@@ -112,6 +117,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        /* head */
        if (detail >= 3) {
                SCAT(trace_string, "------------------------------------------------------------------------------\n");
+#ifdef WITH_MISDN
                /* "Port: 1 (BRI PTMP TE)" */
                if (trace.port >= 0) {
                        mISDNport = mISDNport_first;
@@ -129,6 +135,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
                                SPRINT(buffer, "Port: %d (does not exist)\n", trace.port);
                        SCAT(trace_string, buffer);
                } else
+#endif
                        SCAT(trace_string, "Port: ---");
 
                if (trace.interface[0]) {
@@ -195,6 +202,10 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        /* elements */
        switch(detail) {
                case 1: /* brief */
+               if (trace.interface[0]) {
+                       SPRINT(buffer, "  iface %s", trace.interface);
+                       SCAT(trace_string, buffer);
+               }
                if (trace.port >= 0) {
                        SPRINT(buffer, "  port %d", trace.port);
                        SCAT(trace_string, buffer);
@@ -261,6 +272,7 @@ void _end_trace(const char *__file, int __line)
        FILE *fp;
        struct admin_list       *admin;
        struct admin_queue      *response, **responsep; /* response pointer */
+       int __attribute__((__unused__)) ret;
 
        if (!trace.name[0])
                PERROR("trace not started in file %s line %d\n", __file, __line);
@@ -270,12 +282,12 @@ void _end_trace(const char *__file, int __line)
                if (string) {
                        /* process debug */
                        if (options.deb)
-                               debug(NULL, 0, "trace", string);
+                               debug(NULL, NULL, 0, "TRACE", string);
                        /* process log */
                        if (options.log[0]) {
                                fp = fopen(options.log, "a");
                                if (fp) {
-                                       fwrite(string, strlen(string), 1, fp);
+                                       ret = fwrite(string, strlen(string), 1, fp);
                                        fclose(fp);
                                }
                        }
@@ -307,6 +319,7 @@ void _end_trace(const char *__file, int __line)
                                /* attach to response chain */
                                *responsep = response;
                                responsep = &response->next;
+                               admin->fd.when |= LCR_FD_WRITE;
                        }
                }
                admin = admin->next;