Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add --pid-file option
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Stebalien authored and David Woodhouse committed Sep 9, 2011
1 parent 9785d0c commit f4b5007
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
32 changes: 30 additions & 2 deletions main.c
Expand Up @@ -81,6 +81,7 @@ enum {
OPT_NO_HTTP_KEEPALIVE,
OPT_NO_PASSWD,
OPT_NO_PROXY,
OPT_PIDFILE,
OPT_PASSWORD_ON_STDIN,
OPT_PRINTCOOKIE,
OPT_RECONNECT_TIMEOUT,
Expand All @@ -91,6 +92,7 @@ enum {

static struct option long_options[] = {
{"background", 0, 0, 'b'},
{"pid-file", 1, 0, OPT_PIDFILE},
{"certificate", 1, 0, 'c'},
{"sslkey", 1, 0, 'k'},
{"cookie", 1, 0, 'C'},
Expand Down Expand Up @@ -143,6 +145,7 @@ void usage(void)
printf("Usage: openconnect [options] <server>\n");
printf("Open client for Cisco AnyConnect VPN, version %s\n\n", openconnect_version);
printf(" -b, --background Continue in background after startup\n");
printf(" --pid-file=PIDFILE Write the daemons pid to this file\n");
printf(" -c, --certificate=CERT Use SSL client certificate CERT\n");
printf(" -k, --sslkey=KEY Use SSL private key file KEY\n");
printf(" -K, --key-type=TYPE Private key type (PKCS#12 / TPM / PEM)\n");
Expand Down Expand Up @@ -230,6 +233,8 @@ int main(int argc, char **argv)
int autoproxy = 0;
uid_t uid = getuid();
int opt;
char *pidfile = NULL;
FILE *fp = NULL;

openconnect_init_openssl();

Expand Down Expand Up @@ -268,6 +273,9 @@ int main(int argc, char **argv)
case OPT_CAFILE:
vpninfo->cafile = optarg;
break;
case OPT_PIDFILE:
pidfile = optarg;
break;
case OPT_SERVERCERT:
vpninfo->servercert = optarg;
break;
Expand Down Expand Up @@ -570,14 +578,34 @@ int main(int argc, char **argv)

if (background) {
int pid;

/* Open the pidfile before forking, so we can report errors
more sanely. It's *possible* that we'll fail to write to
it, but very unlikely. */
if (pidfile != NULL) {
fp = fopen(pidfile, "w");
if (!fp) {
fprintf(stderr, "Failed to open '%s' for write: %s\n",
pidfile, strerror(errno));
exit(1);
}
}
if ((pid = fork())) {
if (fp) {
fprintf(fp, "%d\n", pid);
fclose(fp);
}
vpn_progress(vpninfo, PRG_INFO,
"Continuing in background; pid %d\n",
pid);
"Continuing in background; pid %d\n",
pid);
exit(0);
}
if (fp)
fclose(fp);
}
vpn_mainloop(vpninfo);
if (fp)
unlink(pidfile);
exit(1);
}

Expand Down
9 changes: 9 additions & 0 deletions openconnect.8
Expand Up @@ -7,6 +7,10 @@ openconnect \- Connect to Cisco AnyConnect VPN
.B -b,--background
]
[
.B --pid-file
.I PIDFILE
]
[
.B -c,--certificate
.I CERT
]
Expand Down Expand Up @@ -188,6 +192,11 @@ exchanged, which allows data transport over UDP to occur.
.B -b,--background
Continue in background after startup
.TP
.B --pid-file=PIDFILE
Save the pid to
.I PIDFILE
when backgrounding
.TP
.B -c,--certificate=CERT
Use SSL client certificate
.I CERT
Expand Down
5 changes: 3 additions & 2 deletions openconnect.html
Expand Up @@ -185,7 +185,8 @@ <H2>Release Notes / Changelog</H2>
<UL>
<LI>Fix DTLS compatibility with ASA firmware 8.4.11(11) and above.</LI>
<LI>Fix build failures on GNU Hurd, on systems with ancient OpenSSL,
and on Debian.</LI>
and on Debian.</LI>
<LI>Add <TT>--pid-file</TT> option.</LI>
</UL><BR>
</LI>
<LI><B><A HREF="ftp://ftp.infradead.org/pub/openconnect/openconnect-3.11.tar.gz">OpenConnect v3.11</a></B> &mdash; 2011-07-20<BR>
Expand Down Expand Up @@ -498,6 +499,6 @@ <H3>FreeBSD</H3>
<hr>
<address>David Woodhouse &lt;<A HREF="mailto:dwmw2@infradead.org">dwmw2@infradead.org</A>&gt;</address>
<!-- hhmts start -->
Last modified: Thu Sep 8 14:06:19 BST 2011
Last modified: Fri Sep 9 21:10:36 BST 2011
<!-- hhmts end -->
</body> </html>

0 comments on commit f4b5007

Please sign in to comment.