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))) {
67
rl_fatal(EX_SOFTWARE, "ABORT - failed to find function \"%s\" in parser module %s (%s)",
68
funcname, rl_parser, dlerror());
71
rl_fatal(EX_SOFTWARE, "ABORT - failed to load parser module %s (%s)",
72
rl_parser, dlerror());
87
if (rls_term_recv) { /* received SIGTERM or SIGINT */
88
run_library_func("services_free");
92
if(rls_need_parse || rls_reaped) {
98
run_library_func("parse");
102
rl_warn("rlinetd configuration (re)loaded, %ld bytes used\n",
103
m.uordblks - oldmem);
106
rl_warn("rlinetd configuration (re)loaded");
112
rl_pending = (struct pidtab *)rls_reaped;
117
p->next->prev = p->prev;
119
p->prev->next = p->next;
122
} while((p = p->next_cleanup));
130
run_bytecode(oplisttab_get(rl_pending->onexit), rl_pending->inst);
132
inst_free(rl_pending->inst);
133
p = rl_pending->next_cleanup;
139
if((n = select(hisock + 1, &srfds, &swfds, NULL, NULL)) < 0) {
144
rl_warn("select() failed - %s", strerror(errno));
151
for(i = 0; i <= hisock; i++) {
152
if(FD_ISSET(i, &srfds) && FD_ISSET(i, &rfds)) {
153
struct rl_instance *grr;
155
grr = rfd_ops[i].inst;
156
if(!rfd_ops[i].inst) {
160
run_bytecode(rfd_ops[i].op, grr);
162
if(FD_ISSET(i, &swfds) && FD_ISSET(i, &wfds))
163
run_bytecode(wfd_ops[i].op, wfd_ops[i].inst);
168
void listeners_set(int j) {
172
bound = getdtablesize();
173
fds = fdsettab_get(j);
174
for(i = 0; i <= bound; i++)
179
void listeners_clear(int j) {
183
bound = getdtablesize();
184
fds = fdsettab_get(j);
185
for(i = 0; i <= bound; i++)
191
static void fdops_grow(struct fd_ops **ops, int *len, int new) {
194
*ops = realloc(*ops, (new + 1) * sizeof(**ops));
196
rl_fatal(EX_SOFTWARE, "ABORT - Can't allocate memory");
200
void read_hook(int fd, rl_opcode_t *op, struct rl_instance *inst) {
201
fdops_grow(&rfd_ops, &rfd_len, fd);
203
rfd_ops[fd].inst = inst;
209
void read_unhook(int fd) {
210
fdops_grow(&rfd_ops, &rfd_len, fd);
214
void write_hook(int fd, rl_opcode_t *op, struct rl_instance *inst) {
215
fdops_grow(&wfd_ops, &wfd_len, fd);
217
wfd_ops[fd].inst = inst;
223
void write_unhook(int fd) {
224
fdops_grow(&wfd_ops, &wfd_len, fd);
241
struct rl_instance *inst_new() {
242
struct rl_instance *i;
244
i = malloc(sizeof(*i));
246
rl_fatal(EX_SOFTWARE, "ABORT - Can't allocate memory");
247
memset(i, 0, sizeof(*i));
251
void inst_free(struct rl_instance *i) {