summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch')
-rw-r--r--meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch325
1 files changed, 325 insertions, 0 deletions
diff --git a/meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch b/meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch
new file mode 100644
index 0000000000..ee997fd28f
--- /dev/null
+++ b/meta/recipes-extended/xinetd/xinetd/0001-Use-monotonic-time.patch
@@ -0,0 +1,325 @@
1From 753aa53e817d29e979c2a2fca7da40a3d115f93c Mon Sep 17 00:00:00 2001
2From: Li Wang <li.wang@windriver.com>
3Date: Tue, 3 Sep 2024 15:21:52 +0800
4Subject: [PATCH] Use monotonic time
5
6When using xinet.d to limit rsync connections, it can't handle changes
7in system time. When time is set back, the connection limit is reached
8very quickly and rsync gets deactivated, if time is changed again, rsync
9is never reactivated.
10
11The current timer of xinet.d is based on the time() and is affected by
12the system time. Use clock_gettime() with CLOCK_MONOTONIC as the new
13timer because CLOCK_MONOTONIC clock is not affected by discontinuous
14jumps in the system time.
15
16Upstream-Status: Submitted [https://github.com/openSUSE/xinetd/pull/48]
17
18Signed-off-by: Li Wang <li.wang@windriver.com>
19---
20 src/access.c | 6 +++---
21 src/builtins.c | 5 +++--
22 src/internals.c | 2 +-
23 src/log.c | 3 ++-
24 src/sensor.c | 6 +++---
25 src/server.c | 3 ++-
26 src/service.c | 5 +++--
27 src/signals.c | 2 +-
28 src/time.c | 3 ++-
29 src/xlog/filelog.c | 3 ++-
30 src/xtimer.c | 15 ++++++++++++---
31 src/xtimer.h | 1 +
32 12 files changed, 35 insertions(+), 19 deletions(-)
33
34diff --git a/src/access.c b/src/access.c
35index e942db7..eb9da6e 100644
36--- a/src/access.c
37+++ b/src/access.c
38@@ -70,7 +70,7 @@ static void cps_service_restart(void)
39 time_t nowtime;
40 const char *func = "cps_service_restart";
41
42- nowtime = time(NULL);
43+ nowtime = _time(NULL);
44 for( i=0; i < pset_count( SERVICES(ps) ); i++ ) {
45 struct service *sp;
46 struct service_config *scp;
47@@ -104,7 +104,7 @@ void cps_service_stop(struct service *sp, const char *reason)
48 msg(LOG_ERR, "service_stop",
49 "Deactivating service %s due to %s. Restarting in %d seconds.",
50 SC_NAME(scp), reason, (int)SC_TIME_WAIT(scp));
51- nowtime = time(NULL);
52+ nowtime = _time(NULL);
53 SC_TIME_REENABLE(scp) = nowtime + SC_TIME_WAIT(scp);
54 xtimer_add(cps_service_restart, SC_TIME_WAIT(scp));
55 }
56@@ -284,7 +284,7 @@ access_e parent_access_control( struct service *sp, const connection_s *cp )
57 /* CPS handler */
58 if( SC_TIME_CONN_MAX(scp) != 0 ) {
59 int time_diff;
60- nowtime = time(NULL);
61+ nowtime = _time(NULL);
62 time_diff = nowtime - SC_TIME_LIMIT(scp) ;
63
64 if( SC_TIME_CONN(scp) == 0 ) {
65diff --git a/src/builtins.c b/src/builtins.c
66index 042e5dc..c285a02 100644
67--- a/src/builtins.c
68+++ b/src/builtins.c
69@@ -36,6 +36,7 @@
70 #include "nvlists.h"
71 #include "child.h"
72 #include "access.h"
73+#include "xtimer.h"
74
75 #define BUFFER_SIZE 1024
76
77@@ -237,7 +238,7 @@ static void daytime_protocol( char *buf, unsigned int *buflen )
78 int size = *buflen ;
79 int cc ;
80
81- (void) time( &now ) ;
82+ (void) _time( &now ) ;
83 tmp = localtime( &now ) ;
84 cc = strx_nprint( buf, size,
85 "%02d %s %d %02d:%02d:%02d",
86@@ -308,7 +309,7 @@ static void time_protocol( unsigned char *timep )
87 time_t now ;
88 unsigned long base1900;
89
90- (void) time( &now ) ;
91+ (void) _time( &now ) ;
92 base1900 = (unsigned long)now + TIME_OFFSET ;
93 timep[0] = base1900 >> 24;
94 timep[1] = base1900 >> 16;
95diff --git a/src/internals.c b/src/internals.c
96index c5ed4f8..6a19207 100644
97--- a/src/internals.c
98+++ b/src/internals.c
99@@ -85,7 +85,7 @@ void dump_internal_state(void)
100 * Print the program name, version, and timestamp.
101 * Note that the program_version variable contains the program name.
102 */
103- (void) time( &current_time ) ;
104+ (void) _time( &current_time ) ;
105 Sprint( dump_fd, "INTERNAL STATE DUMP: %s\n", program_version ) ;
106 Sprint( dump_fd, "Current time: %s\n", ctime( &current_time ) ) ;
107
108diff --git a/src/log.c b/src/log.c
109index b66ab24..7aba30d 100644
110--- a/src/log.c
111+++ b/src/log.c
112@@ -21,6 +21,7 @@
113 #include "sconf.h"
114 #include "sconst.h"
115 #include "msg.h"
116+#include "xtimer.h"
117
118
119 #define LOGBUF_SIZE 1024
120@@ -202,7 +203,7 @@ void svc_log_exit( struct service *sp, const struct server *serp )
121 {
122 time_t current_time ;
123
124- (void) time( &current_time ) ;
125+ (void) _time( &current_time ) ;
126 cc = strx_nprint( &buf[ len ], bufsize, " duration=%ld(sec)",
127 (long)(current_time - SERVER_STARTTIME( serp )) ) ;
128 len += cc ;
129diff --git a/src/sensor.c b/src/sensor.c
130index cd85806..24bd816 100644
131--- a/src/sensor.c
132+++ b/src/sensor.c
133@@ -68,7 +68,7 @@ void process_sensor( const struct service *sp, const union xsockaddr *addr)
134 time_t nowtime;
135 char time_buf[40], *tmp;
136
137- nowtime = time(NULL);
138+ nowtime = _time(NULL);
139 msg(LOG_CRIT, func,
140 "Adding %s to the global_no_access list for %d minutes",
141 dup_addr, SC_DENY_TIME(SVC_CONF(sp)));
142@@ -113,7 +113,7 @@ void process_sensor( const struct service *sp, const union xsockaddr *addr)
143 {
144 time_t nowtime, new_time;
145
146- nowtime = time(NULL);
147+ nowtime = _time(NULL);
148 new_time = (time_t)nowtime+(60*SC_DENY_TIME(SVC_CONF(sp))); if (difftime(new_time, (time_t)stored_time) > 0.0)
149 { /* new_time is longer save it */
150 char time_buf[40], *new_exp_time;
151@@ -163,7 +163,7 @@ static void scrub_global_access_list( void )
152 {
153 int found_one = 0;
154 unsigned u;
155- time_t nowtime = time(NULL);
156+ time_t nowtime = _time(NULL);
157
158 for (u=0; u < count; u++)
159 {
160diff --git a/src/server.c b/src/server.c
161index 4c4a2b8..e201a57 100644
162--- a/src/server.c
163+++ b/src/server.c
164@@ -30,6 +30,7 @@
165 #include "retry.h"
166 #include "child.h"
167 #include "signals.h"
168+#include "xtimer.h"
169
170
171 #define NEW_SERVER() NEW( struct server )
172@@ -228,7 +229,7 @@ status_e server_start( struct server *serp )
173 return( FAILED ) ;
174
175 default:
176- (void) time( &SERVER_STARTTIME(serp) ) ;
177+ (void) _time( &SERVER_STARTTIME(serp) ) ;
178 SVC_INC_RUNNING_SERVERS( sp ) ;
179
180 /*
181diff --git a/src/service.c b/src/service.c
182index 93c2162..04422c3 100644
183--- a/src/service.c
184+++ b/src/service.c
185@@ -43,6 +43,7 @@
186 #include "logctl.h"
187 #include "xconfig.h"
188 #include "special.h"
189+#include "xtimer.h"
190
191
192 #define NEW_SVC() NEW( struct service )
193@@ -840,7 +841,7 @@ static status_e failed_service(struct service *sp,
194 SVC_LAST_DGRAM_ADDR(sp) = (union xsockaddr *)last;
195 }
196
197- (void) time( &current_time ) ;
198+ (void) _time( &current_time ) ;
199 if ( sinp->sin_addr.s_addr == last->sin_addr.s_addr &&
200 sinp->sin_port == last->sin_port )
201 {
202@@ -867,7 +868,7 @@ static status_e failed_service(struct service *sp,
203 SVC_LAST_DGRAM_ADDR( sp ) = (union xsockaddr *)last;
204 }
205
206- (void) time( &current_time ) ;
207+ (void) _time( &current_time ) ;
208 if ( IN6_ARE_ADDR_EQUAL(&(sinp->sin6_addr), &(last->sin6_addr)) &&
209 sinp->sin6_port == last->sin6_port )
210 {
211diff --git a/src/signals.c b/src/signals.c
212index 3c42db3..4160e6d 100644
213--- a/src/signals.c
214+++ b/src/signals.c
215@@ -301,7 +301,7 @@ static void bad_signal(void)
216 else if ( total_signal_count > MAX_SIGNAL_COUNT )
217 _exit( 1 ) ; /* in case of a problem in exit(3) */
218
219- (void) time( &current_time ) ;
220+ (void) _time( &current_time ) ;
221
222 if ( interval_signal_count > 0 &&
223 current_time - interval_start <= SIGNAL_INTERVAL )
224diff --git a/src/time.c b/src/time.c
225index a4d63fb..68142b0 100644
226--- a/src/time.c
227+++ b/src/time.c
228@@ -16,6 +16,7 @@
229 #include "timex.h"
230 #include "msg.h"
231 #include "util.h"
232+#include "xtimer.h"
233
234
235 #define IN_RANGE( val, low, high ) ( (low) <= (val) && (val) <= (high) )
236@@ -41,7 +42,7 @@ bool_int ti_current_time_check( const pset_h intervals )
237 int16_t min_current ;
238 struct tm *tmp ;
239
240- (void) time( &current_time ) ;
241+ (void) _time( &current_time ) ;
242 tmp = localtime( &current_time ) ;
243 min_current = tmp->tm_hour * 60 + tmp->tm_min ;
244
245diff --git a/src/xlog/filelog.c b/src/xlog/filelog.c
246index ee688e5..46cf1e2 100644
247--- a/src/xlog/filelog.c
248+++ b/src/xlog/filelog.c
249@@ -25,6 +25,7 @@
250 #include "str.h"
251 #include "xlog.h"
252 #include "filelog.h"
253+#include "xtimer.h"
254
255 static int filelog_init(xlog_s *, va_list) ;
256 static void filelog_fini(xlog_s *) ;
257@@ -190,7 +191,7 @@ static int filelog_write( xlog_s *xp, const char buf[], int len, int flags,
258 if ( flp->fl_state != FL_OPEN )
259 return( flp->fl_error ) ;
260
261- (void) time( &current_time ) ;
262+ (void) _time( &current_time ) ;
263 tmp = localtime( &current_time ) ;
264 cc = Sprint( flp->fl_fd, "%02d/%d/%d@%02d:%02d:%02d",
265 tmp->tm_year%100, tmp->tm_mon+1, tmp->tm_mday,
266diff --git a/src/xtimer.c b/src/xtimer.c
267index 2053ef4..7a125d8 100644
268--- a/src/xtimer.c
269+++ b/src/xtimer.c
270@@ -11,6 +11,15 @@
271 #include "pset.h"
272 #include "msg.h"
273
274+time_t _time(time_t *t)
275+{
276+ struct timespec ts;
277+ clock_gettime(CLOCK_MONOTONIC, &ts);
278+ if(t)
279+ *t = ts.tv_sec;
280+ return ts.tv_sec;
281+}
282+
283 /* A note on the usage of timers in these functions:
284 * The timers are composed of 3 elements, a pointer to a callback function,
285 * the expire time of the timer, and a unique (pseudo-monotomically increasing)
286@@ -68,7 +77,7 @@ int xtimer_add( void (*func)(void), time_t secs )
287 return -1;
288 }
289
290- tmptime = time(NULL);
291+ tmptime = _time(NULL);
292 if( tmptime == -1 ) {
293 free( new_xtimer );
294 return -1;
295@@ -107,7 +116,7 @@ int xtimer_poll(void)
296
297 for( i = 0; i < pset_count( xtimer_list ); i++ ) {
298 xtime_h *cur_timer = pset_pointer( xtimer_list, i );
299- time_t cur_time = time(NULL);
300+ time_t cur_time = _time(NULL);
301
302 /* The list is sorted, low to high. If there's no
303 * timers left, return.
304@@ -163,7 +172,7 @@ time_t xtimer_nexttime(void)
305 if( pset_count(xtimer_list) == 0 )
306 return -1;
307
308- ret = ((xtime_h *)pset_pointer(xtimer_list, 0))->when - time(NULL) ;
309+ ret = ((xtime_h *)pset_pointer(xtimer_list, 0))->when - _time(NULL) ;
310 if( ret < 0 )
311 ret = 0;
312 return( ret );
313diff --git a/src/xtimer.h b/src/xtimer.h
314index b0f8451..3ba0d0a 100644
315--- a/src/xtimer.h
316+++ b/src/xtimer.h
317@@ -22,4 +22,5 @@ int xtimer_poll(void);
318 int xtimer_remove(int);
319 time_t xtimer_nexttime(void);
320
321+time_t _time(time_t *t);
322 #endif /* _X_TIMER_H */
323--
3242.34.1
325