mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-26 07:55:01 +00:00
Add pidfile support to ggated(8)
The tests will manipulate the system daemon today, which can cause undesired service interruption when the tests are run. This change allows the geom_gate tests to be run with an arbitrary ggated(8) daemon / geom_gate(4) device pairing. Other changes: - Sort #includes - Use a more common idiom for parsing options with getopt(3) Differential Revision: https://reviews.freebsd.org/D4836 MFC after: 2 weeks Reviewed by: bjk (manpages), pjd (maintainer timeout) Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
parent
e95c55e50d
commit
fc7e71c52d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=294973
@ -6,7 +6,7 @@ PROG= ggated
|
|||||||
MAN= ggated.8
|
MAN= ggated.8
|
||||||
SRCS= ggated.c ggate.c
|
SRCS= ggated.c ggate.c
|
||||||
|
|
||||||
LIBADD= pthread
|
LIBADD= pthread util
|
||||||
|
|
||||||
CFLAGS+= -I${.CURDIR}/../shared
|
CFLAGS+= -I${.CURDIR}/../shared
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 14, 2015
|
.Dd January 27, 2016
|
||||||
.Dt GGATED 8
|
.Dt GGATED 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -37,6 +37,7 @@
|
|||||||
.Op Fl v
|
.Op Fl v
|
||||||
.Op Fl a Ar address
|
.Op Fl a Ar address
|
||||||
.Op Fl p Ar port
|
.Op Fl p Ar port
|
||||||
|
.Op Fl F Ar pidfile
|
||||||
.Op Fl R Ar rcvbuf
|
.Op Fl R Ar rcvbuf
|
||||||
.Op Fl S Ar sndbuf
|
.Op Fl S Ar sndbuf
|
||||||
.Op Ar "exports file"
|
.Op Ar "exports file"
|
||||||
@ -67,6 +68,10 @@ Port on which
|
|||||||
.Nm
|
.Nm
|
||||||
listens for connections.
|
listens for connections.
|
||||||
Default is 3080.
|
Default is 3080.
|
||||||
|
.It Fl F Ar pidfile
|
||||||
|
PID file that
|
||||||
|
.Nm
|
||||||
|
uses.
|
||||||
.It Fl R Ar rcvbuf
|
.It Fl R Ar rcvbuf
|
||||||
Size of receive buffer to use.
|
Size of receive buffer to use.
|
||||||
Default is 131072 (128kB).
|
Default is 131072 (128kB).
|
||||||
@ -86,6 +91,13 @@ The format of an exports file is as follows:
|
|||||||
1.2.3.0/24 RW /tmp/test.img
|
1.2.3.0/24 RW /tmp/test.img
|
||||||
hostname WO /tmp/image
|
hostname WO /tmp/image
|
||||||
.Ed
|
.Ed
|
||||||
|
.Sh FILES
|
||||||
|
.Bl -tag -width ".Pa /var/run/ggated.pid" -compact
|
||||||
|
.It Pa /var/run/ggated.pid
|
||||||
|
The default location of the
|
||||||
|
.Nm
|
||||||
|
PID file.
|
||||||
|
.El
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
Exit status is 0 on success, or 1 if the command fails.
|
Exit status is 0 on success, or 1 if the command fails.
|
||||||
To get details about the failure,
|
To get details about the failure,
|
||||||
|
@ -26,32 +26,34 @@
|
|||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/bio.h>
|
||||||
|
#include <sys/disk.h>
|
||||||
#include <sys/endian.h>
|
#include <sys/endian.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/disk.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/bio.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <syslog.h>
|
#include <libutil.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ggate.h"
|
#include "ggate.h"
|
||||||
|
|
||||||
@ -110,8 +112,8 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf(stderr, "usage: %s [-nv] [-a address] [-p port] [-R rcvbuf] "
|
fprintf(stderr, "usage: %s [-nv] [-a address] [-F pidfile] [-p port] "
|
||||||
"[-S sndbuf] [exports file]\n", getprogname());
|
"[-R rcvbuf] [-S sndbuf] [exports file]\n", getprogname());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,20 +948,18 @@ huphandler(int sig __unused)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
const char *ggated_pidfile = _PATH_VARRUN "/ggated.pid";
|
||||||
|
struct pidfh *pfh;
|
||||||
struct sockaddr_in serv;
|
struct sockaddr_in serv;
|
||||||
struct sockaddr from;
|
struct sockaddr from;
|
||||||
socklen_t fromlen;
|
socklen_t fromlen;
|
||||||
int sfd, tmpsfd;
|
pid_t otherpid;
|
||||||
|
int ch, sfd, tmpsfd;
|
||||||
unsigned port;
|
unsigned port;
|
||||||
|
|
||||||
bindaddr = htonl(INADDR_ANY);
|
bindaddr = htonl(INADDR_ANY);
|
||||||
port = G_GATE_PORT;
|
port = G_GATE_PORT;
|
||||||
for (;;) {
|
while ((ch = getopt(argc, argv, "a:hnp:F:R:S:v")) != -1) {
|
||||||
int ch;
|
|
||||||
|
|
||||||
ch = getopt(argc, argv, "a:hnp:R:S:v");
|
|
||||||
if (ch == -1)
|
|
||||||
break;
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
bindaddr = g_gate_str2ip(optarg);
|
bindaddr = g_gate_str2ip(optarg);
|
||||||
@ -968,6 +968,9 @@ main(int argc, char *argv[])
|
|||||||
"Invalid IP/host name to bind to.");
|
"Invalid IP/host name to bind to.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
ggated_pidfile = optarg;
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nagle = 0;
|
nagle = 0;
|
||||||
break;
|
break;
|
||||||
@ -1004,12 +1007,23 @@ main(int argc, char *argv[])
|
|||||||
exports_file = argv[0];
|
exports_file = argv[0];
|
||||||
exports_get();
|
exports_get();
|
||||||
|
|
||||||
|
pfh = pidfile_open(ggated_pidfile, 0600, &otherpid);
|
||||||
|
if (pfh == NULL) {
|
||||||
|
if (errno == EEXIST) {
|
||||||
|
errx(EXIT_FAILURE, "Daemon already running, pid: %jd.",
|
||||||
|
(intmax_t)otherpid);
|
||||||
|
}
|
||||||
|
err(EXIT_FAILURE, "Cannot open/create pidfile");
|
||||||
|
}
|
||||||
|
|
||||||
if (!g_gate_verbose) {
|
if (!g_gate_verbose) {
|
||||||
/* Run in daemon mode. */
|
/* Run in daemon mode. */
|
||||||
if (daemon(0, 0) == -1)
|
if (daemon(0, 0) == -1)
|
||||||
g_gate_xlog("Cannot daemonize: %s", strerror(errno));
|
g_gate_xlog("Cannot daemonize: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pidfile_write(pfh);
|
||||||
|
|
||||||
signal(SIGCHLD, SIG_IGN);
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
@ -1046,5 +1060,6 @@ main(int argc, char *argv[])
|
|||||||
close(tmpsfd);
|
close(tmpsfd);
|
||||||
}
|
}
|
||||||
close(sfd);
|
close(sfd);
|
||||||
|
pidfile_remove(pfh);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user