/*
- * $Id: cnid_metad.c,v 1.1.4.7 2003-12-01 22:23:12 lenneis Exp $
+ * $Id: cnid_metad.c,v 1.1.4.8 2004-01-03 23:01:40 lenneis Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYRIGHT.
struct server *up;
int i;
time_t t;
+ char buf1[8];
+ char buf2[8];
up = test_usockfn(dbdir, usockfn);
if (up && up->pid) {
* just log it. The client process will fail connecting
* afterwards anyway.
*/
- close(0);
- close(1);
- close(srvfd);
- dup2(up->sv[1], 0);
- dup2(rqstfd, 1);
+ close(srvfd);
close(up->sv[0]);
- close(up->sv[1]);
- close(rqstfd);
- if (execlp(dbdpn, dbdpn, dbdir, NULL) < 0) {
+
+ for (i = 1; i <= MAXSRV; i++) {
+ if (srv[i].pid && up != &srv[i]) {
+ close(srv[i].sv[0]);
+ close(srv[i].sv[1]);
+ }
+ }
+
+ sprintf(buf1, "%i", up->sv[1]);
+ sprintf(buf2, "%i", rqstfd);
+
+ if (execlp(dbdpn, dbdpn, dbdir, buf1, buf2, NULL) < 0) {
LOG(log_error, logtype_cnid, "Fatal error in exec: %s", strerror(errno));
exit(0);
}
* Parent.
*/
up->pid = pid;
+ /* FIXME Any reason we do not close up->sv[1] here? Do we need both
+ descriptors in the srv table? */
return 0;
}
/*
- * $Id: comm.c,v 1.1.4.4 2003-10-30 10:03:19 bfernhomberg 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.
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;
/*
- * $Id: comm.h,v 1.1.4.2 2003-10-30 10:03:19 bfernhomberg Exp $
+ * $Id: comm.h,v 1.1.4.3 2004-01-03 23:01:40 lenneis Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYRIGHT.
#include <atalk/cnid_dbd_private.h>
-extern int comm_init __P((struct db_param *));
+extern int comm_init __P((struct db_param *, int, int));
extern int comm_rcv __P((struct cnid_dbd_rqst *));
extern int comm_snd __P((struct cnid_dbd_rply *));
extern int comm_nbe __P((void));
/*
- * $Id: main.c,v 1.1.4.6 2003-12-12 19:27:57 didg Exp $
+ * $Id: main.c,v 1.1.4.7 2004-01-03 23:01:41 lenneis Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYRIGHT.
struct db_param *dbp;
int err = 0;
struct stat st;
- int lockfd;
+ int lockfd, ctrlfd, clntfd;
struct flock lock;
char *dir;
- if (argc != 2) {
+ if (argc != 4) {
LOG(log_error, logtype_cnid, "main: not enough arguments");
exit(1);
}
+
dir = argv[1];
+ ctrlfd = atoi(argv[2]);
+ clntfd = atoi(argv[3]);
+
if (chdir(dir) < 0) {
LOG(log_error, logtype_cnid, "chdir to %s failed: %s", dir, strerror(errno));
exit(1);
}
LOG(log_info, logtype_cnid, "Startup, DB dir %s", dir);
+
sv.sa_handler = sig_exit;
sv.sa_flags = 0;
sigemptyset(&sv.sa_mask);
if (dbif_txn_commit() < 0)
exit(6);
#endif
- if (comm_init(dbp) < 0) {
+ if (comm_init(dbp, ctrlfd, clntfd) < 0) {
dbif_close();
exit(3);
}