build: shell script portability fixes (TMPDIR, ar path, shellcheck warnings)#2445
build: shell script portability fixes (TMPDIR, ar path, shellcheck warnings)#2445randomizedcoder wants to merge 1 commit intoperformancecopilot:mainfrom
Conversation
|
This Pull Request relates to #2444 |
kmcdonell
left a comment
There was a problem hiding this comment.
Hmm @randomizedcoder we could be in for a bit of a bumpy ride here ...
- The configure change won't fly. Our configure is generated from configure.ac and this fragment of setting AR comes from autoconf ... you'll need to either set AR=...; export AR before you run configure else propose a change for configure.ac that changes the value of AR conditionally if $AR (as set by the autoconf-generated preamble) is not found. This line
dnl check if the tar program is availablein configure.ac is the start of a block that does something similar for gnutar on macOS, but you'll need a test -x rather than a test -z. - The
tmp=${TMPDIR:-/tmp}/foo-$$ones are OK ... we don't use $TMPDIR in the code at all so no nasty aliasing surprises and moving from /var/tmp to /tmp in the default (common) case is also probably the right thing to do these days (the original rationale for using /var/tmp based on common disk and root filesystem sizes went away decades ago) - The "checkshell" ones I don't like. I can't see these actually fixing a problem, some I think are wrong, e.g.
trap "...\$foo"is not a problem and eventrap "...$foois OK if$foois assigned a value before thetrapis declared and is not changed before thetrapis executed. Similarly rewritingtest foo -a barastest foo && test barserves no useful purpose. We're getting into the realm of religious arguments here, and I'd assert if it ain't broken then don't fix it.
I'd suggest reworking the AR change and drop the shellcheck changes.
Once this is merged you can cycle back to the nix PR #2440.
Then if you wish we can revisit the shellcheck issues if any real problems remain after that.
|
Ping @randomizedcoder ... any progress here? |
- $tmp in our scripts are for transient files, they never need to
survive a reboot, so /tmp is a better match than /var/tmp
- /tmp is often a tmpfs these days which provides a potential
reduction in disk i/o
- $TMPDIR provides a standard way of locating *all* these temporary
files someplace else, e.g. for a container or sandbox environment
- consistently uses tmp=${TMPDIR:-/tmp}/<script>-$$ for a script
named <script> to avoid concurrent execution clashes and to help
identify corpses in /tmp
This pre-empts point 2. in PR performancecopilot#2445 and the similar changes in
PR performancecopilot#2444.
|
G'day @randomizedcoder, |
|
G'day mate! I was just started to get back to this, but it looks like you fixed it up already! Nice work. I'm a pretty big fan of shellcheck, and don't see a good reason not to follow it. John Carmack of Doom game fame says lean in on code checkers and I complete agree. How can I help? Thanks, |
|
I think we can close this pull request. I will review the nix one again after this nice fixes you just applied. |
|
Created a pull request for "ar" |
|
OK, @randomizedcoder, I'm going to close this one. Just one last shot on code checkers ... I've been coding in C, sh and troff for more than 50 years. And my experience with code checkers is mixed.
Thanks. |
Shell Script Portability Improvements
Summary
This PR improves portability of PCP's build scripts for non-FHS systems (like NixOS, Guix) and sandboxed build environments. It also fixes shellcheck warnings to improve script quality.
New Pull request in response to
#2444 (review)
Changes
1. Portable
arfallback in configureThe configure script had a hardcoded fallback to
/usr/bin/ar, which doesn't exist on systems that don't follow the Filesystem Hierarchy Standard. Changed to justarwhich will be found via PATH.Please note that the configure script has a very large number of shellcheck exceptions, so this pull request did NOT attempt to resolve these.
2. Use
${TMPDIR:-/tmp}instead of/var/tmpSeveral build scripts hardcode
/var/tmpfor temporary files. This fails in sandboxed build environments (like Nix) where/var/tmpis not writable. The fix uses${TMPDIR:-/tmp}which:$TMPDIRwhen set (required for sandboxed builds)/tmpon traditional systemsAffected files:
src/pmdas/bind2/mk.rewritesrc/pmdas/jbd2/mk.rewritesrc/pmdas/linux/mk.rewritesrc/pmdas/linux_proc/mk.rewritesrc/bashrc/getargssrc/libpcp/src/check-errorcodessrc/libpcp3/src/check-errorcodessrc/libpcp/doc/mk.cgraphsrc/pmlogcompress/check-optimize3. Shellcheck warning fixes (all POSIX sh compatible)
$tmpexpands at signal time, not trap definition time[ -a ]with[ ] && [ ](more portable)$()to prevent word splittingstsbefore trap to avoid false warningTesting