git: 8c121177f063 - main - casper: convert macros to inline functions

Mariusz Zaborski oshogbo at FreeBSD.org
Mon Jan 4 19:57:41 UTC 2021


The branch main has been updated by oshogbo:

URL: https://cgit.FreeBSD.org/src/commit/?id=8c121177f063a187534dcd475b136c34474802cd

commit 8c121177f063a187534dcd475b136c34474802cd
Author:     Mariusz Zaborski <oshogbo at FreeBSD.org>
AuthorDate: 2021-01-04 19:50:58 +0000
Commit:     Mariusz Zaborski <oshogbo at FreeBSD.org>
CommitDate: 2021-01-04 19:55:35 +0000

    casper: convert macros to inline functions
    
    In libcasper, the first argument to the function is a structure that
    represents a connection to Casper. On systems without Casper, macros
    are used to interpose the Casper functions to standard libc ones.
    This may cause errors/warnings that the variable is not used.
    With the inline function, there is no such problem.
---
 lib/libcasper/services/cap_pwd/cap_pwd.h       | 109 +++++++++++++++++++++----
 lib/libcasper/services/cap_sysctl/cap_sysctl.h |  65 ++++++++++++---
 2 files changed, 145 insertions(+), 29 deletions(-)

diff --git a/lib/libcasper/services/cap_pwd/cap_pwd.h b/lib/libcasper/services/cap_pwd/cap_pwd.h
index 74b9de098e2d..d8de56c3bea9 100644
--- a/lib/libcasper/services/cap_pwd/cap_pwd.h
+++ b/lib/libcasper/services/cap_pwd/cap_pwd.h
@@ -66,24 +66,97 @@ int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
 __END_DECLS
 
 #else
