Re: closing file in adjust_data_dir

2022-11-16 Thread Ted Yu
On Wed, Nov 16, 2022 at 12:28 AM Peter Eisentraut < peter.eisentr...@enterprisedb.com> wrote: > On 16.11.22 04:31, Ted Yu wrote: > > On Wed, 16 Nov 2022 at 11:15, Ted Yu > > wrote: > > > On Tue, Nov 15, 2022 at 7:12 PM Japin Li >

Re: closing file in adjust_data_dir

2022-11-16 Thread Peter Eisentraut
On 16.11.22 04:31, Ted Yu wrote: On Wed, 16 Nov 2022 at 11:15, Ted Yu mailto:yuzhih...@gmail.com>> wrote: > On Tue, Nov 15, 2022 at 7:12 PM Japin Li mailto:japi...@hotmail.com>> wrote: >> After some rethinking, I find the origin code do not have problems. >> >> If fd is

Re: closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
On Tue, Nov 15, 2022 at 7:26 PM Japin Li wrote: > > On Wed, 16 Nov 2022 at 11:15, Ted Yu wrote: > > On Tue, Nov 15, 2022 at 7:12 PM Japin Li wrote: > >> After some rethinking, I find the origin code do not have problems. > >> > >> If fd is NULL or fgets() returns NULL, the process exits.

Re: closing file in adjust_data_dir

2022-11-15 Thread Japin Li
On Wed, 16 Nov 2022 at 11:15, Ted Yu wrote: > On Tue, Nov 15, 2022 at 7:12 PM Japin Li wrote: >> After some rethinking, I find the origin code do not have problems. >> >> If fd is NULL or fgets() returns NULL, the process exits. Otherwise, we >> call >> pclose() to close fd. The code isn't

Re: closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
On Tue, Nov 15, 2022 at 7:12 PM Japin Li wrote: > > On Wed, 16 Nov 2022 at 10:52, Ted Yu wrote: > > On Tue, Nov 15, 2022 at 6:35 PM Japin Li wrote: > >> > >> fd = popen(cmd, "r"); > >> - if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL > || > >> pclose(fd) != 0) >

Re: closing file in adjust_data_dir

2022-11-15 Thread Japin Li
On Wed, 16 Nov 2022 at 10:52, Ted Yu wrote: > On Tue, Nov 15, 2022 at 6:35 PM Japin Li wrote: >> >> fd = popen(cmd, "r"); >> - if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL || >> pclose(fd) != 0) >> + if (fd == NULL || fgets(filename, sizeof(filename), fd)

Re: closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
On Tue, Nov 15, 2022 at 6:35 PM Japin Li wrote: > > On Wed, 16 Nov 2022 at 10:06, Ted Yu wrote: > >> Hi, > > That check is a few line above: > > > > + if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL) > > { > > > > Cheers > > Thanks for the explanation. Comment on

Re: closing file in adjust_data_dir

2022-11-15 Thread Japin Li
On Wed, 16 Nov 2022 at 10:06, Ted Yu wrote: >> Hi, > That check is a few line above: > > + if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL) > { > > Cheers Thanks for the explanation. Comment on v2 patch. fd = popen(cmd, "r"); - if (fd == NULL ||

Re: closing file in adjust_data_dir

2022-11-15 Thread Japin Li
On Wed, 16 Nov 2022 at 10:02, Japin Li wrote: > I think we should check whether fd is NULL or not, otherwise, segmentation > fault maybe occur. > > + if (pclose(fd) != 0) > + { > + write_stderr(_("%s: could not close the file following command > \"%s\"\n"), progname, cmd);

Re: closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
On Tue, Nov 15, 2022 at 6:02 PM Japin Li wrote: > > On Wed, 16 Nov 2022 at 02:43, Ted Yu wrote: > > Hi, > > I was looking at the commit: > > > > commit 2fe3bdbd691a5d11626308e7d660440be6c210c8 > > Author: Peter Eisentraut > > Date: Tue Nov 15 15:35:37 2022 +0100 > > > > Check return

Re: closing file in adjust_data_dir

2022-11-15 Thread Japin Li
On Wed, 16 Nov 2022 at 02:43, Ted Yu wrote: > Hi, > I was looking at the commit: > > commit 2fe3bdbd691a5d11626308e7d660440be6c210c8 > Author: Peter Eisentraut > Date: Tue Nov 15 15:35:37 2022 +0100 > > Check return value of pclose() correctly > > In src/bin/pg_ctl/pg_ctl.c : > > if

Re: closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
On Tue, Nov 15, 2022 at 10:43 AM Ted Yu wrote: > Hi, > I was looking at the commit: > > commit 2fe3bdbd691a5d11626308e7d660440be6c210c8 > Author: Peter Eisentraut > Date: Tue Nov 15 15:35:37 2022 +0100 > > Check return value of pclose() correctly > > In src/bin/pg_ctl/pg_ctl.c : > >

closing file in adjust_data_dir

2022-11-15 Thread Ted Yu
Hi, I was looking at the commit: commit 2fe3bdbd691a5d11626308e7d660440be6c210c8 Author: Peter Eisentraut Date: Tue Nov 15 15:35:37 2022 +0100 Check return value of pclose() correctly In src/bin/pg_ctl/pg_ctl.c : if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL ||