On Wednesday, 14 February 2018 18:06:10 CET Eric Blake wrote:
On 02/14/2018 10:53 AM, Pino Toscano wrote:
> Introduce a new helper function to resolve a path name, calling
> nbdkit_error on failure: other than doing what nbdkit_absolute_path
> does, it also checks that the file exists (and thus avoids errors later
> on). To help distinguish it from nbdkit_absolute_path, improve the
> documentation of the latter.
>
> Apply it where an existing path is required, both in nbdkit itself and
> in plugins.
>
> Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1527334
> ---
> +++ b/src/utils.c
> @@ -228,3 +228,22 @@ nbdkit_read_password (const char *value, char **password)
>
> return 0;
> }
> +
> +char *
> +nbdkit_realpath (const char *path)
> +{
> + char *ret;
> +
> + if (path == NULL || *path == '\0') {
> + nbdkit_error ("cannot resolve a null or empty path");
> + return NULL;
> + }
> +
> + ret = realpath (path, NULL);
Wait. Does this even work?
It works in the same way as nbdkit_absolute_path() did: when calling it
on a relative path, nbdkit_absolute_path() will prepend $PWD to it,
while the new nbdkit_realpath() will do something similar.
At least the usages that I changed are called before start_serving()
(and thus before fork_into_background()), so I think there should be no
issue wrt paths.
Did I miss anything?
--
Pino Toscano