Live data from Hacker News

Rust and Nix = easier Unix systems programming

kamalmarhubi.com

1–10 of 85 posts

Re: Rust and Nix = easier Unix systems programming

#3
Minor nit pick but don't you typically do something like this in C

pid_t childPid;

switch (childPid = fork()) {

case -1: ... /error handling /;

case 0: ... /Child Specific/

default: sleep (5); }

edit - seems to mangle formatting but something like that seems fairly clean.

Re: Rust and Nix = easier Unix systems programming

#4

Minor nit pick but don't you typically do something like this in C pid_t childPid; switch (childPid = fork()) { case -1: ... / error handling /; case 0: ... / Child Specific / default: sleep (5); } edit - seems to mangle formatting but something like that seems fairly clean.

It's not that you can't write the code properly in C, it's that the language and function interfaces give you no handrails to protect you from a mistake. And in this case, doing the wrong thing could be disastrous to your system, especially if you had to run it as root.

Great intro to Rust and Unix post!

Re: Rust and Nix = easier Unix systems programming

#6

Minor nit pick but don't you typically do something like this in C pid_t childPid; switch (childPid = fork()) { case -1: ... / error handling /; case 0: ... / Child Specific / default: sleep (5); } edit - seems to mangle formatting but something like that seems fairly clean.

Typically, I would hope so. A good code review process should typically catch when it isn't done like this.

In context, "typically" means your devops people get to work on Christmas to patch a critical CVE being actively exploited in the wild pissing off all your customers that one time someone didn't do the typical pattern anywhere in your codebase or the codebases of any of your 3rd party libaries, frameworks, applications...

Where "didn't do the typical pattern" might be if conditions as shown, or forgetting the "case -1", or missed a key and typed "case 1", or elided the "break;" from the case above (I note no "break;"s in your switch ;)), or didn't rtfm closely enough to see -1 was a special exit code, or mis-assumed kill(-1,...) was a noop, or ...

Re: Rust and Nix = easier Unix systems programming

#8

Minor nit pick but don't you typically do something like this in C pid_t childPid; switch (childPid = fork()) { case -1: ... / error handling /; case 0: ... / Child Specific / default: sleep (5); } edit - seems to mangle formatting but something like that seems fairly clean.

yes, but quite a lot of tutorials i've seen / intro to systems courses seem to think it looks "cleaner" to use an if statement; switch is definitely the move here but i've seen the if version quite a lot

Re: Rust and Nix = easier Unix systems programming

#10
post #5

In reliability theory "X failed" is a poor error message. What we want to know is which failure mode has been triggered. The function of kill is to kill a given pid, so there are two failure modes : "the pid didn't exist" or "the pid didn't die"

It's poorly named, because the function of kill isn't to kill a given PID; it's to send a signal to a given PID.
Post reply on HN