-
Notifications
You must be signed in to change notification settings - Fork 701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake Chem and Chem+KPP Build #2018
base: develop
Are you sure you want to change the base?
Conversation
The Jenkins test results:
|
… value This now mirrors the make build and allows the make build to supply the WRF_CHEM and WRF_KPP option via defines/command line similar to the make build. Likewise, while there are files that use or or any variation of this, these were never being used by the make build. This may be a bug, but the priority of the cmake build is to acheive parity with the make build in compile flags and overall effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While replacing the call to system(cp_command) with a safer alternative would be a good improvement, this system call was not introduced in this PR. Addressing it might be better suited for a future PR.
|
||
system(cp_command); | ||
#ifndef NO_COPY | ||
system(cp_command); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling system() with a command-line-provided argument introduces significant security risks, as it can allow command injection if the input is not carefully sanitized. Could we replace system(cp_command) with a safer alternative that avoids directly invoking the shell?
For example, the following implementation securely copies files using fork() and execlp():
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void copy_file(const char *source, const char *destination) {
pid_t pid = fork();
if (pid == 0) {
// Child process: Securely execute the `cp` command
execlp("cp", "cp", source, destination, NULL);
perror("execlp failed"); // If exec fails
exit(EXIT_FAILURE);
} else if (pid > 0) {
// Parent process: Wait for the child to complete
int status;
waitpid(pid, &status, 0);
if (WIFEXITED(status)) {
printf("Copy completed with exit code %d\n", WEXITSTATUS(status));
} else {
fprintf(stderr, "Copy process terminated abnormally\n");
}
} else {
perror("fork failed");
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s \"<source_file> <destination_file>\"\n", argv[0]);
return EXIT_FAILURE;
}
// Parse the cp_command argument into source and destination
char *cp_command = argv[1];
char *source = strtok(cp_command, " ");
char *destination = strtok(NULL, " ");
if (!source || !destination) {
fprintf(stderr, "Error: Invalid command. Provide source and destination files.\n");
return EXIT_FAILURE;
}
// Call the copy_file function
printf("Copying '%s' to '%s'...\n", source, destination);
copy_file(source, destination);
return EXIT_SUCCESS;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems to compile successfully if I select chem and kpp as additional configuration options, though I actually have no idea how to run anything with chem+kpp to verify that the compiled model includes chemistry functionality.
TYPE: enhancement
KEYWORDS: cmake, chem, kpp
SOURCE: internal
DESCRIPTION OF CHANGES:
Problem:
Current CMake build does not build chem or chem+kpp configurations
Solution:
Build kpp and associated tools, and cmake commands to facilitate simplified logic of the
configure_wkc
andcompile_wkc
scripts. As with all CMake builds, all auto-generated source code is placed in the out-of-source build directory.Notable differences to make build :
-j N
parallel jobs to generate KPP sources up to a limitmodule_kpp_*
tuv_kpp
a directory to locate where include file is to be generated, and allow control of file IO mode*registry
uses-DWRF_CHEM
and-DWRF_KPP
defines passed at command line instead ofgetenv()
to match all other options**Affects make build in subtle ways but do not change user instructions
LIST OF MODIFIED FILES:
M CMakeLists.txt
M chem/CMakeLists.txt
A chem/KPP/CMakeLists.txt
M chem/KPP/compile_wkc
A chem/KPP/kpp/kpp-2.1/CMakeLists.txt
A chem/KPP/util/wkc/CMakeLists.txt
M chem/KPP/util/wkc/gen_kpp.c
M chem/KPP/util/wkc/protos_kpp.h
M chem/KPP/util/wkc/tuv_kpp.c
A chem/KPP/util/write_decomp/CMakeLists.txt
M chem/KPP/util/write_decomp/Makefile
M chem/KPP/util/write_decomp/integr_edit.c
M chem/chem_driver.F
M tools/CMakeLists.txt
M tools/data.h
M tools/registry.c
TESTS CONDUCTED:
RELEASE NOTE:
CMake Chem and Chem+KPP Build