libkvm: Use O_CLOEXEC instead of separate fcntl(F_SETFD) call.
MFC after: 1 week
This commit is contained in:
parent
4136c09143
commit
76dce67f0f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=250230
@ -166,7 +166,7 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, int flag, char *errout)
|
|||||||
if (mf == 0)
|
if (mf == 0)
|
||||||
mf = _PATH_MEM;
|
mf = _PATH_MEM;
|
||||||
|
|
||||||
if ((kd->pmfd = open(mf, flag, 0)) < 0) {
|
if ((kd->pmfd = open(mf, flag | O_CLOEXEC, 0)) < 0) {
|
||||||
_kvm_syserr(kd, kd->program, "%s", mf);
|
_kvm_syserr(kd, kd->program, "%s", mf);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -179,10 +179,6 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, int flag, char *errout)
|
|||||||
_kvm_syserr(kd, kd->program, "empty file");
|
_kvm_syserr(kd, kd->program, "empty file");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (fcntl(kd->pmfd, F_SETFD, FD_CLOEXEC) < 0) {
|
|
||||||
_kvm_syserr(kd, kd->program, "%s", mf);
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
if (S_ISCHR(st.st_mode)) {
|
if (S_ISCHR(st.st_mode)) {
|
||||||
/*
|
/*
|
||||||
* If this is a character special device, then check that
|
* If this is a character special device, then check that
|
||||||
@ -194,11 +190,8 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, int flag, char *errout)
|
|||||||
kd->vmfd = open(_PATH_DEVNULL, O_RDONLY);
|
kd->vmfd = open(_PATH_DEVNULL, O_RDONLY);
|
||||||
return (kd);
|
return (kd);
|
||||||
} else if (strcmp(mf, _PATH_MEM) == 0) {
|
} else if (strcmp(mf, _PATH_MEM) == 0) {
|
||||||
if ((kd->vmfd = open(_PATH_KMEM, flag)) < 0) {
|
if ((kd->vmfd = open(_PATH_KMEM, flag | O_CLOEXEC)) <
|
||||||
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
|
0) {
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
if (fcntl(kd->vmfd, F_SETFD, FD_CLOEXEC) < 0) {
|
|
||||||
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
|
_kvm_syserr(kd, kd->program, "%s", _PATH_KMEM);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -210,11 +203,7 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, int flag, char *errout)
|
|||||||
* Initialize the virtual address translation machinery,
|
* Initialize the virtual address translation machinery,
|
||||||
* but first setup the namelist fd.
|
* but first setup the namelist fd.
|
||||||
*/
|
*/
|
||||||
if ((kd->nlfd = open(uf, O_RDONLY, 0)) < 0) {
|
if ((kd->nlfd = open(uf, O_RDONLY | O_CLOEXEC, 0)) < 0) {
|
||||||
_kvm_syserr(kd, kd->program, "%s", uf);
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
if (fcntl(kd->nlfd, F_SETFD, FD_CLOEXEC) < 0) {
|
|
||||||
_kvm_syserr(kd, kd->program, "%s", uf);
|
_kvm_syserr(kd, kd->program, "%s", uf);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user