[Midnightbsd-cvs] src [11215] trunk/sbin/ggate: sync ggate with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jul 1 16:51:12 EDT 2018


Revision: 11215
          http://svnweb.midnightbsd.org/src/?rev=11215
Author:   laffer1
Date:     2018-07-01 16:51:12 -0400 (Sun, 01 Jul 2018)
Log Message:
-----------
sync ggate with freebsd

Modified Paths:
--------------
    trunk/sbin/ggate/Makefile
    trunk/sbin/ggate/Makefile.inc
    trunk/sbin/ggate/ggatec/Makefile
    trunk/sbin/ggate/ggatec/ggatec.8
    trunk/sbin/ggate/ggatec/ggatec.c
    trunk/sbin/ggate/ggated/Makefile
    trunk/sbin/ggate/ggated/ggated.8
    trunk/sbin/ggate/ggated/ggated.c
    trunk/sbin/ggate/ggatel/Makefile
    trunk/sbin/ggate/ggatel/ggatel.8
    trunk/sbin/ggate/ggatel/ggatel.c
    trunk/sbin/ggate/shared/ggate.c

Property Changed:
----------------
    trunk/sbin/ggate/Makefile.inc
    trunk/sbin/ggate/ggatec/ggatec.8
    trunk/sbin/ggate/ggated/ggated.8
    trunk/sbin/ggate/ggatel/ggatel.8

Modified: trunk/sbin/ggate/Makefile
===================================================================
--- trunk/sbin/ggate/Makefile	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/Makefile	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/ggate/Makefile 177714 2008-03-29 17:44:40Z ru $
 
 .include <bsd.own.mk>
 

Modified: trunk/sbin/ggate/Makefile.inc
===================================================================
--- trunk/sbin/ggate/Makefile.inc	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/Makefile.inc	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,5 +1,4 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/ggate/Makefile.inc 198236 2009-10-19 16:00:24Z ru $
 
-WARNS=3
-
 .include "../Makefile.inc"


Property changes on: trunk/sbin/ggate/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/ggate/ggatec/Makefile
===================================================================
--- trunk/sbin/ggate/ggatec/Makefile	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatec/Makefile	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/ggate/ggatec/Makefile 168422 2007-04-06 11:19:48Z pjd $
 
 .PATH: ${.CURDIR}/../shared
 

Modified: trunk/sbin/ggate/ggatec/ggatec.8
===================================================================
--- trunk/sbin/ggate/ggatec/ggatec.8	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatec/ggatec.8	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
 .\" All rights reserved.
 .\"
@@ -22,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/ggate/ggatec/ggatec.8 307403 2016-10-16 22:02:50Z sevan $
 .\"
-.Dd April 26, 2004
+.Dd April 2, 2015
 .Dt GGATEC 8
 .Os
 .Sh NAME
@@ -67,29 +68,29 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility is a network client for GEOM Gate class.
-It is responsible for creation of
+utility is a network client for the GEOM Gate class.
+It is responsible for the creation of
 .Nm ggate
-devices and forwarding I/O requests between
+devices and forwarding I/O requests between the
 .Nm geom_gate.ko
-kernel module and
+kernel module and the
 .Xr ggated 8
 network daemon.
 Available commands:
 .Bl -tag -width ".Cm destroy"
 .It Cm create
-Connect to given
+Connect to a
 .Xr ggated 8
-daemon and create a
+daemon on the specified host and create a
 .Nm ggate
-provider related to the given remote file or device.
+provider for the specified remote file or device.
 .It Cm rescue
-If
+Create a new connection after the
 .Nm
-process died/has been killed, you can save situation with this
-command, which creates new connection to the
+process has died or been killed.
+The new connection to the
 .Xr ggated 8
-daemon and will handle pending and future requests.
+daemon handles pending and future requests.
 .It Cm destroy
 Destroy the given
 .Nm ggate
@@ -139,12 +140,11 @@
 If not specified, it is taken from device, or set to 512 bytes for files.
 .It Fl t Ar timeout
 Number of seconds to wait before an I/O request will be canceled.
-0 means no timeout.
-Default is 0.
+Default is 0, which means no timeout.
 .It Fl u Ar unit
 Unit number to use.
 .It Fl v
-Do not fork, run in foreground and print debug informations on standard
+Do not fork, run in foreground and print debug information on standard
 output.
 .It Ar host
 Remote host to connect to.
