grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grub2 boot root-on-zfs errors


From: Vladimir 'φ-coder/phcoder' Serbinenko
Subject: Re: grub2 boot root-on-zfs errors
Date: Fri, 22 Nov 2013 14:30:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9

On 22.11.2013 14:16, Colin Watson wrote:
> On Fri, Nov 22, 2013 at 08:30:14AM +0100, Vladimir 'φ-coder/phcoder' 
> Serbinenko wrote:
>> On 22.11.2013 08:09, Beeblebrox wrote:
>>> grub-core/osdep/unix/platform.c:34:28: error: use of undeclared
>>> identifier 'PATH_MAX'
>>>   char *ret = xmalloc (2 * PATH_MAX);
>> Please try
>> diff --git a/grub-core/osdep/unix/platform.c
>> b/grub-core/osdep/unix/platform.c
>> index 65c93f1..a527a1c 100644
>> --- a/grub-core/osdep/unix/platform.c
>> +++ b/grub-core/osdep/unix/platform.c
>> @@ -27,6 +27,7 @@
>>  #include <dirent.h>
>>  #include <string.h>
>>  #include <errno.h>
>> +#include <limits.h>
>>
>>  static char *
>>  get_ofpathname (const char *dev)
>>
> 
> This will not be sufficient to build on GNU/Hurd (get_ofpathname isn't
> directly relevant to that platform, but that function will be compiled
> there anyway).  We need to avoid the use of PATH_MAX entirely, per:
> 
>   https://www.gnu.org/software/hurd/hurd/porting/guidelines.html
> 
Sth like
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
index 65c93f1..684c325 100644
--- a/grub-core/osdep/unix/platform.c
+++ b/grub-core/osdep/unix/platform.c
@@ -31,11 +31,11 @@
 static char *
 get_ofpathname (const char *dev)
 {
-  char *ret = xmalloc (2 * PATH_MAX);
-  char *end = ret + 2 * PATH_MAX - 1;
+  size_t alloced = 4096;
+  char *ret = xmalloc (alloced);
+  size_t offset = 0;
   int fd;
   pid_t pid;
-  char *ptr = ret;
 
   pid = grub_util_exec_pipe ((const char * []){ "ofpathname", dev, NULL }, 
&fd);
   if (!pid)
@@ -45,11 +45,16 @@ get_ofpathname (const char *dev)
   if (!fp)
     goto fail;
 
-  while (!feof (fp) && ptr < end)
+  while (!feof (fp))
     {
       size_t r;
-      r = fread (ptr, 1, end - ptr, fp);
-      ptr += r;
+      if (alloced == offset)
+       {
+         alloced *= 2;
+         ret = xrealloc (ret, alloced);
+       }
+      r = fread (ret + offset, 1, alloced - offset, fp);
+      offset += r;
     }
 
   fclose (fp);


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]