From: Olivier Brunel Date: Sat, 13 Oct 2012 12:24:15 +0000 (+0200) Subject: swap: fix swap behaviour with symlinks X-Git-Tag: v196~184 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=b61e88162a6ce0c30da6984b0120959701283daa;hp=646134dc0d09bd74834aecfbd9a742e2a7069ec7 swap: fix swap behaviour with symlinks Starting a swap unit pointing to (What) a symlink (e.g. /dev/mapper/swap or /dev/disk/by-uuid/...) would have said unit marked active, following the one using the "actual" device (/dev/{dm-1,sda3}), but that new unit would be seen as inactive. Since all requests to stop swap units would follow/redirect to it, and it is seen inactive, nothing would be done (swapoff never called). This is because this unit would be treated twice in swap_process_new_swap, the second call to swap_add_one causing it to eventually be marked inactive. --- diff --git a/src/core/swap.c b/src/core/swap.c index 206bd939c..97145a997 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -427,7 +427,8 @@ static int swap_process_new_swap(Manager *m, const char *device, int prio, bool return log_oom(); dn = udev_device_get_devnode(d); - if (dn) + /* Skip dn==device, since that case will be handled below */ + if (dn && !streq(dn, device)) r = swap_add_one(m, dn, device, prio, false, false, set_flags); /* Add additional units for all symlinks */