mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 15:00:25 +01:00
nm-manager: remove lease file if copying dhclient lease fails
- also use nm_auto_close and nm_close().
This commit is contained in:
parent
ce1f9e6eb9
commit
0c6cd07ec8
1 changed files with 14 additions and 11 deletions
|
|
@ -2698,26 +2698,29 @@ get_existing_connection (NMManager *self,
|
||||||
static gboolean
|
static gboolean
|
||||||
copy_lease (const char *src, const char *dst)
|
copy_lease (const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
int src_fd, dst_fd;
|
nm_auto_close int src_fd = -1;
|
||||||
ssize_t res, size = SSIZE_MAX;
|
int dst_fd;
|
||||||
|
ssize_t res;
|
||||||
|
|
||||||
src_fd = open (src, O_RDONLY|O_CLOEXEC);
|
src_fd = open (src, O_RDONLY|O_CLOEXEC);
|
||||||
if (src_fd < 0)
|
if (src_fd < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
dst_fd = open (dst, O_CREAT|O_EXCL|O_CLOEXEC|O_WRONLY, 0644);
|
dst_fd = open (dst, O_CREAT|O_EXCL|O_CLOEXEC|O_WRONLY, 0644);
|
||||||
if (dst_fd < 0) {
|
if (dst_fd < 0)
|
||||||
close (src_fd);
|
return FALSE;
|
||||||
|
|
||||||
|
while ((res = sendfile (dst_fd, src_fd, NULL, G_MAXSSIZE)) > 0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
nm_close (dst_fd);
|
||||||
|
|
||||||
|
if (res != 0) {
|
||||||
|
unlink (dst);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((res = sendfile (dst_fd, src_fd, NULL, size)) > 0)
|
return TRUE;
|
||||||
size -= res;
|
|
||||||
|
|
||||||
close (src_fd);
|
|
||||||
close (dst_fd);
|
|
||||||
|
|
||||||
return !res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue