From 9d89935d16dd819d5f44715a3237928cb16381a0 Mon Sep 17 00:00:00 2001 From: Simon Rose Date: Thu, 11 Jun 2026 16:52:55 +0200 Subject: [PATCH] Drop environment variables from EPICS base that are too long This is configured in CONFIG_SITE(.local) using the variable `IOCSTATS_MAX_ENV_VAR_LENGTH`; the default is 40, but a given site should tune it for their own PV prefix needs. --- configure/CONFIG_SITE | 6 ++++++ iocAdmin/Db/Makefile | 2 +- iocAdmin/Db/genSiteEnvVars.pl | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/configure/CONFIG_SITE b/configure/CONFIG_SITE index 1e82bb0..8cd57af 100644 --- a/configure/CONFIG_SITE +++ b/configure/CONFIG_SITE @@ -37,6 +37,12 @@ WITH_PVA=$(if $(strip $(EPICS_PVA_MAJOR_VERSION) $(PVXS_MAJOR_VERSION)),YES,NO) +# Variables coming from CONFIG_ENV and CONFIG_SITE_ENV that are +# longer than this will be dropped when expanding iocAdmin*.db. +# This should be configured as a site needs depending on their own +# naming conventions. +IOCSTATS_MAX_ENV_VAR_LENGTH=40 + -include $(SUPPORT)/configure/CONFIG_SITE # These allow developers to override the CONFIG_SITE variable diff --git a/iocAdmin/Db/Makefile b/iocAdmin/Db/Makefile index cd06a9c..d2968f1 100644 --- a/iocAdmin/Db/Makefile +++ b/iocAdmin/Db/Makefile @@ -49,4 +49,4 @@ iocAdminVxWorks.db$(DEP): $(SUBST_DEPS) $(COMMON_DIR)/siteEnvVars.substitutions: $(EPICS_BASE)/configure/CONFIG_SITE_ENV $(EPICS_BASE)/configure/CONFIG_ENV @echo Expanding siteEnvVars.substitutions from $^.... @$(RM) $@ - @$(PERL) ../genSiteEnvVars.pl $^ > $@ + @$(PERL) ../genSiteEnvVars.pl -l $(IOCSTATS_MAX_ENV_VAR_LENGTH) $^ > $@ diff --git a/iocAdmin/Db/genSiteEnvVars.pl b/iocAdmin/Db/genSiteEnvVars.pl index ad98d14..2f8cbf2 100644 --- a/iocAdmin/Db/genSiteEnvVars.pl +++ b/iocAdmin/Db/genSiteEnvVars.pl @@ -1,14 +1,37 @@ #!/usr/bin/env perl # -# Usage: genSiteEnvVars.pl CONFIG_SITE_ENV [ ... ] -# # Reads an EPICS CONFIG_SITE_ENV file and outputs # a substitutions file to generate appropriate EPICS # records for those variables via iocEnvVar.template # +# Will drop environment variables deemed too long as they +# may produce invalid PV names. This is configured in +# CONFIG_SITE. +# use strict; use warnings; +use File::Basename; +use Getopt::Std; + +my $tool = basename($0); + +our ($opt_h, $opt_l); + +sub HELP_MESSAGE { + print STDERR "Usage: $tool [-h] [-l max_length] \n"; + exit 2; +} + +HELP_MESSAGE() if !getopts("hl:") || $opt_h; + +my $max_length; +if ($opt_l) { + $max_length = $opt_l; +} else { + $max_length = 15; +} + print <<__END__; file "iocEnvVar.template" { pattern { ENVNAME, ENVVAR, ENVDESC, ENVTYPE } @@ -24,11 +47,16 @@ my @unique_vars = grep { not $varcount{$_}++ } @epics_vars; foreach (@unique_vars) { + if (length($_) > $max_length) { + print STDERR "Warning: Variable $_ is potentially too long for a "; + print STDERR "PV name given a typical prefix. Skipping.\n"; + next + } my $desc = "EPICS_$_"; if (length($desc) > 40) { $desc = substr($desc, 0, 40); + print STDERR "Warning: Truncated description for $_ to fit 40 characters: $desc\n"; } - print STDERR "Warning: Truncated description for $_ to fit 40 characters: $desc\n" if $desc ne "EPICS_$_"; print "{ $_, EPICS_$_, $desc, epics }\n"; } print("}\n");