SCCS-vsn: usr.sbin/inetd/inetd.c 4.2
-static char sccsid[] = "@(#)inetd.c 4.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)inetd.c 4.2 (Berkeley) %G%";
#include <stdio.h>
#include <signal.h>
#include <netdb.h>
#include <stdio.h>
#include <signal.h>
#include <netdb.h>
+ openlog("inetd", LOG_PID, 0);
config();
signal(SIGHUP, config);
signal(SIGCHLD, reapchild);
config();
signal(SIGHUP, config);
signal(SIGCHLD, reapchild);
fprintf(stderr, "someone wants %s\n", sep->se_service);
if (sep->se_socktype == SOCK_STREAM) {
ctrl = accept(s, 0, 0);
fprintf(stderr, "someone wants %s\n", sep->se_service);
if (sep->se_socktype == SOCK_STREAM) {
ctrl = accept(s, 0, 0);
- if (debug)
- fprintf(stderr, "accept, ctrl %d\n", ctrl);
+ if (debug)
+ fprintf(stderr, "accept, ctrl %d\n", ctrl);
if (ctrl < 0) {
if (errno == EINTR)
continue;
if (ctrl < 0) {
if (errno == EINTR)
continue;
- perror("inetd: accept");
+ syslog(LOG_WARNING, "accept: %m");
getpid(), sep->se_server);
execv(sep->se_server, sep->se_argv);
if (sep->se_socktype != SOCK_STREAM)
getpid(), sep->se_server);
execv(sep->se_server, sep->se_argv);
if (sep->se_socktype != SOCK_STREAM)
- recv(0, buf, sizeof (buf));
- if (debug)
- fprintf(stderr, "execl failed\n");
+ recv(0, buf, sizeof (buf), 0);
+ syslog(LOG_ERR, "execv %s: %m", sep->se_server);
_exit(1);
}
if (sep->se_socktype == SOCK_STREAM)
_exit(1);
}
if (sep->se_socktype == SOCK_STREAM)
for (sep = servtab; sep; sep = sep->se_next)
if (sep->se_wait == pid) {
if (status.w_status)
for (sep = servtab; sep; sep = sep->se_next)
if (sep->se_wait == pid) {
if (status.w_status)
- fprintf(stderr,
- "inetd: %s: exit status %d\n",
+ syslog(LOG_WARNING,
+ "%s: exit status 0x%x",
sep->se_server, status);
if (debug)
fprintf(stderr, "restored %s, fd %d\n",
sep->se_server, status);
if (debug)
fprintf(stderr, "restored %s, fd %d\n",
int omask;
if (!setconfig()) {
int omask;
if (!setconfig()) {
- fprintf(stderr, "inetd: ");
- perror(CONFIG);
+ syslog(LOG_ERR, "%s: %m", CONFIG);
return;
}
for (sep = servtab; sep; sep = sep->se_next)
return;
}
for (sep = servtab; sep; sep = sep->se_next)
continue;
sp = getservbyname(sep->se_service, sep->se_proto);
if (sp == 0) {
continue;
sp = getservbyname(sep->se_service, sep->se_proto);
if (sp == 0) {
- fprintf(stderr,
- "inetd: %s/%s: unknown service\n",
+ syslog(LOG_ERR, "%s/%s: unknown service",
sep->se_service, sep->se_proto);
continue;
}
sep->se_ctrladdr.sin_port = sp->s_port;
if ((sep->se_fd = socket(AF_INET, sep->se_socktype, 0)) < 0) {
sep->se_service, sep->se_proto);
continue;
}
sep->se_ctrladdr.sin_port = sp->s_port;
if ((sep->se_fd = socket(AF_INET, sep->se_socktype, 0)) < 0) {
- fprintf(stderr, "inetd: %s/%s: ",
+ syslog(LOG_ERR, "%s/%s: socket: %m",
sep->se_service, sep->se_proto);
sep->se_service, sep->se_proto);
continue;
}
if (strcmp(sep->se_proto, "tcp") == 0 && (options & SO_DEBUG) &&
setsockopt(sep->se_fd, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
continue;
}
if (strcmp(sep->se_proto, "tcp") == 0 && (options & SO_DEBUG) &&
setsockopt(sep->se_fd, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
- perror("inetd: setsockopt (SO_DEBUG)");
+ syslog(LOG_ERR, "setsockopt (SO_DEBUG): %m");
if (setsockopt(sep->se_fd, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
if (setsockopt(sep->se_fd, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
- perror("inetd: setsockopt (SO_REUSEADDR)");
+ syslog(LOG_ERR, "setsockopt (SO_REUSEADDR): %m");
if (bind(sep->se_fd, &sep->se_ctrladdr,
sizeof (sep->se_ctrladdr), 0) < 0) {
if (bind(sep->se_fd, &sep->se_ctrladdr,
sizeof (sep->se_ctrladdr), 0) < 0) {
- fprintf(stderr, "inetd: %s/%s: ",
+ syslog(LOG_ERR, "%s/%s: bind: %m",
sep->se_service, sep->se_proto);
sep->se_service, sep->se_proto);
continue;
}
if (sep->se_socktype == SOCK_STREAM)
continue;
}
if (sep->se_socktype == SOCK_STREAM)
sep = (struct servtab *)malloc(sizeof (*sep));
if (sep == (struct servtab *)0) {
sep = (struct servtab *)malloc(sizeof (*sep));
if (sep == (struct servtab *)0) {
- fprintf(stderr, "Out of memory.\n");
+ syslog(LOG_ERR, "Out of memory.");
cp = "";
new = malloc(strlen(cp) + 1);
if (new == (char *)0) {
cp = "";
new = malloc(strlen(cp) + 1);
if (new == (char *)0) {
- fprintf(stderr, "Out of memory.\n");
+ syslog(LOG_ERR, "Out of memory.");
exit(-1);
}
strcpy(new, cp);
exit(-1);
}
strcpy(new, cp);