Navigation Menu

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 building on Android by avoiding getpwent() #3441

Merged
merged 4 commits into from Oct 16, 2016
Merged

Fix building on Android by avoiding getpwent() #3441

merged 4 commits into from Oct 16, 2016

Conversation

fornwall
Copy link
Contributor

The getpwent() function does not link when building for Android, and user names on that platform are not interesting anyway.

This patch is part of an effort to upstream patches used by the fish package in Termux.

The getpwent() function does not link when building for Android,
and user names on that platform are not interesting anyway.
Copy link
Member

@floam floam left a comment

Choose a reason for hiding this comment

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

I don't really like the "return 0" thing going on here - and there still should be usernames on Android, interesting or not. I'd like if you checked getpwent linkability in autoconf and provided a workaround of some sort, if practical.

@@ -1187,6 +1187,10 @@ bool completer_t::try_complete_variable(const wcstring &str) {
///
/// \return 0 if unable to complete, 1 otherwise
bool completer_t::try_complete_user(const wcstring &str) {
#ifdef __ANDROID__
// The getpwent() call does not exist on Android (and user names are not interesting).
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is strictly speaking correct and functionally equivalent to return false; please do the latter for clarity. Having said that, I agree with @floam that since Android is derived from Linux it presumably does utilize UIDs and we should therefore be returning something meaningful on that platform if that is possible. If everything doesn't run as UID zero, and there is no other way to map a UID to name, perhaps this should simply synthesize a user name by doing something like return sprintf(buf, "user#%d", getuid());. That is obviously just pseudo-code but you get the idea.

@fornwall
Copy link
Contributor Author

Thanks a lot for the feedback! I've updated from return 0 to return false.

As for a fallback, a Linux user on Android isn't really a user - each installed app gets an UID assigned. Listing all UID:s is not possible without root access, and doing a ~USER type expansion does not make sense since every app is sandboxed and can't access eachother. So I think a fallback is not really possible.

As for an autoconf check if getpwent links instead of ifdef __ANDROID__: Sounds reasonable, can do that after we settle for the fallback behaviour.

@krader1961
Copy link
Contributor

Okay, given that in Android OS there really isn't any such thing as usernames I'm okay with just returning false for that completer. Go ahead and make the behavior dependent on whether there is a usable getpwent() and I think you're done.

@floam
Copy link
Member

floam commented Oct 13, 2016

I found this stuff interesting:

http://androidxref.com/4.2.2_r1/xref/bionic/libc/docs/OVERVIEW.TXT#231

http://androidxref.com/5.0.0_r2/xref/bionic/libc/bionic/stubs.cpp#357

Maybe we could do similar. There are some mappings defined in a header file as well.

@krader1961
Copy link
Contributor

For the record I would prefer an autoconf check for whether getpwent() exists. But if that is impractical for some reason the current implementation is acceptable.

@floam
Copy link
Member

floam commented Oct 16, 2016

Great, we can merge this.

@fornwall
Copy link
Contributor Author

@krader1961 Changed it to an autoconf check instead of ifdef __ANDROID__.

I've left the Android-specific comments for now as it's the only relevant platform I know about lacking getpwent() - let me know if those comments should be removed/changed!

@floam floam merged commit fe8727f into fish-shell:master Oct 16, 2016
@floam floam added the release notes Something that is or should be mentioned in the release notes label Oct 16, 2016
@zanchey zanchey added this to the fish 2.4.0 milestone Oct 16, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release notes Something that is or should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants