Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests for process resuming functionality and fixes move semantics for the Process class to prevent premature cleanup of underlying processes during object moves.
- Implements proper move constructor and assignment operator for the
Processclass - Adds test coverage for process attachment and resuming functionality
- Creates a test binary for use in process manipulation tests
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/testbin.m.cpp | Simple test binary that sleeps for 5 seconds |
| test/sdb_process.t.cpp | Adds tests for invalid PID attachment and process resuming |
| test/CMakeLists.txt | Builds the test binary executable |
| src/sdb_process.cpp | Implements move semantics and fixes process cleanup logic |
| src/sdb_pipe.cpp | Minor cleanup removing redundant bitwise OR with 0 |
| include/libsdb/sdb_process_state.h | Adds stream operator declaration for ProcessState |
| include/libsdb/sdb_process.h | Updates member variables to support move semantics |
Comments suppressed due to low confidence (2)
src/sdb_process.cpp:107
- This line appears to be test code (using ASSERT_EQ) in a production source file. Test assertions should not be in production code. This should be moved to the test file or replaced with appropriate error handling.
proc->waitOnSignal();
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| Process& Process::operator=(Process&& other) | ||
| { |
There was a problem hiding this comment.
The move assignment operator doesn't handle self-assignment properly. If this == &other, the object will invalidate itself by setting other.d_pid = 0 and other.d_cleanupOnExit = false. Add a self-assignment check at the beginning of the function.
| { | |
| { | |
| if (this == &other) | |
| { | |
| return *this; | |
| } |
| std::stringstream ss; | ||
| ss << "Unable to continue proc with pid=" << d_pid << ", rc=" << rc | ||
| << ". perror="; | ||
| perror(ss.str().c_str()); |
There was a problem hiding this comment.
Using stringstream for simple string concatenation in error paths is inefficient. Consider using string concatenation with std::to_string() for better performance: std::string message = "Unable to continue proc with pid=" + std::to_string(d_pid) + ", rc=" + std::to_string(rc) + ". perror=";
| perror(ss.str().c_str()); | |
| std::string message = "Unable to continue proc with pid=" + std::to_string(d_pid) + | |
| ", rc=" + std::to_string(rc) + ". perror="; | |
| perror(message.c_str()); |
#### Context * Address review comments from #9 #### Changes * Fix error message construction in the error path * Handle self-assignment in the move assignment operator #### Test Plan * CI
Context
Changes
Processclass to ensure the underlying process is not cleanedwhen the object moved out of is destructed.
Test Plan