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

fix wrong definitions of getpwent_r and getgrent_r on solarish os #2914

Merged

Conversation

SteveLauC
Copy link
Contributor

Closes #2908

You may find the definitions for getpwnam_r/getpwuid_r/getgrnam_r/getgruid_r exposed by libc are also wrong:

struct passwd *getpwnam_r(const char *name, struct passwd *pwd,
            char *buffer, int buflen);
pub fn getpwnam_r(
    name: *const ::c_char,
    pwd: *mut passwd,
    buf: *mut ::c_cha
    buflen: ::size_t,
    result: *mut *mut passwd,
) -> ::c_int;

But actually they are correct as there are the POSIX-conforming definitions (see Standard conforming section of above man pages):

Standard conforming

       cc [ flag...] file... -D_POSIX_PTHREAD_SEMANTICS [ library... ]

       int getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);


       int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);

getpwent_r/getgrent_r don't get lucky, they do not have the POSIX-conforming alternatives.

To double check this, I searched its source code:

$ rg "__posix_getpwnam_r"
port/mapfile-vers
1582:   __posix_getpwnam_r;

port/gen/getpwnam_r.c
152:__posix_getpwnam_r(const char *name, struct passwd *pwd, char *buffer,

$ rg "__posix_getpwent_r"

$

@rust-highfive
Copy link

Some changes occurred in solarish module

cc @jclulow,@pfmooney

@rust-highfive
Copy link

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

@SteveLauC SteveLauC force-pushed the Wrong-getpwent_r-definition-on-solarish-os branch 2 times, most recently from 41a4306 to 85451c6 Compare September 18, 2022 03:45
@SteveLauC SteveLauC closed this Sep 18, 2022
@SteveLauC SteveLauC reopened this Sep 18, 2022
@JohnTitor
Copy link
Member

This is a breaking change, did you make sure that the change doesn't break any code?

cc @ctrlcctrlv who originally added this

@ctrlcctrlv
Copy link
Contributor

I mean, I have not tested personally on Solaris, but it looks right to me.

@SteveLauC
Copy link
Contributor Author

This is a breaking change, did you make sure that the change doesn't break any code?

Not sure about this. So what are we going to do about this PR?

@jclulow
Copy link
Contributor

jclulow commented Sep 21, 2022

I think @pfmooney and I will take a look at the specifics and make a recommendation, at least wrt. illumos.

@JohnTitor
Copy link
Member

JohnTitor commented Sep 21, 2022

Not sure about this. So what are we going to do about this PR?

We focus on back-compat and changing declarations will break existing code (unless it's totally wrong and doesn't work at all), we have to confirm that the change here doesn't confuse anyone.

@ctrlcctrlv
Copy link
Contributor

I'm to blame for this via #934. I have two questions.

  1. Why isn't the right solution to add POSIX conforming versions of these functions to Illumos?
  2. Why did CI pass even though __posix_get(pw|gr)ent_r doesn't exist?

@ctrlcctrlv
Copy link
Contributor

Well, failing an answer to №2, I've gotten OmniOS (an Illumos distribution) working on my own. I suggest I just author a patch to Illumos to add the missing functions, making this issue moot. Does anyone have an opinion on that course of action?

@SteveLauC
Copy link
Contributor Author

Does anyone have an opinion on that course of action?

Sounds good to me:)

@jclulow
Copy link
Contributor

jclulow commented Oct 1, 2022

I've had a look at this, and I suspect that the right call is probably to implement, in Rust, the behaviour you're expecting based on the other platforms as a wrapper around the native function. I don't believe there's any substantial difference otherwise, so you could presumably do something a bit like this:

extern "C" {
    #[cfg_attr(link_name  = "getpwent_r")]
    pub fn native_getpwent_r(pwd: *mut passwd, buf: *mut ::c_char, buflen: ::c_int) -> *mut passwd;
}

pub unsafe fn getpwent_r(
    pwd: *mut passwd,
    buf: *mut ::c_char,
    buflen: ::size_t,
    result: *mut *mut passwd,
) -> ::c_int {
    let res = native_getpwent_r(passwd, buf, buflen.try_into().unwrap());
    if res.is_null() {
        -1
    } else {
        *result = res;
        0
    }
}

