Improve kqueue(2) utilization:
- Don't invoke kevent(2) for every single event change. Instead collect event changes and try to do them in the event loop. - Handle signals via kevent(2) to avoid race conditions for SIGHUP (which probably exist in the select(2) based implementation, too).
This commit is contained in:
parent
d6b6eb78e4
commit
726769ad02
@ -1,12 +1,12 @@
|
|||||||
/* $NetBSD: inetd.c,v 1.86 2003/02/12 10:03:47 tron Exp $ */
|
/* $NetBSD: inetd.c,v 1.87 2003/02/13 11:47:27 tron Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
* Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
||||||
* NASA Ames Research Center.
|
* NASA Ames Research Center and by Matthias Scheler.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1991, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94";
|
static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: inetd.c,v 1.86 2003/02/12 10:03:47 tron Exp $");
|
__RCSID("$NetBSD: inetd.c,v 1.87 2003/02/13 11:47:27 tron Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -271,6 +271,8 @@ int deny_severity = LIBWRAP_DENY_FACILITY|LIBWRAP_DENY_SEVERITY;
|
|||||||
|
|
||||||
#define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM))
|
#define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM))
|
||||||
|
|
||||||
|
#define A_CNT(a) (sizeof (a) / sizeof (a[0]))
|
||||||
|
|
||||||
int debug;
|
int debug;
|
||||||
#ifdef LIBWRAP
|
#ifdef LIBWRAP
|
||||||
int lflag;
|
int lflag;
|
||||||
@ -295,6 +297,9 @@ rlim_t rlim_ofile_cur = OPEN_MAX;
|
|||||||
struct rlimit rlim_ofile;
|
struct rlimit rlim_ofile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct kevent changebuf[64];
|
||||||
|
size_t changes;
|
||||||
|
|
||||||
struct servtab {
|
struct servtab {
|
||||||
char *se_hostaddr; /* host address to listen on */
|
char *se_hostaddr; /* host address to listen on */
|
||||||
char *se_service; /* name of service */
|
char *se_service; /* name of service */
|
||||||
@ -349,52 +354,52 @@ struct servtab {
|
|||||||
#define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE)
|
#define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE)
|
||||||
|
|
||||||
|
|
||||||
void chargen_dg(int, struct servtab *);
|
static void chargen_dg(int, struct servtab *);
|
||||||
void chargen_stream(int, struct servtab *);
|
static void chargen_stream(int, struct servtab *);
|
||||||
void close_sep(struct servtab *);
|
static void close_sep(struct servtab *);
|
||||||
void config(int);
|
static void config(void);
|
||||||
void daytime_dg(int, struct servtab *);
|
static void daytime_dg(int, struct servtab *);
|
||||||
void daytime_stream(int, struct servtab *);
|
static void daytime_stream(int, struct servtab *);
|
||||||
void discard_dg(int, struct servtab *);
|
static void discard_dg(int, struct servtab *);
|
||||||
void discard_stream(int, struct servtab *);
|
static void discard_stream(int, struct servtab *);
|
||||||
void echo_dg(int, struct servtab *);
|
static void echo_dg(int, struct servtab *);
|
||||||
void echo_stream(int, struct servtab *);
|
static void echo_stream(int, struct servtab *);
|
||||||
void endconfig(void);
|
static void endconfig(void);
|
||||||
struct servtab *enter(struct servtab *);
|
static struct servtab *enter(struct servtab *);
|
||||||
void freeconfig(struct servtab *);
|
static void freeconfig(struct servtab *);
|
||||||
struct servtab *getconfigent(void);
|
static struct servtab *getconfigent(void);
|
||||||
void goaway(int);
|
static void goaway(void);
|
||||||
void machtime_dg(int, struct servtab *);
|
static void machtime_dg(int, struct servtab *);
|
||||||
void machtime_stream(int, struct servtab *);
|
static void machtime_stream(int, struct servtab *);
|
||||||
char *newstr(char *);
|
static char *newstr(char *);
|
||||||
char *nextline(FILE *);
|
static char *nextline(FILE *);
|
||||||
void print_service(char *, struct servtab *);
|
static void print_service(char *, struct servtab *);
|
||||||
void reapchild(int);
|
static void reapchild(void);
|
||||||
void retry(int);
|
static void retry(void);
|
||||||
void run_service(int, struct servtab *);
|
static void run_service(int, struct servtab *);
|
||||||
int setconfig(void);
|
static int setconfig(void);
|
||||||
void setup(struct servtab *);
|
static void setup(struct servtab *);
|
||||||
char *sskip(char **);
|
static char *sskip(char **);
|
||||||
char *skip(char **);
|
static char *skip(char **);
|
||||||
void tcpmux(int, struct servtab *);
|
static void tcpmux(int, struct servtab *);
|
||||||
void usage(void);
|
static void usage(void);
|
||||||
void register_rpc(struct servtab *);
|
static void register_rpc(struct servtab *);
|
||||||
void unregister_rpc(struct servtab *);
|
static void unregister_rpc(struct servtab *);
|
||||||
void bump_nofile(void);
|
static void bump_nofile(void);
|
||||||
void inetd_setproctitle(char *, int);
|
static void inetd_setproctitle(char *, int);
|
||||||
void initring(void);
|
static void initring(void);
|
||||||
uint32_t machtime(void);
|
static uint32_t machtime(void);
|
||||||
int port_good_dg(struct sockaddr *);
|
static int port_good_dg(struct sockaddr *);
|
||||||
int dg_broadcast(struct in_addr *);
|
static int dg_broadcast(struct in_addr *);
|
||||||
static int my_kevent(const struct kevent *, size_t, struct kevent *,
|
static int my_kevent(const struct kevent *, size_t, struct kevent *,
|
||||||
size_t);
|
size_t);
|
||||||
|
static struct kevent * allocchange(void);
|
||||||
static int getline(int, char *, int);
|
static int getline(int, char *, int);
|
||||||
int main(int, char *[]);
|
static void spawn(struct servtab *, int);
|
||||||
void spawn(struct servtab *, int);
|
|
||||||
#ifdef MULOG
|
#ifdef MULOG
|
||||||
void dolog(struct servtab *, int);
|
static void dolog(struct servtab *, int);
|
||||||
static void timeout(int);
|
static void timeout(int);
|
||||||
char *rfc931_name(struct sockaddr *, int);
|
static char *rfc931_name(struct sockaddr *, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct biltin {
|
struct biltin {
|
||||||
@ -441,14 +446,13 @@ u_int16_t bad_ports[] = { 7, 9, 13, 19, 37, 0 };
|
|||||||
#define NUMINT (sizeof(intab) / sizeof(struct inent))
|
#define NUMINT (sizeof(intab) / sizeof(struct inent))
|
||||||
char *CONFIG = _PATH_INETDCONF;
|
char *CONFIG = _PATH_INETDCONF;
|
||||||
|
|
||||||
|
static int my_signals[] = { SIGALRM, SIGHUP, SIGCHLD, SIGTERM, SIGINT };
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
struct servtab *sep;
|
int ch, n, reload = 1;
|
||||||
struct sigvec sv;
|
struct kevent *ev;
|
||||||
int ch;
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv,
|
while ((ch = getopt(argc, argv,
|
||||||
#ifdef LIBWRAP
|
#ifdef LIBWRAP
|
||||||
@ -477,7 +481,7 @@ main(argc, argv)
|
|||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
CONFIG = argv[0];
|
CONFIG = argv[0];
|
||||||
|
|
||||||
if (debug == 0)
|
if (!debug)
|
||||||
daemon(0, 0);
|
daemon(0, 0);
|
||||||
openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
|
openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
|
||||||
pidfile(NULL);
|
pidfile(NULL);
|
||||||
@ -498,26 +502,23 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&sv, 0, sizeof(sv));
|
for (n = 0; n < A_CNT(my_signals); n++) {
|
||||||
sv.sv_mask = SIGBLOCK;
|
(void) signal(my_signals[n], SIG_IGN);
|
||||||
sv.sv_handler = retry;
|
ev = allocchange();
|
||||||
sigvec(SIGALRM, &sv, NULL);
|
EV_SET(ev, my_signals[n], EVFILT_SIGNAL, EV_ADD | EV_ENABLE,
|
||||||
config(SIGHUP);
|
0, 0, NULL);
|
||||||
sv.sv_handler = config;
|
}
|
||||||
sigvec(SIGHUP, &sv, NULL);
|
(void) signal(SIGPIPE, SIG_IGN);
|
||||||
sv.sv_handler = reapchild;
|
|
||||||
sigvec(SIGCHLD, &sv, NULL);
|
|
||||||
sv.sv_handler = goaway;
|
|
||||||
sigvec(SIGTERM, &sv, NULL);
|
|
||||||
sv.sv_handler = goaway;
|
|
||||||
sigvec(SIGINT, &sv, NULL);
|
|
||||||
sv.sv_mask = 0L;
|
|
||||||
sv.sv_handler = SIG_IGN;
|
|
||||||
sigvec(SIGPIPE, &sv, NULL);
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int n, ctrl;
|
int ctrl;
|
||||||
struct kevent ev[256], *evp;
|
struct kevent eventbuf[64];
|
||||||
|
struct servtab *sep;
|
||||||
|
|
||||||
|
if (reload) {
|
||||||
|
reload = 0;
|
||||||
|
config();
|
||||||
|
}
|
||||||
|
|
||||||
if (nsock == 0) {
|
if (nsock == 0) {
|
||||||
(void) sigblock(SIGBLOCK);
|
(void) sigblock(SIGBLOCK);
|
||||||
@ -525,13 +526,33 @@ main(argc, argv)
|
|||||||
sigpause(0L);
|
sigpause(0L);
|
||||||
(void) sigsetmask(0L);
|
(void) sigsetmask(0L);
|
||||||
}
|
}
|
||||||
n = my_kevent(NULL, 0, ev, sizeof(ev) / sizeof(ev[0]));
|
n = my_kevent(changebuf, changes, eventbuf, A_CNT(eventbuf));
|
||||||
for (evp = ev; n > 0; evp++, n--) {
|
changes = 0;
|
||||||
if (evp->filter != EVFILT_READ)
|
|
||||||
|
for (ev = eventbuf; n > 0; ev++, n--) {
|
||||||
|
if (ev->filter == EVFILT_SIGNAL) {
|
||||||
|
switch (ev->ident) {
|
||||||
|
case SIGALRM:
|
||||||
|
retry();
|
||||||
|
break;
|
||||||
|
case SIGCHLD:
|
||||||
|
reapchild();
|
||||||
|
break;
|
||||||
|
case SIGTERM:
|
||||||
|
case SIGINT:
|
||||||
|
goaway();
|
||||||
|
break;
|
||||||
|
case SIGHUP:
|
||||||
|
reload = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
sep = (struct servtab *)evp->udata;
|
}
|
||||||
|
if (ev->filter != EVFILT_READ)
|
||||||
|
continue;
|
||||||
|
sep = (struct servtab *)ev->udata;
|
||||||
/* Paranoia */
|
/* Paranoia */
|
||||||
if (sep->se_fd != evp->ident)
|
if (ev->ident != sep->se_fd)
|
||||||
continue;
|
continue;
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "someone wants %s\n", sep->se_service);
|
fprintf(stderr, "someone wants %s\n", sep->se_service);
|
||||||
@ -556,10 +577,8 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
spawn(sep, ctrl)
|
spawn(struct servtab *sep, int ctrl)
|
||||||
struct servtab *sep;
|
|
||||||
int ctrl;
|
|
||||||
{
|
{
|
||||||
int dofork;
|
int dofork;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -607,12 +626,12 @@ spawn(sep, ctrl)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pid != 0 && sep->se_wait) {
|
if (pid != 0 && sep->se_wait) {
|
||||||
struct kevent ev;
|
struct kevent *ev;
|
||||||
|
|
||||||
sep->se_wait = pid;
|
sep->se_wait = pid;
|
||||||
EV_SET(&ev, sep->se_fd, EVFILT_READ,
|
ev = allocchange();
|
||||||
|
EV_SET(ev, sep->se_fd, EVFILT_READ,
|
||||||
EV_DELETE, 0, 0, 0);
|
EV_DELETE, 0, 0, 0);
|
||||||
(void) my_kevent(&ev, 1, NULL, 0);
|
|
||||||
nsock--;
|
nsock--;
|
||||||
}
|
}
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
@ -634,10 +653,8 @@ spawn(sep, ctrl)
|
|||||||
close(ctrl);
|
close(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
run_service(ctrl, sep)
|
run_service(int ctrl, struct servtab *sep)
|
||||||
int ctrl;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct group *grp = NULL; /* XXX gcc */
|
struct group *grp = NULL; /* XXX gcc */
|
||||||
@ -747,9 +764,8 @@ run_service(ctrl, sep)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
reapchild(signo)
|
reapchild(void)
|
||||||
int signo;
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -760,11 +776,11 @@ reapchild(signo)
|
|||||||
if (pid <= 0)
|
if (pid <= 0)
|
||||||
break;
|
break;
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "%d reaped, status %#x\n",
|
(void) fprintf(stderr, "%d reaped, status %#x\n",
|
||||||
pid, status);
|
pid, status);
|
||||||
for (sep = servtab; sep != NULL; sep = sep->se_next)
|
for (sep = servtab; sep != NULL; sep = sep->se_next)
|
||||||
if (sep->se_wait == pid) {
|
if (sep->se_wait == pid) {
|
||||||
struct kevent ev;
|
struct kevent *ev;
|
||||||
|
|
||||||
if (WIFEXITED(status) && WEXITSTATUS(status))
|
if (WIFEXITED(status) && WEXITSTATUS(status))
|
||||||
syslog(LOG_WARNING,
|
syslog(LOG_WARNING,
|
||||||
@ -775,9 +791,9 @@ reapchild(signo)
|
|||||||
"%s: exit signal 0x%x",
|
"%s: exit signal 0x%x",
|
||||||
sep->se_server, WTERMSIG(status));
|
sep->se_server, WTERMSIG(status));
|
||||||
sep->se_wait = 1;
|
sep->se_wait = 1;
|
||||||
EV_SET(&ev, sep->se_fd, EVFILT_READ,
|
ev = allocchange();
|
||||||
|
EV_SET(ev, sep->se_fd, EVFILT_READ,
|
||||||
EV_ADD | EV_ENABLE, 0, 0, (intptr_t)sep);
|
EV_ADD | EV_ENABLE, 0, 0, (intptr_t)sep);
|
||||||
(void) my_kevent(&ev, 1, NULL, 0);
|
|
||||||
nsock++;
|
nsock++;
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "restored %s, fd %d\n",
|
fprintf(stderr, "restored %s, fd %d\n",
|
||||||
@ -786,9 +802,8 @@ reapchild(signo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
config(signo)
|
config(void)
|
||||||
int signo;
|
|
||||||
{
|
{
|
||||||
struct servtab *sep, *cp, **sepp;
|
struct servtab *sep, *cp, **sepp;
|
||||||
long omask;
|
long omask;
|
||||||
@ -807,7 +822,7 @@ config(signo)
|
|||||||
strcmp(sep->se_proto, cp->se_proto) == 0 &&
|
strcmp(sep->se_proto, cp->se_proto) == 0 &&
|
||||||
ISMUX(sep) == ISMUX(cp))
|
ISMUX(sep) == ISMUX(cp))
|
||||||
break;
|
break;
|
||||||
if (sep != 0) {
|
if (sep != NULL) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#define SWAP(type, a, b) {type c=(type)a; (type)a=(type)b; (type)b=(type)c;}
|
#define SWAP(type, a, b) {type c=(type)a; (type)a=(type)b; (type)b=(type)c;}
|
||||||
@ -990,14 +1005,13 @@ config(signo)
|
|||||||
if (debug)
|
if (debug)
|
||||||
print_service("FREE", sep);
|
print_service("FREE", sep);
|
||||||
freeconfig(sep);
|
freeconfig(sep);
|
||||||
free((char *)sep);
|
free(sep);
|
||||||
}
|
}
|
||||||
(void) sigsetmask(omask);
|
(void) sigsetmask(omask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
retry(signo)
|
retry(void)
|
||||||
int signo;
|
|
||||||
{
|
{
|
||||||
struct servtab *sep;
|
struct servtab *sep;
|
||||||
|
|
||||||
@ -1019,9 +1033,8 @@ retry(signo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
goaway(signo)
|
goaway(void)
|
||||||
int signo;
|
|
||||||
{
|
{
|
||||||
struct servtab *sep;
|
struct servtab *sep;
|
||||||
|
|
||||||
@ -1046,12 +1059,11 @@ goaway(signo)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
setup(sep)
|
setup(struct servtab *sep)
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
int on = 1;
|
int on = 1;
|
||||||
struct kevent ev;
|
struct kevent *ev;
|
||||||
|
|
||||||
if ((sep->se_fd = socket(sep->se_family, sep->se_socktype, 0)) < 0) {
|
if ((sep->se_fd = socket(sep->se_family, sep->se_socktype, 0)) < 0) {
|
||||||
if (debug)
|
if (debug)
|
||||||
@ -1118,9 +1130,9 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
|
|||||||
if (sep->se_socktype == SOCK_STREAM)
|
if (sep->se_socktype == SOCK_STREAM)
|
||||||
listen(sep->se_fd, 10);
|
listen(sep->se_fd, 10);
|
||||||
|
|
||||||
EV_SET(&ev, sep->se_fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0,
|
ev = allocchange();
|
||||||
|
EV_SET(ev, sep->se_fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0,
|
||||||
(intptr_t)sep);
|
(intptr_t)sep);
|
||||||
(void) my_kevent(&ev, 1, NULL, 0);
|
|
||||||
nsock++;
|
nsock++;
|
||||||
if (sep->se_fd > maxsock) {
|
if (sep->se_fd > maxsock) {
|
||||||
maxsock = sep->se_fd;
|
maxsock = sep->se_fd;
|
||||||
@ -1135,9 +1147,8 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
|
|||||||
/*
|
/*
|
||||||
* Finish with a service and its socket.
|
* Finish with a service and its socket.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
close_sep(sep)
|
close_sep(struct servtab *sep)
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
if (sep->se_fd >= 0) {
|
if (sep->se_fd >= 0) {
|
||||||
nsock--;
|
nsock--;
|
||||||
@ -1153,9 +1164,8 @@ close_sep(sep)
|
|||||||
sep->se_wait = 1;
|
sep->se_wait = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
register_rpc(sep)
|
register_rpc(struct servtab *sep)
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
#ifdef RPC
|
#ifdef RPC
|
||||||
int n;
|
int n;
|
||||||
@ -1192,9 +1202,8 @@ register_rpc(sep)
|
|||||||
#endif /* RPC */
|
#endif /* RPC */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
unregister_rpc(sep)
|
unregister_rpc(struct servtab *sep)
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
#ifdef RPC
|
#ifdef RPC
|
||||||
int n;
|
int n;
|
||||||
@ -1218,9 +1227,8 @@ unregister_rpc(sep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct servtab *
|
static struct servtab *
|
||||||
enter(cp)
|
enter(struct servtab *cp)
|
||||||
struct servtab *cp;
|
|
||||||
{
|
{
|
||||||
struct servtab *sep;
|
struct servtab *sep;
|
||||||
long omask;
|
long omask;
|
||||||
@ -1248,8 +1256,8 @@ char *defhost;
|
|||||||
static char *policy = NULL;
|
static char *policy = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
static int
|
||||||
setconfig()
|
setconfig(void)
|
||||||
{
|
{
|
||||||
if (defhost)
|
if (defhost)
|
||||||
free(defhost);
|
free(defhost);
|
||||||
@ -1267,21 +1275,21 @@ setconfig()
|
|||||||
return (fconfig != NULL);
|
return (fconfig != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
endconfig()
|
endconfig(void)
|
||||||
{
|
{
|
||||||
if (fconfig) {
|
if (fconfig != NULL) {
|
||||||
(void) fclose(fconfig);
|
(void) fclose(fconfig);
|
||||||
fconfig = NULL;
|
fconfig = NULL;
|
||||||
}
|
}
|
||||||
if (defhost) {
|
if (defhost != NULL) {
|
||||||
free(defhost);
|
free(defhost);
|
||||||
defhost = 0;
|
defhost = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct servtab *
|
static struct servtab *
|
||||||
getconfigent()
|
getconfigent(void)
|
||||||
{
|
{
|
||||||
struct servtab *sep = &serv;
|
struct servtab *sep = &serv;
|
||||||
int argc, val;
|
int argc, val;
|
||||||
@ -1664,9 +1672,8 @@ do { \
|
|||||||
return (sep);
|
return (sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
freeconfig(cp)
|
freeconfig(struct servtab *cp)
|
||||||
struct servtab *cp;
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1695,9 +1702,8 @@ freeconfig(cp)
|
|||||||
* Safe skip - if skip returns null, log a syntax error in the
|
* Safe skip - if skip returns null, log a syntax error in the
|
||||||
* configuration file and exit.
|
* configuration file and exit.
|
||||||
*/
|
*/
|
||||||
char *
|
static char *
|
||||||
sskip(cpp)
|
sskip(char **cpp)
|
||||||
char **cpp;
|
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
@ -1709,9 +1715,8 @@ sskip(cpp)
|
|||||||
return (cp);
|
return (cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
skip(cpp)
|
skip(char **cpp)
|
||||||
char **cpp;
|
|
||||||
{
|
{
|
||||||
char *cp = *cpp;
|
char *cp = *cpp;
|
||||||
char *start;
|
char *start;
|
||||||
@ -1742,9 +1747,8 @@ again:
|
|||||||
return (start);
|
return (start);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
nextline(fd)
|
nextline(FILE *fd)
|
||||||
FILE *fd;
|
|
||||||
{
|
{
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
@ -1756,20 +1760,17 @@ nextline(fd)
|
|||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
newstr(cp)
|
newstr(char *cp)
|
||||||
char *cp;
|
|
||||||
{
|
{
|
||||||
if ((cp = strdup(cp ? cp : "")))
|
if ((cp = strdup((cp !=NULL )? cp : "")) != NULL)
|
||||||
return (cp);
|
return (cp);
|
||||||
syslog(LOG_ERR, "strdup: %m");
|
syslog(LOG_ERR, "strdup: %m");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
inetd_setproctitle(a, s)
|
inetd_setproctitle(char *a, int s)
|
||||||
char *a;
|
|
||||||
int s;
|
|
||||||
{
|
{
|
||||||
socklen_t size;
|
socklen_t size;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@ -1786,8 +1787,8 @@ inetd_setproctitle(a, s)
|
|||||||
setproctitle("-%s", a);
|
setproctitle("-%s", a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
bump_nofile()
|
bump_nofile(void)
|
||||||
{
|
{
|
||||||
#ifdef RLIMIT_NOFILE
|
#ifdef RLIMIT_NOFILE
|
||||||
|
|
||||||
@ -1827,10 +1828,8 @@ bump_nofile()
|
|||||||
#define BUFSIZE 4096
|
#define BUFSIZE 4096
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
echo_stream(s, sep) /* Echo service -- echo data back */
|
echo_stream(int s, struct servtab *sep) /* Echo service -- echo data back */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZE];
|
char buffer[BUFSIZE];
|
||||||
int i;
|
int i;
|
||||||
@ -1842,10 +1841,8 @@ echo_stream(s, sep) /* Echo service -- echo data back */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
echo_dg(s, sep) /* Echo service -- echo data back */
|
echo_dg(int s, struct servtab *sep) /* Echo service -- echo data back */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZE];
|
char buffer[BUFSIZE];
|
||||||
int i;
|
int i;
|
||||||
@ -1862,10 +1859,8 @@ echo_dg(s, sep) /* Echo service -- echo data back */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
discard_stream(s, sep) /* Discard service -- ignore data */
|
discard_stream(int s, struct servtab *sep) /* Discard service -- ignore data */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZE];
|
char buffer[BUFSIZE];
|
||||||
|
|
||||||
@ -1876,10 +1871,9 @@ discard_stream(s, sep) /* Discard service -- ignore data */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
discard_dg(s, sep) /* Discard service -- ignore data */
|
discard_dg(int s, struct servtab *sep) /* Discard service -- ignore data */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZE];
|
char buffer[BUFSIZE];
|
||||||
|
|
||||||
@ -1891,8 +1885,8 @@ discard_dg(s, sep) /* Discard service -- ignore data */
|
|||||||
char ring[128];
|
char ring[128];
|
||||||
char *endring;
|
char *endring;
|
||||||
|
|
||||||
void
|
static void
|
||||||
initring()
|
initring(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1904,10 +1898,8 @@ initring()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
chargen_stream(s, sep) /* Character generator */
|
chargen_stream(int s,struct servtab *sep) /* Character generator */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *rs, text[LINESIZ+2];
|
char *rs, text[LINESIZ+2];
|
||||||
@ -1936,10 +1928,8 @@ chargen_stream(s, sep) /* Character generator */
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
chargen_dg(s, sep) /* Character generator */
|
chargen_dg(int s, struct servtab *sep) /* Character generator */
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
@ -1982,8 +1972,8 @@ chargen_dg(s, sep) /* Character generator */
|
|||||||
* some seventy years Bell Labs was asleep.
|
* some seventy years Bell Labs was asleep.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32_t
|
static uint32_t
|
||||||
machtime()
|
machtime(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
@ -1998,10 +1988,8 @@ machtime()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
machtime_stream(s, sep)
|
machtime_stream(int s, struct servtab *sep)
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
|
|
||||||
@ -2011,9 +1999,7 @@ machtime_stream(s, sep)
|
|||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
void
|
||||||
machtime_dg(s, sep)
|
machtime_dg(int s, struct servtab *sep)
|
||||||
int s;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@ -2031,10 +2017,9 @@ machtime_dg(s, sep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
static void
|
||||||
daytime_stream(s, sep) /* Return human-readable time of day */
|
daytime_stream(int s,struct servtab *sep)
|
||||||
int s;
|
/* Return human-readable time of day */
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
time_t clock;
|
time_t clock;
|
||||||
@ -2048,9 +2033,8 @@ daytime_stream(s, sep) /* Return human-readable time of day */
|
|||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
void
|
void
|
||||||
daytime_dg(s, sep) /* Return human-readable time of day */
|
daytime_dg(int s, struct servtab *sep)
|
||||||
int s;
|
/* Return human-readable time of day */
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
time_t clock;
|
time_t clock;
|
||||||
@ -2075,10 +2059,8 @@ daytime_dg(s, sep) /* Return human-readable time of day */
|
|||||||
* print_service:
|
* print_service:
|
||||||
* Dump relevant information to stderr
|
* Dump relevant information to stderr
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
print_service(action, sep)
|
print_service(char *action, struct servtab *sep)
|
||||||
char *action;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isrpcservice(sep))
|
if (isrpcservice(sep))
|
||||||
@ -2114,10 +2096,9 @@ print_service(action, sep)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef LIBWRAP
|
#ifdef LIBWRAP
|
||||||
(void)fprintf(stderr, "usage: %s [-dl] [conf]\n", getprogname());
|
(void)fprintf(stderr, "usage: %s [-dl] [conf]\n", getprogname());
|
||||||
#else
|
#else
|
||||||
@ -2133,10 +2114,7 @@ usage()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int /* # of characters upto \r,\n or \0 */
|
static int /* # of characters upto \r,\n or \0 */
|
||||||
getline(fd, buf, len)
|
getline(int fd, char *buf, int len)
|
||||||
int fd;
|
|
||||||
char *buf;
|
|
||||||
int len;
|
|
||||||
{
|
{
|
||||||
int count = 0, n;
|
int count = 0, n;
|
||||||
|
|
||||||
@ -2160,10 +2138,8 @@ getline(fd, buf, len)
|
|||||||
|
|
||||||
#define strwrite(fd, buf) (void) write(fd, buf, sizeof(buf)-1)
|
#define strwrite(fd, buf) (void) write(fd, buf, sizeof(buf)-1)
|
||||||
|
|
||||||
void
|
static void
|
||||||
tcpmux(ctrl, sep)
|
tcpmux(int ctrl, struct servtab *sep)
|
||||||
int ctrl;
|
|
||||||
struct servtab *sep;
|
|
||||||
{
|
{
|
||||||
char service[MAX_SERV_LEN+1];
|
char service[MAX_SERV_LEN+1];
|
||||||
int len;
|
int len;
|
||||||
@ -2213,9 +2189,7 @@ reject:
|
|||||||
|
|
||||||
#ifdef MULOG
|
#ifdef MULOG
|
||||||
void
|
void
|
||||||
dolog(sep, ctrl)
|
dolog(struct servtab *sep, int ctrl)
|
||||||
struct servtab *sep;
|
|
||||||
int ctrl;
|
|
||||||
{
|
{
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
struct sockaddr *sa = (struct sockaddr *)&ss;
|
struct sockaddr *sa = (struct sockaddr *)&ss;
|
||||||
@ -2308,8 +2282,7 @@ static jmp_buf timebuf;
|
|||||||
/* timeout - handle timeouts */
|
/* timeout - handle timeouts */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
timeout(sig)
|
timeout(int sig)
|
||||||
int sig;
|
|
||||||
{
|
{
|
||||||
longjmp(timebuf, sig);
|
longjmp(timebuf, sig);
|
||||||
}
|
}
|
||||||
@ -2317,9 +2290,8 @@ timeout(sig)
|
|||||||
/* rfc931_name - return remote user name */
|
/* rfc931_name - return remote user name */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
rfc931_name(there, ctrl)
|
rfc931_name(struct sockaddr *there, /* remote link information */
|
||||||
struct sockaddr *there; /* remote link information */
|
int ctrl)
|
||||||
int ctrl;
|
|
||||||
{
|
{
|
||||||
struct sockaddr_storage here; /* local link information */
|
struct sockaddr_storage here; /* local link information */
|
||||||
struct sockaddr_storage sin; /* for talking to RFC931 daemon */
|
struct sockaddr_storage sin; /* for talking to RFC931 daemon */
|
||||||
@ -2459,9 +2431,8 @@ rfc931_name(there, ctrl)
|
|||||||
* that are used for denial of service attacks like two echo ports
|
* that are used for denial of service attacks like two echo ports
|
||||||
* just echoing data between them
|
* just echoing data between them
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
port_good_dg(sa)
|
port_good_dg(struct sockaddr *sa)
|
||||||
struct sockaddr *sa;
|
|
||||||
{
|
{
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
@ -2502,7 +2473,7 @@ port_good_dg(sa)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
/* XXX unsupported af, is it safe to assume it to be safe? */
|
/* XXX unsupported af, is it safe to assume it to be safe? */
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; bad_ports[i] != 0; i++) {
|
for (i = 0; bad_ports[i] != 0; i++) {
|
||||||
@ -2522,9 +2493,8 @@ bad:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* XXX need optimization */
|
/* XXX need optimization */
|
||||||
int
|
static int
|
||||||
dg_broadcast(in)
|
dg_broadcast(struct in_addr *in)
|
||||||
struct in_addr *in;
|
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifa, *ifap;
|
struct ifaddrs *ifa, *ifap;
|
||||||
struct sockaddr_in *sin;
|
struct sockaddr_in *sin;
|
||||||
@ -2548,7 +2518,6 @@ dg_broadcast(in)
|
|||||||
static int
|
static int
|
||||||
my_kevent(const struct kevent *changelist, size_t nchanges,
|
my_kevent(const struct kevent *changelist, size_t nchanges,
|
||||||
struct kevent *eventlist, size_t nevents)
|
struct kevent *eventlist, size_t nevents)
|
||||||
|
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
@ -2561,3 +2530,14 @@ my_kevent(const struct kevent *changelist, size_t nchanges,
|
|||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct kevent *
|
||||||
|
allocchange(void)
|
||||||
|
{
|
||||||
|
if (changes == A_CNT(changebuf)) {
|
||||||
|
(void) my_kevent(changebuf, A_CNT(changebuf), NULL, 0);
|
||||||
|
changes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (&changebuf[changes++]);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user