-#define	cap_getpwent(chan)		getpwent()
-#define	cap_getpwnam(chan, login)	getpwnam(login)
-#define	cap_getpwuid(chan, uid)		getpwuid(uid)
-
-#define	cap_getpwent_r(chan, pwd, buffer, bufsize, result)			\
-	getpwent_r(pwd, buffer, bufsize, result)
-#define	cap_getpwnam_r(chan, name, pwd, buffer, bufsize, result)		\
-	getpwnam_r(name, pwd, buffer, bufsize, result)
-#define	cap_getpwuid_r(chan, uid, pwd, buffer, bufsize, result)			\
-	getpwuid_r(uid, pwd, buffer, bufsize, result)
-
-#define	cap_setpassent(chan, stayopen)	setpassent(stayopen)
-#define	cap_setpwent(chan)		setpwent()
-#define	cap_endpwent(chan)		endpwent()
-
-#define	cap_pwd_limit_cmds(chan, cmds, ncmds)			(0)
-#define cap_pwd_limit_fields(chan, fields, nfields)		(0)
-#define cap_pwd_limit_users(chan, names, nnames, uids, nuids)	(0)
+
+static inline struct passwd *
+cap_getpwent(cap_channel_t *chan __unused)
+{
+
+	return (getpwent());
+}
+
+static inline struct passwd *
+cap_getpwnam(cap_channel_t *chan __unused, const char *login)
+{
+
+	return (getpwnam(login));
+}
+
+static inline struct passwd *
+cap_getpwuid(cap_channel_t *chan __unused, uid_t uid)
+{
+
+	return (getpwuid(uid));
+}
+
+static inline int
+cap_getpwent_r(cap_channel_t *chan __unused, struct passwd *pwd, char *buffer,
+    size_t bufsize, struct passwd **result)
+{
+
+	return (getpwent_r(pwd, buffer, bufsize, result));
+}
+
+static inline int
+cap_getpwnam_r(cap_channel_t *chan __unused, const char *name,
+    struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
+{
+
+	return (getpwnam_r(name, pwd, buffer, bufsize, result));
+}
+
+static inline int
+cap_getpwuid_r(cap_channel_t *chan __unused, uid_t uid, struct passwd *pwd,
+    char *buffer, size_t bufsize, struct passwd **result)
+{
+
+	return (getpwuid_r(uid, pwd, buffer, bufsize, result));
+}
+
+static inline int
+cap_setpassent(cap_channel_t *chan __unused, int stayopen)
+{
+
+	return (setpassent(stayopen));
+}
+
+static inline void
+cap_setpwent(cap_channel_t *chan __unused)
+{
+
+	return (setpwent());
+}
+
+static inline void
+cap_endpwent(cap_channel_t *chan __unused)
+{
+
+	return (endpwent());
+}
+
+static inline int
+cap_pwd_limit_cmds(cap_channel_t *chan __unused,
+    const char * const *cmds __unused, size_t ncmds __unused)
+{
+
+	return (0);
+}
+
+static inline int
+cap_pwd_limit_fields(cap_channel_t *chan __unused,
+    const char * const *fields __unused, size_t nfields __unused)
+{
+
+	return (0);
+}
+
+static inline int
+cap_pwd_limit_users(cap_channel_t *chan __unused,
+    const char * const *names __unused, size_t nnames __unused,
+    uid_t *uids __unused, size_t nuids __unused)
+{
+
+	return (0);
+}
 #endif
 
 #endif	/* !_CAP_PWD_H_ */
diff --git a/lib/libcasper/services/cap_sysctl/cap_sysctl.h b/lib/libcasper/services/cap_sysctl/cap_sysctl.h
index 226d7766a95e..df0fb7fd6f45 100644
--- a/lib/libcasper/services/cap_sysctl/cap_sysctl.h
+++ b/lib/libcasper/services/cap_sysctl/cap_sysctl.h
@@ -66,17 +66,60 @@ int cap_sysctl_limit(cap_sysctl_limit_t *limit);
 __END_DECLS
 
 #else /* !WITH_CASPER */
-#define	cap_sysctl(chan, name, namelen, oldp, oldlenp, newp, newlen)	\
-	sysctl((name), (namelen), (oldp), (oldlenp), (newp), (newlen))
-#define	cap_sysctlbyname(chan, name, oldp, oldlenp, newp, newlen)	\
-	sysctlbyname((name), (oldp), (oldlenp), (newp), (newlen))
-#define	cap_sysctlnametomib(chan, name, mibp, sizep)			\
-	sysctlnametomib((name), (mibp), (sizep))
-
-#define	cap_sysctl_limit_init(chan)				(NULL)
-#define	cap_sysctl_limit_name(limit, name, flags)		(NULL)
-#define	cap_sysctl_limit_mib(limit, mibp, miblen, flags)	(NULL)
-#define	cap_sysctl_limit(limit)					(0)
+static inline int
+cap_sysctl(cap_channel_t *chan __unused, const int *name, u_int namelen,
+    void *oldp, size_t *oldlenp, const void *newp, size_t newlen)
+{
+
+	return (sysctl(name, namelen, oldp, oldlenp, newp, newlen));
+}
+
+static inline int
+cap_sysctlbyname(cap_channel_t *chan __unused, const char *name,
+    void *oldp, size_t *oldlenp, const void *newp, size_t newlen)
+{
+
+	return (sysctlbyname(name, oldp, oldlenp, newp, newlen));
+}
+
+static inline int
+cap_sysctlnametomib(cap_channel_t *chan __unused, const char *name, int *mibp,
+    size_t *sizep)
+{
+
+	return (sysctlnametomib(name, mibp, sizep));
+}
+
+static inline cap_sysctl_limit_t *
+cap_sysctl_limit_init(cap_channel_t *limit __unused)
+{
+
+	return (NULL);
+}
+
+static inline cap_sysctl_limit_t *
+cap_sysctl_limit_name(cap_sysctl_limit_t *limit __unused,
+    const char *name __unused, int flags __unused)
+{
+
+	return (NULL);
+}
+
+static inline cap_sysctl_limit_t *
+cap_sysctl_limit_mib(cap_sysctl_limit_t *limit __unused,
+    const int *mibp __unused, u_int miblen __unused,
+    int flags __unused)
+{
+
+	return (NULL);
+}
+
+static inline int
+cap_sysctl_limit(cap_sysctl_limit_t *limit __unused)
+{
+
+	return (0);
+}
 #endif /* WITH_CASPER */
 
 #endif /* !_CAP_SYSCTL_H_ */


More information about the dev-commits-src-all mailing list