read_tmo(int fd, void *ptr, unsigned len, double tmo)
{
int i;
- struct pollfd pfd[1];
+ struct pollfd pfd;
- pfd->fd = fd;
- pfd->events = POLLIN;
- i = poll(pfd, 1, (int)(tmo * 1e3));
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ i = poll(&pfd, 1, (int)(tmo * 1e3));
if (i == 0) {
errno = ETIMEDOUT;
return (-1);
void mgt_cli_init(void);
void mgt_cli_setup(int fdi, int fdo, int verbose);
-int mgt_cli_askchild(int *status, char **resp, const char *fmt, ...);
+int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...);
void mgt_cli_start_child(int fdi, int fdo);
void mgt_cli_stop_child(void);
/* mgt_vcc.c */
void mgt_vcc_init(void);
int mgt_vcc_default(const char *bflag, const char *fflag);
-int mgt_push_vcls_and_start(int *status, char **p);
+int mgt_push_vcls_and_start(unsigned *status, char **p);
/* tcp.c */
int open_tcp(const char *port);
static unsigned child_should_run;
struct evbase *mgt_evb;
+struct ev *ev_poker;
+struct ev *ev_listen;
/*--------------------------------------------------------------------*/
char buf[BUFSIZ];
(void)e;
- if ((what & ~EV_RD))
+ if ((what & ~EV_RD)) {
+ ev_listen = NULL;
return (1);
+ }
i = read(child_fds[0], buf, sizeof buf - 1);
- if (i <= 0)
+ if (i <= 0) {
+ ev_listen = NULL;
return (1);
+ }
buf[i] = '\0';
printf("Child said: <<%s>>\n", buf);
return (0);
e->name = "Child listener";
e->callback = child_listener;
AZ(ev_add(mgt_evb, e));
+ ev_listen = e;
e = ev_new();
assert(e != NULL);
e->callback = child_poker;
e->name = "child poker";
AZ(ev_add(mgt_evb, e));
-
+ ev_poker = e;
mgt_cli_start_child(heritage.fds[0], heritage.fds[3]);
AZ(close(heritage.fds[1]));
if (child_pid < 0)
return;
+ if (ev_poker != NULL)
+ ev_del(mgt_evb, ev_poker);
+ ev_poker = NULL;
+
child_should_run = 0;
printf("Clean child\n");
(void)e;
(void)what;
+
+ if (ev_poker != NULL)
+ ev_del(mgt_evb, ev_poker);
+ ev_poker = NULL;
+
r = wait4(-1, &status, WNOHANG, NULL);
if (r != child_pid) {
printf("Unknown child died pid=%d status=0x%x\n",
heritage.fds[3] = -1;
}
+ if (ev_listen != NULL)
+ ev_del(mgt_evb, ev_listen);
+ ev_listen = NULL;
+
AZ(close(child_fds[0]));
child_fds[0] = -1;
printf("Child cleaned\n");
AZ(sigaction(SIGPIPE, &sac, NULL));
AZ(sigaction(SIGHUP, &sac, NULL));
- printf("rolling...\n");
+ printf("rolling(1)...\n");
+ fprintf(stderr, "rolling(2)...\n");
if (!dflag)
start_child();
*/
int
-mgt_cli_askchild(int *status, char **resp, const char *fmt, ...)
+mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...)
{
char *p;
- int i, j;
+ int i;
va_list ap;
+ unsigned u;
va_start(ap, fmt);
i = vasprintf(&p, fmt, ap);
assert(i == strlen(p));
free(p);
- i = cli_readres(cli_i, &j, resp, 3.0);
+ i = cli_readres(cli_i, &u, resp, 3.0);
assert(i == 0);
if (status != NULL)
- *status = j;
- return (j == CLIS_OK ? 0 : j);
+ *status = u;
+ return (u == CLIS_OK ? 0 : u);
}
/*--------------------------------------------------------------------*/
if (p == NULL)
return (0);
*p = '\0';
+fprintf(stderr, "CLI <%s>\n", cp->buf);
sbuf_clear(cp->cli->sb);
cli_dispatch(cp->cli, cli_proto, cp->buf);
sbuf_finish(cp->cli->sb);
if (evb->npfd > 256)
u = evb->npfd + 256;
- else if (evb->npfd > 8)
- u = evb->npfd * 2;
- else
+ else if (evb->npfd < 8)
u = 8;
+ else
+ u = evb->npfd * 2;
p = realloc(evb->pfd, sizeof *evb->pfd * u);
if (p == NULL)
return (1);
}
if (e->fd >= 0) {
+ assert(evb->lpfd < evb->npfd);
evb->pfd[evb->lpfd].fd = e->fd;
evb->pfd[evb->lpfd].events =
e->fd_flags & (EV_RD|EV_WR|EV_ERR|EV_HUP);
if (e->fd >= 0) {
evb->pfd[e->__poll_idx].fd = -1;
- evb->compact_pfd++;
+ if (e->__poll_idx == evb->lpfd - 1)
+ evb->lpfd--;
+ else
+ evb->compact_pfd++;
e->fd = -1;
}
static void
ev_compact_pfd(struct evbase *evb)
{
- /* XXX TBD */
+ unsigned u;
+ struct pollfd *p;
+ struct ev *ep;
+
+ p = evb->pfd;
+ ep = TAILQ_FIRST(&evb->events);
+ for (u = 0; u < evb->lpfd; u++, p++) {
+ if (p->fd >= 0)
+ continue;
+ for(; ep != NULL; ep = TAILQ_NEXT(ep, __list)) {
+ if (ep->fd >= 0 && ep->__poll_idx > u)
+ break;
+ }
+ if (ep == NULL)
+ break;
+ *p = evb->pfd[ep->__poll_idx];
+ ep->__poll_idx = u;
+ }
+ evb->lpfd = u;
evb->compact_pfd = 0;
}
CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC);
e = binheap_root(evb->binheap);
if (e != NULL) {
- assert(e->__binheap_idx == 1);
CHECK_OBJ_NOTNULL(e, EV_MAGIC);
+ assert(e->__binheap_idx == 1);
t = ev_now();
if (e->__when <= t)
return (ev_sched_timeout(evb, e, t));
if (evb->psig)
return (ev_sched_signal(evb));
+ assert(evb->lpfd < evb->npfd);
i = poll(evb->pfd, evb->lpfd, tmo);
if(i == -1 && errno == EINTR)
return (ev_sched_signal(evb));
assert(e->__poll_idx < evb->lpfd);
pfd = &evb->pfd[e->__poll_idx];
assert(pfd->fd == e->fd);
- assert(pfd->events == e->fd_flags);
if (!pfd->revents)
continue;
j = e->callback(e, pfd->revents);
/*--------------------------------------------------------------------*/
int
-mgt_push_vcls_and_start(int *status, char **p)
+mgt_push_vcls_and_start(unsigned *status, char **p)
{
struct vclprog *vp;
{
char *vf, *p;
struct sbuf *sb;
- int status;
+ unsigned status;
(void)priv;
{
char *vf;
struct sbuf *sb;
- int status;
+ unsigned status;
char *p;
(void)priv;
void
mcf_config_use(struct cli *cli, char **av, void *priv)
{
- int status;
+ unsigned status;
char *p;
struct vclprog *vp;
void
mcf_config_discard(struct cli *cli, char **av, void *priv)
{
- int status;
+ unsigned status;
char *p;
struct vclprog *vp;
void
mcf_config_list(struct cli *cli, char **av, void *priv)
{
- int status;
+ unsigned status;
char *p;
struct vclprog *vp;