Re: Bug#933015: libssh FTBFS on hurd: unconditional usage of PATH_MAX
Hi!
On Thu, 2019-07-25 at 20:36:31 +0200, Paul Sonnenschein wrote:
> Package: src:libssh
> Severity: Important
> Version: 0.9.0-1
> Tags: patch
> User: debian-hurd@lists.debian.org
> Usertags: hurd
> X-Debbugs-CC: debian-hurd@lists.debian.org
> the package libssh fails to build from source on hurd-i386 in sid due
> to an unconditional use of PATH_MAX, which the Hurd does not provide.
> --- a/tests/torture.c
> +++ b/tests/torture.c
> @@ -1029,17 +1029,25 @@ char *torture_get_current_working_dir(void)
>
> char *cwd = NULL;
> char *result = NULL;
> + size_t path_max;
> +
> +#ifdef PATH_MAX
> + path_max = PATH_MAX;
> +#else
> + path_max = 4095;
> +#endif /* PATH_MAX undefined */
I'd probably just unconditionally set the value and avoid PATH_MAX
completely.
> + for ( ; result == NULL; path_max *= 2) {
> + cwd = (char *)realloc(cwd, path_max + 1);
> + if (cwd == NULL) {
> + goto end;
> + }
>
> - cwd = (char *)malloc(PATH_MAX + 1);
> - if (cwd == NULL) {
> - goto end;
> - }
> -
> - result = getcwd(cwd, PATH_MAX);
> + result = getcwd(cwd, path_max);
JFTR, there's also the getcwd(NULL, 0) extension which is supported by
GNU and BSD systems, at least. Or the explicit GNU specific function
get_current_dir_name(), But that would need some kind of configuration
check, and some fallback code anyway.
> - if (result == NULL) {
> - SAFE_FREE(cwd);
> - goto end;
> + if (result == NULL && errno != ERANGE) {
> + SAFE_FREE(cwd);
> + goto end;
> + }
> }
>
> end:
Thanks,
Guillem
Reply to: