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
mainand 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
i32representation 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
toxworks in conjunction with./setup.py. Let this be reminder that the magic trick was to runpython ./setup.py bdistto go through all the steps and find the hook point to copy our executable to the pythonbinfolder.Also not easy was
toxitself. 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-initsupportsdumb-init sh -c echo hididn't work with thestructoptsparsing 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-cis a flag forfooand not fordumb-init)ioctlmacrossscanffor Rust, and I didn't want to marshal pointers.Missing: