pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pbulk pbulk-0.37:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/64d70b8888ec
branches:  trunk
changeset: 553848:64d70b8888ec
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sat Jan 31 23:25:37 2009 +0000

description:
pbulk-0.37:
- replace libevent dependency with internal event loop to make the pbulk
  core standalone
- open success and error log with O_APPEND, which allows e.g. cleaning
  up the error build during build without breaking it if done with care.

diffstat:

 pkgtools/pbulk/Makefile                      |    6 +-
 pkgtools/pbulk/files/pbulk/Makefile.inc      |    9 +-
 pkgtools/pbulk/files/pbulk/lib/event.c       |  235 +++++++++++++++++++++++++-
 pkgtools/pbulk/files/pbulk/lib/pbulk.h       |   30 +++-
 pkgtools/pbulk/files/pbulk/pbuild/jobs.c     |   10 +-
 pkgtools/pbulk/files/pbulk/pbuild/master.c   |   19 +-
 pkgtools/pbulk/files/pbulk/presolve/Makefile |    4 +-
 pkgtools/pbulk/files/pbulk/pscan/master.c    |   19 +-
 8 files changed, 276 insertions(+), 56 deletions(-)

diffs (truncated from 578 to 300 lines):

diff -r bbce0b71487c -r 64d70b8888ec pkgtools/pbulk/Makefile
--- a/pkgtools/pbulk/Makefile   Sat Jan 31 22:13:04 2009 +0000
+++ b/pkgtools/pbulk/Makefile   Sat Jan 31 23:25:37 2009 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.49 2008/10/16 21:52:17 wiz Exp $
+# $NetBSD: Makefile,v 1.50 2009/01/31 23:25:37 joerg Exp $
 
-DISTNAME=      pbulk-0.36
-PKGREVISION=   1
+DISTNAME=      pbulk-0.37
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
@@ -76,5 +75,4 @@
 CPPFLAGS+=     -D_GNU_SOURCE
 .endif
 
-.include "../../devel/libevent/buildlink3.mk"
 .include "../../mk/bsd.pkg.mk"
diff -r bbce0b71487c -r 64d70b8888ec pkgtools/pbulk/files/pbulk/Makefile.inc
--- a/pkgtools/pbulk/files/pbulk/Makefile.inc   Sat Jan 31 22:13:04 2009 +0000
+++ b/pkgtools/pbulk/files/pbulk/Makefile.inc   Sat Jan 31 23:25:37 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.3 2007/07/17 18:11:37 tnn Exp $
+# $NetBSD: Makefile.inc,v 1.4 2009/01/31 23:25:38 joerg Exp $
 
 BINDIR?=       ${PREFIX}/bin
 
@@ -11,10 +11,3 @@
 .endif
 
 LDADD+=                -lnbcompat
