Skip to content
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

handle keys with internal nuls and ignore systemd #8

Merged
merged 1 commit into from
Mar 7, 2021
Merged

Conversation

leifwalsh
Copy link
Collaborator

Deserialize keys that have nuls in them (because these might be ip
addresses), handle nul-terminated strings higher up when we know what
kind of request it is.

Don't use systemd socket activation becuase startup ordering is weird.

fixes #7

Copy link
Collaborator

@geofft geofft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but the systemd stuff also needs changes to the unit files, want to just split them into separate PRs?

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated
let listener = unsafe { UnixListener::from_raw_fd(LISTEN_FDS_START) };
let path = Path::new(SOCKET_PATH);
std::fs::create_dir_all(path.parent().expect("socket path has no parent"))?;
std::fs::remove_file(path).ok();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't let _ = more idiomatic? (I am not actually sure)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let _ = what?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think std::fs::remove_file(path).ok() is equivalent to saying "remove the file if possible, and I expect that if there are any errors with that we should proceed, including the one I expect most which is ENOENT which is fine, any other errors like permissions will probably surface when we try to bind".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm used to seeing let _ = std::fs::remove_file(path). But apparently silencing the warning with .ok() is also reasonable according to https://stackoverflow.com/questions/51141672/how-do-i-ignore-an-error-returned-from-a-rust-function-and-proceed-regardless

@leifwalsh
Copy link
Collaborator Author

Yeah I intentionally didn't touch the unit files, I sort of wanted you to do that. If you can guide my hand I can do it here.

Deserialize keys that have nuls in them (because these might be ip
addresses), handle nul-terminated strings higher up when we know what
kind of request it is.

fixes #7
@leifwalsh leifwalsh merged commit 6fea843 into main Mar 7, 2021
@leifwalsh leifwalsh deleted the nuls branch March 7, 2021 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing log messages about nul termination
2 participants