lcr work (soon done :)
[lcr.git] / main.c
diff --git a/main.c b/main.c
index 24c0039..ac23868 100644 (file)
--- a/main.c
+++ b/main.c
@@ -38,8 +38,9 @@ struct lcr_fdset lcr_fdset[FD_SETSIZE];
 #endif
 
 pthread_mutex_t mutexd; // debug output mutex
-//pthread_mutex_t mutext; // trace output mutex
+pthread_mutex_t mutext; // trace output mutex
 pthread_mutex_t mutexe; // error output mutex
+//pthread_mutex_t mutex_lcr; // lcr process mutex
 
 int memuse = 0;
 int mmemuse = 0;
@@ -175,7 +176,7 @@ void sighandler(int sigset)
                return;
        if (!quit)
        {
-               quit=1;
+               quit = sigset;
                /* set scheduler & priority */
                if (options.schedule > 1)
                {
@@ -184,7 +185,7 @@ void sighandler(int sigset)
                        sched_setscheduler(0, SCHED_OTHER, &schedp);
                }
                fprintf(stderr, "LCR: Signal received: %d\n", sigset);
-               PERROR("Signal received: %d\n", sigset);
+               PDEBUG(DEBUG_LOG, "Signal received: %d\n", sigset);
        }
 }
 
@@ -196,7 +197,7 @@ int main(int argc, char *argv[])
 {
        int                     ret = -1;
        int                     lockfd = -1; /* file lock */
-       struct message          *message;
+       struct lcr_msg          *message;
        class Port              *port;
        class Endpoint          *epoint;
        class Join              *join;
@@ -206,7 +207,8 @@ int main(int argc, char *argv[])
        struct sched_param      schedp;
        char                    *debug_prefix = "alloc";
        int                     created_mutexd = 0,/* created_mutext = 0,*/ created_mutexe = 0,
-                               created_lock = 0, created_signal = 0, created_debug = 0;
+                               created_lock = 0, created_signal = 0, created_debug = 0,
+                               created_misdn = 0;
        int                     idletime = 0, idlecheck = 0;
        char                    tracetext[256];
 
@@ -215,6 +217,9 @@ int main(int argc, char *argv[])
        memset(lcr_fdset, 0, sizeof(lcr_fdset));
 #endif
 
+       /* lock LCR process */
+//     pthread_mutex_lock(&mutex_lcr);
+
        /* current time */
        GET_NOW();
 
@@ -303,6 +308,7 @@ int main(int argc, char *argv[])
        /* init mISDN */
        if (mISDN_initialize() < 0)
                goto free;
+       created_misdn = 1;
        created_debug = 1;
 
        /* read ruleset(s) */
@@ -469,6 +475,7 @@ int main(int argc, char *argv[])
        quit = 0;
        while(!quit)
        {
+
                last_d = now_d;
                GET_NOW();
                if (now_d-last_d > 1.0)
@@ -643,15 +650,17 @@ BUDETECT
                /* did we do nothing? so we wait to give time to other processes */
                if (all_idle)
                {
+//                     pthread_mutex_unlock(&mutex_lcr); // unlock LCR
                        debug_usleep(4000, __FILE__, __LINE__, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec);
+//                     pthread_mutex_lock(&mutex_lcr); // lock LCR
                        idletime += 4000;
                }
        }
        SPRINT(tracetext, "%s terminated", NAME);
        printf("%s\n", tracetext);
        start_trace(0, NULL, NULL, NULL, 0, 0, 0, tracetext);
-       if (ret)
-               add_trace("error", NULL, "%d", ret);
+       if (quit)
+               add_trace("signal", NULL, "%d", quit);
        end_trace();
        ret=0;
 
@@ -744,7 +753,8 @@ free:
                        fprintf(stderr, "cannot destroy 'PDEBUG' mutex\n");
 
        /* deinitialize mISDN */
-       mISDN_deinitialize();
+       if (created_misdn)
+               mISDN_deinitialize();
 
        /* display memory leak */
 #define MEMCHECK(a, b) \
@@ -770,6 +780,9 @@ free:
        MEMCHECK("file descriptor(s) left",fduse)
        MEMCHECK("file handler(s) left",fhuse)
 
+       /* unlock LCR process */
+//     pthread_mutex_unlock(&mutex_lcr);
+
        /* take me out */
        return(ret);
 }