From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:05 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:05 +0000 (UTC) Subject: [master] f985e15c6 build: Collect warnings with a separate variable Message-ID: <20220103141305.C54661091E5@lists.varnish-cache.org> commit f985e15c6c0e46da830950ddddc82d95dfc787c6 Author: Dridi Boukelmoune Date: Mon Dec 6 15:52:19 2021 +0100 build: Collect warnings with a separate variable But inject it back into OCFLAGS for distcheck continuity. diff --git a/configure.ac b/configure.ac index e61cc2730..87ae96a9f 100644 --- a/configure.ac +++ b/configure.ac @@ -654,9 +654,11 @@ gl_LD_VERSION_SCRIPT # idiocy where write is marked as warn_unused_result, causing build # failures. +WFLAGS= + AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="${CFLAGS} -Wall" - OCFLAGS="${OCFLAGS} -Wall"]) + WFLAGS="${WFLAGS} -Wall"]) if test "$SUNCC" = "yes" ; then SUNCC_CFLAGS=" \ @@ -665,27 +667,27 @@ if test "$SUNCC" = "yes" ; then " AX_CHECK_COMPILE_FLAG([${SUNCC_CFLAGS}], [CFLAGS="${CFLAGS} ${SUNCC_CFLAGS}" - OCFLAGS="${OCFLAGS} ${SUNCC_CFLAGS}"]) + WFLAGS="${WFLAGS} ${SUNCC_CFLAGS}"]) else AX_CHECK_COMPILE_FLAG([-Werror], [CFLAGS="${CFLAGS} -Werror" - OCFLAGS="${OCFLAGS} -Werror"]) + WFLAGS="${WFLAGS} -Werror"]) fi case $target in *-*-darwin*) AX_CHECK_COMPILE_FLAG([-Wno-expansion-to-defined], [CFLAGS="${CFLAGS} -Wno-expansion-to-defined" - OCFLAGS="${OCFLAGS} -Wno-expansion-to-defined"]) + WFLAGS="${WFLAGS} -Wno-expansion-to-defined"]) ;; esac AX_CHECK_COMPILE_FLAG([-Werror=unused-result], [CFLAGS="${CFLAGS} -Wno-error=unused-result" - OCFLAGS="${OCFLAGS} -Wno-error=unused-result"], + WFLAGS="${WFLAGS} -Wno-error=unused-result"], [AX_CHECK_COMPILE_FLAG([-Wunused-result], [CFLAGS="${CFLAGS} -Wno-unused-result" - OCFLAGS="${OCFLAGS} -Wno-unused-result"])]) + WFLAGS="${WFLAGS} -Wno-unused-result"])]) # This corresponds to FreeBSD's WARNS level 6 DEVELOPER_CFLAGS=`$PYTHON $srcdir/wflags.py` @@ -721,7 +723,7 @@ if test "x$SUNCC" != "xyes" && test "x$enable_developer_warnings" != "xno"; then []) CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}" - OCFLAGS="${OCFLAGS} ${DEVELOPER_CFLAGS}" + WFLAGS="${WFLAGS} ${DEVELOPER_CFLAGS}" fi # gcc on solaris needs -fstack-protector when calling gcc in linker @@ -804,23 +806,25 @@ else *-*-solaris*) case $PTHREAD_CC in *gcc*) - VCC_CC="$PTHREAD_CC $OCFLAGS $PTHREAD_CFLAGS -fpic -shared -o %o %s" + VCC_CC="$PTHREAD_CC $OCFLAGS $WFLAGS $PTHREAD_CFLAGS -fpic -shared -o %o %s" break ;; *cc) - VCC_CC="$PTHREAD_CC $OCFLAGS -errwarn=%all,no%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" + VCC_CC="$PTHREAD_CC $OCFLAGS $WFLAGS -errwarn=%all,no%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" ;; esac ;; *-*-darwin*) - VCC_CC="exec cc $OCFLAGS -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s" + VCC_CC="exec cc $OCFLAGS $WFLAGS -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s" ;; *) - VCC_CC="exec $PTHREAD_CC $OCFLAGS $PTHREAD_CFLAGS $SAN_CFLAGS -fpic -shared -Wl,-x -o %o %s" + VCC_CC="exec $PTHREAD_CC $OCFLAGS $WFLAGS $PTHREAD_CFLAGS $SAN_CFLAGS -fpic -shared -Wl,-x -o %o %s" ;; esac fi +OCFLAGS="$OCFLAGS $WFLAGS" + AC_DEFINE_UNQUOTED([VCC_CC],"$VCC_CC",[C compiler command line for VCL code]) # Stupid automake needs this From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:05 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:05 +0000 (UTC) Subject: [master] 2967f01ed param: Add a new cc_warnings parameter Message-ID: <20220103141306.002331091E8@lists.varnish-cache.org> commit 2967f01eda99cbafa8e224ac05b9d673cdb91f87 Author: Dridi Boukelmoune Date: Mon Dec 6 18:16:07 2021 +0100 param: Add a new cc_warnings parameter With a new %w expansion in the cc_command parameter. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index f2d2f0f7e..93a9989de 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -233,6 +233,7 @@ void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin, int mgt_push_vcls(struct cli *, unsigned *status, char **p); const char *mgt_has_vcl(void); extern char *mgt_cc_cmd; +extern char *mgt_cc_warn; extern const char *mgt_vcl_path; extern const char *mgt_vmod_path; #define MGT_VCC(t, n, cc) extern t mgt_vcc_ ## n; diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index faedb803b..0229e0cbc 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -63,6 +63,7 @@ struct vcc_priv { }; char *mgt_cc_cmd; +char *mgt_cc_warn; const char *mgt_vcl_path; const char *mgt_vmod_path; #define MGT_VCC(t, n, cc) t mgt_vcc_ ## n; @@ -150,6 +151,9 @@ run_cc(void *priv) case 'o': VSB_cat(sb, VGC_LIB); break; + case 'w': + VSB_cat(sb, mgt_cc_warn); + break; case '%': VSB_putc(sb, '%'); break; diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc new file mode 100644 index 000000000..9574d151d --- /dev/null +++ b/bin/varnishtest/tests/c00109.vtc @@ -0,0 +1,9 @@ +varnishtest "cc_command and cc_warnings" + +varnish v1 -cliok {param.set debug +vcl_keep} +varnish v1 -cliok {param.set cc_command "! printf '%w' >world"} +varnish v1 -cliok {param.set cc_warnings hello} + +varnish v1 -errvcl "VCL compilation failed" "backend be none;" + +shell -expect hello "cat v1/vcl_*/world" diff --git a/configure.ac b/configure.ac index 87ae96a9f..e3ead6bd7 100644 --- a/configure.ac +++ b/configure.ac @@ -806,26 +806,33 @@ else *-*-solaris*) case $PTHREAD_CC in *gcc*) - VCC_CC="$PTHREAD_CC $OCFLAGS $WFLAGS $PTHREAD_CFLAGS -fpic -shared -o %o %s" + VCC_CC="$PTHREAD_CC $OCFLAGS %w $PTHREAD_CFLAGS -fpic -shared -o %o %s" break ;; *cc) - VCC_CC="$PTHREAD_CC $OCFLAGS $WFLAGS -errwarn=%all,no%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" + VCC_CC="$PTHREAD_CC $OCFLAGS %w -errwarn=%all,no%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" ;; esac ;; *-*-darwin*) - VCC_CC="exec cc $OCFLAGS $WFLAGS -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s" + VCC_CC="exec cc $OCFLAGS %w -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s" ;; *) - VCC_CC="exec $PTHREAD_CC $OCFLAGS $WFLAGS $PTHREAD_CFLAGS $SAN_CFLAGS -fpic -shared -Wl,-x -o %o %s" + VCC_CC="exec $PTHREAD_CC $OCFLAGS %w $PTHREAD_CFLAGS $SAN_CFLAGS -fpic -shared -Wl,-x -o %o %s" ;; esac fi +if test "$ac_cv_env_VCC_WARN_set" = set; then + VCC_WARN=$ac_cv_env_VCC_WARN_value +else + VCC_WARN=$WFLAGS +fi + OCFLAGS="$OCFLAGS $WFLAGS" AC_DEFINE_UNQUOTED([VCC_CC],"$VCC_CC",[C compiler command line for VCL code]) +AC_DEFINE_UNQUOTED([VCC_WARN],"$VCC_WARN",[C compiler warnings for VCL code]) # Stupid automake needs this VTC_TESTS="$(cd $srcdir/bin/varnishtest && echo tests/*.vtc)" diff --git a/include/tbl/params.h b/include/tbl/params.h index 964c2d255..8b82b97f1 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1533,7 +1533,20 @@ PARAM_STRING( "Command used for compiling the C source code to a " "dlopen(3) loadable object. Any occurrence of %s in " "the string will be replaced with the source file name, " - "and %o will be replaced with the output file name.", + "%o will be replaced with the output file name, and %w " + "will be replaced by the cc_warnings parameter.", + /* flags */ MUST_RELOAD +) + +PARAM_STRING( + /* name */ cc_warnings, + /* tweak */ tweak_string, + /* priv */ &mgt_cc_warn, + /* def */ VCC_WARN, + /* descr */ + "Warnings used when compiling the C source code with " + "the cc_command parameter. By default, VCL is compiled " + "with the same set of warnings as Varnish itself.", /* flags */ MUST_RELOAD ) From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] 1f36ded9f param: New BUILD_OPTIONS flag Message-ID: <20220103141306.205CA1091EC@lists.varnish-cache.org> commit 1f36ded9f7be01f57326f1dfb57e7ed69d37373b Author: Dridi Boukelmoune Date: Thu Sep 9 07:47:50 2021 +0200 param: New BUILD_OPTIONS flag Similar to PLATFORM_DEPENDENT for things affected by configure options or other build flags that are not necessarily linked to the target platform. diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 3b160dcf9..2b4c293ca 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -110,6 +110,11 @@ static const char PLATFORM_DEPENDENT_TEXT[] = "NB: This parameter depends on a feature which is not available" " on all platforms."; +static const char BUILD_OPTIONS_TEXT[] = + "\n\n" + "NB: The actual default value for this parameter depends on the" + " Varnish build environment and options."; + /*--------------------------------------------------------------------*/ static struct parspec * @@ -343,6 +348,8 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv) mcf_wrap(cli, PROTECTED_TEXT); if (pp->flags & ONLY_ROOT) mcf_wrap(cli, ONLY_ROOT_TEXT); + if (pp->flags & BUILD_OPTIONS) + mcf_wrap(cli, BUILD_OPTIONS_TEXT); VCLI_Out(cli, "\n\n"); } } @@ -464,6 +471,7 @@ mcf_param_show_json(struct cli *cli, const char * const *av, void *priv) flag_out(WIZARD, wizard); flag_out(PROTECTED, protected); flag_out(ONLY_ROOT, only_root); + flag_out(BUILD_OPTIONS, build_options); #undef flag_out @@ -806,6 +814,9 @@ MCF_DumpRstParam(void) if (pp->flags && pp->flags & PLATFORM_DEPENDENT) printf("\n%s\n\n", PLATFORM_DEPENDENT_TEXT); + if (pp->flags && pp->flags & BUILD_OPTIONS) + printf("\n%s\n\n", BUILD_OPTIONS_TEXT); + if (pp->units != NULL && *pp->units != '\0') printf("\t* Units: %s\n", pp->units); #define MCF_DYN_REASON(lbl, nm) \ @@ -823,7 +834,7 @@ MCF_DumpRstParam(void) * XXX: that say if ->min/->max are valid, so we * XXX: can emit those also in help texts. */ - if (pp->flags & ~(NOT_IMPLEMENTED|PLATFORM_DEPENDENT)) { + if (pp->flags & ~DOCS_FLAGS) { printf("\t* Flags: "); q = ""; diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h index f3af67df5..b15286f89 100644 --- a/bin/varnishd/mgt/mgt_param.h +++ b/bin/varnishd/mgt/mgt_param.h @@ -57,6 +57,9 @@ struct parspec { #define ONLY_ROOT (1<<7) #define NOT_IMPLEMENTED (1<<8) #define PLATFORM_DEPENDENT (1<<9) +#define BUILD_OPTIONS (1<<10) + +#define DOCS_FLAGS (NOT_IMPLEMENTED|PLATFORM_DEPENDENT|BUILD_OPTIONS) const char *dyn_min_reason; const char *dyn_max_reason; From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] 6fde72c63 param: Give string parameters canned defaults Message-ID: <20220103141306.3F60E1091F0@lists.varnish-cache.org> commit 6fde72c63c568e7551d36d38d81f31f8feb56d23 Author: Dridi Boukelmoune Date: Thu Sep 9 07:50:36 2021 +0200 param: Give string parameters canned defaults This way the documentation can show neutral defaults for parameters that are highly platform-dependent. diff --git a/include/tbl/params.h b/include/tbl/params.h index 8b82b97f1..20929d823 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1535,7 +1535,10 @@ PARAM_STRING( "the string will be replaced with the source file name, " "%o will be replaced with the output file name, and %w " "will be replaced by the cc_warnings parameter.", - /* flags */ MUST_RELOAD + /* flags */ MUST_RELOAD | BUILD_OPTIONS, + /* dyn_min_reason */ NULL, + /* dyn_max_reason */ NULL, + /* dyn_def_reason */ "exec $CC $CFLAGS %w -shared -o %o %s" ) PARAM_STRING( @@ -1547,7 +1550,10 @@ PARAM_STRING( "Warnings used when compiling the C source code with " "the cc_command parameter. By default, VCL is compiled " "with the same set of warnings as Varnish itself.", - /* flags */ MUST_RELOAD + /* flags */ MUST_RELOAD | BUILD_OPTIONS, + /* dyn_min_reason */ NULL, + /* dyn_max_reason */ NULL, + /* dyn_def_reason */ "-Wall -Werror" ) PARAM_STRING( @@ -1573,7 +1579,11 @@ PARAM_STRING( "VCL files in both the system configuration and shared " "data directories to allow packages to drop their VCL " "files in a standard location where relative includes " - "would work." + "would work.", + /* flags */ BUILD_OPTIONS, + /* dyn_min_reason */ NULL, + /* dyn_max_reason */ NULL, + /* dyn_def_reason */ "${sysconfdir}/varnish:${datadir}/varnish/vcl" ) PARAM_STRING( @@ -1583,7 +1593,11 @@ PARAM_STRING( /* def */ VARNISH_VMOD_DIR, /* descr */ "Directory (or colon separated list of directories) " - "where VMODs are to be found." + "where VMODs are to be found.", + /* flags */ BUILD_OPTIONS, + /* dyn_min_reason */ NULL, + /* dyn_max_reason */ NULL, + /* dyn_def_reason */ "${libdir}/varnish/vmods" ) /*-------------------------------------------------------------------- From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] 624745ccf param: Expand %d to the default cc_command Message-ID: <20220103141306.5E5F81091F5@lists.varnish-cache.org> commit 624745ccf2940f339e9ccc3bbeadd83d2e551f21 Author: Dridi Boukelmoune Date: Tue Dec 7 08:33:18 2021 +0100 param: Expand %d to the default cc_command This is useful for shell script wrappers that can take the original command as an argument as well as the %{o,s,w} expansions as additional parameters. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 93a9989de..9065d9eaa 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -233,6 +233,7 @@ void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin, int mgt_push_vcls(struct cli *, unsigned *status, char **p); const char *mgt_has_vcl(void); extern char *mgt_cc_cmd; +extern char *mgt_cc_cmd_def; extern char *mgt_cc_warn; extern const char *mgt_vcl_path; extern const char *mgt_vmod_path; diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 2b4c293ca..fd77e2942 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -765,6 +765,9 @@ MCF_InitParams(struct cli *cli) mcf_wash_param(cli, pp, MCF_DEFAULT, "default", vsb); } VSB_destroy(&vsb); + + AN(mgt_cc_cmd); + REPLACE(mgt_cc_cmd_def, mgt_cc_cmd); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index 0229e0cbc..97a884ba2 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -63,6 +63,7 @@ struct vcc_priv { }; char *mgt_cc_cmd; +char *mgt_cc_cmd_def; char *mgt_cc_warn; const char *mgt_vcl_path; const char *mgt_vmod_path; @@ -154,6 +155,9 @@ run_cc(void *priv) case 'w': VSB_cat(sb, mgt_cc_warn); break; + case 'd': + VSB_cat(sb, mgt_cc_cmd_def); + break; case '%': VSB_putc(sb, '%'); break; diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc index 9574d151d..40d451296 100644 --- a/bin/varnishtest/tests/c00109.vtc +++ b/bin/varnishtest/tests/c00109.vtc @@ -1,9 +1,11 @@ varnishtest "cc_command and cc_warnings" varnish v1 -cliok {param.set debug +vcl_keep} -varnish v1 -cliok {param.set cc_command "! printf '%w' >world"} varnish v1 -cliok {param.set cc_warnings hello} +varnish v1 -cliok {param.set cc_command << EOF +! printf 'd="%%s" w="%%s"' '%d' '%w' >world +EOF} varnish v1 -errvcl "VCL compilation failed" "backend be none;" -shell -expect hello "cat v1/vcl_*/world" +shell -match {d=".+" w="hello"} "cat v1/vcl_*/world" diff --git a/include/tbl/params.h b/include/tbl/params.h index 20929d823..1fb9c9423 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1534,7 +1534,8 @@ PARAM_STRING( "dlopen(3) loadable object. Any occurrence of %s in " "the string will be replaced with the source file name, " "%o will be replaced with the output file name, and %w " - "will be replaced by the cc_warnings parameter.", + "will be replaced by the cc_warnings parameter. The %d " + "sequence expands to the default value for cc_command.", /* flags */ MUST_RELOAD | BUILD_OPTIONS, /* dyn_min_reason */ NULL, /* dyn_max_reason */ NULL, From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] d3345a772 build: Quote percent signs in $VCC_CC Message-ID: <20220103141306.785DB1091F9@lists.varnish-cache.org> commit d3345a7728e2d618e6959fcb19ebb4cf9176008a Author: Dridi Boukelmoune Date: Tue Dec 7 08:40:11 2021 +0100 build: Quote percent signs in $VCC_CC diff --git a/configure.ac b/configure.ac index e3ead6bd7..2d3757755 100644 --- a/configure.ac +++ b/configure.ac @@ -810,7 +810,7 @@ else break ;; *cc) - VCC_CC="$PTHREAD_CC $OCFLAGS %w -errwarn=%all,no%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" + VCC_CC="$PTHREAD_CC $OCFLAGS %w -errwarn=%%all,no%%E_STATEMENT_NOT_REACHED $PTHREAD_CFLAGS -Kpic -G -o %o %s" ;; esac ;; From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] 601818780 mgt: Expand cc_command in a dedicated function Message-ID: <20220103141306.97B881091FE@lists.varnish-cache.org> commit 6018187807010ae3051608687c93f57d01d58e56 Author: Dridi Boukelmoune Date: Tue Dec 14 07:49:16 2021 +0100 mgt: Expand cc_command in a dedicated function diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index 97a884ba2..070e03ac3 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -125,25 +125,19 @@ run_vcc(void *priv) } /*-------------------------------------------------------------------- - * Invoke system C compiler in a sub-process + * Expand the cc_command argument */ -static void v_matchproto_(vsub_func_f) -run_cc(void *priv) +static void +cc_expand(struct vsb *sb, const char *cc_cmd, char exp) { - struct vcc_priv *vp; - struct vsb *sb; + const char *p; int pct; - char *p; - - VJ_subproc(JAIL_SUBPROC_CC); - CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); - - AZ(chdir(VSB_data(vp->dir))); - sb = VSB_new_auto(); AN(sb); - for (p = mgt_cc_cmd, pct = 0; *p; ++p) { + AN(cc_cmd); + (void)exp; + for (p = cc_cmd, pct = 0; *p; ++p) { if (pct) { switch (*p) { case 's': @@ -175,6 +169,26 @@ run_cc(void *priv) } if (pct) VSB_putc(sb, '%'); +} + +/*-------------------------------------------------------------------- + * Invoke system C compiler in a sub-process + */ + +static void v_matchproto_(vsub_func_f) +run_cc(void *priv) +{ + struct vcc_priv *vp; + struct vsb *sb; + + VJ_subproc(JAIL_SUBPROC_CC); + CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); + + AZ(chdir(VSB_data(vp->dir))); + + sb = VSB_new_auto(); + AN(sb); + cc_expand(sb, mgt_cc_cmd, '\0'); AZ(VSB_finish(sb)); (void)umask(027); From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] b328f7f78 param: Add a %D expansion to cc_command Message-ID: <20220103141306.B7DDB109208@lists.varnish-cache.org> commit b328f7f78fc7564377cd48870bd67347549dba91 Author: Dridi Boukelmoune Date: Tue Dec 14 08:14:03 2021 +0100 param: Add a %D expansion to cc_command And slightly polish the cc_command description. diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index 070e03ac3..d32894b64 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -128,7 +128,7 @@ run_vcc(void *priv) * Expand the cc_command argument */ -static void +static const char * cc_expand(struct vsb *sb, const char *cc_cmd, char exp) { const char *p; @@ -136,7 +136,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) AN(sb); AN(cc_cmd); - (void)exp; + for (p = cc_cmd, pct = 0; *p; ++p) { if (pct) { switch (*p) { @@ -152,6 +152,11 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) case 'd': VSB_cat(sb, mgt_cc_cmd_def); break; + case 'D': + if (exp == pct) + return ("recursive expansion"); + cc_expand(sb, mgt_cc_cmd_def, pct); + break; case '%': VSB_putc(sb, '%'); break; @@ -169,6 +174,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) } if (pct) VSB_putc(sb, '%'); + return (NULL); } /*-------------------------------------------------------------------- @@ -180,6 +186,7 @@ run_cc(void *priv) { struct vcc_priv *vp; struct vsb *sb; + const char *err; VJ_subproc(JAIL_SUBPROC_CC); CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); @@ -188,7 +195,12 @@ run_cc(void *priv) sb = VSB_new_auto(); AN(sb); - cc_expand(sb, mgt_cc_cmd, '\0'); + err = cc_expand(sb, mgt_cc_cmd, '\0'); + if (err != NULL) { + VSB_destroy(&sb); + fprintf(stderr, "cc_command: %s\n", err); + exit(1); + } AZ(VSB_finish(sb)); (void)umask(027); diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc index 40d451296..5321aa43f 100644 --- a/bin/varnishtest/tests/c00109.vtc +++ b/bin/varnishtest/tests/c00109.vtc @@ -3,9 +3,9 @@ varnishtest "cc_command and cc_warnings" varnish v1 -cliok {param.set debug +vcl_keep} varnish v1 -cliok {param.set cc_warnings hello} varnish v1 -cliok {param.set cc_command << EOF -! printf 'd="%%s" w="%%s"' '%d' '%w' >world +! printf 'd="%%s" D="%%s" w="%%s"' '%d' '%D' '%w' >world EOF} varnish v1 -errvcl "VCL compilation failed" "backend be none;" -shell -match {d=".+" w="hello"} "cat v1/vcl_*/world" +shell -match {d=".+" D=".+hello.+" w="hello"} "cat v1/vcl_*/world" diff --git a/include/tbl/params.h b/include/tbl/params.h index 1fb9c9423..6ad2cbe4d 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1530,12 +1530,22 @@ PARAM_STRING( /* priv */ &mgt_cc_cmd, /* def */ VCC_CC, /* descr */ - "Command used for compiling the C source code to a " - "dlopen(3) loadable object. Any occurrence of %s in " - "the string will be replaced with the source file name, " - "%o will be replaced with the output file name, and %w " - "will be replaced by the cc_warnings parameter. The %d " - "sequence expands to the default value for cc_command.", + "The command used for compiling the C source code to a " + "dlopen(3) loadable object. The following expansions can " + "be used:\n\n" + "- %s: the source file name\n" + "- %o: the output file name\n" + "- %w: the cc_warnings parameter\n" + "- %d: the raw default cc_command\n" + "- %D: the expanded default cc_command\n" + "- %%: a percent sign\n" + "\n" + "Unknown percent expansion sequences are ignored, and to " + "avoid future incompatibilities percent characters should " + "be escaped with a double percent sequence.\n\n" + "The %d and %D expansions allow passing the parameter's " + "default value to a wrapper script to perform additional " + "processing.", /* flags */ MUST_RELOAD | BUILD_OPTIONS, /* dyn_min_reason */ NULL, /* dyn_max_reason */ NULL, From dridi.boukelmoune at gmail.com Mon Jan 3 14:13:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 14:13:06 +0000 (UTC) Subject: [master] ea1aa68f9 param: Add a %n expansion to cc_command Message-ID: <20220103141306.D5E25109219@lists.varnish-cache.org> commit ea1aa68f9dd4cb4dbd850abb51ef75de749c95ee Author: Dridi Boukelmoune Date: Tue Dec 14 10:46:36 2021 +0100 param: Add a %n expansion to cc_command diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index d32894b64..ec9b997b7 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -33,6 +33,7 @@ #include "config.h" +#include #include #include #include @@ -131,6 +132,7 @@ run_vcc(void *priv) static const char * cc_expand(struct vsb *sb, const char *cc_cmd, char exp) { + char buf[PATH_MAX]; const char *p; int pct; @@ -157,6 +159,10 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) return ("recursive expansion"); cc_expand(sb, mgt_cc_cmd_def, pct); break; + case 'n': + AN(getcwd(buf, sizeof buf)); + VSB_cat(sb, buf); + break; case '%': VSB_putc(sb, '%'); break; @@ -191,8 +197,6 @@ run_cc(void *priv) VJ_subproc(JAIL_SUBPROC_CC); CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); - AZ(chdir(VSB_data(vp->dir))); - sb = VSB_new_auto(); AN(sb); err = cc_expand(sb, mgt_cc_cmd, '\0'); @@ -203,6 +207,8 @@ run_cc(void *priv) } AZ(VSB_finish(sb)); + AZ(chdir(VSB_data(vp->dir))); + (void)umask(027); (void)execl("/bin/sh", "/bin/sh", "-c", VSB_data(sb), (char*)0); VSB_destroy(&sb); // For flexelint diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc index 5321aa43f..7c4a7463d 100644 --- a/bin/varnishtest/tests/c00109.vtc +++ b/bin/varnishtest/tests/c00109.vtc @@ -3,9 +3,11 @@ varnishtest "cc_command and cc_warnings" varnish v1 -cliok {param.set debug +vcl_keep} varnish v1 -cliok {param.set cc_warnings hello} varnish v1 -cliok {param.set cc_command << EOF -! printf 'd="%%s" D="%%s" w="%%s"' '%d' '%D' '%w' >world +! printf 'd="%%s" D="%%s" w="%%s" n="%%s"' '%d' '%D' '%w' '%n' >world EOF} varnish v1 -errvcl "VCL compilation failed" "backend be none;" -shell -match {d=".+" D=".+hello.+" w="hello"} "cat v1/vcl_*/world" +shell -match {d=".+" D=".+hello.+" w="hello" n="${v1_name}"} { + exec cat v1/vcl_*/world +} diff --git a/include/tbl/params.h b/include/tbl/params.h index 6ad2cbe4d..a96b5225f 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1538,6 +1538,7 @@ PARAM_STRING( "- %w: the cc_warnings parameter\n" "- %d: the raw default cc_command\n" "- %D: the expanded default cc_command\n" + "- %n: the working directory (-n option)\n" "- %%: a percent sign\n" "\n" "Unknown percent expansion sequences are ignored, and to " From dridi.boukelmoune at gmail.com Mon Jan 3 18:35:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 3 Jan 2022 18:35:06 +0000 (UTC) Subject: [master] 247eb50f4 vrt: Perform IP to STRING conversion on the stack Message-ID: <20220103183507.072A2113EDB@lists.varnish-cache.org> commit 247eb50f47d4dae5eeacc54375eb3f2adde086a1 Author: Dridi Boukelmoune Date: Mon Jan 3 18:36:16 2022 +0100 vrt: Perform IP to STRING conversion on the stack Performing the conversion on the stack could lead to a buffer too small to store the string representation of the IP address. There is no test case because the error handling is output to stderr. Refs #3765 diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index df7440ad8..b4e61008c 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -720,23 +720,18 @@ VRT_r_now(VRT_CTX) VCL_STRING v_matchproto_() VRT_IP_string(VRT_CTX, VCL_IP ip) { - char *p; - unsigned len; + char buf[VTCP_ADDRBUFSIZE]; + struct vsb vsb[1]; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); if (ip == NULL) { VRT_fail(ctx, "%s: Illegal IP", __func__); return (NULL); } - len = WS_ReserveAll(ctx->ws); - if (len == 0) { - WS_Release(ctx->ws, 0); - return (NULL); - } - p = WS_Reservation(ctx->ws); - VTCP_name(ip, p, len, NULL, 0); - WS_Release(ctx->ws, strlen(p) + 1); - return (p); + VTCP_name(ip, buf, sizeof buf, NULL, 0); + WS_VSB_new(vsb, ctx->ws); + VSB_cat(vsb, buf); + return (WS_VSB_finish(vsb, ctx->ws, NULL)); } int From dridi.boukelmoune at gmail.com Tue Jan 4 06:56:05 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 4 Jan 2022 06:56:05 +0000 (UTC) Subject: [master] 5ebffdb16 vrt: Whitespace OCD Message-ID: <20220104065605.C9C27102E47@lists.varnish-cache.org> commit 5ebffdb16eccef0e6446eb206f71af6a19ef3510 Author: Dridi Boukelmoune Date: Tue Jan 4 07:55:20 2022 +0100 vrt: Whitespace OCD diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index b4e61008c..bd856193c 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -571,7 +571,7 @@ VRT_ValidHdr(VRT_CTX, VCL_STRANDS s) /*--------------------------------------------------------------------*/ VCL_VOID -VRT_UnsetHdr(VRT_CTX , VCL_HEADER hs) +VRT_UnsetHdr(VRT_CTX, VCL_HEADER hs) { VCL_HTTP hp; @@ -584,7 +584,7 @@ VRT_UnsetHdr(VRT_CTX , VCL_HEADER hs) } VCL_VOID -VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *pfx, VCL_STRANDS s) +VRT_SetHdr(VRT_CTX, VCL_HEADER hs, const char *pfx, VCL_STRANDS s) { VCL_HTTP hp; unsigned u, l, pl; From phk at FreeBSD.org Tue Jan 4 07:10:05 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 07:10:05 +0000 (UTC) Subject: [master] 692be7e7e Flexelinting Message-ID: <20220104071005.E307210355A@lists.varnish-cache.org> commit 692be7e7e4dc2c671990025b3cd3154b1de9cc57 Author: Poul-Henning Kamp Date: Tue Jan 4 07:03:10 2022 +0000 Flexelinting diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index ac8c7bdf2..ff727b4fc 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -410,14 +410,16 @@ logexp_match(const struct logexp *le, struct logexp_test *test, fail = 1; if (fail) { - if (ok) + if (ok) { legend = "fail"; - else if (skip) - legend = "end", skip = 0; - else if (le->m_arg) + } else if (skip) { + legend = "end"; + skip = 0; + } else if (le->m_arg) { legend = "fmiss"; - else + } else { legend = NULL; + } } else if (ok) legend = "match"; From phk at FreeBSD.org Tue Jan 4 07:10:05 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 07:10:05 +0000 (UTC) Subject: [master] bc723f2dc FlexeLinting Message-ID: <20220104071006.00BD910355D@lists.varnish-cache.org> commit bc723f2dc817535473e0a3611a42411c6f0c0ca9 Author: Poul-Henning Kamp Date: Tue Jan 4 07:08:57 2022 +0000 FlexeLinting diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt index 910ace52c..65e77d09e 100644 --- a/bin/varnishd/flint.lnt +++ b/bin/varnishd/flint.lnt @@ -38,7 +38,12 @@ -esym(765, CLI_*) -esym(759, CLI_*) -esym(755, CLI_*) --"esym(793,significant characters in an external identifier)" + +-esym(765, http_IsHdr) +-esym(759, http_IsHdr) +-esym(755, http_IsHdr) + +// -"esym(793,significant characters in an external identifier)" // XXX: I think this is a flexelint bug: -esym(522, vbit_clr) diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index ec9b997b7..9716df6b7 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -157,7 +157,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) case 'D': if (exp == pct) return ("recursive expansion"); - cc_expand(sb, mgt_cc_cmd_def, pct); + AZ(cc_expand(sb, mgt_cc_cmd_def, pct)); break; case 'n': AN(getcwd(buf, sizeof buf)); From phk at FreeBSD.org Tue Jan 4 07:36:05 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 07:36:05 +0000 (UTC) Subject: [master] fd3d71b17 Try to handle reentrant panics more sensibly. Message-ID: <20220104073605.8BE4610435D@lists.varnish-cache.org> commit fd3d71b17eb9b3595b4d0fda297159b713d70f80 Author: Poul-Henning Kamp Date: Tue Jan 4 07:34:25 2022 +0000 Try to handle reentrant panics more sensibly. Relevant to: #3764 diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 3ac6af736..734b801e3 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -67,6 +67,7 @@ static struct vsb pan_vsb_storage, *pan_vsb; static pthread_mutex_t panicstr_mtx; +static pthread_t panicy; static void pan_sess(struct vsb *, const struct sess *); static void pan_req(struct vsb *, const struct req *); @@ -720,12 +721,17 @@ pan_ic(const char *func, const char *file, int line, const char *cond, struct sigaction sa; int err = errno; - AZ(pthread_mutex_lock(&panicstr_mtx)); - - /* If we already panic'ed, do nothing */ - while (heritage.panic_str[0]) + /* If we already panicing in another thread, do nothing */ + while (heritage.panic_str[0] && panicy != pthread_self()) sleep(1); + if (pthread_mutex_lock(&panicstr_mtx)) { + /* Reentrant panic */ + VSB_printf(pan_vsb,"\n\nPANIC REENTRANCY\n\n"); + abort(); + } + panicy = pthread_self(); + /* * should we trigger a SIGSEGV while handling a panic, our sigsegv * handler would hide the panic, so we need to reset the handler to From phk at FreeBSD.org Tue Jan 4 09:46:06 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 09:46:06 +0000 (UTC) Subject: [master] 76d55e740 Rename `enum sess_close` to `stream_close_t` with a typedef. Message-ID: <20220104094606.D1ECA107BCC@lists.varnish-cache.org> commit 76d55e740d9eb6c2075b3d7a12eef3d7c92ea957 Author: Poul-Henning Kamp Date: Tue Jan 4 09:44:10 2022 +0000 Rename `enum sess_close` to `stream_close_t` with a typedef. This is preparation to change the enum to a struct. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 0f528d9a2..3343bab96 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -432,7 +432,7 @@ struct req { #define REQ_MAGIC 0xfb4abf6d body_status_t req_body_status; - enum sess_close doclose; + stream_close_t doclose; unsigned restarts; unsigned esi_level; @@ -628,7 +628,7 @@ int HTTP_IterHdrPack(struct worker *, struct objcore *, const char **); #define HTTP_FOREACH_PACK(wrk, oc, ptr) \ for ((ptr) = NULL; HTTP_IterHdrPack(wrk, oc, &(ptr));) const char *HTTP_GetHdrPack(struct worker *, struct objcore *, hdr_t); -enum sess_close http_DoConnection(struct http *hp, enum sess_close sc_close); +stream_close_t http_DoConnection(struct http *hp, stream_close_t sc_close); int http_IsFiltered(const struct http *hp, unsigned u, unsigned how); #define HTTPH_R_PASS (1 << 0) /* Request (c->b) in pass mode */ diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 9f286a55f..132cd2f4e 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -344,11 +344,11 @@ vbe_dir_getip(VRT_CTX, VCL_BACKEND d) /*--------------------------------------------------------------------*/ -static enum sess_close v_matchproto_(vdi_http1pipe_f) +static stream_close_t v_matchproto_(vdi_http1pipe_f) vbe_dir_http1pipe(VRT_CTX, VCL_BACKEND d) { int i; - enum sess_close retval; + stream_close_t retval; struct backend *bp; struct v1p_acct v1a; struct pfd *pfd; diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c index 5bb3ac7b7..166916da4 100644 --- a/bin/varnishd/cache/cache_director.c +++ b/bin/varnishd/cache/cache_director.c @@ -197,7 +197,7 @@ VDI_Finish(struct busyobj *bo) /* Get a connection --------------------------------------------------*/ -enum sess_close +stream_close_t VDI_Http1Pipe(struct req *req, struct busyobj *bo) { const struct director *d; diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c index 516e09648..148cb9e94 100644 --- a/bin/varnishd/cache/cache_http.c +++ b/bin/varnishd/cache/cache_http.c @@ -956,11 +956,11 @@ http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi) /*-------------------------------------------------------------------- */ -enum sess_close -http_DoConnection(struct http *hp, enum sess_close sc_close) +stream_close_t +http_DoConnection(struct http *hp, stream_close_t sc_close) { const char *h, *b, *e; - enum sess_close retval; + stream_close_t retval; unsigned u, v; struct http_hdrflg *f; diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 734b801e3..e5468397e 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -88,7 +88,7 @@ boc_state_2str(enum boc_state_e e) /*--------------------------------------------------------------------*/ const char * -sess_close_2str(enum sess_close sc, int want_desc) +sess_close_2str(stream_close_t sc, int want_desc) { switch (sc) { case SC_NULL: return (want_desc ? "(null)" : "NULL"); diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c index 27cfe3034..99e9653a1 100644 --- a/bin/varnishd/cache/cache_req.c +++ b/bin/varnishd/cache/cache_req.c @@ -300,7 +300,7 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req) */ void v_matchproto_(vtr_req_fail_f) -Req_Fail(struct req *req, enum sess_close reason) +Req_Fail(struct req *req, stream_close_t reason) { CHECK_OBJ_NOTNULL(req, REQ_MAGIC); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index f0013de1b..1e646e5ae 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -510,7 +510,7 @@ SES_Wait(struct sess *sp, const struct transport *xp) */ static void -ses_close_acct(enum sess_close reason) +ses_close_acct(stream_close_t reason) { int i = 0; @@ -537,7 +537,7 @@ ses_close_acct(enum sess_close reason) */ void -SES_Close(struct sess *sp, enum sess_close reason) +SES_Close(struct sess *sp, stream_close_t reason) { int i; @@ -554,7 +554,7 @@ SES_Close(struct sess *sp, enum sess_close reason) */ void -SES_Delete(struct sess *sp, enum sess_close reason, vtim_real now) +SES_Delete(struct sess *sp, stream_close_t reason, vtim_real now) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -576,7 +576,7 @@ SES_Delete(struct sess *sp, enum sess_close reason, vtim_real now) } if (reason == SC_NULL) - reason = (enum sess_close)-sp->fd; + reason = (stream_close_t)-sp->fd; VSL(SLT_SessClose, sp->vxid, "%s %.3f", sess_close_2str(reason, 0), now - sp->t_open); @@ -589,7 +589,7 @@ SES_Delete(struct sess *sp, enum sess_close reason, vtim_real now) void SES_DeleteHS(struct sess *sp, enum htc_status_e hs, vtim_real now) { - enum sess_close reason; + stream_close_t reason; switch (hs) { case HTC_S_JUNK: diff --git a/bin/varnishd/cache/cache_transport.h b/bin/varnishd/cache/cache_transport.h index 6815ce446..0e5f03c65 100644 --- a/bin/varnishd/cache/cache_transport.h +++ b/bin/varnishd/cache/cache_transport.h @@ -42,7 +42,7 @@ typedef void vtr_deliver_f (struct req *, struct boc *, int sendbody); typedef void vtr_req_body_f (struct req *); typedef void vtr_sess_panic_f (struct vsb *, const struct sess *); typedef void vtr_req_panic_f (struct vsb *, const struct req *); -typedef void vtr_req_fail_f (struct req *, enum sess_close); +typedef void vtr_req_fail_f (struct req *, stream_close_t); typedef void vtr_reembark_f (struct worker *, struct req *); typedef int vtr_minimal_response_f (struct req *, uint16_t status); @@ -87,8 +87,8 @@ int VPX_Send_Proxy(int fd, int version, const struct sess *); /* cache_session.c */ struct sess *SES_New(struct pool *); -void SES_Delete(struct sess *, enum sess_close reason, vtim_real now); +void SES_Delete(struct sess *, stream_close_t reason, vtim_real now); void SES_DeleteHS(struct sess *, enum htc_status_e hs, vtim_real now); -void SES_Close(struct sess *, enum sess_close reason); +void SES_Close(struct sess *, stream_close_t reason); void SES_SetTransport(struct worker *, struct sess *, struct req *, const struct transport *); diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h index 59ea9b1cb..5d534df6a 100644 --- a/bin/varnishd/cache/cache_varnishd.h +++ b/bin/varnishd/cache/cache_varnishd.h @@ -97,7 +97,7 @@ struct http_conn { #define HTTP_CONN_MAGIC 0x3e19edd1 int *rfd; - enum sess_close doclose; + stream_close_t doclose; body_status_t body_status; struct ws *ws; char *rxbuf_b; @@ -183,7 +183,7 @@ void VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **busyobj); int VDI_GetHdr(struct busyobj *); VCL_IP VDI_GetIP(struct busyobj *); void VDI_Finish(struct busyobj *bo); -enum sess_close VDI_Http1Pipe(struct req *, struct busyobj *); +stream_close_t VDI_Http1Pipe(struct req *, struct busyobj *); void VDI_Panic(const struct director *, struct vsb *, const char *nm); void VDI_Event(const struct director *d, enum vcl_event_e ev); void VDI_Init(void); @@ -382,7 +382,7 @@ int PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr, #define PAN_dump_once_oneline(vsb, ptr, magic, ...) \ PAN__DumpStruct(vsb, 0, 0, ptr, #magic, magic, __VA_ARGS__) -const char *sess_close_2str(enum sess_close sc, int want_desc); +const char *sess_close_2str(stream_close_t sc, int want_desc); /* cache_pool.c */ void Pool_Init(void); @@ -403,7 +403,7 @@ struct req *Req_New(struct sess *); void Req_Release(struct req *); void Req_Rollback(VRT_CTX); void Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req); -void Req_Fail(struct req *req, enum sess_close reason); +void Req_Fail(struct req *req, stream_close_t reason); void Req_AcctLogCharge(struct VSC_main_wrk *, struct req *); void Req_LogHit(struct worker *, struct req *, struct objcore *, intmax_t); diff --git a/bin/varnishd/http1/cache_http1.h b/bin/varnishd/http1/cache_http1.h index 2e8b03ac3..a9f905376 100644 --- a/bin/varnishd/http1/cache_http1.h +++ b/bin/varnishd/http1/cache_http1.h @@ -62,6 +62,6 @@ void V1L_Chunked(const struct worker *w); void V1L_EndChunk(const struct worker *w); void V1L_Open(struct worker *, struct ws *, int *fd, struct vsl_log *, vtim_real deadline, unsigned niov); -enum sess_close V1L_Flush(const struct worker *w); -enum sess_close V1L_Close(struct worker *w, uint64_t *cnt); +stream_close_t V1L_Flush(const struct worker *w); +stream_close_t V1L_Close(struct worker *w, uint64_t *cnt); size_t V1L_Write(const struct worker *w, const void *ptr, ssize_t len); diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c index b051499ee..282f4d9a0 100644 --- a/bin/varnishd/http1/cache_http1_deliver.c +++ b/bin/varnishd/http1/cache_http1_deliver.c @@ -89,7 +89,7 @@ void v_matchproto_(vtr_deliver_f) V1D_Deliver(struct req *req, struct boc *boc, int sendbody) { int err = 0, chunked = 0; - enum sess_close sc; + stream_close_t sc; uint64_t hdrbytes, bytes; CHECK_OBJ_NOTNULL(req, REQ_MAGIC); diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 1861d9a12..57df205ce 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -74,7 +74,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, uint64_t *ctr_bodybytes) { struct http *hp; - enum sess_close sc; + stream_close_t sc; ssize_t i; uint64_t bytes, hdrbytes; struct http_conn *htc; diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index ccd9ee340..d27d8485e 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -174,7 +174,7 @@ http1_req_panic(struct vsb *vsb, const struct req *req) } static void v_matchproto_(vtr_req_fail_f) -http1_req_fail(struct req *req, enum sess_close reason) +http1_req_fail(struct req *req, stream_close_t reason) { assert(reason > 0); assert(req->sp->fd != 0); diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index 006119e98..7274b446f 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -55,7 +55,7 @@ struct v1l { unsigned magic; #define V1L_MAGIC 0x2f2142e5 int *wfd; - enum sess_close werr; /* valid after V1L_Flush() */ + stream_close_t werr; /* valid after V1L_Flush() */ struct iovec *iov; unsigned siov; unsigned niov; @@ -123,13 +123,13 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl, WS_Release(ws, u * sizeof(struct iovec)); } -enum sess_close +stream_close_t V1L_Close(struct worker *wrk, uint64_t *cnt) { struct v1l *v1l; struct ws *ws; uintptr_t ws_snap; - enum sess_close sc; + stream_close_t sc; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); AN(cnt); @@ -169,7 +169,7 @@ v1l_prune(struct v1l *v1l, size_t bytes) AZ(v1l->liov); } -enum sess_close +stream_close_t V1L_Flush(const struct worker *wrk) { ssize_t i; diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h index 09c88187a..eb6e8f6a9 100644 --- a/bin/varnishd/http2/cache_http2.h +++ b/bin/varnishd/http2/cache_http2.h @@ -44,7 +44,7 @@ struct h2_error_s { uint32_t val; int stream; int connection; - enum sess_close reason; + stream_close_t reason; }; typedef const struct h2_error_s *h2_error; diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index f2d238769..fc05f7779 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -1161,7 +1161,7 @@ h2_req_body(struct req *req) /**********************************************************************/ void v_matchproto_(vtr_req_fail_f) -h2_req_fail(struct req *req, enum sess_close reason) +h2_req_fail(struct req *req, stream_close_t reason) { assert(reason > 0); assert(req->sp->fd != 0); diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c index 1740d2a0a..846b319f1 100644 --- a/bin/varnishd/http2/cache_http2_session.c +++ b/bin/varnishd/http2/cache_http2_session.c @@ -136,7 +136,7 @@ h2_init_sess(struct sess *sp, } static void -h2_del_sess(struct worker *wrk, struct h2_sess *h2, enum sess_close reason) +h2_del_sess(struct worker *wrk, struct h2_sess *h2, stream_close_t reason) { struct sess *sp; struct req *req; diff --git a/include/tbl/h2_error.h b/include/tbl/h2_error.h index e8104f8aa..2cd06f011 100644 --- a/include/tbl/h2_error.h +++ b/include/tbl/h2_error.h @@ -30,7 +30,7 @@ * RFC7540 section 11.4 * * Types: conn=1|stream=2 - * Reason: enum sess_close + * Reason: stream_close_t */ /*lint -save -e525 -e539 */ diff --git a/include/tbl/sess_close.h b/include/tbl/sess_close.h index 97483147c..3660bb9bb 100644 --- a/include/tbl/sess_close.h +++ b/include/tbl/sess_close.h @@ -31,7 +31,7 @@ /*lint -save -e525 -e539 */ -// enum sess_close sc_* stat is_err Description +// stream_close_t sc_* stat is_err Description SESS_CLOSE(REM_CLOSE, rem_close, 0, "Client Closed") SESS_CLOSE(REQ_CLOSE, req_close, 0, "Client requested close") SESS_CLOSE(REQ_HTTP10, req_http10, 1, "Proto < HTTP/1.1") diff --git a/include/vrt.h b/include/vrt.h index 1a47ac8ba..0efc616b1 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -268,6 +268,8 @@ struct vsl_log; struct vsmw_cluster; struct ws; +typedef enum sess_close stream_close_t; + /*********************************************************************** * VCL_STRANDS: * @@ -662,7 +664,7 @@ typedef VCL_BACKEND vdi_resolve_f(VRT_CTX, VCL_BACKEND); typedef int vdi_gethdrs_f(VRT_CTX, VCL_BACKEND); typedef VCL_IP vdi_getip_f(VRT_CTX, VCL_BACKEND); typedef void vdi_finish_f(VRT_CTX, VCL_BACKEND); -typedef enum sess_close vdi_http1pipe_f(VRT_CTX, VCL_BACKEND); +typedef stream_close_t vdi_http1pipe_f(VRT_CTX, VCL_BACKEND); typedef void vdi_event_f(VCL_BACKEND, enum vcl_event_e); typedef void vdi_destroy_f(VCL_BACKEND); typedef void vdi_panic_f(VCL_BACKEND, struct vsb *); From phk at FreeBSD.org Tue Jan 4 15:40:06 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 15:40:06 +0000 (UTC) Subject: [master] 819ed3f29 Be explict about SC_NULL in initialization and tests. Message-ID: <20220104154006.9EC8611390D@lists.varnish-cache.org> commit 819ed3f299f8429544bb01c34a73d67d0ba50c65 Author: Poul-Henning Kamp Date: Tue Jan 4 14:34:03 2022 +0000 Be explict about SC_NULL in initialization and tests. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 132cd2f4e..b62ea248e 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -126,7 +126,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); AN(bp->vsc); - if (! VRT_Healthy(ctx, dir, NULL)) { + if (!VRT_Healthy(ctx, dir, NULL)) { VSLb(bo->vsl, SLT_FetchError, "backend %s: unhealthy", VRT_BACKEND_string(dir)); bp->vsc->unhealthy++; @@ -207,6 +207,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, INIT_OBJ(bo->htc, HTTP_CONN_MAGIC); bo->htc->priv = pfd; bo->htc->rfd = fdp; + bo->htc->doclose = SC_NULL; FIND_TMO(first_byte_timeout, bo->htc->first_byte_timeout, bo, bp); FIND_TMO(between_bytes_timeout, diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c index 99e9653a1..844e51b5a 100644 --- a/bin/varnishd/cache/cache_req.c +++ b/bin/varnishd/cache/cache_req.c @@ -153,15 +153,16 @@ Req_New(struct sess *sp) INIT_OBJ(req->vfc, VFP_CTX_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->vfc)); - req->htc = (void*)p; + req->htc = (void*)p; // XXX: TWICE ?! p = (void*)PRNDUP(p + sizeof(*req->htc)); req->vdc = (void*)p; memset(req->vdc, 0, sizeof *req->vdc); p = (void*)PRNDUP(p + sizeof(*req->vdc)); - req->htc = (void*)p; + req->htc = (void*)p; // XXX: TWICE ?! INIT_OBJ(req->htc, HTTP_CONN_MAGIC); + req->htc->doclose = SC_NULL; p = (void*)PRNDUP(p + sizeof(*req->htc)); req->top = (void*)p; @@ -176,8 +177,8 @@ Req_New(struct sess *sp) req->t_first = NAN; req->t_prev = NAN; req->t_req = NAN; - req->req_step = R_STP_TRANSPORT; + req->doclose = SC_NULL; return (req); } @@ -289,6 +290,8 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req) req->is_hit = 0; req->req_step = R_STP_TRANSPORT; req->vcf = NULL; + req->doclose = SC_NULL; + req->htc->doclose = SC_NULL; if (WS_Overflowed(req->ws)) wrk->stats->ws_client_overflow++; diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index ee4159005..e5bd6beeb 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -245,7 +245,7 @@ VRB_Ignore(struct req *req) CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - if (req->doclose) + if (req->doclose != SC_NULL) return (0); if (req->req_body_status->avail > 0) (void)VRB_Iterate(req->wrk, req->vsl, req, diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 86a74b0cb..9556ab722 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -363,7 +363,8 @@ cnt_synth(struct worker *wrk, struct req *req) http_PrintfHeader(req->resp, "Content-Length: %zd", VSB_len(synth_body)); - if (!req->doclose && http_HdrIs(req->resp, H_Connection, "close")) + if (req->doclose == SC_NULL && + http_HdrIs(req->resp, H_Connection, "close")) req->doclose = SC_RESP_CLOSE; /* Discard any lingering request body before delivery */ @@ -489,10 +490,11 @@ cnt_transmit(struct worker *wrk, struct req *req) HSH_Cancel(wrk, req->objcore, boc); - if (!req->doclose && (req->objcore->flags & OC_F_FAILED)) + if (req->doclose == SC_NULL && (req->objcore->flags & OC_F_FAILED)) { /* The object we delivered failed due to a streaming error. * Fail the request. */ req->doclose = SC_TX_ERROR; + } if (boc != NULL) HSH_DerefBoc(wrk, req->objcore); diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c index 282f4d9a0..e90d1d48e 100644 --- a/bin/varnishd/http1/cache_http1_deliver.c +++ b/bin/varnishd/http1/cache_http1_deliver.c @@ -52,7 +52,7 @@ v1d_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv, if (len > 0) wl = V1L_Write(vdx->wrk, ptr, len); - if (act > VDP_NULL && V1L_Flush(vdx->wrk)) + if (act > VDP_NULL && V1L_Flush(vdx->wrk) != SC_NULL) return (-1); if (len != wl) return (-1); @@ -96,9 +96,10 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody) CHECK_OBJ_ORNULL(boc, BOC_MAGIC); CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); - if (!req->doclose && http_HdrIs(req->resp, H_Connection, "close")) { + if (req->doclose == SC_NULL && + http_HdrIs(req->resp, H_Connection, "close")) { req->doclose = SC_RESP_CLOSE; - } else if (req->doclose) { + } else if (req->doclose != SC_NULL) { if (!http_HdrIs(req->resp, H_Connection, "close")) { http_Unset(req->resp, H_Connection); http_SetHeader(req->resp, "Connection: close"); diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 57df205ce..fd491fc32 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -55,7 +55,7 @@ vbf_iter_req_body(void *priv, unsigned flush, const void *ptr, ssize_t l) if (l > 0) { (void)V1L_Write(bo->wrk, ptr, l); - if (flush && V1L_Flush(bo->wrk)) + if (flush && V1L_Flush(bo->wrk) != SC_NULL) return (-1); } return (0); diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index d27d8485e..641f6e805 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -176,7 +176,7 @@ http1_req_panic(struct vsb *vsb, const struct req *req) static void v_matchproto_(vtr_req_fail_f) http1_req_fail(struct req *req, stream_close_t reason) { - assert(reason > 0); + assert(reason != SC_NULL); assert(req->sp->fd != 0); if (req->sp->fd > 0) SES_Close(req->sp, reason); @@ -210,7 +210,7 @@ http1_minimal_response(struct req *req, uint16_t status) if (wl != l) { if (wl < 0) VTCP_Assert(1); - if (!req->doclose) + if (req->doclose == SC_NULL) req->doclose = SC_REM_CLOSE; return (-1); } @@ -237,7 +237,7 @@ struct transport HTTP1_transport = { static inline void http1_abort(struct req *req, uint16_t status) { - AN(req->doclose); + assert(req->doclose != SC_NULL); assert(status >= 400); (void)http1_minimal_response(req, status); } @@ -358,7 +358,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; if (i) { - assert(req->doclose > 0); + assert(req->doclose != SC_NULL); SES_Close(req->sp, req->doclose); assert(!WS_IsReserved(req->ws)); assert(!WS_IsReserved(wrk->aws)); diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index 7274b446f..a73eb0b55 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -118,6 +118,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl, v1l->wfd = fd; v1l->deadline = deadline; v1l->vsl = vsl; + v1l->werr = SC_NULL; wrk->v1l = v1l; WS_Release(ws, u * sizeof(struct iovec)); @@ -134,9 +135,7 @@ V1L_Close(struct worker *wrk, uint64_t *cnt) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); AN(cnt); sc = V1L_Flush(wrk); - v1l = wrk->v1l; - wrk->v1l = NULL; - CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC); + TAKE_OBJ_NOTNULL(v1l, &wrk->v1l, V1L_MAGIC); *cnt = v1l->cnt; ws = v1l->ws; ws_snap = v1l->ws_snap; @@ -241,7 +240,7 @@ V1L_Flush(const struct worker *wrk) VSLb(v1l->vsl, SLT_Debug, "Write error, retval = %zd, len = %zd, errno = %s", i, v1l->liov, VAS_errtxt(errno)); - AZ(v1l->werr); + assert(v1l->werr == SC_NULL); if (errno == EPIPE) v1l->werr = SC_REM_CLOSE; else diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index fc05f7779..c408acd65 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -1163,7 +1163,7 @@ h2_req_body(struct req *req) void v_matchproto_(vtr_req_fail_f) h2_req_fail(struct req *req, stream_close_t reason) { - assert(reason > 0); + assert(reason != SC_NULL); assert(req->sp->fd != 0); VSLb(req->vsl, SLT_Debug, "H2FAILREQ"); } From phk at FreeBSD.org Tue Jan 4 15:40:06 2022 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 4 Jan 2022 15:40:06 +0000 (UTC) Subject: [master] dbd1028a1 Turn `enum sess_close` into `const struct stream_close *` Message-ID: <20220104154006.B9210113910@lists.varnish-cache.org> commit dbd1028a192ccd0370507298c135334819911ae1 Author: Poul-Henning Kamp Date: Tue Jan 4 15:38:39 2022 +0000 Turn `enum sess_close` into `const struct stream_close *` More asserts than strictly needed to catch anything I have missed. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 3343bab96..cb69f2c2c 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -73,11 +73,19 @@ typedef const char *hdr_t; /*--------------------------------------------------------------------*/ -enum sess_close { - SC_NULL = 0, -#define SESS_CLOSE(nm, stat, err, desc) SC_##nm, -#include "tbl/sess_close.h" +struct stream_close { + unsigned magic; +#define STREAM_CLOSE_MAGIC 0xc879c93d + int idx; + unsigned is_err; + const char *name; + const char *desc; }; + extern const struct stream_close SC_NULL[1]; +#define SESS_CLOSE(nm, stat, err, desc) \ + extern const struct stream_close SC_##nm[1]; +#include "tbl/sess_close.h" + /*-------------------------------------------------------------------- * Indices into http->hd[] diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index b62ea248e..7ac117cc4 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -150,6 +150,7 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, return (NULL); } bo->htc->doclose = SC_NULL; + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); FIND_TMO(connect_timeout, tmod, bo, bp); pfd = VCP_Get(bp->conn_pool, tmod, wrk, force_fresh, &err); @@ -176,6 +177,8 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp, bp->vsc->req++; Lck_Unlock(bp->director->mtx); + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); + err = 0; if (bp->proxy_header != 0) err += VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp); @@ -229,13 +232,13 @@ vbe_dir_finish(VRT_CTX, VCL_BACKEND d) CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC); + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); + pfd = bo->htc->priv; bo->htc->priv = NULL; - if (PFD_State(pfd) != PFD_STATE_USED) - AN(bo->htc->doclose); if (bo->htc->doclose != SC_NULL || bp->proxy_header != 0) { - VSLb(bo->vsl, SLT_BackendClose, "%d %s close", *PFD_Fd(pfd), - VRT_BACKEND_string(d)); + VSLb(bo->vsl, SLT_BackendClose, "%d %s close %s", *PFD_Fd(pfd), + VRT_BACKEND_string(d), bo->htc->doclose->desc); VCP_Close(&pfd); AZ(pfd); Lck_Lock(bp->director->mtx); @@ -270,6 +273,8 @@ vbe_dir_gethdrs(VRT_CTX, VCL_BACKEND d) CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); bo = ctx->bo; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); + if (bo->htc != NULL) + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); wrk = ctx->bo->wrk; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); @@ -283,10 +288,13 @@ vbe_dir_gethdrs(VRT_CTX, VCL_BACKEND d) http_PrintfHeader(bo->bereq, "Host: %s", bp->hosthdr); do { + if (bo->htc != NULL) + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); pfd = vbe_dir_getfd(ctx, wrk, d, bp, extrachance == 0 ? 1 : 0); if (pfd == NULL) return (-1); AN(bo->htc); + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); if (PFD_State(pfd) != PFD_STATE_STOLEN) extrachance = 0; @@ -312,6 +320,7 @@ vbe_dir_gethdrs(VRT_CTX, VCL_BACKEND d) return (0); } } + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); /* * If we recycled a backend connection, there is a finite chance @@ -385,6 +394,7 @@ vbe_dir_http1pipe(VRT_CTX, VCL_BACKEND d) retval = SC_TX_PIPE; } V1P_Charge(ctx->req, &v1a, bp->vsc); + CHECK_OBJ_NOTNULL(retval, STREAM_CLOSE_MAGIC); return (retval); } diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 942a611f8..e28c432f0 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -332,6 +332,8 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo) bo->was_304 = 0; bo->err_code = 0; bo->err_reason = NULL; + if (bo->htc != NULL) + bo->htc->doclose = SC_NULL; // XXX: BereqEnd + BereqAcct ? VSL_ChgId(bo->vsl, "bereq", "retry", VXID_Get(wrk, VSL_BACKENDMARKER)); @@ -426,6 +428,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) VSLb_ts_busyobj(bo, "Fetch", W_TIM_real(wrk)); i = VDI_GetHdr(bo); + if (bo->htc != NULL) + CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC); bo->t_resp = now = W_TIM_real(wrk); VSLb_ts_busyobj(bo, "Beresp", now); diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c index 148cb9e94..61849ab04 100644 --- a/bin/varnishd/cache/cache_http.c +++ b/bin/varnishd/cache/cache_http.c @@ -999,6 +999,7 @@ http_DoConnection(struct http *hp, stream_close_t sc_close) hp->hdf[v] |= HDF_FILTER; } } + CHECK_OBJ_NOTNULL(retval, STREAM_CLOSE_MAGIC); return (retval); } diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index e5468397e..473c2f1aa 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -87,17 +87,14 @@ boc_state_2str(enum boc_state_e e) /*--------------------------------------------------------------------*/ -const char * -sess_close_2str(stream_close_t sc, int want_desc) +static void +pan_stream_close(struct vsb *vsb, stream_close_t sc) { - switch (sc) { - case SC_NULL: return (want_desc ? "(null)" : "NULL"); -#define SESS_CLOSE(nm, s, err, desc) \ - case SC_##nm: return(want_desc ? desc : #nm); -#include "tbl/sess_close.h" - default: return (want_desc ? "(invalid)" : "INVALID"); - } + if (sc != NULL && sc->magic == STREAM_CLOSE_MAGIC) + VSB_printf(vsb, "%s(%s)", sc->name, sc->desc); + else + VSB_printf(vsb, "%p", sc); } /*--------------------------------------------------------------------*/ @@ -162,7 +159,9 @@ pan_htc(struct vsb *vsb, const struct http_conn *htc) return; if (htc->rfd != NULL) VSB_printf(vsb, "fd = %d (@%p),\n", *htc->rfd, htc->rfd); - VSB_printf(vsb, "doclose = %s,\n", sess_close_2str(htc->doclose, 0)); + VSB_printf(vsb, "doclose = "); + pan_stream_close(vsb, htc->doclose); + VSB_printf(vsb, "\n"); WS_Panic(vsb, htc->ws); VSB_printf(vsb, "{rxbuf_b, rxbuf_e} = {%p, %p},\n", htc->rxbuf_b, htc->rxbuf_e); diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 9556ab722..d496e6e97 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -1178,6 +1178,7 @@ CNT_Request(struct req *req) CHECK_OBJ_NOTNULL(wrk->wpriv, WORKER_PRIV_MAGIC); CHECK_OBJ_ORNULL(wrk->wpriv->nobjhead, OBJHEAD_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + CHECK_OBJ_NOTNULL(req->doclose, STREAM_CLOSE_MAGIC); AN(req->req_step); AN(req->req_step->name); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 1e646e5ae..d0834fc6c 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -59,6 +59,38 @@ static const struct { #include "tbl/sess_attr.h" }; +enum sess_close { + SCE_NULL = 0, +#define SESS_CLOSE(nm, stat, err, desc) SCE_##nm, +#include "tbl/sess_close.h" + SCE_MAX, +}; + +const struct stream_close SC_NULL[1] = {{ + .magic = STREAM_CLOSE_MAGIC, + .idx = SCE_NULL, + .is_err = 0, + .name = "null", + .desc = "Not Closing", +}}; + +#define SESS_CLOSE(nm, stat, err, text) \ + const struct stream_close SC_##nm[1] = {{ \ + .magic = STREAM_CLOSE_MAGIC, \ + .idx = SCE_##nm, \ + .is_err = err, \ + .name = #nm, \ + .desc = text, \ + }}; +#include "tbl/sess_close.h" + +static const stream_close_t sc_lookup[SCE_MAX] = { + [SCE_NULL] = SC_NULL, +#define SESS_CLOSE(nm, stat, err, desc) \ + [SCE_##nm] = SC_##nm, +#include "tbl/sess_close.h" +}; + /*--------------------------------------------------------------------*/ void @@ -512,21 +544,19 @@ SES_Wait(struct sess *sp, const struct transport *xp) static void ses_close_acct(stream_close_t reason) { - int i = 0; - assert(reason != SC_NULL); - switch (reason) { + CHECK_OBJ_NOTNULL(reason, STREAM_CLOSE_MAGIC); + switch (reason->idx) { #define SESS_CLOSE(reason, stat, err, desc) \ - case SC_ ## reason: \ + case SCE_ ## reason: \ VSC_C_main->sc_ ## stat++; \ - i = err; \ break; #include "tbl/sess_close.h" default: WRONG("Wrong event in ses_close_acct"); } - if (i) + if (reason->is_err) VSC_C_main->sess_closed_err++; } @@ -541,11 +571,12 @@ SES_Close(struct sess *sp, stream_close_t reason) { int i; - assert(reason > 0); + CHECK_OBJ_NOTNULL(reason, STREAM_CLOSE_MAGIC); + assert(reason->idx > 0); assert(sp->fd > 0); i = close(sp->fd); assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */ - sp->fd = -(int)reason; + sp->fd = -reason->idx; ses_close_acct(reason); } @@ -558,6 +589,7 @@ SES_Delete(struct sess *sp, stream_close_t reason, vtim_real now) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(reason, STREAM_CLOSE_MAGIC); if (reason != SC_NULL) SES_Close(sp, reason); @@ -575,11 +607,13 @@ SES_Delete(struct sess *sp, stream_close_t reason, vtim_real now) now = sp->t_open; /* Do not log negatives */ } - if (reason == SC_NULL) - reason = (stream_close_t)-sp->fd; + if (reason == SC_NULL) { + assert(sp->fd < 0 && -sp->fd < SCE_MAX); + reason = sc_lookup[-sp->fd]; + } - VSL(SLT_SessClose, sp->vxid, "%s %.3f", - sess_close_2str(reason, 0), now - sp->t_open); + CHECK_OBJ_NOTNULL(reason, STREAM_CLOSE_MAGIC); + VSL(SLT_SessClose, sp->vxid, "%s %.3f", reason->name, now - sp->t_open); VSL(SLT_End, sp->vxid, "%s", ""); if (WS_Overflowed(sp->ws)) VSC_C_main->ws_session_overflow++; diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h index 5d534df6a..1827ae008 100644 --- a/bin/varnishd/cache/cache_varnishd.h +++ b/bin/varnishd/cache/cache_varnishd.h @@ -382,8 +382,6 @@ int PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr, #define PAN_dump_once_oneline(vsb, ptr, magic, ...) \ PAN__DumpStruct(vsb, 0, 0, ptr, #magic, magic, __VA_ARGS__) -const char *sess_close_2str(stream_close_t sc, int want_desc); - /* cache_pool.c */ void Pool_Init(void); int Pool_Task(struct pool *pp, struct pool_task *task, enum task_prio prio); diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 18d820fe4..293c199ba 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -101,6 +101,7 @@ VCL_Req2Ctx(struct vrt_ctx *ctx, struct req *req) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + CHECK_OBJ_NOTNULL(req->doclose, STREAM_CLOSE_MAGIC); ctx->vcl = req->vcl; ctx->syntax = ctx->vcl->conf->syntax; diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index fd491fc32..7d0e6c015 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -139,6 +139,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, } sc = V1L_Close(wrk, &bytes); + CHECK_OBJ_NOTNULL(sc, STREAM_CLOSE_MAGIC); /* Bytes accounting */ if (bytes < hdrbytes) @@ -151,13 +152,15 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes, if (sc == SC_NULL && i < 0) sc = SC_TX_ERROR; + CHECK_OBJ_NOTNULL(sc, STREAM_CLOSE_MAGIC); if (sc != SC_NULL) { - VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)", - errno, VAS_errtxt(errno)); + VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s) (%s", + errno, VAS_errtxt(errno), sc->desc); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); htc->doclose = sc; return (-1); } + CHECK_OBJ_NOTNULL(sc, STREAM_CLOSE_MAGIC); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); return (0); } diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index a73eb0b55..ac14d8cb7 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -178,6 +178,7 @@ V1L_Flush(const struct worker *wrk) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); v1l = wrk->v1l; CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC); + CHECK_OBJ_NOTNULL(v1l->werr, STREAM_CLOSE_MAGIC); AN(v1l->wfd); assert(v1l->niov <= v1l->siov); @@ -252,6 +253,7 @@ V1L_Flush(const struct worker *wrk) v1l->niov = 0; if (v1l->ciov < v1l->siov) v1l->ciov = v1l->niov++; + CHECK_OBJ_NOTNULL(v1l->werr, STREAM_CLOSE_MAGIC); return (v1l->werr); } diff --git a/bin/varnishtest/tests/r02219.vtc b/bin/varnishtest/tests/r02219.vtc index 599f2ced7..86403fa53 100644 --- a/bin/varnishtest/tests/r02219.vtc +++ b/bin/varnishtest/tests/r02219.vtc @@ -22,7 +22,7 @@ varnish v1 -arg "-p workspace_client=9k" \ } -start client c1 { - send "PROXY TCP4 127.0.0.1 127.0.0.1 1111 2222\r\nGET /${string,repeat,744,A} HTTP/1.1\r\n\r\n" + send "PROXY TCP4 127.0.0.1 127.0.0.1 1111 2222\r\nGET /${string,repeat,736,A} HTTP/1.1\r\n\r\n" rxresp } -run @@ -39,6 +39,6 @@ ${string,repeat,732,"42 "} } -run client c3 { - send "PROXY TCP4 127.0.0.1 127.0.0.1 1111 2222\r\nGET /${string,repeat,748,C} HTTP/1.1\r\n\r\n" + send "PROXY TCP4 127.0.0.1 127.0.0.1 1111 2222\r\nGET /${string,repeat,740,C} HTTP/1.1\r\n\r\n" rxresp } -run diff --git a/include/vrt.h b/include/vrt.h index 0efc616b1..25fbabfb6 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -253,6 +253,7 @@ struct http; struct lock; struct req; struct stevedore; +struct stream_close; struct suckaddr; struct vcl; struct vcldir; @@ -268,7 +269,7 @@ struct vsl_log; struct vsmw_cluster; struct ws; -typedef enum sess_close stream_close_t; +typedef const struct stream_close *stream_close_t; /*********************************************************************** * VCL_STRANDS: From dridi.boukelmoune at gmail.com Tue Jan 4 17:45:06 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 4 Jan 2022 17:45:06 +0000 (UTC) Subject: [master] 3e6048753 req: Don't reserve space for htc twice Message-ID: <20220104174506.C067E1172FE@lists.varnish-cache.org> commit 3e604875323e0c6a2ac635bf6fcb497ad47d9cfa Author: Dridi Boukelmoune Date: Tue Jan 4 18:34:05 2022 +0100 req: Don't reserve space for htc twice When struct req changed to no longer store its htc, which was somewhat hidden in a larger seemingly unrelated change, it ended up being reserved twice. This looks like a case of starting something, being interrupted, and starting again. I decided to remove the one sitting between the reservation of VDP and VFP contexts since the two are related, and this reservation didn't even initialize htc. Refs fee476acc085e6563225d35fd8e19f1b10f04139 diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c index 844e51b5a..c5a394ef9 100644 --- a/bin/varnishd/cache/cache_req.c +++ b/bin/varnishd/cache/cache_req.c @@ -153,14 +153,11 @@ Req_New(struct sess *sp) INIT_OBJ(req->vfc, VFP_CTX_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->vfc)); - req->htc = (void*)p; // XXX: TWICE ?! - p = (void*)PRNDUP(p + sizeof(*req->htc)); - req->vdc = (void*)p; memset(req->vdc, 0, sizeof *req->vdc); p = (void*)PRNDUP(p + sizeof(*req->vdc)); - req->htc = (void*)p; // XXX: TWICE ?! + req->htc = (void*)p; INIT_OBJ(req->htc, HTTP_CONN_MAGIC); req->htc->doclose = SC_NULL; p = (void*)PRNDUP(p + sizeof(*req->htc)); From dridi.boukelmoune at gmail.com Tue Jan 4 17:55:05 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 4 Jan 2022 17:55:05 +0000 (UTC) Subject: [master] c348aa5c0 vtc: Revisit c109 to avoid symlink or chroot issues Message-ID: <20220104175506.082841178A1@lists.varnish-cache.org> commit c348aa5c00870c40058ad98e6809730a9c10096e Author: Dridi Boukelmoune Date: Tue Jan 4 18:53:56 2022 +0100 vtc: Revisit c109 to avoid symlink or chroot issues diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc index 7c4a7463d..aff4b4ab4 100644 --- a/bin/varnishtest/tests/c00109.vtc +++ b/bin/varnishtest/tests/c00109.vtc @@ -3,11 +3,16 @@ varnishtest "cc_command and cc_warnings" varnish v1 -cliok {param.set debug +vcl_keep} varnish v1 -cliok {param.set cc_warnings hello} varnish v1 -cliok {param.set cc_command << EOF -! printf 'd="%%s" D="%%s" w="%%s" n="%%s"' '%d' '%D' '%w' '%n' >world +printf 'd="%%s" D="%%s" w="%%s"' '%d' '%D' '%w' >world +printf '%%s' '%n' >v1_name EOF} varnish v1 -errvcl "VCL compilation failed" "backend be none;" -shell -match {d=".+" D=".+hello.+" w="hello" n="${v1_name}"} { +shell -match {d=".+" D=".+hello.+" w="hello"} { exec cat v1/vcl_*/world } + +shell -expect "Value is: hello" { + exec varnishadm -n "$(cat v1/vcl_*/v1_name)" param.show cc_warnings +} From dridi.boukelmoune at gmail.com Wed Jan 5 18:31:05 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 5 Jan 2022 18:31:05 +0000 (UTC) Subject: [master] 31ab68818 vcc: Avoid magic indentation numbers Message-ID: <20220105183105.7F2F111A420@lists.varnish-cache.org> commit 31ab68818f1dbbb0ff615e2c868fa4cbab457da8 Author: Dridi Boukelmoune Date: Wed Jan 5 19:24:19 2022 +0100 vcc: Avoid magic indentation numbers diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 1b5926499..c4e0380b8 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -253,8 +253,8 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1) VSB_putc(d, *p++); } else { switch (*++p) { - case '+': ind += 2; break; - case '-': ind -= 2; break; + case '+': ind += INDENT; break; + case '-': ind -= INDENT; break; default: WRONG("Illegal format in VCC expression"); } p++; From dridi.boukelmoune at gmail.com Wed Jan 5 22:19:08 2022 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 5 Jan 2022 22:19:08 +0000 (UTC) Subject: [master] a246cfe03 man: Indentation fix for some varnish-cli commands Message-ID: <20220105221909.0F46C5731@lists.varnish-cache.org> commit a246cfe0346be77546c4a54a8b7b21aa45abcf84 Author: Dridi Boukelmoune Date: Wed Jan 5 23:16:45 2022 +0100 man: Indentation fix for some varnish-cli commands diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h index 7b989e2ca..d4466e4c7 100644 --- a/include/tbl/cli_cmds.h +++ b/include/tbl/cli_cmds.h @@ -92,7 +92,7 @@ CLI_CMD(VCL_INLINE, CLI_CMD(VCL_STATE, "vcl.state", "vcl.state [auto|cold|warm]", - "Force the state of the named configuration.", + " Force the state of the named configuration.", "", 2, 2 ) @@ -101,7 +101,7 @@ CLI_CMD(VCL_DISCARD, "vcl.discard", "vcl.discard ...", "Unload the named configurations (when possible).", - "Unload the named configurations and labels matching at least" + " Unload the named configurations and labels matching at least" " one name pattern. All matching configurations and labels" " are discarded in the correct order with respect to potential" " dependencies. If one configuration or label could not be" @@ -139,7 +139,7 @@ CLI_CMD(VCL_DEPS, " separated by white space with the fields:\n\n" " * VCL: a VCL program\n\n" " * Dependency: another VCL program it depends on\n\n" - "Only direct dependencies are listed, and VCLs with" + " Only direct dependencies are listed, and VCLs with" " multiple dependencies are listed multiple times.", 0, 0 ) @@ -164,9 +164,9 @@ CLI_CMD(VCL_LABEL, "vcl.label", "vcl.label