/*
- * $Id: cnid_metad.c,v 1.17 2009-10-18 18:25:13 didg Exp $
+ * $Id: cnid_metad.c,v 1.18 2009-10-18 19:02:43 didg Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYING.
static int srvfd;
static int rqstfd;
static volatile sig_atomic_t alarmed = 0;
+static volatile sig_atomic_t sigchild = 0;
#define MAXSPAWN 3 /* Max times respawned in.. */
#define TESTTIME 42 /* this much seconds apfd client tries to *
alarmed = 1;
}
+static void catch_child(int sig _U_)
+{
+ sigchild = 1;
+}
+
+/* ----------------------- */
+static void set_signal(void)
+{
+ struct sigaction sv;
+ sigset_t set;
+
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGALRM, catch_alarm);
+
+ sv.sa_handler = catch_child;
+ sv.sa_flags = SA_NOCLDSTOP;
+ sigemptyset(&sv.sa_mask);
+ if (sigaction(SIGCHLD, &sv, NULL) < 0) {
+ LOG(log_error, logtype_cnid, "cnid_metad: sigaction: %s", strerror(errno));
+ exit(1);
+ }
+ /* block everywhere but in pselect */
+ sigemptyset(&set);
+ sigaddset(&set, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &set, NULL);
+}
+
/* ------------------ */
int main(int argc, char *argv[])
{
int ret;
char *loglevel = NULL;
char *logfile = NULL;
+ sigset_t set;
set_processname("cnid_metad");
}
}
- signal(SIGPIPE, SIG_IGN);
- signal(SIGALRM, catch_alarm);
+ set_signal();
+
+ sigemptyset(&set);
+ sigprocmask(SIG_SETMASK, NULL, &set);
+ sigdelset(&set, SIGCHLD);
while (1) {
- rqstfd = usockfd_check(srvfd, 10000000);
+ rqstfd = usockfd_check(srvfd, &set);
/* Collect zombie processes and log what happened to them */
- while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+ if (sigchild) while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
for (i = 0; i < MAXVOLS; i++) {
if (srv[i].pid == pid) {
srv[i].pid = 0;
LOG(log_info, logtype_cnid, "cnid_dbd pid %i exited with signal %i",
pid, WTERMSIG(status));
}
- /* FIXME should */
-
+ sigchild = 0;
}
if (rqstfd <= 0)
continue;
/*
- * $Id: usockfd.c,v 1.3 2005-05-03 14:55:11 didg Exp $
+ * $Id: usockfd.c,v 1.4 2009-10-18 19:02:43 didg Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYING.
#include <atalk/logger.h>
#include "usockfd.h"
+#include <sys/select.h>
int usockfd_create(char *usock_fn, mode_t mode, int backlog)
{
}
/* --------------------- */
-int usockfd_check(int sockfd, unsigned long ndelay)
+int usockfd_check(int sockfd, const sigset_t *sigset)
{
int fd;
socklen_t size;
fd_set readfds;
- struct timeval tv;
int ret;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
- tv.tv_usec = ndelay % 1000000;
- tv.tv_sec = ndelay / 1000000;
- if ((ret = select(sockfd + 1, &readfds, NULL, NULL, &tv)) < 0) {
+ if ((ret = pselect(sockfd + 1, &readfds, NULL, NULL, NULL, sigset)) < 0) {
if (errno == EINTR)
return 0;
LOG(log_error, logtype_cnid, "error in select: %s",
/*
- * $Id: usockfd.h,v 1.3 2009-10-13 22:55:37 didg Exp $
+ * $Id: usockfd.h,v 1.4 2009-10-18 19:02:43 didg Exp $
*
* Copyright (C) Joerg Lenneis 2003
* All Rights Reserved. See COPYING.
extern int usockfd_create (char *, mode_t, int);
extern int tsockfd_create (char *, u_int16_t, int);
-extern int usockfd_check (int, unsigned long);
+extern int usockfd_check (int, const sigset_t *);
#ifndef OSSH_ALIGNBYTES
#define OSSH_ALIGNBYTES (sizeof(int) - 1)