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

add pid to tokio::net::unix::UCred #2633

Merged
merged 1 commit into from Oct 31, 2020
Merged

Conversation

Kloenk
Copy link
Contributor

@Kloenk Kloenk commented Jun 25, 2020

Motivation

Fixed: #2632

Solution

Provided pid as Optionlibc::pid_t so solaris and macos does not break.

@Darksonn
Copy link
Contributor

This is a breaking change:

use tokio::net::unix::UCred;

fn main() {
    let a = UCred {
        uid: 10,
        gid: 10,
    };
}

@Darksonn Darksonn added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net labels Jun 25, 2020
@Kloenk
Copy link
Contributor Author

Kloenk commented Jun 25, 2020

This is a breaking change:

use tokio::net::unix::UCred;

fn main() {
    let a = UCred {
        uid: 10,
        gid: 10,
    };
}

Should it be behind a feature flag? How should that be named?

@Darksonn
Copy link
Contributor

A feature flag does not solve the issue. If some code compiles without a certain feature flag, it should also compile with that feature flag enabled. This is because when compiling code using Tokio, every feature required by any dependency is enabled for every dependency, and adding one dependency should not break other dependencies.

This change will have to wait for v0.3 of Tokio.

@Darksonn
Copy link
Contributor

I will close the PR for now and come back to this once we prepare to release v0.3.

@Darksonn Darksonn closed this Jul 20, 2020
@Darksonn Darksonn reopened this Oct 4, 2020
@Darksonn
Copy link
Contributor

Darksonn commented Oct 4, 2020

We are working on v0.3 now. Can you submit a commit that merges in the master branch to your branch?

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 10, 2020

We are working on v0.3 now. Can you submit a commit that merges in the master branch to your branch?

rebased it onto master

@Darksonn
Copy link
Contributor

Hi. We made a change to this struct such that changes like this are not breaking changes in the future in #2936. Can you rebase again? Sorry about that.

@Darksonn
Copy link
Contributor

It's a bit awkward that we can't get it under MacOS. What would be missing to change that? Perhaps it's better to not provide the function on mac and not use an Option?

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 11, 2020

It's a bit awkward that we can't get it under MacOS. What would be missing to change that? Perhaps it's better to not provide the function on mac and not use an Option?

For me it's a mac. So I don't know enough about macos api, if it is possible

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 11, 2020

Will disable it for now under MacOS.

I think since 4.2BSD MacOS also supports getsockopt. But I'm not sure, and don't have anything to test it on.

@Kloenk Kloenk force-pushed the socket_pid branch 2 times, most recently from eb86bb4 to 936333b Compare October 11, 2020 11:16
@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 16, 2020

As far as I can understand the docs and the source of darwin, it's not possible for us to get the PID of the peer process.
The LOCAL_PEERCRED option was added to macos, but it seems like xucred does not contain a PID.

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 16, 2020

Found another option, will try to get something working for darwin

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 16, 2020

It breaks, while saying bad address. Not yet sure why

@Darksonn
Copy link
Contributor

Let me know if you figure out that its not possible on MacOS.

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 17, 2020

Got it to work on my local MacOS hackintosh.

@taiki-e taiki-e self-assigned this Oct 17, 2020
@taiki-e
Copy link
Member

taiki-e commented Oct 17, 2020

not use an Option?

I don't think this is a good idea, as users must specify complex cfgs (cfg(any(target_os * 2 or 4)) for proper use. Also, even if this function becomes available on more platforms, it is not available to users unless they manually update cfgs.

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Please change the return type to Option or use #[cfg_attr(docsrs, doc(cfg(any(target_os = ...))))] on pid function to improve docs.

@taiki-e taiki-e removed their assignment Oct 17, 2020
@Darksonn
Copy link
Contributor

I was hoping we could make it work everywhere and get rid of both the option and cfg.

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 17, 2020

I didn't find this LOCAL_PEEREPID on another bsd. So no luck there

@taiki-e
Copy link
Member

taiki-e commented Oct 17, 2020

I was hoping we could make it work everywhere and get rid of both the option and cfg.

That is most preferable if that is possible, but I don't think we need to block this PR until it becomes work everywhere. Also, if it becomes work everywhere in the future, we can add a document that says "This function always returns Some since tokio v1.x.y".

@Darksonn
Copy link
Contributor

Fair enough. We can return an Option and document on which OSes it works.

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 17, 2020

So readding the Option<pid_t> I removed before?

@Darksonn
Copy link
Contributor

Yes.

@Kloenk
Copy link
Contributor Author

Kloenk commented Oct 22, 2020

Added it, with a small comment saying, where it is implemented

@Darksonn Darksonn merged commit 382ee6b into tokio-rs:master Oct 31, 2020
@Kloenk Kloenk deleted the socket_pid branch October 31, 2020 09:45
Keruspe added a commit to Keruspe/tokio that referenced this pull request Nov 2, 2020
* master:
  tracing: replace future names with spawn locations in task spans (tokio-rs#3074)
  util: add back public poll_read_buf() function (tokio-rs#3079)
  net: add pid to tokio::net::unix::UCred (tokio-rs#2633)
  chore: prepare tokio-util v0.5.0 release (tokio-rs#3078)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PID as part of UCred
3 participants