From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JLHdh-0003lQ-L0 for mharc-grub-devel@gnu.org; Sat, 02 Feb 2008 07:38:33 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JLHdf-0003hG-Bh for grub-devel@gnu.org; Sat, 02 Feb 2008 07:38:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JLHde-0003g6-QO for grub-devel@gnu.org; Sat, 02 Feb 2008 07:38:30 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JLHde-0003fr-JX for grub-devel@gnu.org; Sat, 02 Feb 2008 07:38:30 -0500 Received: from ns39764.ovh.net ([91.121.25.85] helo=nexedi.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JLHde-0005oq-Ep for grub-devel@gnu.org; Sat, 02 Feb 2008 07:38:30 -0500 Received: from [10.8.0.46] (unknown [10.8.0.46]) by nexedi.com (Postfix) with ESMTP id 4081A3EB26 for ; Sat, 2 Feb 2008 13:45:13 +0100 (CET) From: "Yoshinori K. Okuji" Organization: enbug.org To: The development of GRUB 2 Date: Sat, 2 Feb 2008 13:38:28 +0100 User-Agent: KMail/1.9.4 References: <20080201224550.GA11984@thorin> <20080201224800.GA12043@thorin> In-Reply-To: <20080201224800.GA12043@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802021338.28362.okuji@enbug.org> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] read command X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Feb 2008 12:38:31 -0000 On Friday 01 February 2008 23:48, Robert Millan wrote: > On Fri, Feb 01, 2008 at 11:45:50PM +0100, Robert Millan wrote: > > +static void * > > +grub_xrealloc (void *ptr, grub_size_t size) > > +{ > > + void *value = grub_realloc (ptr, size); > > + if (value == 0) > > + grub_fatal ("Virtual memory exhausted"); > > + return value; > > +} > > + > > +static char * > > +grub_getline (void) > > +{ > > + int i; > > + char *line; > > + > > + i = 0; > > + line = grub_malloc (1 + i + sizeof('\0')); > > + > > + while ((line[i - 1] != '\n') && (line[i - 1] != '\r')) > > + { > > + line[i] = grub_getkey (); > > + if (grub_isprint (line[i])) > > + grub_putchar (line[i]); > > + i++; > > + line = grub_xrealloc (line, 1 + i + sizeof('\0')); > > + } > > + line[i] = '\0'; > > + > > + return line; > > +} > > Does it make sense to move any of these two to kernel? Or to normal.mod ? > Or maybe just to un-static-ize them and leave them here? What would be other use cases? BTW it is a bad idea to use xrealloc. xmalloc and xrealloc are sometimes used in the GNU Project, but they must not be used in GRUB. If a program runs in user space, when it panics, the control is back to the OS. But GRUB is a standalone program. When it panics, the user loses any kind of control. Thus grub_fatal must be used only if there is nothing else you can do. In this case, grub_getline should simply return NULL. How the user deals with this situation is up to the user. Okuji