This is a small library replacing the setusershell()
, getusershell()
and endusershell()
functions of glibc with a variant, which uses libeconf to read the valid shells following the
Configuration Files Specification of the
Linux Userspace API Group.
usershell_econf requires libeconf in version 0.4.9 or newer and meson version 0.58 or newer.
Building with meson is quite simple:
$ meson setup build
$ meson compile -C build
$ meson test -C build
If you want to build with the address sanitizer enabled, add
-Db_sanitize=address
as an argument to meson setup build
.
$ sudo meson install -C build
There are two ways to use the new functions:
The glibc functions can be replaced without further code changes by additionally linking the application against libusershell_econf
. It is important that the linker does not optimize away the library, this can happen if e.g. as-needed
is used for linking.
To avoid problems, it's recommended to modify the applications source code and exchange all function calls by appending _econf
to them:
- setusershell() -> setusershell_econf()
- getusershell() -> getusershell_econf()
- endusershell() -> endusershell_econf()
Additional you need to include an additional header file:
#include <usershell_econf.h>
and link against libusershell_econf
.
Example code:
...
#include <usershell_econf.h>
...
int
main (void)
{
char *shell;
...
setusershell_econf ();
while ((shell = getusershell_econf ()) != NULL)
printf ("[%s]\n", shell);
endusershell_econf ();
...
}
See the file COPYING for full text and copying restrictions.