-/* $OpenBSD: aproc.c,v 1.7 2008/08/14 09:44:15 ratchov Exp $ */
+/* $OpenBSD: aproc.c,v 1.8 2008/08/14 09:45:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
void
aproc_del(struct aproc *p)
{
+ if (p->ops->done)
+ p->ops->done(p);
DPRINTF("aproc_del: %s: %s: deleted\n", p->ops->name, p->name);
free(p);
}
}
void
-rpipe_del(struct aproc *p)
+rpipe_done(struct aproc *p)
{
struct file *f = p->u.io.file;
f->rproc = NULL;
f->events &= ~POLLIN;
- aproc_del(p);
}
void
{
DPRINTFN(3, "rpipe_eof: %s\n", p->name);
abuf_eof(LIST_FIRST(&p->obuflist));
- rpipe_del(p);
+ aproc_del(p);
}
void
rpipe_hup(struct aproc *p, struct abuf *obuf)
{
DPRINTFN(3, "rpipe_hup: %s\n", p->name);
- rpipe_del(p);
+ aproc_del(p);
}
struct aproc_ops rpipe_ops = {
- "rpipe", rpipe_in, rpipe_out, rpipe_eof, rpipe_hup, NULL, NULL
+ "rpipe", rpipe_in, rpipe_out, rpipe_eof, rpipe_hup, NULL, NULL, rpipe_done
};
struct aproc *
}
void
-wpipe_del(struct aproc *p)
+wpipe_done(struct aproc *p)
{
struct file *f = p->u.io.file;
f->wproc = NULL;
f->events &= ~POLLOUT;
- aproc_del(p);
}
int
abuf_rdiscard(ibuf, count);
if (ABUF_EOF(ibuf)) {
abuf_hup(ibuf);
- wpipe_del(p);
+ aproc_del(p);
return 0;
}
abuf_fill(ibuf);
wpipe_eof(struct aproc *p, struct abuf *ibuf)
{
DPRINTFN(3, "wpipe_eof: %s\n", p->name);
- wpipe_del(p);
+ aproc_del(p);
}
void
{
DPRINTFN(3, "wpipe_hup: %s\n", p->name);
abuf_hup(LIST_FIRST(&p->ibuflist));
- wpipe_del(p);
+ aproc_del(p);
}
struct aproc_ops wpipe_ops = {
- "wpipe", wpipe_in, wpipe_out, wpipe_eof, wpipe_hup, NULL, NULL
+ "wpipe", wpipe_in, wpipe_out, wpipe_eof, wpipe_hup, NULL, NULL, wpipe_done
};
struct aproc *
}
struct aproc_ops mix_ops = {
- "mix", mix_in, mix_out, mix_eof, mix_hup, mix_newin, mix_newout
+ "mix", mix_in, mix_out, mix_eof, mix_hup, mix_newin, mix_newout, NULL
};
struct aproc *
DPRINTF("sub_rm: %s\n", p->name);
}
-void
-sub_del(struct aproc *p)
-{
- aproc_del(p);
-}
-
int
sub_in(struct aproc *p, struct abuf *ibuf)
{
abuf_eof(i);
}
ibuf->wproc = NULL;
- sub_del(p);
+ aproc_del(p);
return 0;
}
abuf_fill(ibuf);
sub_rm(p, obuf);
abuf_eof(obuf);
}
- sub_del(p);
+ aproc_del(p);
}
void
sub_rm(p, obuf);
if (LIST_EMPTY(&p->obuflist)) {
abuf_hup(ibuf);
- sub_del(p);
+ aproc_del(p);
} else
abuf_run(ibuf);
DPRINTF("sub_hup: done\n");
}
struct aproc_ops sub_ops = {
- "sub", sub_in, sub_out, sub_eof, sub_hup, NULL, sub_newout
+ "sub", sub_in, sub_out, sub_eof, sub_hup, NULL, sub_newout, NULL
};
struct aproc *
abuf_wcommit(obuf, ocount);
}
-void
-conv_del(struct aproc *p)
-{
- aproc_del(p);
-}
-
int
conv_in(struct aproc *p, struct abuf *ibuf)
{
if (ABUF_EOF(ibuf)) {
obuf->wproc = NULL;
abuf_hup(ibuf);
- conv_del(p);
+ aproc_del(p);
return 0;
}
abuf_fill(ibuf);
conv_eof(struct aproc *p, struct abuf *ibuf)
{
abuf_eof(LIST_FIRST(&p->obuflist));
- conv_del(p);
+ aproc_del(p);
}
void
conv_hup(struct aproc *p, struct abuf *obuf)
{
abuf_hup(LIST_FIRST(&p->ibuflist));
- conv_del(p);
+ aproc_del(p);
}
void
}
struct aproc_ops conv_ops = {
- "conv", conv_in, conv_out, conv_eof, conv_hup, NULL, NULL
+ "conv", conv_in, conv_out, conv_eof, conv_hup, NULL, NULL, NULL
};
struct aproc *
-/* $OpenBSD: aproc.h,v 1.2 2008/06/02 17:06:36 ratchov Exp $ */
+/* $OpenBSD: aproc.h,v 1.3 2008/08/14 09:45:23 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
* A new output was connected
*/
void (*newout)(struct aproc *, struct abuf *);
+
+ /*
+ * destroy the aproc, called just before to free the
+ * aproc structure
+ */
+ void (*done)(struct aproc *);
};
struct aconv {
} u;
};
+struct aproc *aproc_new(struct aproc_ops *, char *);
void aproc_del(struct aproc *);
void aproc_setin(struct aproc *, struct abuf *);
void aproc_setout(struct aproc *, struct abuf *);
struct aproc *rpipe_new(struct file *);
+int rpipe_in(struct aproc *, struct abuf *);
+int rpipe_out(struct aproc *, struct abuf *);
+void rpipe_done(struct aproc *);
+void rpipe_eof(struct aproc *, struct abuf *);
+void rpipe_hup(struct aproc *, struct abuf *);
+
struct aproc *wpipe_new(struct file *);
+void wpipe_done(struct aproc *);
+int wpipe_in(struct aproc *, struct abuf *);
+int wpipe_out(struct aproc *, struct abuf *);
+void wpipe_eof(struct aproc *, struct abuf *);
+void wpipe_hup(struct aproc *, struct abuf *);
+
struct aproc *mix_new(void);
struct aproc *sub_new(void);
struct aproc *conv_new(char *, struct aparams *, struct aparams *);