OSSP CVS Repository

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

ossp-pkg/l2/l2_env.c 1.3 -> 1.4

--- l2_env.c     2001/11/07 11:37:18     1.3
+++ l2_env.c     2001/11/16 19:45:12     1.4
@@ -49,6 +49,7 @@
     env->szError[0] = '\0';
     env->levelmask = L2_LEVEL_ALL;
     env->flushmask = L2_LEVEL_NONE;
+    env->interval  = 0;
     for (i = 0; i < L2_MAX_FORMATTERS; i++)
         env->formatters[i].cb = NULL;
     for (i = 0; i < L2_MAX_HANDLERS; i++)
@@ -212,3 +213,65 @@
     return env->szError;
 }
 
+/* sets the virtual timer to the interval value in env */
+static int set_alarm(l2_env_t *env)
+{
+#if defined(HAVE_SETITIMER) && defined(HAVE_SYS_TIME_H)
+    struct itimerval valtest, valnew;
+
+    /* initialize auto vars before using them */
+    memset(&valnew, 0, sizeof(valnew));
+
+    valnew.it_interval.tv_sec = (long)env->interval;
+    valnew.it_interval.tv_usec = 0L;       /* no microsecond granularity */
+    valnew.it_value.tv_sec = (long)env->interval;
+    valnew.it_value.tv_usec = 0L;          /* no microsecond granularity */
+    if ((getitimer(L2_BUFFER_TIMER, &valtest) == 0) &&
+       ((valtest.it_value.tv_sec | valtest.it_value.tv_usec |
+       valtest.it_interval.tv_sec | valtest.it_interval.tv_usec) == 0L))
+        return (setitimer(L2_BUFFER_TIMER, &valnew, 0) ? L2_ERR_INT : L2_OK);
+    else {
+        env->interval = L2_BROKEN_TIMER;    /* mark this timer as broken */
+        assert(FALSE);     /* throw the switch right away when debugging */
+        return L2_ERR_ARG;
+    }
+#else
+    unsigned int uiAlarmed = 0;
+
+    assert(env->interval >= 0);          /* guard against a broken timer */
+    assert(!(uiAlarmed = alarm((unsigned int)iInterval)));
+    if (uiAlarmed) {             /* check if SIGALRM is occupied         */
+        alarm(uiAlarmed);        /* ...if so, then hack in the old value */
+        env->interval = L2_BROKEN_TIMER; /* ...mark this timer as broken */
+        return L2_ERR_INT;
+    }
+    else
+        return L2_OK;
+#endif
+}
+
+/* l2_env_settimer will change or disappear with  */
+/* the arrival of the multiplexed L2 timer object */
+/* set the L2 timer */
+l2_result_t l2_env_settimer(l2_env_t *env, int iInterval)
+{
+    if ((env == NULL) || (iInterval < 0))  /* argument sanity check */
+        return L2_ERR_ARG;
+
+    /* short circuit if setting again with identical interval value */
+    if (env->interval == iInterval)
+        return L2_OK;
+
+                    /* one value only, no multiplexed timer support */
+    if (env->interval != 0)      /* && (env->interval != iInterval) */
+        return L2_ERR_ARG;
+
+    env->interval = iInterval;
+    if (set_alarm(env) != L2_OK) {
+        env->interval = L2_BROKEN_TIMER;      /* L2 timer is broken */
+        return L2_ERR_INT;
+    }
+    else
+        return L2_OK;
+}
+

CVSTrac 2.0.1