From owner-svn-src-all@FreeBSD.ORG Thu Mar 29 20:11:17 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3CC831065680; Thu, 29 Mar 2012 20:11:17 +0000 (UTC) (envelope-from trociny@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0E8AB8FC21; Thu, 29 Mar 2012 20:11:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2TKBGn3008423; Thu, 29 Mar 2012 20:11:16 GMT (envelope-from trociny@svn.freebsd.org) Received: (from trociny@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2TKBG67008421; Thu, 29 Mar 2012 20:11:16 GMT (envelope-from trociny@svn.freebsd.org) Message-Id: <201203292011.q2TKBG67008421@svn.freebsd.org> From: Mikolaj Golub Date: Thu, 29 Mar 2012 20:11:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233679 - head/sbin/hastd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Mar 2012 20:11:17 -0000 Author: trociny Date: Thu Mar 29 20:11:16 2012 New Revision: 233679 URL: http://svn.freebsd.org/changeset/base/233679 Log: 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 Modified: head/sbin/hastd/hastd.c Modified: head/sbin/hastd/hastd.c ============================================================================== --- head/sbin/hastd/hastd.c Thu Mar 29 19:29:24 2012 (r233678) +++ head/sbin/hastd/hastd.c Thu Mar 29 20:11:16 2012 (r233679) @@ -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,