.\"
.\" $DragonFly: src/usr.sbin/vknetd/vknetd.8,v 1.3 2008/05/31 12:04:15 swildner Exp $
.\"
-.Dd May 21, 2009
+.Dd Dec 5, 2011
.Dt VKNETD 8
.Os
.Sh NAME
.Op Fl cdU
.Op Fl b Ar bridgeN
.Op Fl p Ar socket_path
+.Op Fl i Ar pidfile
.Op Fl t Ar tapN
.Op Ar address Ns / Ns Ar cidrbits
.Sh DESCRIPTION
Specify where to create the unix domain socket in the filesystem space.
By default the socket is called
.Pa /var/run/vknet .
+.It Fl i Ar pidfile
+When specified, write process id to
+.Ar pidfile
+instead of the default
+.Pa /var/run/vknetd.pid .
.It Fl t Ar tapN
Specify a particular
.Xr tap 4
static int vknet_connect(const char *pathName);
static void vknet_monitor(int net_fd);
static void usage(void);
+static void writepid(void);
+static void cleanup(int);
pthread_mutex_t BridgeMutex;
int SecureOpt = 1;
int DebugOpt = 0;
int SetAddrOpt = 0;
+const char *pidfile = "/var/run/vknetd.pid";
+
struct in_addr NetAddress;
struct in_addr NetMask;
ioinfo_t tap_info;
pthread_t dummy_td;
- while ((c = getopt(ac, av, "b:cdp:t:U")) != -1) {
+ while ((c = getopt(ac, av, "b:cdp:i:t:U")) != -1) {
switch (c) {
case 'U':
SecureOpt = 0;
case 'p':
pathName = optarg;
break;
+ case 'i':
+ pidfile = optarg;
+ break;
case 't':
tapName = optarg;
break;
exit(1);
}
+ writepid();
+
+ signal(SIGINT, cleanup);
+ signal(SIGHUP, cleanup);
+ signal(SIGTERM, cleanup);
+
/*
* Now make us a demon and start the threads going.
*/
/*
* Misc
*/
+static void
+writepid(void)
+{
+ FILE *pf;
+
+ if ((pf = fopen(pidfile, "w+")) == NULL)
+ errx(1, "Failed to create pidfile %s", pidfile);
+
+ if ((fprintf(pf, "%d\n", getpid())) < 1)
+ err(1, "fprintf");
+
+ fclose(pf);
+}
+
+static void
+cleanup(int __unused sig)
+{
+ if (pidfile)
+ unlink(pidfile);
+}
+
static
void
usage(void)
{
- fprintf(stderr, "usage: vknet [-cdU] [-b bridgeN] [-p socket_path] [-t tapN] [address/cidrbits]\n");
+ fprintf(stderr, "usage: vknet [-cdU] [-b bridgeN] [-p socket_path] [-i pidfile] [-t tapN] [address/cidrbits]\n");
fprintf(stderr, "address/cidrbits must be specified in default secure mode.\n");
exit(1);
}