Project:Toolchain/Glibc 2.26 porting notes/RPC implementation
This page provides a guideline and example code snippets to port packages away from SunRPC - necessary for everything listed in tracker bug #381391. The snippets are taken from the first package on the tracker that I encountered, net-analyzer/dsniff, from which I prepared a reference implementation in my overlay.
SunRPC is optional in glibc-2.25 and earlier (use-flag rpc) and removed in glibc-2.26 and later. Note that glibc-2.26 will go stable soon.
Two strategies are possible:
- either switch your package already now to hard-require libtirpc,
- or make the RPC implementation controllable via a use-flag
libtirpc, as discussed in detail below.
For applications (leaf packages), a hard switch may make more sense. For libraries a controllable implementation is more useful (since things may explode when different object files linked into the same application use different implementations).
If RPC support is optional, please use a use-flag
rpc to enable / disable it entirely.
For switching between implementations, please use
- if unset, use glibc's SunRPC,
- if set, pull in net-lib/libtirpc.
It makes sense to default this flag to "on", for two reasons:
- libtirpc is the more modern and likely faster implementation
- libtirpc works independent of the installed glibc, while SunRPC will go away with glibc-2.26.
!libtirpc? ( elibc_glibc? ( sys-libs/glibc[rpc(-)] ) ) libtirpc? ( net-libs/libtirpc ) net-libs/rpcsvc-proto
Depending on the package you may need net-libs/rpcsvc-proto or not. It provides the rpcgen binary and some header files. If you need those, you can safely depend on net-libs/rpcsvc-proto unconditionally.
Patching the build system
Here's an example
configure.ac snippet for providing switchable RPC implementation:
AC_ARG_WITH([libtirpc], [AS_HELP_STRING([--with-libtirpc], [Use libtirpc as RPC implementation (instead of sunrpc)])]) AS_IF([test "x$with_libtirpc" = xyes], [PKG_CHECK_MODULES([TIRPC], [libtirpc], [RPC_CFLAGS=$TIRPC_CFLAGS; RPC_LIBS=$TIRPC_LIBS;], [AC_MSG_ERROR([libtirpc requested, but library not found.])] )], [AC_CHECK_HEADER(rpc/rpc.h, [RPC_CFLAGS=""; RPC_LIBS="";], [AC_MSG_ERROR([sunrpc requested, but headers are not present.])] )] ) AC_SUBST(RPC_CFLAGS) AC_SUBST(RPC_LIBS)
And here is a corresponding
Makefile.in example snippet:
INCS = -I. @RPC_CFLAGS@ LIBS = @LIBS@ -L$(srcdir) @RPC_LIBS@
(When automake is used, you may want to patch
econf $(use_with libtirpc)