OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_ch_buffer.c versions 1.25 and 1.26
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_ch_buffer.c 1.25 -> 1.26

--- l2_ch_buffer.c       2001/10/22 16:32:29     1.25
+++ l2_ch_buffer.c       2001/10/23 10:05:53     1.26
@@ -41,7 +41,7 @@
     char       *buf;
     int         bufpos;
     int         bufsize;
-    int         bufinterval;
+    long        bufinterval;
     struct      sigaction sigalrm;
 #ifdef HAVE_SETITIMER
     struct      itimerval valprev;
@@ -111,6 +111,9 @@
     L2_PARAM_SET(pa[2], levelflush, INT, &cfg->levelflush);
     L2_PARAM_END(pa[3]);
     rv = l2_util_setparams(pa, fmt, ap);
+    if (cfg->bufinterval == -1L) /* -1 is reserved by L2 */
+        return L2_ERR_ARG;       /* set_alarm() uses it  */
+
     if (cfg->bufsize < 0) 
         return L2_ERR_ARG;
 
@@ -124,7 +127,7 @@
 static int set_alarm(l2_ch_buffer_t *cfg)
 {
 #ifdef HAVE_INET_SETITIMER
-    struct itimerval valnew;
+    struct itimerval valtest, valnew;
 
     /* initialize auto vars before using them */
     memset(&valnew, 0, sizeof(valnew));
@@ -133,9 +136,23 @@
     valnew.it_interval.tv_usec = 0;
     valnew.it_value.tv_sec = cfg->bufinterval;
     valnew.it_value.tv_usec = 0;
-    return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev);
+    if  ((getitimer(L2_BUFFER_TIMER, &testval) == 0) &&
+        ((testval.it_value.tv_sec | testval.it_value.tv_usec |
+        testval.it_interval.tv_sec | testval.it_interval.tv_usec) == 0))
+        return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev);
+    else {
+        cfg->bufinterval = -1L; /* mark this timer as broken */
+        assert(FALSE);
+    }
 #else
-    alarm(cfg->bufinterval);
+    unsigned int uiAlarmed = 0;
+
+    uiAlarmed = alarm(cfg->bufinterval);
+    if (uiAlarmed) {            /* check if SIGALRM is occupied          */
+        alarm(uiAlarmed);       /* ...if so, then hack in the old value  */
+        cfg->bufinterval = -1L; /* ...mark this timer as broken          */
+        assert(FALSE);          /* ...and warn the user about problems   */
+    }
     return 0;
 #endif
 }
@@ -171,7 +188,7 @@
     struct sigaction locact;
     l2_result_t rv;
 
-    if (cfg->bufinterval != 0) {
+    if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
         /* initialize auto vars before using them */
         memset(&locact, 0, sizeof(locact));
 
@@ -184,7 +201,7 @@
         if (sigaction(SIGALRM, &locact, &cfg->sigalrm) < 0)
             return L2_ERR_SYS;
 
-        if (set_alarm(cfg))
+        if (set_alarm(cfg))      /* this is our own L2 set_alarm */
             return L2_ERR_SYS;
     }
 
@@ -259,7 +276,7 @@
     }
 
     /* reset the flush alarm timer to synchronize the buffer */
-    if (cfg->bufinterval != 0)
+    if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L))
         if (reset_alarm(cfg))
             return L2_ERR_SYS;
 
@@ -277,7 +294,7 @@
     l2_channel_t *downstream = l2_channel_downstream(ch);
     l2_result_t rv;
 
-    if (cfg->bufinterval != 0) {
+    if ((cfg->bufinterval != 0) && (cfg->bufinterval != -1L)) {
 #ifdef HAVE_INET_SETITIMER
         if (setitimer(L2_BUFFER_TIMER, &cfg->valprev, 0)) /* restore timer */
             return L2_ERR_SYS;

CVSTrac 2.0.1