@@ -159,7 +159,7 @@
 .Fl v
 option.
 .Sh EXAMPLES
-Make use of CD-ROM device from remote host.
+Use a CD-ROM device on a remote host.
 .Bd -literal -offset indent
 server# cat /etc/gg.exports
 client RO /dev/acd0
@@ -178,4 +178,4 @@
 The
 .Nm
 utility as well as this manual page was written by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org .
+.An Pawel Jakub Dawidek Aq Mt pjd at FreeBSD.org .


Property changes on: trunk/sbin/ggate/ggatec/ggatec.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/ggate/ggatec/ggatec.c
===================================================================
--- trunk/sbin/ggate/ggatec/ggatec.c	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatec/ggatec.c	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/ggate/ggatec/ggatec.c 285748 2015-07-21 14:25:21Z brueffer $
  */
 
 #include <stdio.h>
@@ -55,7 +56,7 @@
 #include "ggate.h"
 
 
-enum { UNSET, CREATE, DESTROY, LIST, RESCUE } action = UNSET;
+static enum { UNSET, CREATE, DESTROY, LIST, RESCUE } action = UNSET;
 
 static const char *path = NULL;
 static const char *host = NULL;
@@ -447,6 +448,7 @@
 	/*
 	 * Ok, got both sockets, time to create provider.
 	 */
+	memset(&ggioc, 0, sizeof(ggioc));
 	ggioc.gctl_version = G_GATE_VERSION;
 	ggioc.gctl_mediasize = mediasize;
 	ggioc.gctl_sectorsize = sectorsize;

Modified: trunk/sbin/ggate/ggated/Makefile
===================================================================
--- trunk/sbin/ggate/ggated/Makefile	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggated/Makefile	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/ggate/ggated/Makefile 296815 2016-03-13 23:32:59Z ngie $
 
 .PATH: ${.CURDIR}/../shared
 
@@ -6,8 +7,8 @@
 MAN=	ggated.8
 SRCS=	ggated.c ggate.c
 
-DPADD=	${LIBPTHREAD}
-LDADD=	-lpthread
+DPADD=	${LIBPTHREAD} ${LIBUTIL}
+LDADD=	-lpthread -lutil
 
 CFLAGS+= -I${.CURDIR}/../shared
 

Modified: trunk/sbin/ggate/ggated/ggated.8
===================================================================
--- trunk/sbin/ggate/ggated/ggated.8	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggated/ggated.8	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
 .\" All rights reserved.
 .\"
@@ -22,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/ggate/ggated/ggated.8 307403 2016-10-16 22:02:50Z sevan $
 .\"
-.Dd April 29, 2004
+.Dd January 27, 2016
 .Dt GGATED 8
 .Os
 .Sh NAME
@@ -37,6 +38,7 @@
 .Op Fl v
 .Op Fl a Ar address
 .Op Fl p Ar port
+.Op Fl F Ar pidfile
 .Op Fl R Ar rcvbuf
 .Op Fl S Ar sndbuf
 .Op Ar "exports file"
@@ -67,6 +69,10 @@
 .Nm
 listens for connection.
 Default is 3080.
+.It Fl F Ar pidfile
+PID file that
+.Nm
+uses.
 .It Fl R Ar rcvbuf
 Size of receive buffer to use.
 Default is 131072 (128kB).
@@ -86,6 +92,13 @@
 1.2.3.0/24	RW	/tmp/test.img
 hostname	WO	/tmp/image
 .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
 Exit status is 0 on success, or 1 if the command fails.
 To get details about the failure,
@@ -108,4 +121,4 @@
 The
 .Nm
 utility as well as this manual page was written by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org .
+.An Pawel Jakub Dawidek Aq Mt pjd at FreeBSD.org .


Property changes on: trunk/sbin/ggate/ggated/ggated.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/ggate/ggated/ggated.c
===================================================================
--- trunk/sbin/ggate/ggated/ggated.c	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggated/ggated.c	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -23,35 +24,37 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/ggate/ggated/ggated.c 296815 2016-03-13 23:32:59Z ngie $
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <pthread.h>
 #include <sys/param.h>
+#include <sys/bio.h>
+#include <sys/disk.h>
+#include <sys/endian.h>
+#include <sys/ioctl.h>
 #include <sys/queue.h>
-#include <sys/endian.h>
 #include <sys/socket.h>
