OSSP CVS Repository

ossp - Check-in [1181]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1181
Date: 2001-Oct-12 16:46:16 (local)
2001-Oct-12 14:46:16 (UTC)
User:ms
Branch:
Comment: Make usage of setitimer(2) dependent on if it exists on the target system. Quick hack, future fix will replace lost functionality by issuing a call to alarm(3) instead.
Tickets:
Inspections:
Files:
ossp-pkg/l2/configure.ac      1.11 -> 1.12     1 inserted, 1 deleted
ossp-pkg/l2/l2_ch_buffer.c      1.23 -> 1.24     26 inserted, 7 deleted

ossp-pkg/l2/configure.ac 1.11 -> 1.12

--- configure.ac 2001/10/06 14:33:09     1.11
+++ configure.ac 2001/10/12 14:46:16     1.12
@@ -81,7 +81,7 @@
 fi  
 AC_CHECK_LIB(socket, accept)
 
-AC_CHECK_FUNCS(inet_aton inet_pton inet_ntoa inet_ntop snprintf vsnprintf)
+AC_CHECK_FUNCS(inet_aton inet_pton inet_ntoa inet_ntop snprintf vsnprintf setitimer)
 
 sinclude(l2_ut_sa.ac)
 AC_CHECK_SA


ossp-pkg/l2/l2_ch_buffer.c 1.23 -> 1.24

--- l2_ch_buffer.c       2001/10/05 14:25:57     1.23
+++ l2_ch_buffer.c       2001/10/12 14:46:17     1.24
@@ -28,11 +28,13 @@
 */
 
 #include "l2.h"
-#include "l2_p.h"   /* for TRACE() */
+#include "l2_p.h"   /* for TRACE()                        */
 
 #include <string.h>
-#include <unistd.h> /* has setitime() in standard unix functions */
-#include <signal.h> /* for use of sigaction() and SIGALRM        */
+#include <unistd.h> /* for alarm() and setitime()         */
+#include <signal.h> /* for use of sigaction() and SIGALRM */
+
+#define L2_BUFFER_TIMER ITIMER_REAL /* calls to [s|g]etitimer() and alarm() */
 
 /* declare private channel configuration */
 typedef struct {
@@ -41,7 +43,9 @@
     int         bufsize;
     int         bufinterval;
     struct      sigaction sigalrm;
+#ifdef HAVE_SETITIMER
     struct      itimerval valprev;
+#endif
     int         levelflush;
     l2_level_t  level;
 } l2_ch_buffer_t;
@@ -79,7 +83,9 @@
     cfg->levelflush  = 0;
     cfg->level       = L2_LEVEL_NONE;
     memset(&cfg->sigalrm, 0, sizeof(cfg->sigalrm));
+#ifdef HAVE_SETITIMER
     memset(&cfg->valprev, 0, sizeof(cfg->valprev));
+#endif
 
     /* link private channel configuration into channel context */
     ctx->vp = cfg;
@@ -112,6 +118,7 @@
  ************************************************************/
 static int set_alarm(l2_ch_buffer_t *cfg)
 {
+#ifdef HAVE_INET_SETITIMER
     struct itimerval valnew;
 
     /* initialize auto vars before using them */
@@ -121,7 +128,10 @@
     valnew.it_interval.tv_usec = 0;
     valnew.it_value.tv_sec = cfg->bufinterval;
     valnew.it_value.tv_usec = 0;
-    return setitimer(ITIMER_REAL, &valnew, &cfg->valprev); /* set flush timer */
+    return setitimer(L2_BUFFER_TIMER, &valnew, &cfg->valprev);
+#else
+    return 0;
+#endif
 }
 
 /************************************************************
@@ -130,6 +140,7 @@
  ************************************************************/
 static int reset_alarm(l2_ch_buffer_t *cfg)
 {
+#ifdef HAVE_INET_SETITIMER
     struct itimerval valnew;
 
     /* initialize auto vars before using them */
@@ -139,7 +150,10 @@
     valnew.it_interval.tv_usec = 0;
     valnew.it_value.tv_sec = cfg->bufinterval;
     valnew.it_value.tv_usec = 0;
-    return setitimer(ITIMER_REAL, &valnew, 0); /* reset flush timer */
+    return setitimer(L2_BUFFER_TIMER, &valnew, 0);
+#else
+    return 0;
+#endif
 }
 
 /* open channel */
@@ -256,8 +270,13 @@
     l2_result_t rv;
 
     if (cfg->bufinterval != 0) {
-        setitimer(ITIMER_REAL, &cfg->valprev, 0); /* restore timer values */
-        /* restore previous signal context if previously saved & replaced    */
+#ifdef HAVE_INET_SETITIMER
+        if (setitimer(L2_BUFFER_TIMER, &cfg->valprev, 0)) /* restore timer */
+            return L2_ERR_SYS;
+#else
+        alarm(0);
+#endif
+        /* restore previous signal context if previously saved & replaced  */
         if (&cfg->sigalrm.sa_handler)
             if (sigaction(SIGALRM, &cfg->sigalrm, 0) < 0)
                 rv = L2_ERR_SYS;

CVSTrac 2.0.1