summaryrefslogtreecommitdiffstats
path: root/net/stund
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2005-07-29 12:36:30 +0000
committersobomax <sobomax@FreeBSD.org>2005-07-29 12:36:30 +0000
commitd4e73d4e3fd8725bc60c25343f2b35cb45db77b8 (patch)
tree638b5539ae1f3245df618f61f0221310f95c9295 /net/stund
parente96a4e7c81c299c7f953f3eaca0c5b5147df2108 (diff)
downloadFreeBSD-ports-d4e73d4e3fd8725bc60c25343f2b35cb45db77b8.zip
FreeBSD-ports-d4e73d4e3fd8725bc60c25343f2b35cb45db77b8.tar.gz
o Add support for generating pidfile;
o newrc startup script; o bump PORTREVISION.
Diffstat (limited to 'net/stund')
-rw-r--r--net/stund/Makefile3
-rw-r--r--net/stund/files/patch-server.cxx67
-rw-r--r--net/stund/files/stund.sh.in34
3 files changed, 101 insertions, 3 deletions
diff --git a/net/stund/Makefile b/net/stund/Makefile
index d6eff7e..af75064 100644
--- a/net/stund/Makefile
+++ b/net/stund/Makefile
@@ -7,7 +7,7 @@
PORTNAME= stund
PORTVERSION= 0.94
-PORTREVISION= 1
+PORTREVISION= 2
CATEGORIES= net
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
MASTER_SITE_SUBDIR= stun
@@ -20,6 +20,7 @@ COMMENT= A simple STUN (RFC 3489) server and client
WRKSRC= ${WRKDIR}/${PORTNAME}
USE_GMAKE= yes
+USE_RC_SUBR= stund.sh
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/server ${LOCALBASE}/sbin/stund
diff --git a/net/stund/files/patch-server.cxx b/net/stund/files/patch-server.cxx
index d732ccd..d94567c 100644
--- a/net/stund/files/patch-server.cxx
+++ b/net/stund/files/patch-server.cxx
@@ -3,7 +3,22 @@ $FreeBSD$
--- server.cxx.orig
+++ server.cxx
-@@ -32,7 +32,7 @@
+@@ -6,10 +6,14 @@
+ #ifndef WIN32
+ #include <sys/time.h>
+ #include <sys/types.h>
++#include <sys/file.h>
++#include <fcntl.h>
+ #include <unistd.h>
+ #include <netinet/in.h>
+ #include <errno.h>
+ #include <stdlib.h>
++#include <err.h>
++#include <stdio.h>
+ #endif
+
+ #include "udp.h"
+@@ -32,13 +36,16 @@
<< " -a sets the secondary IP" << endl
<< " -p sets the primary port and defaults to 3478" << endl
<< " -o sets the secondary port and defaults to 3479" << endl
@@ -12,7 +27,39 @@ $FreeBSD$
<< " -m sets up a STERN server starting at port m" << endl
<< " -v runs in verbose mode" << endl
// in makefile too
-@@ -188,30 +188,14 @@
+ << endl;
+ }
+
++#define DEFAULT_PIDFILE "/var/run/stund.pid"
++
++int pf = -1;
+
+ int
+ main(int argc, char* argv[])
+@@ -63,6 +70,7 @@
+ int myPort = 0;
+ int altPort = 0;
+ int myMediaPort = 0;
++ const char *pidfile = DEFAULT_PIDFILE;
+
+ UInt32 interfaces[10];
+ int numInterfaces = stunFindLocalInterfaces(interfaces,10);
+@@ -135,6 +143,14 @@
+ }
+ myMediaPort = UInt16(strtol( argv[arg], NULL, 10));
+ }
++ else if( !strcmp( argv[arg], "-i" ) ) {
++ ++arg;
++ if( argc <= arg ) {
++ usage();
++ exit(-1);
++ }
++ pidfile = argv[arg];
++ }
+ else
+ {
+ usage();
+@@ -188,30 +204,30 @@
//exit(1);
}
@@ -41,6 +88,22 @@ $FreeBSD$
+ cerr << "daemon() call failed" << endl;
+ exit(1);
+ }
++ // Create pidfile
++ pf = open( pidfile, O_RDWR|O_CREAT, 0644 );
++ if( pf == -1 )
++ err( 1, "open(pidfile)" );
++ if( flock( pf, LOCK_EX | LOCK_NB ) == -1 ) {
++ if( errno == EWOULDBLOCK )
++ errx( 1, "pidfile is locked by another process" );
++ err( 1, "flock(pidfile)" );
++ }
++ if( ftruncate( pf, 0 ) == -1 )
++ err( 1, "ftruncate(pidfile)" );
++ char buf[20];
++ ssize_t blen = snprintf( buf, sizeof buf, "%d\n", (int) getpid() );
++ if( write( pf, buf, blen ) != blen )
++ err( 1, "write(pidfile)" );
++ // Don't close pf as we hold lock on it
}
-#endif
diff --git a/net/stund/files/stund.sh.in b/net/stund/files/stund.sh.in
new file mode 100644
index 0000000..755eff5
--- /dev/null
+++ b/net/stund/files/stund.sh.in
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: stund
+# REQUIRE: NETWORKING SERVERS
+# BEFORE: DAEMON
+# KEYWORD: shutdown
+
+. %%RC_SUBR%%
+
+: ${stund_enable:=NO}
+: ${stund_pidfile:=/var/run/stund.pid}
+: ${stund_flags="-h \"\$stund_ip1\" -a \"\$stund_ip2\" -b"}
+
+name="stund"
+command="%%PREFIX%%/sbin/stund"
+rcvar=`set_rcvar`
+extra_commands="status"
+pidfile="$stund_pidfile"
+
+load_rc_config $name
+
+start_precmd=stund_prestart
+stund_prestart() {
+ if [ -z "$stund_ip1" -o -z "$stund_ip2" ]; then
+ echo stund: failed: you must set stund_ip1 and stund_ip2 1>&2
+ return 1
+ fi
+ return 0
+}
+
+run_rc_command "$1"
OpenPOWER on IntegriCloud