* Copyright (c) 1992 The Regents of the University of California
* Copyright (c) 1990, 1992 Jan-Simon Pendry
* This code is derived from software donated to Berkeley by
* %sccs.include.redist.c%
* @(#)mount_portal.c 1.1 (Berkeley) %G%
* $Id: portald.c,v 1.3 1992/05/27 07:09:27 jsp Exp jsp $
static sig_atomic_t readcf
; /* Set when SIGHUP received */
while ((pid
= waitpid((pid_t
) -1, (int *) 0, WNOHANG
)) > 0)
syslog(LOG_WARNING
, "waitpid: %s", strerror(errno
));
* Crack command line args
while ((ch
= getopt(c
, v
, "F:")) != EOF
) {
fprintf(stderr
, "Usage: mount_portal [ fsoptions ] config mount-point\n");
* Get config file and mount point
* Construct the listening socket
if (sizeof(_PATH_TMPPORTAL
) >= sizeof(un
.sun_path
)) {
fprintf(stderr
, "mount_portal: portal socket name too long\n");
strcpy(un
.sun_path
, _PATH_TMPPORTAL
);
un
.sun_len
= strlen(un
.sun_path
);
so
= socket(AF_UNIX
, SOCK_STREAM
, 0);
fprintf(stderr
, "mount_portal: socket: %s\n", strerror(errno
));
(void) unlink(un
.sun_path
);
if (bind(so
, (struct sockaddr
*) &un
, sizeof(un
)) < 0) {
fprintf(stderr
, "mount_portal: bind: %s\n", strerror(errno
));
(void) unlink(un
.sun_path
);
sprintf(tag
, "portal:%d", getpid());
rc
= mount(MOUNT_PORTAL
, mountpt
, mntflags
, &args
);
fprintf(stderr
, "mount_portal: mount: %s\n", strerror(errno
));
* Everything is ready to go - now is a good time to fork
* Start logging (and change name)
openlog("portald", LOG_CONS
|LOG_PID
, LOG_DAEMON
);
q
.q_forw
= q
.q_back
= &q
;
signal(SIGCHLD
, sigchld
);
* Just loop waiting for new connections and activating them
* Check whether we need to re-read the configuration file
* Accept a new connection
* Will get EINTR if a signal has arrived, so just
rc
= select(so
+1, &fdset
, (void *) 0, (void *) 0, (void *) 0);
syslog(LOG_ERR
, "select: %s", strerror(errno
));
so2
= accept(so
, (struct sockaddr
*) &un2
, &len2
);
* The unmount function does a shutdown on the socket
* which will generated ECONNABORTED on the accept.
if (errno
== ECONNABORTED
)
syslog(LOG_ERR
, "accept: %s", strerror(errno
));
* Now fork a new child to deal with the connection
syslog(LOG_ERR
, "fork: %s", strerror(errno
));
syslog(LOG_INFO
, "%s unmounted", mountpt
);