cmd: version command should not call before or after procs Since the original IBM code import, the cmd_Dispatch processor has avoided calling beforeProc and afterProc for the built-in 'help' and 'apropos' commands. This is important, because these procs may rely on application-defined common arguments (e.g., -cell <cell> or -noauth) for proper operation. However, application common arguments are not defined for built-in commands 'help' and 'apropos'. Unfortunately, when a new built-in 'version' command was added (350c140d89198cb7 libcmd-support-version-switch-20060630), it was not exempted from the before and after procs. In order to avoid a segmentation fault in 'libadmin/test/afscp version', modify cmd to also avoid calling beforeProc and afterProc for the 'version' command. Change-Id: Ic899397de808fd6c4a5f66a0f5add102340064e6 Reviewed-on: https://gerrit.openafs.org/14645 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
clang-10: use AFS_FALLTHROUGH for case fallthrough Clang-10 will not recognize '/* fallthrough */' as an indicator to turn off the fallthrough diagnostic due to the lack of a 'break' in a case statement. Clang-10 requires the '__attribute__((fallthrough))' statement to disable the diagnostic. In addition clang-10 is finding additional locations where fall throughs occur. Determine if the compiler supports '__attribute__((fallthrough))' to disable the implicit fallthrough diagnostic. Define a new macro 'AFS_FALLTHROUGH' that will disable the fallthrough diagnostic. Set it as a wrapper for the Linux kernel's 'fallthrough' macro if available, otherwise set it as a wrapper macro for '__attribute__((fallthrough))' if the compiler supports it. Update CODING to document the use of AFS_FALLTHROUGH when needing to fallthrough between case statements. Replace the '/* fallthrough */' comments with AFS_FALLTHROUGH, and add AFS_FALLTHROUGH as needed. Replace some fallthroughs with a break (or goto) if the flow was was just to a break (or goto). e.g. case x: case x: somestmt; somestmt; break; case y: case y: break; break; Correct a mis-indented brace '}' in src/WINNT/afsd/smb3.c Note, the clang maintainers have rejected the use of comments as a flag to turn off the fall through warnings. Change-Id: Ia5da10fc14fc1874baca035a3cf471e618e0d5f5 Reviewed-on: https://gerrit.openafs.org/14274 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Add more 'fall through' switch comments Commit a455452d (LINUX 5.3: Add comments for fallthrough switch cases) added the special /* fall through */ comment to various switch/case blocks, in order to avoid implicit-fallthrough warnings from causing the build to fail when building the Linux kernel module. In this commit, add additional /* fall through */ comments to the rest of the tree where falling through is intentional. Add a "break;" in one place in dumptool.c where falling through seems like a mistake, and flag certain functions as AFS_NORETURN to avoid needing to explicitly break or fallthrough. Check for the availability of the -Wimplicit-fallthrough compiler flag and use it when --enable-checking is set, to prevent additional cases from creeping into the tree. Note: the -Wimplicit-fallthrough compiler flag was added in gcc 7. Change-Id: Iae34e7969606603da8358d7cfa5fd04279b218dc Reviewed-on: https://gerrit.openafs.org/14125 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
cmd: bail if out of memory while printing syntax Bail with an error message to stderr if we are unable to format the command syntax due to a string allocation error. Found via scan-build. [mmeffie: updated commit] Change-Id: Ib3bc7f53c295d8dde6c07b9c4990cd1b3bcee58c Reviewed-on: https://gerrit.openafs.org/13335 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
cmd: improve help for programs without subcommands Some programs do not have subcommands (other than the standard "help", and "version" subcommands). The cmd library provides the "noopcode" mechanism for new subcommand-less programs, but older programs take advantage of the optional "initcmd" token to simulate subcommand-less programs. The "initcmd" token is optional to run the command, however it is required to display the command help. For example, running the xstat_cm_test program without any options gives a syntax error: $ xstat_cm_test xstat_cm_test: Missing required parameter '-cmname' ... Retrying with -help (or help, -h, --help), gives the rather unhelpful output: $ xstat_cm_test -help xstat_cm_test: Commands are: apropos search by help text help get help on commands initcmd initialize the program It is not obvious to the user how to get the command usage for the program, nor that the initcmd subcommand to "initialize the program" is actually is a placeholder to run the program. Instead, display the command usage when help is requested and initcmd is the only defined subcommand for a program. For example: $ xstat_cm_test -help Usage: src/xstat/xstat_cm_test [initcmd] -cmname <Cache Manager name(s) to monitor>+ -collID <Collection(s) to fetch>+ [-onceonly] [-frequency <poll frequency, in seconds>] [-period <data collection time, in minutes>] [-debug] [-help] Where: -onceonly Collect results exactly once, then quit -debug turn on debugging output The libcmd library now supports an "noopcode", which should used for future subcommand-less programs, but converting old programs to remove the initcmd opcode could break scripts which actually specify the optional initcmd token. This commit adds a new libcmd flag called CMD_IMPLICIT which is used to denote built-in subcommands such as "version" and "help". Change-Id: Iee9cb2761254543f74166e5c240685f85b6915b6 Reviewed-on: https://gerrit.openafs.org/10983 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Fix unchecked calls to asprintf The return value of asprintf() is the number of bytes printed, or -1 if there was an error allocating a large enough buffer. In the latter case, the value of the result string is undefined, and so it cannot be counted on to be NULL. This change fixes numerous places where the result of asprintf is checked incorrectly (by examining the output pointer and not the return value) or not at all. Change-Id: I9fef14d60c096795d59c42798f3906041fb18c86 Reviewed-on: http://gerrit.openafs.org/9978 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: D Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com>
cmd: avoid piggy-backing flags in the help string Remove the hack to piggy-back the hidden command option in the help string argument. Change-Id: Iedcb6b96e98b766e3ef2c87cd6e5d41874f2c0b7 Reviewed-on: http://gerrit.openafs.org/10982 Reviewed-by: D Brashear <shadow@your-file-system.com> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Tested-by: BuildBot <buildbot@rampaginggeek.com>
cmd: add flags argument to create syntax function Add the flags argument to cmd_CreateSyntax() and update all callers. The flags argument will be used to set command options, such as CMD_HIDDEN. Change-Id: Ia51be9635f262516cb084d236a9e0756f608bf16 Reviewed-on: http://gerrit.openafs.org/11430 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
remove cmd-suite-option-for-hiding-admin-commands Remove the incomplete and non-functional cmd option for hiding admin commands, introduced in commit 36d02757fd6863a845163daf0d730bdcc0a28343. This patch removes the CMD_ADMIN flag, the non-functional help -admin parameter, and the non-functional cmd_IsAdministratorCommand() function. Thanks to Jeffrey Altman for pointing out this old commit and for suggestions on cleanup. Change-Id: I72c7d2ed7109b1238713fe0d6d177c5af6fc6b7d Reviewed-on: http://gerrit.openafs.org/11429 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Reviewed-by: Garrett Wollman <wollman@csail.mit.edu> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com> Reviewed-by: D Brashear <shadow@your-file-system.com>
build: remove trailing whitespace from makefiles Remove trailing whitespace from the makefiles, except for trailing whitespace in the boilerplate comment headers. Change-Id: Ib8ee87a51f00633ba15e1974ac0b311969bef1bf Reviewed-on: http://gerrit.openafs.org/11456 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Reviewed-by: D Brashear <shadow@your-file-system.com> Tested-by: D Brashear <shadow@your-file-system.com>
cmd: List version in help for commands List version in help for commands using cmd library Change-Id: I4da64be11244e64d961e8de47cecb24cbbadce32 Reviewed-on: http://gerrit.openafs.org/10956 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: D Brashear <shadow@your-file-system.com>
build: separate source and header compile_et rules Generate source and header files separately to support parallel make without contortions. Add a complete list of dependencies for each generated header file to avoid build errors during parallel make. Change-Id: I804ff553e08d411a1cfe20a4ef4e57da9d321837 Reviewed-on: http://gerrit.openafs.org/10370 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Reviewed-by: D Brashear <shadow@your-file-system.com>
Satisfy clang's aggressive strlcpy warnings Passing something related to the length of the source as the length argument to strlcpy triggers a warning, which is converted to an error with --enable-checking (on FreeBSD 10.0). The current code is safe, since it is using the same expression that was used to allocate the destination buffer, but switch to using a separate variable to hold the length and use that variable for both allocation and copying, to appease the compiler. Change-Id: I580083d142fd19a4e7828c915b4846868fa8f917 Reviewed-on: http://gerrit.openafs.org/10818 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Perry Ruiter <pruiter@sinenomine.net> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
build: compile_et rules for parallel make Change all makefile rules which run compile_et in order support parallel make. The compile_et generates two outputs, so special care must be taken in rules which run compile_et. All the rules for compile_et have been changed to the form: foo.c foo.h: foo.et compile_et foo.et -h foo foo.h: foo.c The above rules are equivalent to: foo.c: foo.et compile_et foo.et -h foo foo.h: foo.et foo.c compile_et foo.et -h foo therefore a parallel make will serialize the builds of foo.c and foo.h, and should detect that the second is no longer needed once the first is over. This form works since foo.et is not a phony target, and does not depend on a phony target. Previously, the rules for compile_et were of the one of the two forms: a) foo.c foo.h: foo.et compile_et foo.et -h foo or b) foo.h: foo.c foo.c: foo.et compile_et foo.et -h foo Form a) is problematic for parallel makes, since it is equivalent to: foo.c: compile_et foo.et -h foo foo.h: compile_et foo.et -h foo In a parallel make, compile_et will be run concurrently, clobbering each other's output files. Form b) is better, but is problematic when foo.h is removed, since foo.h will not be updated. Thanks to Russ Allbery for pointing out the automake documentation which describes issues with commands that produce multiple outputs, and portable solutions. http://www.gnu.org/software/automake/manual/automake.html#Multiple-Outputs Change-Id: I14c056606084f80270e05592d3d09a600f804e24 Reviewed-on: http://gerrit.openafs.org/10237 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Sort all libtool symbol lists The original plan for the libtool symbol lists was that they be in alphabetical order. This should make them easier to maintain, as it becomes harder to accidentaly introduce duplicates, and makes merge conflicts when adding new symbols less likely. However, not all of them are properly sorted. Update the ones that aren't. This was done with for A in `find . -name *.la.sym`; do sort $A -o $A; done Change-Id: I6a3fd621098466e8275b2e42c0fe54cfb38b5128 Reviewed-on: http://gerrit.openafs.org/9900 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Add krb5_enomem for config parser & kernel crypto The imported code form Heimdal that forms our config file parser and kernel rfc3961 library now makes use of krb5_enomem. Provide an implementation so we build again ... Change-Id: Ie7162d73aa97e6f7594c0e7c68ed6939f57ae884 Reviewed-on: http://gerrit.openafs.org/9265 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Split up libtool support into LWP and pthread Currently, the type of library you build is determined by whether the library is build in a pthread, or an lwp build directory. However, this prevents building an LWP library in a directory that builds pthreaded clients and servers. As we want to continue to provide LWP libraries for backwards compatibility, but move over to pthreaded binaries, this causes some issues. So, split up the libtool logic, so we have Makefile.libtool, which you include if you want to build a pthreaded libtool library, and Makefile.lwptool, for building a library which supports LWP and pthreaded use. These only affect how .lo files are built - so the .o files used for non-library objects are managed with the Makefile.pthread and Makefile.lwp includes as before. Change-Id: Ib1af48342253230abab9056eb15a3f79bd77a6de Reviewed-on: http://gerrit.openafs.org/8126 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
cmd: exit status zero from -help Return of an exit status of zero when running commands with -help, instead of returning an error. By general convention, and in previous versions, tools do not not treat -help as an error. The AFS::Command perl modules, use -help as an introspection technique, and fail when commands run with the -help option returns non-zero. Change-Id: I6ecd95f6ccd07218a2657dbb4dbf1c13599159f4 Reviewed-on: http://gerrit.openafs.org/8087 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com> Tested-by: BuildBot <buildbot@rampaginggeek.com>
comerr, cmd, opr: fix library install targets Fix a couple of issues in the install targets following the libtool changes: - don't install liboafs_comerr or liboafs_opr, they're not ready to be exposed to the outside world - fix the libcmd.a install target to use INSTALL_DATA and the correct library name Change-Id: I2bf241cfff419d51bf170fdc871248e9b0c7ab33 Reviewed-on: http://gerrit.openafs.org/8063 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
cmd: Convert to using libtool Convert the libcmd and libcmd_pic libaries to being built using libtool. Historically, these have been built as LWP code, but they have no LWP dependencies, and no LWP-specific code within them. So, make cmd a pthread-only library. In addition to the libtool library liboafs_cmd.la, we build the legacy libcmd.a and libcmd_pic.a as convenience libraries. libcmd64.a (a 64bit variant, used solely by kdump), remains built through "normal" means. Update pthreaded users of libcmd to use the new liboafs_cmd.la. For now, non-pthreaded users are left alone. Change-Id: Id8445949754d1942f6e8752ae182b4e6f86fe94f Reviewed-on: http://gerrit.openafs.org/8055 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@your-file-system.com>