o Add support for generating pidfile;

o newrc startup script;

o bump PORTREVISION.
This commit is contained in:
Maxim Sobolev 2005-07-29 12:36:30 +00:00
parent 18543e1e62
commit 9d762de626
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=140395
3 changed files with 101 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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"