ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.47 by root, Sat Nov 3 11:44:44 2007 UTC vs.
Revision 1.50 by root, Sat Nov 3 19:41:55 2007 UTC

26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#if EV_USE_CONFIG_H 31#ifndef EV_STANDALONE
32# include "config.h" 32# include "config.h"
33#endif 33#endif
34 34
35#include <math.h> 35#include <math.h>
36#include <stdlib.h> 36#include <stdlib.h>
175 175
176/*****************************************************************************/ 176/*****************************************************************************/
177 177
178typedef struct 178typedef struct
179{ 179{
180 struct ev_io *head; 180 struct ev_watcher_list *head;
181 unsigned char events; 181 unsigned char events;
182 unsigned char reify; 182 unsigned char reify;
183} ANFD; 183} ANFD;
184 184
185static ANFD *anfds; 185static ANFD *anfds;
235fd_event (int fd, int events) 235fd_event (int fd, int events)
236{ 236{
237 ANFD *anfd = anfds + fd; 237 ANFD *anfd = anfds + fd;
238 struct ev_io *w; 238 struct ev_io *w;
239 239
240 for (w = anfd->head; w; w = w->next) 240 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
241 { 241 {
242 int ev = w->events & events; 242 int ev = w->events & events;
243 243
244 if (ev) 244 if (ev)
245 event ((W)w, ev); 245 event ((W)w, ev);
262 ANFD *anfd = anfds + fd; 262 ANFD *anfd = anfds + fd;
263 struct ev_io *w; 263 struct ev_io *w;
264 264
265 int events = 0; 265 int events = 0;
266 266
267 for (w = anfd->head; w; w = w->next) 267 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
268 events |= w->events; 268 events |= w->events;
269 269
270 anfd->reify = 0; 270 anfd->reify = 0;
271 271
272 if (anfd->events != events) 272 if (anfd->events != events)
295static void 295static void
296fd_kill (int fd) 296fd_kill (int fd)
297{ 297{
298 struct ev_io *w; 298 struct ev_io *w;
299 299
300 printf ("killing fd %d\n", fd);//D
301 while ((w = anfds [fd].head)) 300 while ((w = (struct ev_io *)anfds [fd].head))
302 { 301 {
303 ev_io_stop (w); 302 ev_io_stop (w);
304 event ((W)w, EV_ERROR | EV_READ | EV_WRITE); 303 event ((W)w, EV_ERROR | EV_READ | EV_WRITE);
305 } 304 }
306} 305}
383 382
384/*****************************************************************************/ 383/*****************************************************************************/
385 384
386typedef struct 385typedef struct
387{ 386{
388 struct ev_signal *head; 387 struct ev_watcher_list *head;
389 sig_atomic_t volatile gotsig; 388 sig_atomic_t volatile gotsig;
390} ANSIG; 389} ANSIG;
391 390
392static ANSIG *signals; 391static ANSIG *signals;
393static int signalmax; 392static int signalmax;
413{ 412{
414 signals [signum - 1].gotsig = 1; 413 signals [signum - 1].gotsig = 1;
415 414
416 if (!gotsig) 415 if (!gotsig)
417 { 416 {
417 int old_errno = errno;
418 gotsig = 1; 418 gotsig = 1;
419 write (sigpipe [1], &signum, 1); 419 write (sigpipe [1], &signum, 1);
420 errno = old_errno;
420 } 421 }
421} 422}
422 423
423static void 424static void
424sigcb (struct ev_io *iow, int revents) 425sigcb (struct ev_io *iow, int revents)
425{ 426{
426 struct ev_signal *w; 427 struct ev_watcher_list *w;
427 int signum; 428 int signum;
428 429
429 read (sigpipe [0], &revents, 1); 430 read (sigpipe [0], &revents, 1);
430 gotsig = 0; 431 gotsig = 0;
431 432
480static void 481static void
481child_reap (struct ev_signal *sw, int chain, int pid, int status) 482child_reap (struct ev_signal *sw, int chain, int pid, int status)
482{ 483{
483 struct ev_child *w; 484 struct ev_child *w;
484 485
485 for (w = childs [chain & (PID_HASHSIZE - 1)]; w; w = w->next) 486 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
486 if (w->pid == pid || !w->pid) 487 if (w->pid == pid || !w->pid)
487 { 488 {
488 w->priority = sw->priority; /* need to do it *now* */ 489 w->priority = sw->priority; /* need to do it *now* */
489 w->rpid = pid; 490 w->rpid = pid;
490 w->rstatus = status; 491 w->rstatus = status;
491 printf ("rpid %p %d %d\n", w, pid, w->pid);//D
492 event ((W)w, EV_CHILD); 492 event ((W)w, EV_CHILD);
493 } 493 }
494} 494}
495 495
496static void 496static void
497childcb (struct ev_signal *sw, int revents) 497childcb (struct ev_signal *sw, int revents)
498{ 498{
499 int pid, status; 499 int pid, status;
500 500
501 printf ("chld %x\n", revents);//D
502 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 501 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
503 { 502 {
504 /* make sure we are called again until all childs have been reaped */ 503 /* make sure we are called again until all childs have been reaped */
505 event ((W)sw, EV_SIGNAL); 504 event ((W)sw, EV_SIGNAL);
506 505
536ev_version_minor (void) 535ev_version_minor (void)
537{ 536{
538 return EV_VERSION_MINOR; 537 return EV_VERSION_MINOR;
539} 538}
540 539
541/* return true if we are running with elevated privileges and ignore env variables */ 540/* return true if we are running with elevated privileges and should ignore env variables */
542static int 541static int
543enable_secure () 542enable_secure ()
544{ 543{
544#ifdef WIN32
545 return 0;
546#else
545 return getuid () != geteuid () 547 return getuid () != geteuid ()
546 || getgid () != getegid (); 548 || getgid () != getegid ();
549#endif
547} 550}
548 551
549int ev_init (int methods) 552int ev_init (int methods)
550{ 553{
551 if (!ev_method) 554 if (!ev_method)
565 568
566 if (pipe (sigpipe)) 569 if (pipe (sigpipe))
567 return 0; 570 return 0;
568 571
569 if (methods == EVMETHOD_AUTO) 572 if (methods == EVMETHOD_AUTO)
570 if (!enable_secure () && getenv ("LIBEV_METHODS")) 573 if (!enable_secure () && getenv ("LIBEV_METHODS"))
571 methods = atoi (getenv ("LIBEV_METHODS")); 574 methods = atoi (getenv ("LIBEV_METHODS"));
572 else 575 else
573 methods = EVMETHOD_ANY; 576 methods = EVMETHOD_ANY;
574 577
575 ev_method = 0; 578 ev_method = 0;
576#if EV_USE_KQUEUE 579#if EV_USE_KQUEUE
577 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods); 580 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods);
578#endif 581#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines