Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is risky. I know, please bear with me.
I've had some fun in the last couple of day studying how a random project could be converted to Rust.
Things that were important:
So, what's my expectation by opening this PR? Nothing really. I expect it'll be closed.
However, since I did spend a significant time on this it felt like a waste of time NOT to share this with the community.
Looking at it now, as someone who didn't do that much
C/C++
it definitely feels more readable. In Rust things are just... more explicit. And yea, I know I'm talking to these wrappers of just the good ol'libc
, but that doesn't take away from the fact I feel that intent is better expressed in the Rust version.I learned about the definition of unsafe behavior, how to get around it, mapping back and forth between C and Rust and how to express things in a more Rust-manner way.
One thing I looked at was how to have the 5 global variables as part of
main
and then just pass them around all the time, this would avoid the need for them beingstatic
. But that felt unneeded given the single-threaded mode this application runs in.Next to that I also looked into the arrays where the
i32
representation of the signal is the index of an array, something seen quite often in C. I wanted to use a HashMap, but because of not wanting to pass everything around I also abandoned that.Lastly, the array access is probably faster, a little bit more checks.
A good amount of time was then spent in understanding how
tox
works in conjunction with./setup.py
. Let this be reminder that the magic trick was to runpython ./setup.py bdist
to go through all the steps and find the hook point to copy our executable to the pythonbin
folder.Also not easy was
tox
itself. I still haven't figured out how to actually attach a debugger. I tried VS Code and PyCharm, both interfacing with WSL but I never got the experience I wanted to.Lastly a good amount of time was spent on making the CLI interface match. The fact that
dumb-init
supportsdumb-init sh -c echo hi
didn't work with thestructopts
parsing library, so I had to switch togetopts
. But surprisingly I got it to work. Having drop-in capabilities was extremely important for this. Can't change the contract of all of our customers right?Rust dependencies worth used:
nix
)dumb-init foo -c bar
(where-c
is a flag forfoo
and not fordumb-init
)ioctl
macrossscanf
for Rust, and I didn't want to marshal pointers.Missing: