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

Don't panic if /var/run/utmp is missing #136

Merged
merged 2 commits into from
May 20, 2024
Merged

Conversation

pothos
Copy link
Contributor

@pothos pothos commented May 19, 2024

  • Don't panic if /var/run/utmp is missing
    In a container as set up by Podman there is no utmp file in (/var)/run.
    When no file is present, we can return NULL.
  • Document requirements for runtime environment. (Based on the above this is only about getent.)

@pothos
Copy link
Contributor Author

pothos commented May 20, 2024

Tested it and it doesn't panic anymore as wanted. Reading the glibc code I don't see errno being set up for this case. I will remove set_errno(Errno(libc::ENOENT)); and maybe I think we should also skip setting errno. Or we could use set_errno(Errno(0)) to make this explicit.

Copy link
Owner

@sunfishcode sunfishcode 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 the patch!

I tried a testcase in glibc:

 cat t.c
#include <utmp.h>
#include <utmpx.h>
#include <errno.h>
#include <stdio.h>

int main() {
	errno = 0;
	struct utmpx* p = getutxent();
	printf("%p; %m\n", p);
	return 0;
}

on a system where /var/run/utmp doesn't exist and it set errno to ENOENT. Probably it does an open which does this implicitly.

should support the arguments `passwd`, `group`, `initgroups`, `services`,
`ahosts`, `ahostsv4`, and `ahostsv6`. On a regular glibc system the
`getent` binary is provided by it and uses the NSS setup as usual.
Similar, a musl system also provides `getent` (but does not use NSS).
Copy link
Owner

Choose a reason for hiding this comment

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

My sense is it's not necessary to list all the getent subcommands here. And this list will grow over time if c-ward adds support for more of the NSS APIs; we can just say it needs getent as provided on glibc and musl systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good, removed the subcommand list.

In a container as set up by Podman there is no utmp file in (/var)/run.
When no file is present, we can return NULL and report the error which
applications normally would handle gracefully.
@pothos
Copy link
Contributor Author

pothos commented May 20, 2024

Thanks for the test! I've switched back to my initial version which was to set ENOENT. The man page also says: On failure, these functions errno set to indicate the error.

@sunfishcode
Copy link
Owner

Thanks!

@sunfishcode sunfishcode merged commit a479ab8 into sunfishcode:main May 20, 2024
5 checks passed
@sunfishcode
Copy link
Owner

This is now released in c-gull 0.16.1.

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.

2 participants