libc: Make various internal file descriptors from fopen() close-on-exec.

This commit is contained in:
Jilles Tjoelker 2013-08-23 13:59:47 +00:00
parent e77c507d60
commit a93705b06e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=254700
13 changed files with 21 additions and 21 deletions

View File

@ -148,7 +148,7 @@ ether_ntohost(char *hostname, const struct ether_addr *e)
char *yp_domain;
#endif
if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
if ((fp = fopen(_PATH_ETHERS, "re")) == NULL)
return (1);
while (fgets(buf,BUFSIZ,fp)) {
if (buf[0] == '#')
@ -197,7 +197,7 @@ ether_hostton(const char *hostname, struct ether_addr *e)
char *yp_domain;
#endif
if ((fp = fopen(_PATH_ETHERS, "r")) == NULL)
if ((fp = fopen(_PATH_ETHERS, "re")) == NULL)
return (1);
while (fgets(buf,BUFSIZ,fp)) {
if (buf[0] == '#')

View File

@ -227,7 +227,7 @@ eui64_ntohost(char *hostname, size_t len, const struct eui64 *id)
char eui64_a[24];
char *yp_domain;
#endif
if ((fp = fopen(_PATH_EUI64, "r")) == NULL)
if ((fp = fopen(_PATH_EUI64, "re")) == NULL)
return (1);
while (fgets(buf,BUFSIZ,fp)) {
@ -277,7 +277,7 @@ eui64_hostton(const char *hostname, struct eui64 *id)
int resultlen;
char *yp_domain;
#endif
if ((fp = fopen(_PATH_EUI64, "r")) == NULL)
if ((fp = fopen(_PATH_EUI64, "re")) == NULL)
return (1);
while (fgets(buf,BUFSIZ,fp)) {

View File

@ -2240,7 +2240,7 @@ static void
_sethtent(FILE **hostf)
{
if (!*hostf)
*hostf = fopen(_PATH_HOSTS, "r");
*hostf = fopen(_PATH_HOSTS, "re");
else
rewind(*hostf);
}
@ -2264,7 +2264,7 @@ _gethtent(FILE **hostf, const char *name, const struct addrinfo *pai)
const char *addr;
char hostbuf[8*1024];
if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r")))
if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "re")))
return (NULL);
again:
if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf)))

View File

@ -72,7 +72,7 @@ void
_sethosthtent(int f, struct hostent_data *hed)
{
if (!hed->hostf)
hed->hostf = fopen(_PATH_HOSTS, "r");
hed->hostf = fopen(_PATH_HOSTS, "re");
else
rewind(hed->hostf);
hed->stayopen = f;
@ -96,7 +96,7 @@ gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped,
int af, len;
char hostbuf[BUFSIZ + 1];
if (!hed->hostf && !(hed->hostf = fopen(_PATH_HOSTS, "r"))) {
if (!hed->hostf && !(hed->hostf = fopen(_PATH_HOSTS, "re"))) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
return (-1);
}

View File

@ -63,7 +63,7 @@ _setnethtent(int f, struct netent_data *ned)
{
if (ned->netf == NULL)
ned->netf = fopen(_PATH_NETWORKS, "r");
ned->netf = fopen(_PATH_NETWORKS, "re");
else
rewind(ned->netf);
ned->stayopen |= f;
@ -89,7 +89,7 @@ getnetent_p(struct netent *ne, struct netent_data *ned)
char line[BUFSIZ + 1];
if (ned->netf == NULL &&
(ned->netf = fopen(_PATH_NETWORKS, "r")) == NULL)
(ned->netf = fopen(_PATH_NETWORKS, "re")) == NULL)
return (-1);
again:
p = fgets(line, sizeof line, ned->netf);

View File

@ -342,7 +342,7 @@ void
__setprotoent_p(int f, struct protoent_data *ped)
{
if (ped->fp == NULL)
ped->fp = fopen(_PATH_PROTOCOLS, "r");
ped->fp = fopen(_PATH_PROTOCOLS, "re");
else
rewind(ped->fp);
ped->stayopen |= f;
@ -365,7 +365,7 @@ __getprotoent_p(struct protoent *pe, struct protoent_data *ped)
char *cp, **q, *endp;
long l;
if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL)
if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "re")) == NULL)
return (-1);
again:
if ((p = fgets(ped->line, sizeof ped->line, ped->fp)) == NULL)

View File

@ -335,7 +335,7 @@ files_servent(void *retval, void *mdata, va_list ap)
if (st->fp == NULL)
st->compat_mode_active = 0;
if (st->fp == NULL && (st->fp = fopen(_PATH_SERVICES, "r")) == NULL) {
if (st->fp == NULL && (st->fp = fopen(_PATH_SERVICES, "re")) == NULL) {
*errnop = errno;
return (NS_UNAVAIL);
}
@ -449,7 +449,7 @@ files_setservent(void *retval, void *mdata, va_list ap)
case SETSERVENT:
f = va_arg(ap,int);
if (st->fp == NULL)
st->fp = fopen(_PATH_SERVICES, "r");
st->fp = fopen(_PATH_SERVICES, "re");
else
rewind(st->fp);
st->stayopen |= f;

View File

@ -286,7 +286,7 @@ read_config_file(ctx, filename)
ctx->classes[1] = C_HS;
/* Try to open the configuration file. */
fp = fopen(filename, "r");
fp = fopen(filename, "re");
if (!fp) {
/* Use compiled in default domain names. */
ctx->lhs = strdup(DEF_LHS);

View File

@ -361,7 +361,7 @@ nss_configure(void)
if (result != 0)
goto fin2;
}
_nsyyin = fopen(path, "r");
_nsyyin = fopen(path, "re");
if (_nsyyin == NULL)
goto fin;
VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap),

View File

@ -458,7 +458,7 @@ iruserok_sa(ra, rlen, superuser, ruser, luser)
raddr = (struct sockaddr *)&ss;
first = 1;
hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "re");
again:
if (hostf) {
if (__ivaliduser_sa(hostf, raddr, rlen, luser, ruser) == 0) {
@ -481,7 +481,7 @@ iruserok_sa(ra, rlen, superuser, ruser, luser)
*/
uid = geteuid();
(void)seteuid(pwd->pw_uid);
hostf = fopen(pbuf, "r");
hostf = fopen(pbuf, "re");
(void)seteuid(uid);
if (hostf == NULL)

View File

@ -179,7 +179,7 @@ mac_init_internal(int ignore_errors)
filename = getenv("MAC_CONFFILE");
else
filename = MAC_CONFFILE;
file = fopen(filename, "r");
file = fopen(filename, "re");
if (file == NULL)
return (0);

View File

@ -304,7 +304,7 @@ __res_vinit(res_state statp, int preinit) {
line[sizeof(name) - 1] == '\t'))
nserv = 0;
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) {
/* read the config file */
while (fgets(buf, sizeof(buf), fp) != NULL) {
/* skip comments */

View File

@ -457,7 +457,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
if (issetugid())
return (NULL);
file = getenv("HOSTALIASES");
if (file == NULL || (fp = fopen(file, "r")) == NULL)
if (file == NULL || (fp = fopen(file, "re")) == NULL)
return (NULL);
setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';