* kern/emu/getroot.c (find_root_device_from_mountinfo): Use getline instead

of fgets into a static buffer.  Use sizeof instead of strlen on a constant
string.  Thanks to Vladimir for review.
This commit is contained in:
Colin Watson committed 2010-06-01 18:05:29 +01:00
1 parent 26c9e9bf61
commit 0d9ff59345
2 files changed
+6 -4

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
2010-05-18 Colin Watson <cjwatson@ubuntu.com> 2010-06-01 Colin Watson <cjwatson@ubuntu.com>
Add btrfs probing support, currently only in the single-device case. Add btrfs probing support, currently only in the single-device case.
+5 -3
View File
@@ -93,14 +93,15 @@ static char *
find_root_device_from_mountinfo (const char *dir) find_root_device_from_mountinfo (const char *dir)
{ {
FILE *fp; FILE *fp;
char buf[1024]; /* XXX */ char *buf = NULL;
size_t len = 0;
char *ret = NULL; char *ret = NULL;
fp = fopen ("/proc/self/mountinfo", "r"); fp = fopen ("/proc/self/mountinfo", "r");
if (! fp) if (! fp)
return NULL; /* fall through to other methods */ return NULL; /* fall through to other methods */
while (fgets (buf, sizeof (buf), fp)) while (getline (&buf, &len, fp) > 0)
{ {
int mnt_id, parent_mnt_id; int mnt_id, parent_mnt_id;
unsigned int major, minor; unsigned int major, minor;
@@ -139,7 +140,7 @@ find_root_device_from_mountinfo (const char *dir)
if (!sep) if (!sep)
continue; continue;
sep += strlen (" - "); sep += sizeof (" - ") - 1;
if (sscanf (sep, "%s %s", fstype, device) != 2) if (sscanf (sep, "%s %s", fstype, device) != 2)
continue; continue;
@@ -152,6 +153,7 @@ find_root_device_from_mountinfo (const char *dir)
ret = strdup (device); ret = strdup (device);
} }
free (buf);
fclose (fp); fclose (fp);
return ret; return ret;
} }