Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 275112 | Differences between
and this patch

Collapse All | Expand All

(-)net/uroute.c.prev (+12 lines)
Lines 74-82 Link Here
74
	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
74
	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
75
#define ADVANCE(x, n)	((x) += ROUNDUP((n)->sa_len))
75
#define ADVANCE(x, n)	((x) += ROUNDUP((n)->sa_len))
76
76
77
#ifdef RTF_CLONING
77
#define WRITABLE_FLAGS	(RTF_STATIC | RTF_LLINFO | RTF_REJECT | RTF_BLACKHOLE \
78
#define WRITABLE_FLAGS	(RTF_STATIC | RTF_LLINFO | RTF_REJECT | RTF_BLACKHOLE \
78
			    | RTF_PROTO1 | RTF_PROTO2 | RTF_CLONING \
79
			    | RTF_PROTO1 | RTF_PROTO2 | RTF_CLONING \
79
			    | RTF_XRESOLVE | RTF_UP | RTF_GATEWAY)
80
			    | RTF_XRESOLVE | RTF_UP | RTF_GATEWAY)
81
#else
82
#define WRITABLE_FLAGS	(RTF_STATIC | RTF_REJECT | RTF_BLACKHOLE \
83
			    | RTF_PROTO1 | RTF_PROTO2 \
84
			    | RTF_XRESOLVE | RTF_UP | RTF_GATEWAY)