-#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <sys/disk.h>
-#include <sys/bio.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <signal.h>
 #include <assert.h>
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <libutil.h>
+#include <paths.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
-#include <libgen.h>
 #include <syslog.h>
-#include <stdarg.h>
+#include <unistd.h>
 
 #include "ggate.h"
 
@@ -92,12 +95,12 @@
 
 static const char *exports_file = GGATED_EXPORT_FILE;
 static int got_sighup = 0;
-in_addr_t bindaddr;
+static in_addr_t bindaddr;
 
 static TAILQ_HEAD(, ggd_request) inqueue = TAILQ_HEAD_INITIALIZER(inqueue);
 static TAILQ_HEAD(, ggd_request) outqueue = TAILQ_HEAD_INITIALIZER(outqueue);
-pthread_mutex_t inqueue_mtx, outqueue_mtx;
-pthread_cond_t inqueue_cond, outqueue_cond;
+static pthread_mutex_t inqueue_mtx, outqueue_mtx;
+static pthread_cond_t inqueue_cond, outqueue_cond;
 
 static SLIST_HEAD(, ggd_export) exports = SLIST_HEAD_INITIALIZER(exports);
 static LIST_HEAD(, ggd_connection) connections = LIST_HEAD_INITIALIZER(connections);
@@ -110,8 +113,8 @@
 usage(void)
 {
 
-	fprintf(stderr, "usage: %s [-nv] [-a address] [-p port] [-R rcvbuf] "
-	    "[-S sndbuf] [exports file]\n", getprogname());
+	fprintf(stderr, "usage: %s [-nv] [-a address] [-F pidfile] [-p port] "
+	    "[-R rcvbuf] [-S sndbuf] [exports file]\n", getprogname());
 	exit(EXIT_FAILURE);
 }
 
@@ -906,8 +909,8 @@
 
 	ex = exports_find(from, &cinit, conn);
 	if (ex == NULL) {
+		sendfail(sfd, errno, NULL);
 		connection_remove(conn);
-		sendfail(sfd, errno, NULL);
 		return (0);
 	}
 	if (conn->c_mediasize == 0) {
@@ -946,20 +949,18 @@
 int
 main(int argc, char *argv[])
 {
+	const char *ggated_pidfile = _PATH_VARRUN "/ggated.pid";
+	struct pidfh *pfh;
 	struct sockaddr_in serv;
 	struct sockaddr from;
 	socklen_t fromlen;
-	int sfd, tmpsfd;
+	pid_t otherpid;
+	int ch, sfd, tmpsfd;
 	unsigned port;
 
 	bindaddr = htonl(INADDR_ANY);
 	port = G_GATE_PORT;
-	for (;;) {
-		int ch;
-
-		ch = getopt(argc, argv, "a:hnp:R:S:v");
-		if (ch == -1)
-			break;
+	while ((ch = getopt(argc, argv, "a:hnp:F:R:S:v")) != -1) {
 		switch (ch) {
 		case 'a':
 			bindaddr = g_gate_str2ip(optarg);
@@ -968,6 +969,9 @@
 				    "Invalid IP/host name to bind to.");
 			}
 			break;
+		case 'F':
+			ggated_pidfile = optarg;
+			break;
 		case 'n':
 			nagle = 0;
 			break;
@@ -1004,6 +1008,15 @@
 		exports_file = argv[0];
 	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) {
 		/* Run in daemon mode. */
 		if (daemon(0, 0) == -1)
@@ -1010,6 +1023,8 @@
 			g_gate_xlog("Cannot daemonize: %s", strerror(errno));
 	}
 
+	pidfile_write(pfh);
+
 	signal(SIGCHLD, SIG_IGN);
 
 	sfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -1046,5 +1061,6 @@
 			close(tmpsfd);
 	}
 	close(sfd);
+	pidfile_remove(pfh);
 	exit(EXIT_SUCCESS);
 }

Modified: trunk/sbin/ggate/ggatel/Makefile
===================================================================
--- trunk/sbin/ggate/ggatel/Makefile	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatel/Makefile	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sbin/ggate/ggatel/Makefile 130837 2004-06-21 09:20:06Z pjd $
 
 .PATH: ${.CURDIR}/../shared
 

Modified: trunk/sbin/ggate/ggatel/ggatel.8
===================================================================
--- trunk/sbin/ggate/ggatel/ggatel.8	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatel/ggatel.8	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
 .\" All rights reserved.
 .\"