This would go in the src/unix/solarish/compat.rs file, alongside the handful of similar routines that are present there.

We can and likely eventually will figure out a path for reworking these routines in illumos, but it will take time and coordination. Even when that lands it will be months or years before users have updated all their machines past LTS releases of various distributions to get the new symbol available.

@SteveLauC
Copy link
Contributor Author

@jclulow's walkaround looks good and I just added it. Any opinion on this?

(friendly ping @JohnTitor)

Copy link
Contributor

@jclulow jclulow left a comment

Choose a reason for hiding this comment

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

Thanks for taking a swing at this! I have put a few thoughts in comments.

src/unix/solarish/compat.rs Outdated Show resolved Hide resolved
buflen: ::size_t,
result: *mut *mut passwd,
) -> ::c_int;
pub fn native_getpwent_r(pwd: *mut passwd, buf: *mut ::c_char, buflen: ::c_int) -> *mut passwd;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear to me if native_getpwent_r() and native_getgrent_r() should be pub or perhaps rather pub(crate) -- or maybe no access qualifier is necessary because they're only used from a child module? If they're pub it would seem that we'd have to keep exposing them forever, because removing them would then break libc crate backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the pub qualifier since these two functions are only used inside this child module

Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

If this doesn't introduce any breaking change (i.e. ABI change, MSRV breaking, liking change), I'm fine to accept, has anyone confirmed that?

src/unix/solarish/compat.rs Outdated Show resolved Hide resolved
src/unix/solarish/compat.rs Outdated Show resolved Hide resolved
src/unix/solarish/compat.rs Outdated Show resolved Hide resolved
@SteveLauC SteveLauC force-pushed the Wrong-getpwent_r-definition-on-solarish-os branch 2 times, most recently from 3df8435 to 265b2dd Compare October 3, 2022 03:34
@SteveLauC
Copy link
Contributor Author

I just squashed and rebased, could I trouble you guys for another review:)

@SteveLauC SteveLauC requested review from jclulow and JohnTitor and removed request for jclulow October 3, 2022 03:35
@SteveLauC
Copy link
Contributor Author

SteveLauC commented Oct 3, 2022

API:

Current APIs are the same as the original ones, so no API break here:

MSRV:

IMHO, no MSRV break occurs. Associated constants like ::c_int::MAX require 1.43.0 or above, so I replace it with c_int::max_value(). This function is marked as deprecated, so I am not sure if this is a good approach.

About that native_getpwent_r() in mod.rs

In the current implementation, this native fn is only visible to that child module. When the desired definition introduced in compat.rs is submitted to the upstream kernel, this fn can be easily replaced with the new one without breaking any APIs.

fn native_getpwent_r(pwd: *mut passwd, buf: *mut ::c_char, buflen: ::c_int) -> *mut passwd;

@SteveLauC SteveLauC force-pushed the Wrong-getpwent_r-definition-on-solarish-os branch from a73b12c to 2238af3 Compare October 3, 2022 09:43
@SteveLauC SteveLauC force-pushed the Wrong-getpwent_r-definition-on-solarish-os branch from 2238af3 to 8a914ca Compare October 3, 2022 09:47
@ctrlcctrlv
Copy link
Contributor

Thanks a lot @jclulow for helping out. As I said in IRC, I think your solution offers the best of my proposed solution and the solution @SteveLauC originally proposed.

@JohnTitor
Copy link
Member

LGTM, thanks for clarifying!
@jclulow I'm not sure if you approved this or not, could you approve explicitly?

Meanwhile, let's see if CI agrees, @bors try

@bors
Copy link
Contributor

bors commented Oct 3, 2022

⌛ Trying commit 8a914ca with merge 54eb80f...

bors added a commit that referenced this pull request Oct 3, 2022
…sh-os, r=<try>

fix wrong definitions of getpwent_r and getgrent_r on solarish os

Closes #2908