85
#endif
80
86
81
struct route_flag {
87
struct route_flag {
82
	const char	*name;
88
	const char	*name;
Lines 92-106 static const struct route_flag route_fla Link Here
92
	FLAG(DYNAMIC),
98
	FLAG(DYNAMIC),
93
	FLAG(MODIFIED),
99
	FLAG(MODIFIED),
94
	FLAG(DONE),
100
	FLAG(DONE),
101
#ifdef RTF_CLONING
95
	FLAG(CLONING),
102
	FLAG(CLONING),
103
#endif
96
	FLAG(XRESOLVE),
104
	FLAG(XRESOLVE),
105
#ifdef RTF_LLINFO
97
	FLAG(LLINFO),
106
	FLAG(LLINFO),
107
#endif
98
	FLAG(STATIC),
108
	FLAG(STATIC),
99
	FLAG(BLACKHOLE),
109
	FLAG(BLACKHOLE),
100
	FLAG(PROTO2),
110
	FLAG(PROTO2),
101
	FLAG(PROTO1),
111
	FLAG(PROTO1),
102
	FLAG(PRCLONING),
112
	FLAG(PRCLONING),
113
#ifdef RTF_WASCLONED
103
	FLAG(WASCLONED),
114
	FLAG(WASCLONED),
115
#endif
104
	FLAG(PROTO3),
116
	FLAG(PROTO3),
105
	FLAG(PINNED),
117
	FLAG(PINNED),
106
	FLAG(LOCAL),
118
	FLAG(LOCAL),
(-)net/if_arp.c.prev (-42 / +62 lines)
Lines 68-74 Link Here
68
#include "structs/type/array.h"
68
#include "structs/type/array.h"
69
69
70
#include "net/if_util.h"
70
#include "net/if_util.h"
71
#include "net/uroute.h"
72
#include "util/typed_mem.h"
71
#include "util/typed_mem.h"
73
72
74
#define ROUNDUP(a) \
73
#define ROUNDUP(a) \
Lines 124-130 if_get_arp(struct in_addr ip, u_char *et Link Here
124
	mib[2] = 0;
123
	mib[2] = 0;
125
	mib[3] = AF_INET;
124
	mib[3] = AF_INET;
126
	mib[4] = NET_RT_FLAGS;
125
	mib[4] = NET_RT_FLAGS;
126
#ifdef RTF_LLINFO
127
	mib[5] = RTF_LLINFO;
127
	mib[5] = RTF_LLINFO;
128
#else
129
	mib[5] = 0;
130
#endif
128
	if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
131
	if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
129
		return (-1);
132
		return (-1);
130
	needed += 128;
133
	needed += 128;
Lines 227-235 tryagain: Link Here
227
	sdl = (struct sockaddr_dl *)(void *)
230
	sdl = (struct sockaddr_dl *)(void *)
228
	    (ROUNDUP(sin->sin_len) + (char *)sin);
231
	    (ROUNDUP(sin->sin_len) + (char *)sin);
229
	if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
232
	if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
230
		if (sdl->sdl_family == AF_LINK
233
		if (sdl->sdl_family == AF_LINK &&
231
		    && (rtm->rtm_flags & (RTF_LLINFO|RTF_GATEWAY))
234
#ifdef RTF_LLINFO
232
		      == RTF_LLINFO) {
235
		    (rtm->rtm_flags & RTF_LLINFO) != 0 &&
236
#endif
237
		    (rtm->rtm_flags & RTF_GATEWAY) == 0) {
233
			switch (sdl->sdl_type) {
238
			switch (sdl->sdl_type) {
234
			case IFT_ETHER:
239
			case IFT_ETHER:
235
			case IFT_FDDI:
240
			case IFT_FDDI:
Lines 278-283 arp_delete(int sock, struct in_addr ip) Link Here
278
	struct rt_msghdr *const rtm = &m_rtmsg.m_rtm;
283
	struct rt_msghdr *const rtm = &m_rtmsg.m_rtm;
279
	struct sockaddr_dl *sdl;
284
	struct sockaddr_dl *sdl;
280
285
286
	sdl_m = zero_sdl;
281
	sin_m = zero_sin;
287
	sin_m = zero_sin;
282
	sin->sin_addr = ip;
288
	sin->sin_addr = ip;
283
tryagain:
289
tryagain:
Lines 286-299 tryagain: Link Here
286
	sin = (struct sockaddr_inarp *)(rtm + 1);
292
	sin = (struct sockaddr_inarp *)(rtm + 1);
287
	sdl = (struct sockaddr_dl *)(void *)
293
	sdl = (struct sockaddr_dl *)(void *)
288
	    (ROUNDUP(sin->sin_len) + (char *)sin);
294
	    (ROUNDUP(sin->sin_len) + (char *)sin);
289
	if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
295
	if (sdl->sdl_family == AF_LINK &&
290
		if (sdl->sdl_family == AF_LINK &&
296
#ifdef RTF_LLINFO
291
		    (rtm->rtm_flags & RTF_LLINFO) &&
297
	    (rtm->rtm_flags & RTF_LLINFO) &&
292
		    !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
298
#endif
299
	    !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
293
		case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
300
		case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
294
		case IFT_ISO88024: case IFT_ISO88025:
301
		case IFT_ISO88024: case IFT_ISO88025:
302
			sin->sin_addr.s_addr = sin_m.sin_addr.s_addr;
295
			goto delete;
303
			goto delete;
296
		}
297
	}
304
	}
298
	if (sin_m.sin_other & SIN_PROXY) {
305
	if (sin_m.sin_other & SIN_PROXY) {
299
		errno = ENOENT;
306
		errno = ENOENT;
Lines 384-425 int Link Here
384
if_flush_arp(void)
391
if_flush_arp(void)
385
{
392
{
386
	int errno_save = errno;
393
	int errno_save = errno;
387
	struct uroute **list;
394
	int mib[6];
388
	int rtn = 0;
395
	size_t needed;
389
	int num;
396
	char *lim, *buf, *next;
390
	int i;
397
	struct rt_msghdr *rtm;
391
398
	struct sockaddr_inarp *sin;
392
	/* Get list of routes */
399
	struct sockaddr_dl *sdl;
393
	if ((num = uroute_get_all(&list, TYPED_MEM_TEMP)) == -1)
400
	int sock, rtn = -1;
394
		return (-1);
395
396
	/* Delete ARP routes */
397
	for (i = 0; i < num; i++) {
398
		struct uroute *const route = list[i];
399
		const struct sockaddr *dest;
400
		const struct sockaddr *gw;
401
402
		/* Is this an ARP entry? */
403
		dest = uroute_get_dest(route);
404
		gw = uroute_get_gateway(route);
405
		if ((uroute_get_flags(route)
406
		      & (RTF_HOST|RTF_LLINFO|RTF_WASCLONED))
407
		      != (RTF_HOST|RTF_LLINFO|RTF_WASCLONED)
408
		    || dest->sa_family != AF_INET
409
		    || gw->sa_family != AF_LINK)
410
			continue;
411
401
412
		/* Delete it */
402
	/* Get socket */
413
		if (uroute_delete(route) == -1) {
403
	if ((sock = socket(PF_ROUTE, SOCK_RAW, 0)) == -1)
414
			errno_save = errno;
404
		return (-1);
415
			rtn = -1;
405
416
		}
406
	/* Get ARP table */
407
	mib[0] = CTL_NET;
408
	mib[1] = PF_ROUTE;
409
	mib[2] = 0;
410
	mib[3] = AF_INET;
411
	mib[4] = NET_RT_FLAGS;
412
#ifdef RTF_LLINFO
413
	mib[5] = RTF_LLINFO;
414
#else
415
	mib[5] = 0;
416
#endif
417
	if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
418
		goto done;
419
	needed += 128;
420
	if ((buf = MALLOC(TYPED_MEM_TEMP, needed)) == NULL)
421
		goto done;
422
	if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
423
		goto done2;
424
	}
425
426
	/* Find desired entry */
427
	lim = buf + needed;
428
	for (next = buf; next < lim; next += rtm->rtm_msglen) {
429
		rtm = (struct rt_msghdr *)(void *)next;
430
		sin = (struct sockaddr_inarp *)(rtm + 1);
431
		sdl = (struct sockaddr_dl *)(void *)
432
		   ((char *)sin + ROUNDUP(sin->sin_len));
433
		if (sdl->sdl_alen == 0)
434
			break;
435
		arp_delete(sock, sin->sin_addr);
417
	}
436
	}
418
437
419
	/* Clean up */
438
	rtn = 0;
420
	while (num > 0)
439
done2:
421
		uroute_destroy(&list[--num]);
440
	FREE(TYPED_MEM_TEMP, buf);
422
	FREE(TYPED_MEM_TEMP, list);
441
done:
442
	(void)close(sock);
423
	errno = errno_save;
443
	errno = errno_save;
424
	return (rtn);
444
	return (rtn);
425
}
445
}
(-)http/servlet/http_servlet_cookieauth.c.orig (+1 lines)
Lines 54-59 Link Here
54
#include <pthread.h>
54
#include <pthread.h>
55
55
56
#include <openssl/ssl.h>
56
#include <openssl/ssl.h>
57
#include <openssl/md5.h>
57
58
58
#include "structs/structs.h"
59
#include "structs/structs.h"
59
#include "structs/type/array.h"
60
#include "structs/type/array.h"
(-)ppp/ppp_l2tp_ctrl.c (-3 / +3 lines)
Lines 200-206 struct ppp_l2tp_sess { Link Here
200
	u_int16_t		peer_id;		/* peer session id */
200
	u_int16_t		peer_id;		/* peer session id */
201
	struct ppp_log		*log;			/* log */
201
	struct ppp_log		*log;			/* log */
202
	ng_ID_t			node_id;		/* tee node id */
202
	ng_ID_t			node_id;		/* tee node id */
203
	char			hook[NG_HOOKLEN + 1];	/* session hook name */
203
	char			hook[NG_HOOKSIZ];	/* session hook name */
204
	void			*link_cookie;		/* opaque link cookie */
204
	void			*link_cookie;		/* opaque link cookie */
205
	u_int16_t		result;			/* close result code */
205
	u_int16_t		result;			/* close result code */
206
	u_int16_t		error;			/* close error code */
206
	u_int16_t		error;			/* close error code */
Lines 608-614 ppp_l2tp_ctrl_create(struct pevent_ctx * Link Here
608
608
609
	/* Done */
609
	/* Done */
610
	*nodep = ctrl->node_id;
610
	*nodep = ctrl->node_id;
611
	strlcpy(hook, NG_L2TP_HOOK_LOWER, NG_HOOKLEN + 1);
611
	strlcpy(hook, NG_L2TP_HOOK_LOWER, NG_HOOKSIZ);
612
	return (ctrl);
612
	return (ctrl);
613
613
614
fail:
614
fail:
Lines 1860-1866 ppp_l2tp_ctrl_event(void *arg) Link Here
1860
	    struct ng_mesg msg;
1860
	    struct ng_mesg msg;
1861
	} buf;
1861
	} buf;
1862
	struct ng_mesg *const msg = &buf.msg;
1862
	struct ng_mesg *const msg = &buf.msg;
1863
	char raddr[NG_PATHLEN + 1];
1863
	char raddr[NG_PATHSIZ];
1864
	int len;
1864
	int len;
1865
1865
1866
	/* Read netgraph control message */
1866
	/* Read netgraph control message */
(-)ppp/ppp_l2tp_ctrl.h (-1 / +1 lines)
Lines 201-207 __BEGIN_DECLS Link Here
201
 *	peer_id	Unique identifier for peer (used for tie-breakers)
201
 *	peer_id	Unique identifier for peer (used for tie-breakers)
202
 *	initiate Whether to send a SCCRQ or just wait for one
202
 *	initiate Whether to send a SCCRQ or just wait for one
203
 *	nodep	Pointer to netgraph node ID variable
203
 *	nodep	Pointer to netgraph node ID variable
204
 *	hook	Buffer for hook on L2TP netgraph node (size >= NG_HOOKLEN + 1)
204
 *	hook	Buffer for hook on L2TP netgraph node (size >= NG_HOOKSIZ)
205
 *	avps	List of AVP's to include in the associated
205
 *	avps	List of AVP's to include in the associated
206
 *		Start-Control-Connection-Request or
206
 *		Start-Control-Connection-Request or
207
 *		Start-Control-Connection-Reply control message.
207
 *		Start-Control-Connection-Reply control message.
(-)ppp/ppp_l2tp_server.c (-2 / +2 lines)
Lines 103-109 struct ppp_l2tp_peer { Link Here
103
	struct ppp_channel		*chan;		/* pointer to channel */
103
	struct ppp_channel		*chan;		/* pointer to channel */
104
	struct ppp_auth_config		auth;		/* auth config */
104
	struct ppp_auth_config		auth;		/* auth config */
105
	char				node[32];		/* node path */
105
	char				node[32];		/* node path */
106
	char				hook[NG_HOOKLEN + 1];	/* node hook */
106
	char				hook[NG_HOOKSIZ];	/* node hook */
107
	char				logname[32];	/* peer logname */
107
	char				logname[32];	/* peer logname */
108
	struct in_addr			ip;		/* peer ip address */
108
	struct in_addr			ip;		/* peer ip address */
109
	u_int16_t			port;		/* peer port */
109
	u_int16_t			port;		/* peer port */
Lines 536-542 ppp_l2tp_server_sock_event(void *arg) Link Here
536
	struct sockaddr_in sin;
536
	struct sockaddr_in sin;
537
	const size_t bufsize = 8192;
537
	const size_t bufsize = 8192;
538
	u_int16_t *buf = NULL;
538
	u_int16_t *buf = NULL;
539
	char hook[NG_HOOKLEN + 1];
539
	char hook[NG_HOOKSIZ];
540
	socklen_t sin_len;
540
	socklen_t sin_len;
541
	char namebuf[64];
541
	char namebuf[64];
542
	ng_ID_t node_id;
542
	ng_ID_t node_id;
(-)ppp/ppp_node.c (-2 / +2 lines)
Lines 431-437 int Link Here
431
ppp_node_send_msg(struct ppp_node *node, const char *relpath,
431
ppp_node_send_msg(struct ppp_node *node, const char *relpath,
432
	u_int32_t cookie, u_int32_t cmd, const void *payload, size_t plen)
432
	u_int32_t cookie, u_int32_t cmd, const void *payload, size_t plen)
433
{
433
{
434
	char path[NG_PATHLEN + 1];
434
	char path[NG_PATHSIZ];
435
435
436
	if (relpath == NULL)
436
	if (relpath == NULL)
437
		strlcpy(path, NODE_HOOK, sizeof(path));
437
		strlcpy(path, NODE_HOOK, sizeof(path));
Lines 494-500 ppp_node_read_message(void *arg) Link Here
494
{
494
{
495
	struct ppp_node *const node = arg;
495
	struct ppp_node *const node = arg;
496
	const size_t max_msglen = 4096;
496
	const size_t max_msglen = 4096;
497
	char raddr[NG_PATHLEN + 1];
497
	char raddr[NG_PATHSIZ];
498
	struct ppp_node_recvmsg *rm;
498
	struct ppp_node_recvmsg *rm;
499
	struct ng_mesg *msg;
499
	struct ng_mesg *msg;
500
	int found = 0;
500
	int found = 0;
(-)ppp/ppp_auth_radius.c.orig (+2 lines)
Lines 44-49 Link Here
44
#include "ppp/ppp_auth.h"
44
#include "ppp/ppp_auth.h"
45
#include "ppp/ppp_msoft.h"
45
#include "ppp/ppp_msoft.h"
46
46
47
#include <openssl/md5.h>
48
47
#include <poll.h>
49
#include <poll.h>
48
#include <radlib.h>
50
#include <radlib.h>
49
#include <radlib_vs.h>
51
#include <radlib_vs.h>
(-)ppp/ppp_auth_radius.c.orig (-1 / +1 lines)
Lines 462-468 Link Here
462
462
463
		/* Compensate for broken servers that leave out the ID byte */
463
		/* Compensate for broken servers that leave out the ID byte */
464
		if (len > 0 && (len < 3 || ((const char *)data)[1] != '=')) {
464
		if (len > 0 && (len < 3 || ((const char *)data)[1] != '=')) {
465
			((const char *)data)++;
465
			data = (const char *)data + 1;
466
			len--;
466
			len--;
467
		}
467
		}
468
468
(-)util/rsa_util.c.orig (+1 lines)
Lines 50-55 Link Here
50
50
51
#include <openssl/ssl.h>
51
#include <openssl/ssl.h>
52
#include <openssl/err.h>
52
#include <openssl/err.h>
53
#include <openssl/md5.h>
53
54
54
#include "structs/structs.h"
55
#include "structs/structs.h"
55
#include "structs/type/array.h"
56
#include "structs/type/array.h"
(-)util/paction.c (-7 / +16 lines)
Lines 39-45 Link Here
39
#endif
39
#endif
40
	paction_finish_t	*finish;	/* action finisher */
40
	paction_finish_t	*finish;	/* action finisher */
41
	void			*arg;		/* action argument */
41
	void			*arg;		/* action argument */
42
	u_char			started;	/* action thread started */
42
	u_char			may_cancel;	/* ok to cancel action thread */
43
	u_char			canceled;	/* action was canceled */
43
	u_char			canceled;	/* action was canceled */
44
};
44
};
45
45
Lines 118-127 Link Here
118
118
119
	/*
119
	/*
120
	 * Don't cancel the thread before paction_main() starts, because
120
	 * Don't cancel the thread before paction_main() starts, because
121
	 * then paction_cleanup() would never get invoked. Instead, use
121
	 * then paction_cleanup() would never get invoked. Also don't
122
	 * the 'started' and 'canceled' flags to avoid this race condition.
122
	 * pthread_cancel() the thread after the handler has completed,
123
	 * because we might cancel in the middle of the cleanup.
123
	 */
124
	 */
124
	if (action->started)
125
	if (action->may_cancel)
125
		pthread_cancel(action->tid);
126
		pthread_cancel(action->tid);
126
127
127
	/* Unlock action */
128
	/* Unlock action */
Lines 139-147 Link Here
139
	/* Cleanup when thread exits */
140
	/* Cleanup when thread exits */
140
	pthread_cleanup_push(paction_cleanup, action);
141
	pthread_cleanup_push(paction_cleanup, action);
141
142
142
	/* Mark thread as started */
143
	/* Begin allowing pthread_cancel()'s */
143
	assert(!action->started);
144
	assert(!action->may_cancel);
144
	action->started = 1;			/* race condition ok */
145
	action->may_cancel = 1;
145
146
146
	/* Handle race between paction_cancel() and paction_main() */
147
	/* Handle race between paction_cancel() and paction_main() */
147
	if (action->canceled)			/* race condition ok */
148
	if (action->canceled)			/* race condition ok */
Lines 151-156 Link Here
151
	(*action->handler)(action->arg);
152
	(*action->handler)(action->arg);
152
153
153
done:;
154
done:;
155
	/* Stop allowing pthread_cancel()'s */
156
	MUTEX_LOCK(&action->mutex, action->mutex_count);
157
	action->may_cancel = 0;
158
	MUTEX_UNLOCK(&action->mutex, action->mutex_count);
159
160
	/* Consume any last-minute pthread_cancel() still pending */
161
	pthread_testcancel();
162
154
	/* Done */
163
	/* Done */
155
	pthread_cleanup_pop(1);
164
	pthread_cleanup_pop(1);
156
	return (NULL);
165
	return (NULL);
(-)util/pevent.c.orig (-22 / +35 lines)
Lines 155-160 Link Here
155
		_pevent_unref(ev);					\
155
		_pevent_unref(ev);					\
156
	} while (0)
156
	} while (0)
157
157
158
#define PEVENT_SET_OCCURRED(ctx, ev)					\
159
	do {								\
160
		(ev)->flags |= PEVENT_OCCURRED;				\
161
		if ((ev) != TAILQ_FIRST(&ctx->events)) {		\
162
			TAILQ_REMOVE(&(ctx)->events, (ev), next);	\
163
			TAILQ_INSERT_HEAD(&(ctx)->events, (ev), next);	\
164
		}							\
165
	} while (0)
166
158
/* Internal functions */
167
/* Internal functions */
159
static void	pevent_ctx_service(struct pevent *ev);
168
static void	pevent_ctx_service(struct pevent *ev);
160
static void	*pevent_ctx_main(void *arg);
169
static void	*pevent_ctx_main(void *arg);
Lines 338-344 Link Here
338
			ev->u.millis = 0;
347
			ev->u.millis = 0;
339
		gettimeofday(&ev->when, NULL);
348
		gettimeofday(&ev->when, NULL);
340
		ev->when.tv_sec += ev->u.millis / 1000;
349
		ev->when.tv_sec += ev->u.millis / 1000;
341
		ev->when.tv_usec += ev->u.millis % 1000;
350
		ev->when.tv_usec += (ev->u.millis % 1000) * 1000;
351
		if (ev->when.tv_usec > 1000000) {
352
			ev->when.tv_sec++;
353
			ev->when.tv_usec -= 1000000;
354
		}
342
		break;
355
		break;
343
	case PEVENT_MESG_PORT:
356
	case PEVENT_MESG_PORT:
344
		va_start(args, type);
357
		va_start(args, type);
Lines 394-408 Link Here
394
	} else
407
	} else
395
		pevent_ctx_notify(ctx);
408
		pevent_ctx_notify(ctx);
396
409
410
	/* Caller gets the one reference */
411
	ev->peventp = peventp;
412
	*peventp = ev;
413
397
	/* Add event to the pending event list */
414
	/* Add event to the pending event list */
398
	PEVENT_ENQUEUE(ctx, ev);
415
	PEVENT_ENQUEUE(ctx, ev);
399
416
400
	/* Unlock context */
417
	/* Unlock context */
401
	MUTEX_UNLOCK(&ctx->mutex, ctx->mutex_count);
418
	MUTEX_UNLOCK(&ctx->mutex, ctx->mutex_count);
402
419
403
	/* Done; caller gets the one reference */
404
	ev->peventp = peventp;
405
	*peventp = ev;
406
	return (0);
420
	return (0);
407
}
421
}
408
422
Lines 469-475 Link Here
469
		goto done;
483
		goto done;
470
484
471
	/* Mark event as having occurred */
485
	/* Mark event as having occurred */
472
	ev->flags |= PEVENT_OCCURRED;
486
	PEVENT_SET_OCCURRED(ctx, ev);
473
487
474
	/* Wake up thread if event is still in the queue */
488
	/* Wake up thread if event is still in the queue */
475
	if ((ev->flags & PEVENT_ENQUEUED) != 0)
489
	if ((ev->flags & PEVENT_ENQUEUED) != 0)
Lines 523-528 Link Here
523
	struct timeval now;
537
	struct timeval now;
524
	struct pollfd *fd;
538
	struct pollfd *fd;
525
	struct pevent *ev;
539
	struct pevent *ev;
540
	struct pevent *next_ev;
526
	int poll_idx;
541
	int poll_idx;
527
	int timeout;
542
	int timeout;
528
	int r;
543
	int r;
Lines 562-567 Link Here
562
		}
577
		}
563
	}
578
	}