@@ -22,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/ggate/ggatel/ggatel.8 307403 2016-10-16 22:02:50Z sevan $
 .\"
-.Dd April 2, 2011
+.Dd April 9, 2015
 .Dt GGATEL 8
 .Os
 .Sh NAME
@@ -40,12 +41,6 @@
 .Op Fl u Ar unit
 .Ar path
 .Nm
-.Cm attach
-.Op Fl v
-.Op Fl o Cm ro | wo | rw
-.Fl u Ar unit
-.Ar path
-.Nm
 .Cm destroy
 .Op Fl f
 .Fl u Ar unit
@@ -53,6 +48,12 @@
 .Cm list
 .Op Fl v
 .Op Fl u Ar unit
+.Nm
+.Cm rescue
+.Op Fl v
+.Op Fl o Cm ro | wo | rw
+.Fl u Ar unit
+.Ar path
 .Sh DESCRIPTION
 The
 .Nm
@@ -70,10 +71,6 @@
 Create a
 .Nm ggate
 provider related to the given regular file or device.
-.It Cm attach
-Attach a worker process to an existing
-.Nm ggate
-provider.
 .It Cm destroy
 Destroy the given
 .Nm ggate
@@ -82,6 +79,12 @@
 List
 .Nm ggate
 providers.
+.It Cm rescue
+Take over a previously created provider and handle pending and future
+requests. This is useful if the initial
+.Nm
+process died. To prevent data loss, the given path must lead to the
+regular file or device that was used to create the provider.
 .El
 .Pp
 Available options:
@@ -111,7 +114,7 @@
 .It Fl u Ar unit
 Unit number to use.
 .It Fl v
-Do not fork, run in foreground and print debug informations on standard
+Do not fork, run in foreground and print debug information on standard
 output.
 .It Ar path
 Path to a regular file or device.
@@ -152,4 +155,4 @@
 The
 .Nm
 utility as well as this manual page was written by
-.An Pawel Jakub Dawidek Aq pjd at FreeBSD.org .
+.An Pawel Jakub Dawidek Aq Mt pjd at FreeBSD.org .


Property changes on: trunk/sbin/ggate/ggatel/ggatel.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/ggate/ggatel/ggatel.c
===================================================================
--- trunk/sbin/ggate/ggatel/ggatel.c	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/ggatel/ggatel.c	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/ggate/ggatel/ggatel.c 285748 2015-07-21 14:25:21Z brueffer $
  */
 
 #include <stdio.h>
@@ -47,7 +48,7 @@
 #include "ggate.h"
 
 
-enum { UNSET, CREATE, DESTROY, LIST, RESCUE } action = UNSET;
+static enum { UNSET, CREATE, DESTROY, LIST, RESCUE } action = UNSET;
 
 static const char *path = NULL;
 static int unit = G_GATE_UNIT_AUTO;
@@ -173,6 +174,7 @@
 	fd = open(path, g_gate_openflags(flags) | O_DIRECT | O_FSYNC);
 	if (fd == -1)
 		err(EXIT_FAILURE, "Cannot open %s", path);
+	memset(&ggioc, 0, sizeof(ggioc));
 	ggioc.gctl_version = G_GATE_VERSION;
 	ggioc.gctl_unit = unit;
 	ggioc.gctl_mediasize = g_gate_mediasize(fd);

Modified: trunk/sbin/ggate/shared/ggate.c
===================================================================
--- trunk/sbin/ggate/shared/ggate.c	2018-07-01 20:48:40 UTC (rev 11214)
+++ trunk/sbin/ggate/shared/ggate.c	2018-07-01 20:51:12 UTC (rev 11215)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/ggate/shared/ggate.c 204075 2010-02-18 23:04:01Z pjd $
  */
 
 #include <stdio.h>
@@ -131,7 +132,7 @@
 off_t
 g_gate_mediasize(int fd)
 {
-	off_t mediasize = 0;
+	off_t mediasize;
 	struct stat sb;
 
 	if (fstat(fd, &sb) == -1)
@@ -152,7 +153,7 @@
 unsigned
 g_gate_sectorsize(int fd)
 {
-	unsigned secsize = 0;
+	unsigned secsize;
 	struct stat sb;
 
 	if (fstat(fd, &sb) == -1)



More information about the Midnightbsd-cvs mailing list