* util/getroot.c (grub_util_is_imsm): Fix descriptor and
memory leak.
This commit is contained in:
parent
dea55e2a95
commit
5e7d94641b
2 changed files with 20 additions and 14 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-08-14 Andrey Borzenkov <arvidjaar@gmail.com>
|
||||||
|
|
||||||
|
* util/getroot.c (grub_util_is_imsm): Fix descriptor and
|
||||||
|
memory leak.
|
||||||
|
|
||||||
2013-08-14 Andrey Borzenkov <arvidjaar@gmail.com>
|
2013-08-14 Andrey Borzenkov <arvidjaar@gmail.com>
|
||||||
|
|
||||||
* util/getroot.c (pull_lvm_by_command): add --separator option
|
* util/getroot.c (pull_lvm_by_command): add --separator option
|
||||||
|
|
|
@ -1461,10 +1461,12 @@ out:
|
||||||
static int
|
static int
|
||||||
grub_util_is_imsm (const char *os_dev)
|
grub_util_is_imsm (const char *os_dev)
|
||||||
{
|
{
|
||||||
int try;
|
int retry;
|
||||||
|
int is_imsm = 0;
|
||||||
|
int container_seen = 0;
|
||||||
const char *dev = os_dev;
|
const char *dev = os_dev;
|
||||||
|
|
||||||
for (try = 0; try < 2; try++)
|
do
|
||||||
{
|
{
|
||||||
char *argv[5];
|
char *argv[5];
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -1473,6 +1475,8 @@ grub_util_is_imsm (const char *os_dev)
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
|
retry = 0; /* We'll do one more pass if device is part of container */
|
||||||
|
|
||||||
/* execvp has inconvenient types, hence the casts. None of these
|
/* execvp has inconvenient types, hence the casts. None of these
|
||||||
strings will actually be modified. */
|
strings will actually be modified. */
|
||||||
argv[0] = (char *) "mdadm";
|
argv[0] = (char *) "mdadm";
|
||||||
|
@ -1505,7 +1509,8 @@ grub_util_is_imsm (const char *os_dev)
|
||||||
|
|
||||||
while (getline (&buf, &len, mdadm) > 0)
|
while (getline (&buf, &len, mdadm) > 0)
|
||||||
{
|
{
|
||||||
if (strncmp (buf, "MD_CONTAINER=", sizeof ("MD_CONTAINER=") - 1) == 0)
|
if (strncmp (buf, "MD_CONTAINER=", sizeof ("MD_CONTAINER=") - 1) == 0
|
||||||
|
&& !container_seen)
|
||||||
{
|
{
|
||||||
char *newdev, *ptr;
|
char *newdev, *ptr;
|
||||||
newdev = xstrdup (buf + sizeof ("MD_CONTAINER=") - 1);
|
newdev = xstrdup (buf + sizeof ("MD_CONTAINER=") - 1);
|
||||||
|
@ -1514,31 +1519,27 @@ grub_util_is_imsm (const char *os_dev)
|
||||||
ptr[1] = 0;
|
ptr[1] = 0;
|
||||||
grub_util_info ("Container of %s is %s", dev, newdev);
|
grub_util_info ("Container of %s is %s", dev, newdev);
|
||||||
dev = newdev;
|
dev = newdev;
|
||||||
goto out;
|
container_seen = retry = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (strncmp (buf, "MD_METADATA=imsm",
|
if (strncmp (buf, "MD_METADATA=imsm",
|
||||||
sizeof ("MD_METADATA=imsm") - 1) == 0)
|
sizeof ("MD_METADATA=imsm") - 1) == 0)
|
||||||
{
|
{
|
||||||
close (fd);
|
is_imsm = 1;
|
||||||
waitpid (pid, NULL, 0);
|
|
||||||
grub_util_info ("%s is imsm", dev);
|
grub_util_info ("%s is imsm", dev);
|
||||||
if (dev != os_dev)
|
break;
|
||||||
free ((void *) dev);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free (buf);
|
free (buf);
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
out:
|
|
||||||
close (fd);
|
close (fd);
|
||||||
waitpid (pid, NULL, 0);
|
waitpid (pid, NULL, 0);
|
||||||
}
|
}
|
||||||
|
while (retry);
|
||||||
|
|
||||||
if (dev != os_dev)
|
if (dev != os_dev)
|
||||||
free ((void *) dev);
|
free ((void *) dev);
|
||||||
return 0;
|
return is_imsm;
|
||||||
}
|
}
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue