Skip to content

Commit

Permalink
Disable user name lookup in static builds against glibc
Browse files Browse the repository at this point in the history
Static linking against glibc might crash due to usage of NSS modules,
e.g. via getpwuid() (see htop-dev#503).
The linker also warns about it:

    warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  • Loading branch information
cgzones committed Aug 24, 2024
1 parent 2503239 commit 5d43d60
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UsersTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void UsersTable_delete(UsersTable* this) {
}

char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
#if !defined(BUILD_STATIC) || !defined(__GLIBC__)
char* name = Hashtable_get(this->users, uid);
if (name == NULL) {
const struct passwd* userData = getpwuid(uid);
Expand All @@ -39,6 +40,11 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
}
}
return name;
#else
(void)this;
(void)uid;
return NULL;
#endif
}

inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) {
Expand Down

0 comments on commit 5d43d60

Please sign in to comment.