4
#include <netinet/in.h>
12
#include <sys/types.h>
13
#include <sys/socket.h>
29
struct rl_cleanup *rl_cleanups = NULL;
31
extern char *rl_parser;
32
struct pidtab *rl_pending;
33
struct rl_instance *inst_new();
37
struct rl_instance *inst;
41
struct fd_ops *rfd_ops = NULL, *wfd_ops = NULL;
42
int rfd_len = 0, wfd_len = 0;
44
/* runs the specified function from our parser library */
45
static void run_library_func(char* funcname) {
50
if((handle = dlopen(rl_parser, RTLD_NOW
55
if((libfunc = dlsym(handle, funcname))) {
65
rl_fatal(EX_SOFTWARE, _("ABORT - failed to find function \"%s\" in parser module %s (%s)"),
66
funcname, rl_parser, dlerror());
69
rl_fatal(EX_SOFTWARE, _("ABORT - failed to load parser module %s (%s)"),
70
rl_parser, dlerror());
85
if (rls_term_recv) { /* received SIGTERM or SIGINT */
86
run_library_func("services_free");
90
if(rls_need_parse || rls_reaped) {
96
run_library_func("parse");
100
rl_warn(_("rlinetd configuration (re)loaded, %ld bytes used\n"),
101
m.uordblks - oldmem);
104
rl_warn(_("rlinetd configuration (re)loaded"));
110
rl_pending = (struct pidtab *)rls_reaped;
115
p->next->prev = p->prev;
117
p->prev->next = p->next;
120
} while((p = p->next_cleanup));
128
run_bytecode(oplisttab_get(rl_pending->onexit), rl_pending->inst);
130
inst_free(rl_pending->inst);
131
p = rl_pending->next_cleanup;
137
if((n = select(hisock + 1, &srfds, &swfds, NULL, NULL)) < 0) {
142
rl_warn(_("select() failed - %s"), strerror(errno));
149
for(i = 0; i <= hisock; i++) {
150
if(FD_ISSET(i, &srfds) && FD_ISSET(i, &rfds)) {
151
struct rl_instance *grr;
153
grr = rfd_ops[i].inst;
154
if(!rfd_ops[i].inst) {
158
run_bytecode(rfd_ops[i].op, grr);
160
if(FD_ISSET(i, &swfds) && FD_ISSET(i, &wfds))
161
run_bytecode(wfd_ops[i].op, wfd_ops[i].inst);
166
void listeners_set(int j) {
170
bound = getdtablesize();
171
fds = fdsettab_get(j);
172
for(i = 0; i <= bound; i++)
177
void listeners_clear(int j) {
181
bound = getdtablesize();
182
fds = fdsettab_get(j);
183
for(i = 0; i <= bound; i++)
189
static void fdops_grow(struct fd_ops **ops, int *len, int new) {
192
*ops = realloc(*ops, (new + 1) * sizeof(**ops));
194
rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
198
void read_hook(int fd, rl_opcode_t *op, struct rl_instance *inst) {
199
fdops_grow(&rfd_ops, &rfd_len, fd);
201
rfd_ops[fd].inst = inst;
207
void read_unhook(int fd) {
208
fdops_grow(&rfd_ops, &rfd_len, fd);
212
void write_hook(int fd, rl_opcode_t *op, struct rl_instance *inst) {
213
fdops_grow(&wfd_ops, &wfd_len, fd);
215
wfd_ops[fd].inst = inst;
221
void write_unhook(int fd) {
222
fdops_grow(&wfd_ops, &wfd_len, fd);
239
struct rl_instance *inst_new() {
240
struct rl_instance *i;
242
i = malloc(sizeof(*i));
244
rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
245
memset(i, 0, sizeof(*i));
249
void inst_free(struct rl_instance *i) {