mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
build: don't hand-roll cloexec code
No need to repeat common code. * bootstrap.conf (gnulib_modules): Import calloc-posix. * src/util/bridge.c (brInit): Use virSetCloseExec. (brSetInterfaceUp): Adjust flags name. * src/uml/uml_driver.c (umlSetCloseExec): Delete. (umlStartVMDaemon): Use util version instead.
This commit is contained in:
parent
e17d3e7fe7
commit
ff98359d51
@ -27,6 +27,7 @@ byteswap
|
|||||||
c-ctype
|
c-ctype
|
||||||
c-strcase
|
c-strcase
|
||||||
c-strcasestr
|
c-strcasestr
|
||||||
|
calloc-posix
|
||||||
canonicalize-lgpl
|
canonicalize-lgpl
|
||||||
chown
|
chown
|
||||||
close
|
close
|
||||||
|
@ -114,19 +114,6 @@ static int umlOpenMonitor(struct uml_driver *driver,
|
|||||||
static int umlReadPidFile(struct uml_driver *driver,
|
static int umlReadPidFile(struct uml_driver *driver,
|
||||||
virDomainObjPtr vm);
|
virDomainObjPtr vm);
|
||||||
|
|
||||||
static int umlSetCloseExec(int fd) {
|
|
||||||
int flags;
|
|
||||||
if ((flags = fcntl(fd, F_GETFD)) < 0)
|
|
||||||
goto error;
|
|
||||||
flags |= FD_CLOEXEC;
|
|
||||||
if ((fcntl(fd, F_SETFD, flags)) < 0)
|
|
||||||
goto error;
|
|
||||||
return 0;
|
|
||||||
error:
|
|
||||||
VIR_ERROR(_("Failed to set close-on-exec file descriptor flag"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int umlStartVMDaemon(virConnectPtr conn,
|
static int umlStartVMDaemon(virConnectPtr conn,
|
||||||
struct uml_driver *driver,
|
struct uml_driver *driver,
|
||||||
virDomainObjPtr vm);
|
virDomainObjPtr vm);
|
||||||
@ -889,9 +876,9 @@ static int umlStartVMDaemon(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
VIR_FREE(logfile);
|
VIR_FREE(logfile);
|
||||||
|
|
||||||
if (umlSetCloseExec(logfd) < 0) {
|
if (virSetCloseExec(logfd) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno, "%s",
|
||||||
"%s", _("Unable to set VM logfile close-on-exec flag"));
|
_("Unable to set VM logfile close-on-exec flag"));
|
||||||
VIR_FORCE_CLOSE(logfd);
|
VIR_FORCE_CLOSE(logfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -72,25 +72,16 @@ int
|
|||||||
brInit(brControl **ctlp)
|
brInit(brControl **ctlp)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int flags;
|
|
||||||
|
|
||||||
if (!ctlp || *ctlp)
|
if (!ctlp || *ctlp)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (fd < 0)
|
if (fd < 0 ||
|
||||||
|
virSetCloseExec(fd) < 0 ||
|
||||||
|
VIR_ALLOC(*ctlp) < 0) {
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
if ((flags = fcntl(fd, F_GETFD)) < 0 ||
|
|
||||||
fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
|
|
||||||
int err = errno;
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(*ctlp) < 0) {
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*ctlp)->fd = fd;
|
(*ctlp)->fd = fd;
|
||||||
@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl,
|
|||||||
int up)
|
int up)
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int flags;
|
int ifflags;
|
||||||
|
|
||||||
if (!ctl || !ifname)
|
if (!ctl || !ifname)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@ -612,10 +603,10 @@ brSetInterfaceUp(brControl *ctl,
|
|||||||
if (ioctl(ctl->fd, SIOCGIFFLAGS, &ifr) < 0)
|
if (ioctl(ctl->fd, SIOCGIFFLAGS, &ifr) < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
flags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP);
|
ifflags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP);
|
||||||
|
|
||||||
if (ifr.ifr_flags != flags) {
|
if (ifr.ifr_flags != ifflags) {
|
||||||
ifr.ifr_flags = flags;
|
ifr.ifr_flags = ifflags;
|
||||||
|
|
||||||
if (ioctl(ctl->fd, SIOCSIFFLAGS, &ifr) < 0)
|
if (ioctl(ctl->fd, SIOCSIFFLAGS, &ifr) < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user