564
579
580
	/* If we were intentionally woken up, read the wakeup byte */
581
	if (ctx->notified) {
582
		DBG(PEVENT, "ctx %p thread was notified", ctx);
583
		(void)read(ctx->pipe[0], &pevent_byte, 1);
584
		ctx->notified = 0;
585
	}
586
565
	/* Add event for the notify pipe */
587
	/* Add event for the notify pipe */
566
	poll_idx = 0;
588
	poll_idx = 0;
567
	if (ctx->fds_alloc > 0) {
589
	if (ctx->fds_alloc > 0) {
Lines 620-626 Link Here
620
		switch (ev->type) {
642
		switch (ev->type) {
621
		case PEVENT_MESG_PORT:
643
		case PEVENT_MESG_PORT:
622
			if (mesg_port_qlen(ev->u.port) > 0)
644
			if (mesg_port_qlen(ev->u.port) > 0)
623
				ev->flags |= PEVENT_OCCURRED;
645
				PEVENT_SET_OCCURRED(ctx, ev);
624
			break;
646
			break;
625
		default:
647
		default:
626
			break;
648
			break;
Lines 654-660 Link Here
654
	gettimeofday(&now, NULL);
676
	gettimeofday(&now, NULL);
655
677
656
	/* Mark poll() events that have occurred */
678
	/* Mark poll() events that have occurred */
657
	TAILQ_FOREACH(ev, &ctx->events, next) {
679
	for (ev = TAILQ_FIRST((&ctx->events)); ev != NULL; ev = next_ev) {
680
		next_ev = TAILQ_NEXT(ev, next);
658
		assert(ev->magic == PEVENT_MAGIC);
681
		assert(ev->magic == PEVENT_MAGIC);
659
		switch (ev->type) {
682
		switch (ev->type) {
660
		case PEVENT_READ:
683
		case PEVENT_READ:
Lines 664-696 Link Here
664
			fd = &ctx->fds[ev->poll_idx];
687
			fd = &ctx->fds[ev->poll_idx];
665
			if ((fd->revents & ((ev->type == PEVENT_READ) ?
688
			if ((fd->revents & ((ev->type == PEVENT_READ) ?
666
			    READABLE_EVENTS : WRITABLE_EVENTS)) != 0)
689
			    READABLE_EVENTS : WRITABLE_EVENTS)) != 0)
667
				ev->flags |= PEVENT_OCCURRED;
690
				PEVENT_SET_OCCURRED(ctx, ev);
668
			break;
691
			break;
669
		case PEVENT_TIME:
692
		case PEVENT_TIME:
670
			if (timercmp(&ev->when, &now, <=))
693
			if (timercmp(&ev->when, &now, <=))
671
				ev->flags |= PEVENT_OCCURRED;
694
				PEVENT_SET_OCCURRED(ctx, ev);
672
			break;
695
			break;
673
		default:
696
		default:
674
			break;
697
			break;
675
		}
698
		}
676
	}
699
	}
677
700
678
	/* If we were intentionally woken up, read the wakeup byte */
679
	if (ctx->notified) {
680
		DBG(PEVENT, "ctx %p thread was notified", ctx);
681
		(void)read(ctx->pipe[0], &pevent_byte, 1);
682
		ctx->notified = 0;
683
	}
684
685
	/* Service all events that are marked as having occurred */
701
	/* Service all events that are marked as having occurred */
686
	while (1) {
702
	while (1) {
687
703
688
		/* Find next event that needs service XXX this is O(n^2) XXX */
704
		/* Find next event that needs service */
689
		TAILQ_FOREACH(ev, &ctx->events, next) {
705
		ev = TAILQ_FIRST(&ctx->events);
690
			if ((ev->flags & PEVENT_OCCURRED) != 0)
706
		if (ev == NULL || (ev->flags & PEVENT_OCCURRED) == 0)
691
				break;
692
		}
693
		if (ev == NULL)
694
			break;
707
			break;
695
		DBG(PEVENT, "ctx %p thread servicing ev %p", ctx, ev);
708
		DBG(PEVENT, "ctx %p thread servicing ev %p", ctx, ev);
696
709

Return to bug 275112