summaryrefslogtreecommitdiff
path: root/libparted/arch/linux.c
diff options
context:
space:
mode:
authorBrian C. Lane <bcl@redhat.com>2017-05-25 09:42:23 -0700
committerBrian C. Lane <bcl@redhat.com>2017-05-25 10:19:02 -0700
commite7870afe3c13dcc77845d48409daa35e3e42b5fb (patch)
treecb6c6da66abc5a5152c533d17593c638fa69ecf9 /libparted/arch/linux.c
parent8d149b24eb2789fdf00743ef735e0cffde598040 (diff)
downloadparted-e7870afe3c13dcc77845d48409daa35e3e42b5fb.tar.gz
libparted: Fix udev cookie leak in _dm_resize_partition
The function is setting udev cookies, but not using them when waiting for the task. This results in leaked cookies, which can eventually exhaust the available number of semaphores. 'dmsetup udevcookies' will show a cookie remaining afterwards, and 'ipcs -s' will show the semaphores in use. Also simplified the exit so that the task is always destroyed and memory is all freed in the same path. Resolves: rhbz#1455564
Diffstat (limited to 'libparted/arch/linux.c')
-rw-r--r--libparted/arch/linux.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 9886d6e..1a35964 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2943,6 +2943,7 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
char* vol_name = NULL;
const char* dev_name = NULL;
uint32_t cookie = 0;
+ int rc = 0;
/* Get map name from devicemapper */
struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
@@ -2983,8 +2984,9 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
/* device-mapper uses 512b units, not the device's sector size */
dm_task_add_target (task, 0, part->geom.length * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT),
"linear", params);
- if (!dm_task_set_cookie (task, &cookie, 0))
- goto err;
+ /* NOTE: DM_DEVICE_RELOAD doesn't generate udev events, so no cookie is needed (it will freeze).
+ * DM_DEVICE_RESUME does, so get a cookie and synchronize with udev.
+ */
if (dm_task_run (task)) {
dm_task_destroy (task);
task = dm_task_create (DM_DEVICE_RESUME);
@@ -2993,10 +2995,8 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
dm_task_set_name (task, vol_name);
if (!dm_task_set_cookie (task, &cookie, 0))
goto err;
- if (dm_task_run (task)) {
- free (params);
- free (vol_name);
- return 1;
+ if (_dm_task_run_wait (task, cookie)) {
+ rc = 1;
}
}
err:
@@ -3005,7 +3005,7 @@ err:
dm_task_destroy (task);
free (params);
free (vol_name);
- return 0;
+ return rc;
}
#endif