summaryrefslogtreecommitdiffstats
path: root/sbin/hastd
diff options
context:
space:
mode:
authortrociny <trociny@FreeBSD.org>2012-03-29 20:11:16 +0000
committertrociny <trociny@FreeBSD.org>2012-03-29 20:11:16 +0000
commit5780d99776e896928beee4a75a587e3cfe6d80b3 (patch)
tree86281d054d4f279f7916623b355fa1e0b50e69e0 /sbin/hastd
parenta48f8f3f0c8b1317eadad9cb24febef107eb16a0 (diff)
downloadFreeBSD-src-5780d99776e896928beee4a75a587e3cfe6d80b3.zip
FreeBSD-src-5780d99776e896928beee4a75a587e3cfe6d80b3.tar.gz
If hastd is invoked with "-P pidfile" option always create pidfile
regardless of whether -F (foreground) option is set or not. Also, if -P option is specified, ignore pidfile setting from configuration not only on start but on reload too. This fixes the issue when for hastd run with -P option reload caused the pidfile change. Reviewed by: pjd MFC after: 1 week
Diffstat (limited to 'sbin/hastd')
-rw-r--r--sbin/hastd/hastd.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c
index e3b946c..ccce81d 100644
--- a/sbin/hastd/hastd.c
+++ b/sbin/hastd/hastd.c
@@ -66,6 +66,8 @@ const char *cfgpath = HAST_CONFIG;
static struct hastd_config *cfg;
/* Was SIGINT or SIGTERM signal received? */
bool sigexit_received = false;
+/* Path to pidfile. */
+static const char *pidfile;
/* PID file handle. */
struct pidfh *pfh;
/* Do we run in foreground? */
@@ -537,7 +539,8 @@ hastd_reload(void)
/*
* Check if pidfile's path has changed.
*/
- if (!foreground && strcmp(cfg->hc_pidfile, newcfg->hc_pidfile) != 0) {
+ if (!foreground && pidfile == NULL &&
+ strcmp(cfg->hc_pidfile, newcfg->hc_pidfile) != 0) {
newpfh = pidfile_open(newcfg->hc_pidfile, 0600, &otherpid);
if (newpfh == NULL) {
if (errno == EEXIST) {
@@ -1163,14 +1166,12 @@ int
main(int argc, char *argv[])
{
struct hastd_listen *lst;
- const char *pidfile;
pid_t otherpid;
int debuglevel;
sigset_t mask;
foreground = false;
debuglevel = 0;
- pidfile = NULL;
for (;;) {
int ch;
@@ -1230,7 +1231,7 @@ main(int argc, char *argv[])
}
}
- if (!foreground) {
+ if (pidfile != NULL || !foreground) {
pfh = pidfile_open(cfg->hc_pidfile, 0600, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST) {
@@ -1291,7 +1292,8 @@ main(int argc, char *argv[])
/* Start logging to syslog. */
pjdlog_mode_set(PJDLOG_MODE_SYSLOG);
-
+ }
+ if (pidfile != NULL || !foreground) {
/* Write PID to a file. */
if (pidfile_write(pfh) == -1) {
pjdlog_errno(LOG_WARNING,
OpenPOWER on IntegriCloud