/*
- * $Id: comm.c,v 1.1.4.3 2003-10-12 13:50:16 didg Exp $
+ * $Id: comm.c,v 1.1.4.5 2004-01-03 23:01:40 lenneis Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYRIGHT.
#endif
#include <sys/param.h>
+#define _XPG4_2 1
#include <sys/socket.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/uio.h>
#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
#include <assert.h>
#include <time.h>
#include "usockfd.h"
#include "comm.h"
+/* Length of the space taken up by a padded control message of length len */
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len))
+#endif
+
+
struct connection {
time_t tm; /* When respawned last */
int fd;
};
-static int usock_fd;
+static int control_fd;
static int cur_fd;
static struct connection *fd_table;
static int fd_table_size;
{
int i;
- if (fd == usock_fd)
+ if (fd == control_fd)
return;
for (i = 0; i != fds_in_use; i++)
if (fd_table[i].fd == fd)
/*
* Check for client requests. We keep up to fd_table_size open descriptors in
- * fd_table. If the table is full and we get a request for a new descriptor via
- * usock_fd, we close a random decriptor in the table to make space. The
+ * fd_table. If the table is full and we get a new descriptor via
+ * control_fd, we close a random decriptor in the table to make space. The
* affected client will automatically reconnect. For an EOF (descriptor is
* closed by the client, so a read here returns 0) comm_rcv will take care of
* things and clean up fd_table. The same happens for any read/write errors.
struct timeval tv;
int ret;
int i;
- int maxfd = usock_fd;
+ int maxfd = control_fd;
time_t t;
FD_ZERO(&readfds);
- FD_SET(usock_fd, &readfds);
+ FD_SET(control_fd, &readfds);
for (i = 0; i != fds_in_use; i++) {
FD_SET(fd_table[i].fd, &readfds);
time(&t);
- if (FD_ISSET(usock_fd, &readfds)) {
+ if (FD_ISSET(control_fd, &readfds)) {
int l = 0;
- fd = recv_cred(usock_fd);
+ fd = recv_cred(control_fd);
if (fd < 0) {
return -1;
}
return 0;
}
-int comm_init(struct db_param *dbp)
+int comm_init(struct db_param *dbp, int ctrlfd, int clntfd)
{
int i;
for (i = 0; i != fd_table_size; i++)
fd_table[i].fd = -1;
/* from dup2 */
- usock_fd = 0;
+ control_fd = ctrlfd;
#if 0
int b = 1;
/* this one dump core in recvmsg, great */
- if ( setsockopt(usock_fd, SOL_SOCKET, SO_PASSCRED, &b, sizeof (b)) < 0) {
+ if ( setsockopt(control_fd, SOL_SOCKET, SO_PASSCRED, &b, sizeof (b)) < 0) {
LOG(log_error, logtype_cnid, "setsockopt SO_PASSCRED %s", strerror(errno));
return -1;
}
#endif
- /* push the first from dup2 */
- fd_table[fds_in_use].fd = 1;
+ /* push the first client fd */
+ fd_table[fds_in_use].fd = clntfd;
fds_in_use++;
return 0;