libc: Use namespace.h in a few more files.

libc now no longer calls fstat(), socketpair() and wait(), only the
underscore-prefixed versions (_waitpid() instead of wait()).
This commit is contained in:
jilles 2015-12-20 23:05:20 +00:00
parent d49c59ad67
commit 0acd4707c2
4 changed files with 19 additions and 11 deletions

View File

@ -27,6 +27,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ucred.h>
@ -34,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <unistd.h>
#include "un-namespace.h"
int
getpeereid(int s, uid_t *euid, gid_t *egid)
@ -43,7 +45,7 @@ getpeereid(int s, uid_t *euid, gid_t *egid)
int error;
xuclen = sizeof(xuc);
error = getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen);
error = _getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen);
if (error != 0)
return (error);
if (xuc.cr_version != XUCRED_VERSION)

View File

@ -36,6 +36,7 @@ static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/param.h>
#include <sys/time.h>
#include <sys/sysctl.h>
@ -49,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <pthread.h> /* we just need the limits */
#include <time.h>
#include <unistd.h>
#include "un-namespace.h"
#include "../stdlib/atexit.h"
#include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */
@ -575,10 +577,10 @@ sysconf(int name)
case _SC_IPV6:
#if _POSIX_IPV6 == 0
sverrno = errno;
value = socket(PF_INET6, SOCK_DGRAM, 0);
value = _socket(PF_INET6, SOCK_DGRAM, 0);
errno = sverrno;
if (value >= 0) {
close(value);
_close(value);
return (200112L);
} else
return (0);

View File

@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
#include "namespace.h"
#include <sys/cdefs.h>
#include <sys/mman.h>
#include <sys/types.h>
@ -40,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "un-namespace.h"
#include "citrus_namespace.h"
#include "citrus_region.h"
@ -57,10 +59,10 @@ _citrus_map_file(struct _citrus_region * __restrict r,
_region_init(r, NULL, 0);
if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1)
if ((fd = _open(path, O_RDONLY | O_CLOEXEC)) == -1)
return (errno);
if (fstat(fd, &st) == -1) {
if (_fstat(fd, &st) == -1) {
ret = errno;
goto error;
}
@ -78,7 +80,7 @@ _citrus_map_file(struct _citrus_region * __restrict r,
_region_init(r, head, (size_t)st.st_size);
error:
(void)close(fd);
(void)_close(fd);
return (ret);
}

View File

@ -36,6 +36,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
@ -48,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "un-namespace.h"
/*
* This is a replacement rcmd() function that uses the rsh(1)
@ -99,7 +101,7 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser,
}
/* Get a socketpair we'll use for stdin and stdout. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) {
if (_socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) {
perror("rcmdsh: socketpair");
return (-1);
}
@ -112,8 +114,8 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser,
/*
* Child. We use sp[1] to be stdin/stdout, and close sp[0].
*/
(void)close(sp[0]);
if (dup2(sp[1], 0) == -1 || dup2(0, 1) == -1) {
(void)_close(sp[0]);
if (_dup2(sp[1], 0) == -1 || _dup2(0, 1) == -1) {
perror("rcmdsh: dup2 failed");
_exit(255);
}
@ -156,9 +158,9 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser,
_exit(255);
} else {
/* Parent. close sp[1], return sp[0]. */
(void)close(sp[1]);
(void)_close(sp[1]);
/* Reap child. */
(void)wait(NULL);
(void)_waitpid(cpid, NULL, 0);
return (sp[0]);
}
/* NOTREACHED */