mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-01 18:32:05 +00:00
libselinux: Ensure that we only close the selinux netlink socket once.
Taken from our Android libselinux tree. From Stephen Smalley. Signed-off-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
parent
a8a36f88c2
commit
1c8a7c194d
@ -53,7 +53,7 @@ int avc_setenforce = 0;
|
|||||||
int avc_netlink_trouble = 0;
|
int avc_netlink_trouble = 0;
|
||||||
|
|
||||||
/* netlink socket code */
|
/* netlink socket code */
|
||||||
static int fd;
|
static int fd = -1;
|
||||||
|
|
||||||
int avc_netlink_open(int blocking)
|
int avc_netlink_open(int blocking)
|
||||||
{
|
{
|
||||||
@ -69,6 +69,7 @@ int avc_netlink_open(int blocking)
|
|||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
if (!blocking && fcntl(fd, F_SETFL, O_NONBLOCK)) {
|
if (!blocking && fcntl(fd, F_SETFL, O_NONBLOCK)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -81,6 +82,7 @@ int avc_netlink_open(int blocking)
|
|||||||
|
|
||||||
if (bind(fd, (struct sockaddr *)&addr, len) < 0) {
|
if (bind(fd, (struct sockaddr *)&addr, len) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -90,7 +92,9 @@ int avc_netlink_open(int blocking)
|
|||||||
|
|
||||||
void avc_netlink_close(void)
|
void avc_netlink_close(void)
|
||||||
{
|
{
|
||||||
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avc_netlink_receive(char *buf, unsigned buflen, int blocking)
|
static int avc_netlink_receive(char *buf, unsigned buflen, int blocking)
|
||||||
@ -269,6 +273,7 @@ void avc_netlink_loop(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
avc_netlink_trouble = 1;
|
avc_netlink_trouble = 1;
|
||||||
avc_log(SELINUX_ERROR,
|
avc_log(SELINUX_ERROR,
|
||||||
"%s: netlink thread: errors encountered, terminating\n",
|
"%s: netlink thread: errors encountered, terminating\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user