-static int
-safe_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
-{
- int rv, sv_errno=0;
-
- if (seteuid(0)) /* iterator needs root write access to sysctl */
- err(1, "seteuid(0) failed");
-
- rv = sysctlbyname(name, oldp, oldlenp, newp, newlen);
- if (rv < 0)
- sv_errno = errno;
-
- if (seteuid(getuid()))
- err(1, "seteuid(%d) failed", getuid());
-
- if (rv < 0)
- errno = sv_errno;
- return rv;
-}
-