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

Adjust logic for compat shims. #11

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions compat/getgrent_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* Copyright © 2015 Kevin Bowling <k@kev009.com>
*/

#include <sys/param.h>

#ifdef BSD
// This compat layer is only built for BSD, or Linux without the GNU C
// Library.
#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__))

#include <grp.h>
#include <stddef.h>
Expand All @@ -37,6 +37,16 @@
#include <errno.h>
#include <string.h>

#if defined(BSD)
#include <sys/param.h>
#else
// This branch is necessarily Linux and not GNU because of the checks
// defined above that guard the rest of the compat layer. On Linux we
// don't pull in param.h as it is very obsolete.
#include <stdint.h>
#define ALIGNBYTES _Alignof(max_align_t)
Copy link
Contributor

Choose a reason for hiding this comment

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

This type requires C11 which isn't a real problem but the symbols might not be visible depending on the system. What do you think about removing the ifdefs and param.h include altogether and doing this:

#define ALIGNBYTES (sizeof(uintptr_t) - 1)

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 had considered the C11 issue when drafting this patch but thought it shouldn't be an issue on FreeBSD or most modern *nix's. I'm all for removing param.h dependencies, so if you are confident that changing from the _Alignof won't affect any currently working target I'd say go ahead and send the PR.

#define ALIGN(p)(((uintptr_t)(p) + ALIGNBYTES & ~ALIGNBYTES))
#endif // defined(BSD)
static unsigned atou(char **s)
{
unsigned x;
Expand Down Expand Up @@ -104,5 +114,4 @@ int fgetgrent_r(FILE *f, struct group *gr, char *line, size_t size, struct group
if(rv) errno = rv;
return rv;
}

#endif // ifdef BSD
#endif //#if defined(BSD) || defined(__LINUX__) && !defined(__GLIBC__)
9 changes: 4 additions & 5 deletions compat/getpwent_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* Copyright © 2015 Kevin Bowling <k@kev009.com>
*/

#include <sys/param.h>

#ifdef BSD
// This compat layer is only built for BSD, or Linux without the GNU C
// Library.
#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__))

#include <pwd.h>
#include <stdio.h>
Expand Down Expand Up @@ -83,5 +83,4 @@ int fgetpwent_r(FILE *f, struct passwd *pw, char *line, size_t size, struct pass
if (rv) errno = rv;
return rv;
}

#endif // ifdef BSD
#endif //#if defined(BSD) || defined(__LINUX__) && !defined(__GLIBC__)
11 changes: 8 additions & 3 deletions nss_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,10 @@ enum nss_status _nss_cache_getgrnam_r(const char *name, struct group *result,
//
// Routines for shadow map defined here.
//
#ifndef BSD
#if defined(__LINUX__) && defined(__GLIBC__)
// This is only built on GLIBC as caching the shadow file is generally
// not permissable from the perspective of other libc's, so the
// symbols are simply unused in those environments.

// _nss_cache_setspent_path()
// Helper function for testing
Expand Down Expand Up @@ -915,6 +918,8 @@ enum nss_status _nss_cache_getspnam_r(const char *name, struct spwd *result,

return ret;
}
#else
#endif

#ifdef BSD
#include "bsdnss.c"
#endif // ifndef BSD
#endif // #if defined(__LINUX__) && defined(__GLIBC__)