* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
* This code is derived from software donated to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1992, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)mount_portal.c 8.6 (Berkeley) 4/26/95";
struct mntopt mopts
[] = {
static void usage
__P((void));
static sig_atomic_t readcf
; /* Set when SIGHUP received */
while ((pid
= waitpid((pid_t
) -1, (int *) 0, WNOHANG
)) > 0)
if (pid
< 0 && errno
!= ECHILD
)
syslog(LOG_WARNING
, "waitpid: %s", strerror(errno
));
* Crack command line args
while ((ch
= getopt(argc
, argv
, "o:")) != EOF
) {
getmntopts(optarg
, mopts
, &mntflags
, 0);
if (optind
!= (argc
- 2))
* Get config file and mount point
mountpt
= argv
[optind
+1];
* 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)
(void) unlink(un
.sun_path
);
sprintf(tag
, "portal:%d", getpid());
rc
= mount("portal", mountpt
, mntflags
, &args
);
* 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
);
"usage: mount_portal [-o options] config mount-point\n");