X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fswap.c;h=5de6ba61c718927779c0a8f769d53191b58d5c95;hp=67d553ae1b256da42ce16a9e99a9ca0d65904958;hb=4f6bd18d2e2a9c1d317a07b59072579d8fff42ac;hpb=9e0b31a2af26b8d58a44dd80993a5e73d4942307 diff --git a/daemon/swap.c b/daemon/swap.c index 67d553a..5de6ba6 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -28,6 +28,9 @@ #include "actions.h" #include "optgroups.h" +/* Confirmed this is true for Linux swap partitions from the Linux sources. */ +#define SWAP_LABEL_MAX 16 + /* Convenient place to test for the later version of e2fsprogs * and util-linux which supports -U parameters to specify UUIDs. * (Not supported in RHEL 5). @@ -77,6 +80,12 @@ do_mkswap (const char *device) int do_mkswap_L (const char *label, const char *device) { + if (strlen (label) > SWAP_LABEL_MAX) { + reply_with_error ("%s: Linux swap labels are limited to %d bytes", + label, SWAP_LABEL_MAX); + return -1; + } + return mkswap (device, "-L", label); } @@ -122,6 +131,11 @@ swaponoff (const char *cmd, const char *flag, const char *value) free (err); + /* Possible fix for RHBZ#516096. It probably doesn't hurt to do + * this in any case. + */ + udev_settle (); + return 0; } @@ -174,12 +188,24 @@ do_swapoff_file (const char *path) int do_swapon_label (const char *label) { + if (strlen (label) > SWAP_LABEL_MAX) { + reply_with_error ("%s: Linux swap labels are limited to %d bytes", + label, SWAP_LABEL_MAX); + return -1; + } + return swaponoff ("swapon", "-L", label); } int do_swapoff_label (const char *label) { + if (strlen (label) > SWAP_LABEL_MAX) { + reply_with_error ("%s: Linux swap labels are limited to %d bytes", + label, SWAP_LABEL_MAX); + return -1; + } + return swaponoff ("swapoff", "-L", label); }