aboutsummaryrefslogtreecommitdiffstats
path: root/mail/sendmail/files/patch-worker.c
blob: 8852ca003f7dbe1486a2b2c53184ea7d8cebadf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
--- libmilter/worker.c.orig 2007-12-03 23:06:05.000000000 +0100
+++ libmilter/worker.c  2009-06-15 09:46:29.000000000 +0200
@@ -328,6 +328,8 @@
    int dim_pfd = 0;
    bool rebuild_set = true;
    int pcnt = 0; /* error count for poll() failures */
+   time_t lastcheck;
+   int nfd = 0;
 
    Tskmgr.tm_tid = sthread_get_id();
    if (pthread_detach(Tskmgr.tm_tid) != 0)
@@ -345,12 +347,12 @@
    }
    dim_pfd = PFD_STEP;
 
+   lastcheck = time(NULL);
    for (;;)
    {
        SMFICTX_PTR ctx;
-       int nfd, rfd, i;
+       int rfd, i;
        time_t now;
-       time_t lastcheck;
 
        POOL_LEV_DPRINTF(4, ("Let's %s again...", WAITFN));
 
@@ -364,20 +366,20 @@
        /* check for timed out sessions? */
        if (lastcheck + DT_CHECK_OLD_SESSIONS < now)
        {
-           SM_TAILQ_FOREACH(ctx, &WRK_CTX_HEAD, ctx_link)
+           ctx = SM_TAILQ_FIRST(&WRK_CTX_HEAD);
+           while (ctx != SM_TAILQ_END(&WRK_CTX_HEAD))
            {
+               SMFICTX_PTR ctx_nxt;
+
+               ctx_nxt = SM_TAILQ_NEXT(ctx, ctx_link);
                if (ctx->ctx_wstate == WKST_WAITING)
                {
                    if (ctx->ctx_wait == 0)
-                   {
                        ctx->ctx_wait = now;
-                       continue;
-                   }
-
-                   /* if session timed out, close it */
-                   if (ctx->ctx_wait + OLD_SESSION_TIMEOUT
-                       < now)
+                   else if (ctx->ctx_wait + OLD_SESSION_TIMEOUT
+                        < now)
                    {
+                       /* if session timed out, close it */
                        sfsistat (*fi_close) __P((SMFICTX *));
 
                        POOL_LEV_DPRINTF(4,
@@ -389,10 +391,9 @@
                            (void) (*fi_close)(ctx);
 
                        mi_close_session(ctx);
-                       ctx = SM_TAILQ_FIRST(&WRK_CTX_HEAD);
-                       continue;
                    }
                }
+               ctx = ctx_nxt;
            }
            lastcheck = now;
        }
@@ -465,6 +466,7 @@
                    }
                }
            }
+           rebuild_set = false;
        }
 
        TASKMGR_UNLOCK();
--- libsharedmilter/worker.c.orig   2007-12-03 23:06:05.000000000 +0100
+++ libsharedmilter/worker.c    2009-06-15 09:46:29.000000000 +0200
@@ -328,6 +328,8 @@
    int dim_pfd = 0;
    bool rebuild_set = true;
    int pcnt = 0; /* error count for poll() failures */
+   time_t lastcheck;
+   int nfd = 0;
 
    Tskmgr.tm_tid = sthread_get_id();
    if (pthread_detach(Tskmgr.tm_tid) != 0)
@@ -345,12 +347,12 @@
    }
    dim_pfd = PFD_STEP;
 
+   lastcheck = time(NULL);
    for (;;)
    {
        SMFICTX_PTR ctx;
-       int nfd, rfd, i;
+       int rfd, i;
        time_t now;
-       time_t lastcheck;
 
        POOL_LEV_DPRINTF(4, ("Let's %s again...", WAITFN));
 
@@ -364,20 +366,20 @@
        /* check for timed out sessions? */
        if (lastcheck + DT_CHECK_OLD_SESSIONS < now)
        {
-           SM_TAILQ_FOREACH(ctx, &WRK_CTX_HEAD, ctx_link)
+           ctx = SM_TAILQ_FIRST(&WRK_CTX_HEAD);
+           while (ctx != SM_TAILQ_END(&WRK_CTX_HEAD))
            {
+               SMFICTX_PTR ctx_nxt;
+
+               ctx_nxt = SM_TAILQ_NEXT(ctx, ctx_link);
                if (ctx->ctx_wstate == WKST_WAITING)
                {
                    if (ctx->ctx_wait == 0)
-                   {
                        ctx->ctx_wait = now;
-                       continue;
-                   }
-
-                   /* if session timed out, close it */
-                   if (ctx->ctx_wait + OLD_SESSION_TIMEOUT
-                       < now)
+                   else if (ctx->ctx_wait + OLD_SESSION_TIMEOUT
+                        < now)
                    {
+                       /* if session timed out, close it */
                        sfsistat (*fi_close) __P((SMFICTX *));
 
                        POOL_LEV_DPRINTF(4,
@@ -389,10 +391,9 @@
                            (void) (*fi_close)(ctx);
 
                        mi_close_session(ctx);
-                       ctx = SM_TAILQ_FIRST(&WRK_CTX_HEAD);
-                       continue;
                    }
                }
+               ctx = ctx_nxt;
            }
            lastcheck = now;
        }
@@ -465,6 +466,7 @@
                    }
                }
            }
+           rebuild_set = false;
        }
 
        TASKMGR_UNLOCK();