Re: New option for pg_basebackup, to specify a different directory for pg_xlog

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Haribabu kommi <haribabu(dot)kommi(at)huawei(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: New option for pg_basebackup, to specify a different directory for pg_xlog
Date: 2013-11-18 17:55:25
Message-ID: 20131118175525.GA26763@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2013-11-18 15:01:42 +0000, Haribabu kommi wrote:
>
> /*
> + * Returns the malloced string of containing current working directory.
> + * The caller has to take care of freeing the memory.
> + * On failure exits with error code.
> + */
> +static char *
> +get_current_working_dir()
> +{
> + char *buf;
> + size_t buflen;
> +
> + buflen = MAXPGPATH;
> + for (;;)
> + {
> + buf = pg_malloc(buflen);
> + if (getcwd(buf, buflen))
> + break;
> + else if (errno == ERANGE)
> + {
> + pg_free(buf);
> + buflen *= 2;
> + continue;
> + }
> + else
> + {
> + pg_free(buf);
> + fprintf(stderr,
> + _("%s: could not get current working directory: %s\n"),
> + progname, strerror(errno));
> + exit(1);
> + }
> + }
> +
> + return buf;
> +}
> +
> +/*
> + * calculates the absolute path for the given path. The output absolute path
> + * is a malloced string. The caller needs to take care of freeing the memory.
> + */
> +static char *
> +get_absolute_path(const char *input_path)
> +{
> + char *pwd = NULL;
> + char *abspath = NULL;
> +
> + /* Getting the present working directory */
> + pwd = get_current_working_dir();
> +
> + if (chdir(input_path) < 0)
> + {
> + /* Directory doesn't exist */
> + if (errno == ENOENT)
> + return NULL;
> +
> + fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
> + progname, input_path, strerror(errno));
> + exit(1);
> + }
> +
> + abspath = get_current_working_dir();
> +
> + /* Returning back to old working directory */
> + if (chdir(pwd) < 0)
> + {
> + fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
> + progname, pwd, strerror(errno));
> + exit(1);
> + }
> +
> + pg_free(pwd);
> + return abspath;
> +}

This looks like it should be replaced by moving make_absolute_path from
pg_regress.c to path.[ch] and then use that.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2013-11-18 18:00:14 Re: New option for pg_basebackup, to specify a different directory for pg_xlog
Previous Message Josh Berkus 2013-11-18 17:49:23 Re: additional json functionality