* [man page for `getpwent_r`](https://illumos.org/man/3C/getpwnam)
* [man page for `getgrent_r`](https://illumos.org/man/3C/getgrnam)

You may find the definitions for `getpwnam_r/getpwuid_r/getgrnam_r/getgruid_r` exposed by `libc` are also wrong:
```c
struct passwd *getpwnam_r(const char *name, struct passwd *pwd,
            char *buffer, int buflen);
```
```rust
pub fn getpwnam_r(
    name: *const ::c_char,
    pwd: *mut passwd,
    buf: *mut ::c_cha
    buflen: ::size_t,
    result: *mut *mut passwd,
) -> ::c_int;
```
But actually they are **correct** as there are the POSIX-conforming definitions (see `Standard conforming` section of above man pages):
```
Standard conforming

       cc [ flag...] file... -D_POSIX_PTHREAD_SEMANTICS [ library... ]

       int getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);

       int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);
```

`getpwent_r/getgrent_r` don't get lucky, they do not have the POSIX-conforming alternatives.

To double check this, I searched its [source code](https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getpwnam_r.c):
```shell
$ rg "__posix_getpwnam_r"
port/mapfile-vers
1582:   __posix_getpwnam_r;

port/gen/getpwnam_r.c
152:__posix_getpwnam_r(const char *name, struct passwd *pwd, char *buffer,

$ rg "__posix_getpwent_r"

$
```
@bors
Copy link
Contributor

bors commented Oct 3, 2022

💔 Test failed - checks-actions

@SteveLauC
Copy link
Contributor Author

CI Build Channels macOS (1.13.0) and Docker Linux Tier2 (sparc64-unknown-linux-gnu) failed, seems unrelated to this pr

@JohnTitor
Copy link
Member

CI issue has been fixed, @bors try

bors added a commit that referenced this pull request Oct 4, 2022
…sh-os, r=<try>

fix wrong definitions of getpwent_r and getgrent_r on solarish os

Closes #2908

* [man page for `getpwent_r`](https://illumos.org/man/3C/getpwnam)
* [man page for `getgrent_r`](https://illumos.org/man/3C/getgrnam)

You may find the definitions for `getpwnam_r/getpwuid_r/getgrnam_r/getgruid_r` exposed by `libc` are also wrong:
```c
struct passwd *getpwnam_r(const char *name, struct passwd *pwd,
            char *buffer, int buflen);
```
```rust
pub fn getpwnam_r(
    name: *const ::c_char,
    pwd: *mut passwd,
    buf: *mut ::c_cha
    buflen: ::size_t,
    result: *mut *mut passwd,
) -> ::c_int;
```
But actually they are **correct** as there are the POSIX-conforming definitions (see `Standard conforming` section of above man pages):
```
Standard conforming

       cc [ flag...] file... -D_POSIX_PTHREAD_SEMANTICS [ library... ]

       int getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);

       int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
            size_t bufsize, struct passwd **result);
```

`getpwent_r/getgrent_r` don't get lucky, they do not have the POSIX-conforming alternatives.

To double check this, I searched its [source code](https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getpwnam_r.c):
```shell
$ rg "__posix_getpwnam_r"
port/mapfile-vers
1582:   __posix_getpwnam_r;

port/gen/getpwnam_r.c
152:__posix_getpwnam_r(const char *name, struct passwd *pwd, char *buffer,

$ rg "__posix_getpwent_r"

$
```
@bors
Copy link
Contributor

bors commented Oct 4, 2022

⌛ Trying commit 8a914ca with merge 9d82dce...

@bors
Copy link
Contributor

bors commented Oct 4, 2022

☀️ Try build successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14
Build commit: 9d82dce (9d82dce8d9ef27620d29e4ea6a0c8e333a7087a7)

@JohnTitor
Copy link
Member

Since this PR gets no response for a month, I'd like to go ahead assuming @jclulow overall agreed with the change (if you have any objections/concerns, let us know!).
@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2022

📌 Commit 8a914ca has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 3, 2022

⌛ Testing commit 8a914ca with merge 1ca1c41...

@bors
Copy link
Contributor

bors commented Nov 3, 2022

☀️ Test successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14
Approved by: JohnTitor
Pushing 1ca1c41 to master...

@bors bors merged commit 1ca1c41 into rust-lang:master Nov 3, 2022
@SteveLauC SteveLauC deleted the Wrong-getpwent_r-definition-on-solarish-os branch November 3, 2022 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong getpwent_r and getgrent_r definitions on illumos and solaris
7 participants