-
-.if !defined(NO_LIBEVENT_NEEDED)
-CPPFLAGS+=
-.if !defined(LIBPBULK_ONLY)
-LDADD+=                -levent
-.endif
-.endif
diff -r bbce0b71487c -r 64d70b8888ec pkgtools/pbulk/files/pbulk/lib/event.c
--- a/pkgtools/pbulk/files/pbulk/lib/event.c    Sat Jan 31 22:13:04 2009 +0000
+++ b/pkgtools/pbulk/files/pbulk/lib/event.c    Sat Jan 31 23:25:37 2009 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: event.c,v 1.3 2007/06/25 21:38:44 joerg Exp $ */
+/* $NetBSD: event.c,v 1.4 2009/01/31 23:25:38 joerg Exp $ */
 
 /*-
- * Copyright (c) 2007 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
+ * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
  * All rights reserved.
  *
  * This code was developed as part of Google's Summer of Code 2007 program.
@@ -38,11 +38,13 @@
 #ifdef __sun
 #include <sys/filio.h>
 #endif
+#include <nbcompat/poll.h>
 #include <nbcompat/time.h>
-#include <event.h>
 #include <nbcompat/stdlib.h>
 #include <nbcompat/unistd.h>
 
+#include <signal.h>
+
 #include "pbulk.h"
 
 struct deferred_read_arg {
@@ -70,7 +72,7 @@
 };
 
 static void
-deferred_read_handler(int fd, short event, void *arg)
+deferred_read_handler(int fd, void *arg)
 {
        struct deferred_read_arg *data = arg;
        ssize_t received;
@@ -88,7 +90,7 @@
                free(data);
                return;
        }
-       event_add(&data->ev, NULL);
+       event_add(&data->ev, data->fd, 0, 0, deferred_read_handler, data);
 }
 
 void
@@ -105,13 +107,11 @@
        data->buf = buf;
        data->remaining = buf_len;
 
-       event_set(&data->ev, data->fd, EV_READ,
-           deferred_read_handler, data);
-       event_add(&data->ev, NULL);
+       event_add(&data->ev, data->fd, 0, 0, deferred_read_handler, data);
 }
 
 static void
-deferred_write_handler(int fd, short event, void *arg)
+deferred_write_handler(int fd, void *arg)
 {
        struct deferred_write_arg *data = arg;
        ssize_t sent;
@@ -129,7 +129,7 @@
                free(data);
                return;
        }
-       event_add(&data->ev, NULL);
+       event_add(&data->ev, data->fd, 1, 0, deferred_write_handler, data);
 }
 
 void
@@ -146,9 +146,7 @@
        data->buf = buf;
        data->remaining = buf_len;
 
-       event_set(&data->ev, data->fd, EV_WRITE,
-           deferred_write_handler, data);
-       event_add(&data->ev, NULL);
+       event_add(&data->ev, data->fd, 1, 0, deferred_write_handler, data);
 }
 
 int
@@ -161,3 +159,214 @@
                return -1;
        return 0;
 }
+
+static size_t active_events;
+static LIST_HEAD(, event) all_events;
+static LIST_HEAD(, signal_event) all_signals;
+static struct pollfd *poll_list;
+static size_t poll_allocated;
+
+static int signal_pipe[2];
+static struct event signal_event;
+
+static void signal_read_handler(int, void *);
+
+void
+event_init(void)
+{
+       LIST_INIT(&all_events);
+       LIST_INIT(&all_signals);
+
+       if (pipe(signal_pipe))
+               err(1, "can't create signal pipe");
+
+       event_add(&signal_event, signal_pipe[0], 0, 1, signal_read_handler,
+           NULL);
+       set_nonblocking(signal_pipe[0]);
+       set_nonblocking(signal_pipe[1]);
+}
+
+void
+event_add(struct event *ev, int fd, int do_write, int is_persistent,
+    void (*handler)(int, void *), void *arg)
+{
+       ev->ev_fd = fd;
+       ev->ev_write = do_write;
+       ev->ev_persistent = is_persistent;
+       ev->ev_handler = handler;
+       ev->ev_arg = arg;
+       LIST_INSERT_HEAD(&all_events, ev, ev_link);
+       ++active_events;
+}
+
+void
+event_del(struct event *ev)
+{
+       LIST_REMOVE(ev, ev_link);
+       --active_events;
+}
+
+static void
+mask_all(void)
+{
+       sigset_t mask;
+
+       sigfillset(&mask);
+
+       sigprocmask(SIG_SETMASK, &mask, NULL);
+}
+
+static void
+unmask_all(void)
+{
+       sigset_t mask;
+
+       sigemptyset(&mask);
+
+       sigprocmask(SIG_SETMASK, &mask, NULL);
+}
+
+static void
+signal_read_handler(int fd, void *arg)
+{
+       struct signal_event *sig, *next;
+       int got_something;
+       char buf[256];
+
+       for (;;) {
+               got_something = 0;
+
+               while (read(signal_pipe[0], buf, sizeof(buf)) > 0)
+                       got_something = 1;
+               if (got_something == 0)
+                       break;
+
+               for (sig = LIST_FIRST(&all_signals);
+                   sig && (next = LIST_NEXT(sig, sig_link), 1);
+                   sig = next) {
+                       if (sig->sig_received) {
+                               sig->sig_received = 0;
+                               (*sig->sig_handler)(sig);
+                       }
+               }
+       }
+}
+
+static void
+signal_handler(int sig_id)
+{
+       struct signal_event *sig;
+       char buf = 0;
+       int old_errno;
+
+       LIST_FOREACH(sig, &all_signals, sig_link) {
+               if (sig->sig_id == sig_id)
+                       sig->sig_received = 1;
+       }
+
+       old_errno = errno;
+       write(signal_pipe[1], &buf, 1);
+       errno = old_errno;
+}
+
+void
+signal_add(struct signal_event *sig, int sigtype,
+    void (*handler)(struct signal_event *))
+{
+       sig->sig_id = sigtype;
+       sig->sig_received = 0;
+       sig->sig_handler = handler;
+
+       mask_all();
+       LIST_INSERT_HEAD(&all_signals, sig, sig_link);
+       signal(sigtype, signal_handler);
+       unmask_all();
+}
+
+void
+signal_del(struct signal_event *sig)
+{
+       mask_all();
+       LIST_REMOVE(sig, sig_link);
+       /* XXX Unset signal handler */
+       unmask_all();
+}
+
+static struct timeval exit_time;
+
+void
+event_dispatch(void)
+{
+       struct timeval now;
+       struct event *ev, *next;
+       struct pollfd *iter, *last_iter;
+       int ret, timeout;
+
+loop:
+       if (active_events > poll_allocated) {
+               if (poll_allocated == 0)
+                       poll_allocated = 512;
+               while (active_events > poll_allocated)
+                       poll_allocated <<= 1;
+               poll_list = xrealloc(poll_list,
+                   sizeof(struct pollfd) * poll_allocated);
+       }
+
+       iter = poll_list;
+       LIST_FOREACH(ev, &all_events, ev_link) {
+               iter->fd = ev->ev_fd;
+               if (ev->ev_write)
+                       iter->events = POLLOUT;
+               else
+                       iter->events = POLLIN;
+               ++iter;
+       }
+       last_iter = iter;
+
+       if (exit_time.tv_sec || exit_time.tv_usec) {
+               gettimeofday(&now, NULL);
+               timeout = (exit_time.tv_sec - now.tv_sec) * 1000;
+               timeout += (exit_time.tv_usec - now.tv_usec + 999) / 1000;
+               if (timeout < 0)
+                       timeout = 0;
+       } else
+               timeout = -1;
+
+       ret = poll(poll_list, active_events, timeout);
+       if (ret < 0 && errno != EINTR)



Home | Main Index | Thread Index | Old Index