grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trivial fix for config_file without directory part
@ 2013-12-07 19:51 Andrey Borzenkov
  2013-12-07 19:57 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-12-07 20:06 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 5+ messages in thread
From: Andrey Borzenkov @ 2013-12-07 19:51 UTC (permalink / raw)
  To: grub-devel

It is legal to use "configfile <top level filename>" where filename does
not contain directory part. In this case config_directory is set to filename.
Set it to empty string so $config_directory/file works as expected.

May be it makes sense to generate full pathname (including device part)
so that interpretation of $config_directory does not depend on possible
change of $root.

---
 grub-core/normal/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 991a595..16f22fb 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -196,6 +196,8 @@ read_config_file (const char *config)
     ptr = grub_strrchr (config_dir, '/');
   if (ptr)
     *ptr = 0;
+  else if (config_dir)
+    *config_dir = 0;
   grub_env_set ("config_directory", config_dir);
   grub_free (config_dir);
 
-- 
tg: (bb05e31..) u/config_file_without_dir (depends on: master)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] trivial fix for config_file without directory part
  2013-12-07 19:51 [PATCH] trivial fix for config_file without directory part Andrey Borzenkov
@ 2013-12-07 19:57 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-12-07 20:06 ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 0 replies; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-07 19:57 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]

On 07.12.2013 20:51, Andrey Borzenkov wrote:
> It is legal to use "configfile <top level filename>" where filename does
> not contain directory part. In this case config_directory is set to filename.
> Set it to empty string so $config_directory/file works as expected.
> 
The only filenames valid in GRUB are of forms:
[(device)]/path
[(device)]blocklist
All others are invalid even if the happend to be accepted by current
version.
> May be it makes sense to generate full pathname (including device part)
> so that interpretation of $config_directory does not depend on possible
> change of $root.
> 
> ---
>  grub-core/normal/main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
> index 991a595..16f22fb 100644
> --- a/grub-core/normal/main.c
> +++ b/grub-core/normal/main.c
> @@ -196,6 +196,8 @@ read_config_file (const char *config)
>      ptr = grub_strrchr (config_dir, '/');
>    if (ptr)
>      *ptr = 0;
> +  else if (config_dir)
> +    *config_dir = 0;
>    grub_env_set ("config_directory", config_dir);
>    grub_free (config_dir);
>  
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] trivial fix for config_file without directory part
  2013-12-07 19:51 [PATCH] trivial fix for config_file without directory part Andrey Borzenkov
  2013-12-07 19:57 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-12-07 20:06 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-12-08 21:05   ` [PATCH] always define config_directory and config_file as full pathname Andrey Borzenkov
  1 sibling, 1 reply; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-07 20:06 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

On 07.12.2013 20:51, Andrey Borzenkov wrote:
> May be it makes sense to generate full pathname (including device part)
> so that interpretation of $config_directory does not depend on possible
> change of $root.
Adding ($root) to config_file/config_directory if none present would be
good.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] always define config_directory and config_file as full pathname
  2013-12-07 20:06 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-12-08 21:05   ` Andrey Borzenkov
  2013-12-09 23:27     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Borzenkov @ 2013-12-08 21:05 UTC (permalink / raw)
  To: grub-devel

> Adding ($root) to config_file/config_directory if none present would be
> good.

Like this?

If configfile is relative pathname, extend it with current ($root) so its
interpretation does not change if $root is changed later.

Suggested by Vladimir Serbienko.

---
 grub-core/normal/main.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 991a595..84df360 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -190,14 +190,26 @@ read_config_file (const char *config)
   ctmp = grub_env_get ("config_directory");
   if (ctmp)
     old_dir = grub_strdup (ctmp);
-  grub_env_set ("config_file", config);
-  config_dir = grub_strdup (config);
+  if (*config == '(')
+    {
+      grub_env_set ("config_file", config);
+      config_dir = grub_strdup (config);
+    }
+  else
+    {
+      /* $root is guranteed to be defined, otherwise open above would fail */
+      config_dir = grub_xasprintf ("(%s)%s", grub_env_get ("root"), config);
+      if (config_dir)
+	grub_env_set ("config_file", config_dir);
+    }
   if (config_dir)
-    ptr = grub_strrchr (config_dir, '/');
-  if (ptr)
-    *ptr = 0;
-  grub_env_set ("config_directory", config_dir);
-  grub_free (config_dir);
+    {
+      ptr = grub_strrchr (config_dir, '/');
+      if (ptr)
+	*ptr = 0;
+      grub_env_set ("config_directory", config_dir);
+      grub_free (config_dir);
+    }
 
   grub_env_export ("config_file");
   grub_env_export ("config_directory");
-- 
tg: (78b2b0a..) u/config_file_without_dir (depends on: master)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] always define config_directory and config_file as full pathname
  2013-12-08 21:05   ` [PATCH] always define config_directory and config_file as full pathname Andrey Borzenkov
@ 2013-12-09 23:27     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-09 23:27 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 1765 bytes --]

Go ahead.
On 08.12.2013 22:05, Andrey Borzenkov wrote:
>> Adding ($root) to config_file/config_directory if none present would be
>> good.
> 
> Like this?
> 
> If configfile is relative pathname, extend it with current ($root) so its
> interpretation does not change if $root is changed later.
> 
> Suggested by Vladimir Serbienko.
> 
> ---
>  grub-core/normal/main.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
> index 991a595..84df360 100644
> --- a/grub-core/normal/main.c
> +++ b/grub-core/normal/main.c
> @@ -190,14 +190,26 @@ read_config_file (const char *config)
>    ctmp = grub_env_get ("config_directory");
>    if (ctmp)
>      old_dir = grub_strdup (ctmp);
> -  grub_env_set ("config_file", config);
> -  config_dir = grub_strdup (config);
> +  if (*config == '(')
> +    {
> +      grub_env_set ("config_file", config);
> +      config_dir = grub_strdup (config);
> +    }
> +  else
> +    {
> +      /* $root is guranteed to be defined, otherwise open above would fail */
> +      config_dir = grub_xasprintf ("(%s)%s", grub_env_get ("root"), config);
> +      if (config_dir)
> +	grub_env_set ("config_file", config_dir);
> +    }
>    if (config_dir)
> -    ptr = grub_strrchr (config_dir, '/');
> -  if (ptr)
> -    *ptr = 0;
> -  grub_env_set ("config_directory", config_dir);
> -  grub_free (config_dir);
> +    {
> +      ptr = grub_strrchr (config_dir, '/');
> +      if (ptr)
> +	*ptr = 0;
> +      grub_env_set ("config_directory", config_dir);
> +      grub_free (config_dir);
> +    }
>  
>    grub_env_export ("config_file");
>    grub_env_export ("config_directory");
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-09 23:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-07 19:51 [PATCH] trivial fix for config_file without directory part Andrey Borzenkov
2013-12-07 19:57 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-07 20:06 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-08 21:05   ` [PATCH] always define config_directory and config_file as full pathname Andrey Borzenkov
2013-12-09 23:27     ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).