X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fcnid_dbd%2Fcomm.c;h=89355d767b8c0072a01d42763a935850b03e5a9c;hb=64c01c136e708085840814c92ff7cf829a794317;hp=9b3ffad5cf65073012d7faa867b9442ff1089cb2;hpb=815d557e167e76015934397dffbfa869180dcdbc;p=netatalk.git diff --git a/etc/cnid_dbd/comm.c b/etc/cnid_dbd/comm.c index 9b3ffad5..89355d76 100644 --- a/etc/cnid_dbd/comm.c +++ b/etc/cnid_dbd/comm.c @@ -1,7 +1,7 @@ /* - * $Id: comm.c,v 1.4 2009-10-13 22:55:37 didg Exp $ - * * Copyright (C) Joerg Lenneis 2003 + * Copyright (C) Frank Lahm 2010 + * * All Rights Reserved. See COPYING. */ @@ -13,36 +13,19 @@ #include #include #include - -#ifdef HAVE_UNISTD_H #include -#endif - #include -#define _XPG4_2 1 -#include - -#ifdef HAVE_SYS_TYPES_H #include -#endif - -#ifdef HAVE_SYS_TIME_H #include -#endif - -#ifdef HAVE_SYS_UIO_H #include -#endif - -#ifdef HAVE_SYS_SOCKET_H +#define _XPG4_2 1 #include -#endif - - +#include #include #include #include +#include #include #include "db_param.h" @@ -141,11 +124,11 @@ static int recv_cred(int fd) * things and clean up fd_table. The same happens for any read/write errors. */ -static int check_fd(void) +static int check_fd(time_t timeout, const sigset_t *sigmask, time_t *now) { int fd; fd_set readfds; - struct timeval tv; + struct timespec tv; int ret; int i; int maxfd = control_fd; @@ -160,19 +143,22 @@ static int check_fd(void) maxfd = fd_table[i].fd; } - tv.tv_usec = 0; - tv.tv_sec = 1; - if ((ret = select(maxfd + 1, &readfds, NULL, NULL, &tv)) < 0) { + tv.tv_nsec = 0; + tv.tv_sec = timeout; + if ((ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tv, sigmask)) < 0) { if (errno == EINTR) return 0; LOG(log_error, logtype_cnid, "error in select: %s",strerror(errno)); return -1; } + time(&t); + if (now) + *now = t; + if (!ret) return 0; - time(&t); if (FD_ISSET(control_fd, &readfds)) { int l = 0; @@ -250,18 +236,27 @@ int comm_nbe(void) } /* ------------ */ -int comm_rcv(struct cnid_dbd_rqst *rqst) +int comm_rcv(struct cnid_dbd_rqst *rqst, time_t timeout, const sigset_t *sigmask, time_t *now) { char *nametmp; int b; - if ((cur_fd = check_fd()) < 0) + if ((cur_fd = check_fd(timeout, sigmask, now)) < 0) return -1; if (!cur_fd) return 0; + + LOG(log_maxdebug, logtype_cnid, "comm_rcv: got data on fd %u", cur_fd); + + if (setnonblock(cur_fd, 1) != 0) { + LOG(log_error, logtype_cnid, "comm_rcv: setnonblock: %s", strerror(errno)); + return -1; + } + nametmp = rqst->name; - if ((b = read(cur_fd, rqst, sizeof(struct cnid_dbd_rqst))) != sizeof(struct cnid_dbd_rqst)) { + if ((b = readt(cur_fd, rqst, sizeof(struct cnid_dbd_rqst), 1, CNID_DBD_TIMEOUT)) + != sizeof(struct cnid_dbd_rqst)) { if (b) LOG(log_error, logtype_cnid, "error reading message header: %s", strerror(errno)); invalidate_fd(cur_fd); @@ -269,7 +264,8 @@ int comm_rcv(struct cnid_dbd_rqst *rqst) return 0; } rqst->name = nametmp; - if (rqst->namelen && read(cur_fd, rqst->name, rqst->namelen) != rqst->namelen) { + if (rqst->namelen && readt(cur_fd, rqst->name, rqst->namelen, 1, CNID_DBD_TIMEOUT) + != rqst->namelen) { LOG(log_error, logtype_cnid, "error reading message name: %s", strerror(errno)); invalidate_fd(cur_fd); return 0; @@ -278,6 +274,8 @@ int comm_rcv(struct cnid_dbd_rqst *rqst) needs zero terminated strings. */ rqst->name[rqst->namelen] = '\0'; + LOG(log_maxdebug, logtype_cnid, "comm_rcv: got %u bytes", b + rqst->namelen); + return 1; }