-
Notifications
You must be signed in to change notification settings - Fork 22
WIP: Add a process manager "class" #130
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
base: master
Are you sure you want to change the base?
Conversation
d298749
to
7397247
Compare
7397247
to
8d8774b
Compare
I replaced the file descriptors by |
8d8774b
to
839af1f
Compare
80179dd
to
c61c251
Compare
c61c251
to
317bc63
Compare
Actually, we will need the termination functionality for custom promise modules. |
317bc63
to
38ee191
Compare
60adb29
to
af97d5a
Compare
@olehermanse please review, if you have a chance. The only missing bit here, AFAICT, are unit tests for the termination functions. |
af97d5a
to
d8a4e45
Compare
d8a4e45
to
ea96219
Compare
ea96219
to
ce3a560
Compare
@cf-bottom jenkins, please |
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/6479/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-6479/ |
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.
Looks good in general, just some smaller comments.
memmove(map->values + i, map->values + i + 1, | ||
sizeof(MapKeyValue) * (map->size - i - 1)); |
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.
Especially because of the memmove()
, I think this function should have unit tests (which would be running using ASAN).
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.
It's just a copy-pasted code from ArrayMapRemove()
.
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.
Actually, we don't have any unit tests doing ArrayMapRemove()
. I created CFE-3643 instead of trying to save the world in this PR.
Allowing values being removed from the map without being destroyed (keys are always owned by the map and thus destroyed). Ticket: CFE-3572 Changelog: None
In many places there's a need to keep track of sub-processes spawned by the main process. Such processes need to be looked up by various parameters and interacted with. Having a common, reliable and fast implementation with high test coverage that holds the various pieces of information about sub-processes together is beneficial. In the future, we should extend this new API with the process spawning and termination functionality. Ticket: CFE-3572 Changelog: None
ce3a560
to
042b7b9
Compare
@cf-bottom jenkins with exotics, please |
Alright, I triggered a build: (with exotics) Jenkins: https://ci.cfengine.com/job/pr-pipeline/6482/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-6482/ |
There are failures on exotics. And we also need to be able to associate some custom data with the sub-processes managed. |
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.
Looks good to me, thanks for working on this! I see there are some remaining TODOs, but feel free to address those in separate PRs.
pid_t pid; /** PID of the subprocess [always >= 0] */ | ||
FILE *input; /** stream of the input to the subprocess [can be %NULL] */ | ||
FILE *output; /** stream of the output from the subprocess [can be %NULL] */ | ||
char lookup_io; /** which stream/FD to use for lookup by stream/FD ['i', 'o' or '\0'] */ |
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.
To me, this seems like a setting that would be in the top level proc manager, not each subprocess entry.
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.
This depends on the direction of the communication with the particular subprocess.
* @return whether the subprocess was successfully added or not (e.g. in case of | ||
* the process with the same id, PID or lookup stream/FD added before) | ||
* | ||
* @note Ownership of #id, #cmd and #description is transferred to the #manager. |
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.
What about the file streams? Are they closed by Subprocess / ProcManager?
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.
Only in case of termination.
pid, input, output, 'o'); | ||
assert_true(success); | ||
|
||
bool graceful_termination_failed = false;; |
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.
bool graceful_termination_failed = false;; | |
bool graceful_termination_failed = false; |
close(parent_write_child_read[1]); | ||
close(parent_read_child_write[0]); | ||
|
||
/* Also close the ends the child should normally use, we don't need them. */ |
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.
/* Also close the ends the child should normally use, we don't need them. */ | |
/* Also close the ends the child should normally use, we don't need them */ |
/* Ignore SIGTERM */ | ||
signal(SIGTERM, SIG_IGN); | ||
|
||
/* Wait to be killed. */ |
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.
/* Wait to be killed. */ | |
/* Wait to be killed */ |
/** | ||
* This file contains ProcManager tests that need to fork() a child process | ||
* which totally confuses the unit test framework used by the other tests. | ||
*/ |
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.
Worth mentioning that this file does not use said test framework.
/** | |
* This file contains ProcManager tests that need to fork() a child process | |
* which totally confuses the unit test framework used by the other tests. | |
*/ | |
/** | |
* This file contains ProcManager tests that need to fork() a child process | |
* which totally confuses the unit test framework used by the other tests. | |
* This test doesn't use the framework, it instead implements it's own | |
* assert macros with failure printing and a "normal" main function. | |
*/ |
/* Now try to insert the process again (with a different command and | ||
* description). This shouldn't be allowed. */ | ||
ret = ProcManagerAddProcess(manager, | ||
xstrdup("test-process"), xstrdup("/some/command2 arg1 arg2"), xstrdup("better test process"), | ||
(pid_t) 1234, input, output, 'i'); |
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.
Unclear here whether this should fail because of id
or pid
or both.
if (id == NULL) | ||
{ | ||
NDEBUG_UNUSED int ret = xasprintf(&id, "%jd", (intmax_t) pid); | ||
assert(ret > 0); | ||
} |
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.
Untested functionality.
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.
There are failures on exotics. And we also need to be able to associate some custom data with the sub-processes managed.
Need to be addressed one way or another, before merging.
In many places there's a need to keep track of sub-processes
spawned by the main process. Such processes need to be looked up
by various parameters, interacted with, and, eventually,
terminated.
Having a common, reliable and fast implementation with high test
coverage that holds the various pieces of information about
sub-processes together is beneficial.
Ticket: CFE-3572
Changelog: None
Steps:
void *data
to theSubprocess
struct