Skip to content

NetBSD: add sysctl backend for std::env::current_exe - #46373

Merged
bors merged 1 commit into
rust-lang:masterfrom
jakllsch:netbsd-kern_proc_pathname
Dec 2, 2017
Merged

NetBSD: add sysctl backend for std::env::current_exe#46373
bors merged 1 commit into
rust-lang:masterfrom
jakllsch:netbsd-kern_proc_pathname

Conversation

@jakllsch

Copy link
Copy Markdown
Contributor

Use the CTL_KERN.KERN_PROC_ARGS.-1.KERN_PROC_PATHNAME sysctl in
preference over the /proc/curproc/exe symlink.

Additionally, perform more validation of aformentioned symlink.
Particularly on pre-8.x NetBSD this symlink will point to '/' when
accurate information is unavailable.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@kennytmkennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 29, 2017
Comment threadsrc/libstd/sys/unix/os.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use sysctl().or_else(procfs) here, otherwise procfs() will always be called.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

OK

Comment threadsrc/libstd/sys/unix/os.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why a PathBuf instead of Path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

For no reason other than to match the linux,android,emscripten current_exe(). I had path::Path::new() in a previous version of this. I'll restore it.

Comment threadsrc/libstd/sys/unix/os.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need to check path_len == 0 just like the FreeBSD implementation above? Or is it possible to merge the implementations of the BSDs (only the mib differ as far as I can see).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Possibly could even check for path_len <= 1 for additional safety. There are a few very subtle differences between the FreeBSD & DragonFly block and what I implemented, but I imagine they could be merged if thought best. While they are nearly identical, I have this purist view that as there is no shared lineage in the kernel-side implementation of these sysctls, they may as well stay seperate here.

Comment threadsrc/libstd/sys/unix/os.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line is too long, causing CI to fail :(

[00:04:06] tidy error: /checkout/src/libstd/sys/unix/os.rs:246: line longer than 100 chars

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll wrap that line.

@jakllsch

Copy link
Copy Markdown
ContributorAuthor

CI might have missed this:

error[E0277]: the trait bound core::result::Result<path::PathBuf, io::error::Error>: core::ops::FnOnce<(io::error::Error,)> is not satisfied
--> /local/jakllsch/rust/rust/src/libstd/sys/unix/os.rs:253:14
|
253 | sysctl().or_else(procfs())
| ^^^^^^^ the trait core::ops::FnOnce<(io::error::Error,)> is not implemented for core::result::Result<path::PathBuf, io::error::Error>

@kennytm

Copy link
Copy Markdown
Member

The CI for PR only runs on Linux, so it will definitely miss any change made to NetBSD.

Comment threadsrc/libstd/sys/unix/os.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sysctl().or_else(procfs) without the last ().

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I had tried that and got:

error[E0593]: function is expected to take 1 argument, but it takes 0 arguments
--> /local/jakllsch/rust/rust/src/libstd/sys/unix/os.rs:253:14
|
253 | sysctl().or_else(procfs)
| ^^^^^^^ expected function that takes 1 argument
error: aborting due to previous error

I'd really like to keep the prototypes/signatures of sysctl() and procfs() identical..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jakllsch Oh ok. Call through a closure sysctl().or_else(|_| procfs()) then.

@kennytm

Copy link
Copy Markdown
Member

@jakllsch Are we supposed to wait for you to squash the commits or can these be merged as-is?

Use the CTL_KERN.KERN_PROC_ARGS.-1.KERN_PROC_PATHNAME sysctl in
preference over the /proc/curproc/exe symlink.
Additionally, perform more validation of aformentioned symlink.
Particularly on pre-8.x NetBSD this symlink will point to '/' when
accurate information is unavailable.
@jakllsch
jakllschforce-pushed the netbsd-kern_proc_pathname branch from 8de0cde to ccef969CompareNovember 30, 2017 18:18
@jakllsch

Copy link
Copy Markdown
ContributorAuthor

@kennytm I've squashed it.

@kennytm

Copy link
Copy Markdown
Member

Thanks for the contribution!

@bors r+

@bors

bors commented Nov 30, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit ccef969 has been approved by kennytm

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Dec 1, 2017
… r=kennytm
NetBSD: add sysctl backend for std::env::current_exe
Use the CTL_KERN.KERN_PROC_ARGS.-1.KERN_PROC_PATHNAME sysctl in
preference over the /proc/curproc/exe symlink.
Additionally, perform more validation of aformentioned symlink.
Particularly on pre-8.x NetBSD this symlink will point to '/' when
accurate information is unavailable.
@kennytmkennytm mentioned this pull request Dec 1, 2017
bors added a commit that referenced this pull request Dec 1, 2017
Rollup of 13 pull requests
- Successful merges: #45880, #46280, #46373, #46376, #46385, #46386, #46387, #46392, #46400, #46401, #46405, #46412, #46421
- Failed merges:
@bors
bors merged commit ccef969 into rust-lang:masterDec 2, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jakllsch@rust-highfive@kennytm@bors