[master] 71d30ee Repatriate some non-child related stuff from mgt_child.c to mgt_main.c
Poul-Henning Kamp
phk at FreeBSD.org
Sat Jan 14 19:30:05 CET 2017
commit 71d30eeaede2b51618aff211b45e2bf47db705f8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sat Jan 14 18:28:55 2017 +0000
Repatriate some non-child related stuff from mgt_child.c to mgt_main.c
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index e992eb2..d480456 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -81,7 +81,6 @@ static struct vev *ev_listen;
static struct vlu *child_std_vlu;
static struct vsb *child_panic = NULL;
-static double mgt_uptime_t0 = 0.;
static void mgt_reap_child(void);
@@ -667,37 +666,6 @@ mcf_server_status(struct cli *cli, const char * const *av, void *priv)
/*--------------------------------------------------------------------*/
-static int __match_proto__(vev_cb_f)
-mgt_sigint(const struct vev *e, int what)
-{
-
- (void)e;
- (void)what;
- MGT_Complain(C_ERR, "Manager got SIGINT");
- (void)fflush(stdout);
- if (child_pid >= 0)
- mgt_stop_child();
- exit(0);
-}
-
-/*--------------------------------------------------------------------*/
-
-static int __match_proto__(vev_cb_f)
-mgt_uptime(const struct vev *e, int what)
-{
-
- (void)e;
- (void)what;
- AN(VSC_C_mgt);
- VSC_C_mgt->uptime = static_VSC_C_mgt.uptime =
- (uint64_t)(VTIM_real() - mgt_uptime_t0);
- if (heritage.vsm != NULL)
- VSM_common_ageupdate(heritage.vsm);
- return (0);
-}
-
-/*--------------------------------------------------------------------*/
-
static struct cli_proto cli_child[] = {
{ CLICMD_SERVER_STATUS, "", mcf_server_status },
{ CLICMD_SERVER_START, "", mcf_server_start },
@@ -716,45 +684,9 @@ static struct cli_proto cli_child[] = {
int
MGT_Run(void)
{
- struct sigaction sac;
- struct vev *e;
- int i;
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_child);
- mgt_uptime_t0 = VTIM_real();
- e = vev_new();
- XXXAN(e);
- e->callback = mgt_uptime;
- e->timeout = 1.0;
- e->name = "mgt_uptime";
- AZ(vev_add(mgt_evb, e));
-
- e = vev_new();
- XXXAN(e);
- e->sig = SIGTERM;
- e->callback = mgt_sigint;
- e->name = "mgt_sigterm";
- AZ(vev_add(mgt_evb, e));
-
- e = vev_new();
- XXXAN(e);
- e->sig = SIGINT;
- e->callback = mgt_sigint;
- e->name = "mgt_sigint";
- AZ(vev_add(mgt_evb, e));
-
-#ifdef HAVE_SETPROCTITLE
- setproctitle("Varnish-Mgr %s", heritage.name);
-#endif
-
- memset(&sac, 0, sizeof sac);
- sac.sa_handler = SIG_IGN;
- sac.sa_flags = SA_RESTART;
-
- AZ(sigaction(SIGPIPE, &sac, NULL));
- AZ(sigaction(SIGHUP, &sac, NULL));
-
if (!d_flag && !mgt_has_vcl())
MGT_Complain(C_ERR, "No VCL loaded yet");
else if (!d_flag) {
@@ -763,11 +695,5 @@ MGT_Run(void)
return (2);
}
- i = mgt_SHM_Commit();
- if (i != 0) {
- MGT_Complain(C_ERR, "Could not commit SHM file");
- return (2);
- }
-
return(0);
}
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 7b730dd..cc36f27 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -31,12 +31,11 @@
#include "config.h"
-#include <sys/utsname.h>
-
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
@@ -397,6 +396,40 @@ mgt_eric_im_done(int eric_fd, unsigned u)
/*--------------------------------------------------------------------*/
+static int __match_proto__(vev_cb_f)
+mgt_sigint(const struct vev *e, int what)
+{
+
+ (void)e;
+ (void)what;
+ MGT_Complain(C_ERR, "Manager got SIGINT");
+ (void)fflush(stdout);
+ if (child_pid >= 0)
+ mgt_stop_child();
+ exit(0);
+}
+
+/*--------------------------------------------------------------------*/
+
+static int __match_proto__(vev_cb_f)
+mgt_uptime(const struct vev *e, int what)
+{
+ static double mgt_uptime_t0 = 0;
+
+ (void)e;
+ (void)what;
+ AN(VSC_C_mgt);
+ if (mgt_uptime_t0 == 0)
+ mgt_uptime_t0 = VTIM_real();
+ VSC_C_mgt->uptime = static_VSC_C_mgt.uptime =
+ (uint64_t)(VTIM_real() - mgt_uptime_t0);
+ if (heritage.vsm != NULL)
+ VSM_common_ageupdate(heritage.vsm);
+ return (0);
+}
+
+/*--------------------------------------------------------------------*/
+
int
main(int argc, char * const *argv)
{
@@ -424,6 +457,8 @@ main(int argc, char * const *argv)
char Cn_arg[] = "/tmp/varnishd_C_XXXXXXX";
const char * opt_spec = "a:b:Cdf:Fh:i:j:l:M:n:P:p:r:S:s:T:t:VW:x:";
unsigned u;
+ struct sigaction sac;
+ struct vev *e;
mgt_tests();
@@ -507,6 +542,10 @@ main(int argc, char * const *argv)
mgt_pid = getpid();
}
+#ifdef HAVE_SETPROCTITLE
+ setproctitle("Varnish-Mgr %s", heritage.name);
+#endif
+
/* Set up the mgt counters */
memset(&static_VSC_C_mgt, 0, sizeof static_VSC_C_mgt);
VSC_C_mgt = &static_VSC_C_mgt;
@@ -718,10 +757,6 @@ main(int argc, char * const *argv)
S_arg = make_secret(dirname);
AN(S_arg);
- /**************************************************************
- * After this point diagnostics will only be seen with -d
- */
-
assert(pfh == NULL || !VPF_Write(pfh));
MGT_Complain(C_DEBUG, "Platform: %s", VSB_data(vident) + 1);
@@ -739,15 +774,52 @@ main(int argc, char * const *argv)
/* Instantiate VSM */
mgt_SHM_Create();
-
- u = MGT_Run();
+ if (mgt_SHM_Commit()) {
+ MGT_Complain(C_ERR, "Could not commit SHM file");
+ u = 2;
+ } else {
+ u = MGT_Run();
+ }
if (eric_fd >= 0)
mgt_eric_im_done(eric_fd, u);
+ if (u)
+ exit(u);
+
+ /* Failure is no longer an option */
+
if (F_flag)
VFIL_null_fd(STDIN_FILENO);
+ e = vev_new();
+ AN(e);
+ e->callback = mgt_uptime;
+ e->timeout = 1.0;
+ e->name = "mgt_uptime";
+ AZ(vev_add(mgt_evb, e));
+
+ e = vev_new();
+ AN(e);
+ e->sig = SIGTERM;
+ e->callback = mgt_sigint;
+ e->name = "mgt_sigterm";
+ AZ(vev_add(mgt_evb, e));
+
+ e = vev_new();
+ AN(e);
+ e->sig = SIGINT;
+ e->callback = mgt_sigint;
+ e->name = "mgt_sigint";
+ AZ(vev_add(mgt_evb, e));
+
+ memset(&sac, 0, sizeof sac);
+ sac.sa_handler = SIG_IGN;
+ sac.sa_flags = SA_RESTART;
+
+ AZ(sigaction(SIGPIPE, &sac, NULL));
+ AZ(sigaction(SIGHUP, &sac, NULL));
+
o = vev_schedule(mgt_evb);
if (o != 0)
MGT_Complain(C_ERR, "vev_schedule() = %d", o);
More information about the varnish-commit
mailing list