pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Compilation of timezone source with zic fails (on mountpoint)
10+ messages / 2 participants
[nested] [flat]

* Compilation of timezone source with zic fails (on mountpoint)
@ 2016-10-25 16:03  Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Sandeep Thakkar @ 2016-10-25 16:03 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

During building of the ongoing PG updates (9.6.1, 9.5.5 to 9.1.24), we
found that the build failed for Linux on 9.3 and 9.2 with the following
error:
--
/bin/mkdir -p '/mnt/hgfs/pginstaller-repo/server/staging/linux/share/
postgresql'
./zic -d '/mnt/hgfs/pginstaller-repo/server/staging/linux/share/postgresql/timezone'
-p 'US/Eastern' ./data/africa ./data/antarctica ./data/asia
./data/australasia ./data/europe ./data/northamerica ./data/southamerica
./data/pacificnew ./data/etcetera ./data/factory ./data/backward
./data/systemv
warning: "./data/africa", line 159: symbolic link used because hard link
failed: Operation not permitted
warning: "./data/africa", line 160: symbolic link used because hard link
failed: Operation not permitted
....
....
warning: "./data/backward", line 125: symbolic link used because hard link
failed: Operation not permitted
.*/zic: link from
/mnt/hgfs/pginstaller-repo/**server/staging/linux/share/postgresql/timezone/US/Eastern
failed: Operation not permitted*
make[2]: *** [install] Error 1
--

On investigating, we found that it was because of the few commits in the
new updates related to zic.c which tries to create hard links. These hard
links failed to create on our build farm because we were building the
source on the mount point (/mnt/hgfs/) where hard links cannot be created.
The Linux machine is a Virtual Machine hosted on VMware Fusion on the Mac
Server and the Fusion doesn't allow to create hard links inside the shared
location. It errors out with "Operation not permitted". Symbolic links can
be created though.

On other build farm where we don't have VMs installed on Fusion, this error
is not seen.

--


-- 
Sandeep Thakkar

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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-10-25 16:37  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Tom Lane @ 2016-10-25 16:37 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> On investigating, we found that it was because of the few commits in the
> new updates related to zic.c which tries to create hard links. These hard
> links failed to create on our build farm because we were building the
> source on the mount point (/mnt/hgfs/) where hard links cannot be created.
> The Linux machine is a Virtual Machine hosted on VMware Fusion on the Mac
> Server and the Fusion doesn't allow to create hard links inside the shared
> location. It errors out with "Operation not permitted". Symbolic links can
> be created though.

Although the IANA guys did fool around with their link-creation code in
the latest update, zic has always attempted to create hard links between
timezone files.  How did that build infrastructure ever work?

I'm not especially inclined to regard this as a bug...

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-10-26 16:41  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Tom Lane @ 2016-10-26 16:41 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> During building of the ongoing PG updates (9.6.1, 9.5.5 to 9.1.24), we
> found that the build failed for Linux on 9.3 and 9.2 with the following
> error:
> ...
> warning: "./data/backward", line 125: symbolic link used because hard link
> failed: Operation not permitted
> .*/zic: link from
> /mnt/hgfs/pginstaller-repo/**server/staging/linux/share/postgresql/timezone/US/Eastern
> failed: Operation not permitted*
> make[2]: *** [install] Error 1

> On investigating, we found that it was because of the few commits in the
> new updates related to zic.c which tries to create hard links. These hard
> links failed to create on our build farm because we were building the
> source on the mount point (/mnt/hgfs/) where hard links cannot be created.
> The Linux machine is a Virtual Machine hosted on VMware Fusion on the Mac
> Server and the Fusion doesn't allow to create hard links inside the shared
> location. It errors out with "Operation not permitted". Symbolic links can
> be created though.

I took a closer look at this.  As I said earlier, zic has always attempted
to use hard links, and now that I look, the fallback to symlinks has been
there right along as well.  So you were always getting those warnings on
that platform.  What is new, apparently, is this bit at the end of zic.c's
main() which came in with tzcode2016c (ie, our *previous* set of releases):

	if (warnings && (ferror(stderr) || fclose(stderr) != 0))
		return EXIT_FAILURE;

I cannot reproduce any failure locally by forcing "warnings" on, but I
speculate that for some reason fclose(stderr) fails on your platform.

We could probably persuade the IANA guys that fclose() is a bad idea here
and fflush() would be saner.  Could you determine whether "make install"
passes in that environment if you replace this code with

	if (warnings && (fflush(stderr) != 0 || ferror(stderr)))
		return EXIT_FAILURE;

?

Independently of that, though, I think it's a bad idea to be using such
an environment as your build platform, because it means you are getting
different results (different package contents) depending on whether you
happen to build with the install target directory on that mount or not.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-02 12:41  Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Sandeep Thakkar @ 2016-11-02 12:41 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Yes, zic has always attempted to create hard links and it never failed on
our build farm and we haven't changed anything.

The patch given doesn't help. I guess the problem is that in dolink(), the
fromfield value is a directory (path to postgresql/timezone) and hence the
make install fails at following check:
--
fromisdir = itsdir(fromfield);
if (fromisdir)
        {
                char const *e = strerror(fromisdir < 0 ? errno : EPERM);

                fprintf(stderr, _("%s: link from %s/%s failed: %s\n"),
                                progname, directory, fromfield, e);

                exit(EXIT_FAILURE);
        }
--

"fromfield" value should have been the file inside the timezone directory.

On Wed, Oct 26, 2016 at 10:11 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> > During building of the ongoing PG updates (9.6.1, 9.5.5 to 9.1.24), we
> > found that the build failed for Linux on 9.3 and 9.2 with the following
> > error:
> > ...
> > warning: "./data/backward", line 125: symbolic link used because hard
> link
> > failed: Operation not permitted
> > .*/zic: link from
> > /mnt/hgfs/pginstaller-repo/**server/staging/linux/share/
> postgresql/timezone/US/Eastern
> > failed: Operation not permitted*
> > make[2]: *** [install] Error 1
>
> > On investigating, we found that it was because of the few commits in the
> > new updates related to zic.c which tries to create hard links. These hard
> > links failed to create on our build farm because we were building the
> > source on the mount point (/mnt/hgfs/) where hard links cannot be
> created.
> > The Linux machine is a Virtual Machine hosted on VMware Fusion on the Mac
> > Server and the Fusion doesn't allow to create hard links inside the
> shared
> > location. It errors out with "Operation not permitted". Symbolic links
> can
> > be created though.
>
> I took a closer look at this.  As I said earlier, zic has always attempted
> to use hard links, and now that I look, the fallback to symlinks has been
> there right along as well.  So you were always getting those warnings on
> that platform.  What is new, apparently, is this bit at the end of zic.c's
> main() which came in with tzcode2016c (ie, our *previous* set of releases):
>
>         if (warnings && (ferror(stderr) || fclose(stderr) != 0))
>                 return EXIT_FAILURE;
>
> I cannot reproduce any failure locally by forcing "warnings" on, but I
> speculate that for some reason fclose(stderr) fails on your platform.
>
> We could probably persuade the IANA guys that fclose() is a bad idea here
> and fflush() would be saner.  Could you determine whether "make install"
> passes in that environment if you replace this code with
>
>         if (warnings && (fflush(stderr) != 0 || ferror(stderr)))
>                 return EXIT_FAILURE;
>
> ?
>
> Independently of that, though, I think it's a bad idea to be using such
> an environment as your build platform, because it means you are getting
> different results (different package contents) depending on whether you
> happen to build with the install target directory on that mount or not.
>
>                         regards, tom lane
>



-- 
Sandeep Thakkar

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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-02 13:29  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2016-11-02 13:29 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> Yes, zic has always attempted to create hard links and it never failed on
> our build farm and we haven't changed anything.

> The patch given doesn't help. I guess the problem is that in dolink(), the
> fromfield value is a directory (path to postgresql/timezone) and hence the
> make install fails at following check:

Well, that should have failed for anyone.  Maybe you mean that it's
trying to symlink from a symlink?

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-03 07:18  Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 10+ messages in thread

From: Sandeep Thakkar @ 2016-11-03 07:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On Wed, Nov 2, 2016 at 6:59 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> > Yes, zic has always attempted to create hard links and it never failed on
> > our build farm and we haven't changed anything.
>
> > The patch given doesn't help. I guess the problem is that in dolink(),
> the
> > fromfield value is a directory (path to postgresql/timezone) and hence
> the
> > make install fails at following check:
>
> Well, that should have failed for anyone.  Maybe you mean that it's
> trying to symlink from a symlink?
>
> No, I mean the itsdir(fromname); is returning the non zero value and I
thought it is because it thinks the fromname is a directory and not a file.
Anyway, I observed that there is change in the itsdir() function that it
now returns '2' for the symbolic links. Hence the error. Till previous
release, it used to return '0' for symbolic links.  If hard links cannot be
used and it fallsback to symbolic links, then itsdir() should return '0'
for symbolic links. Isn't it?



>                         regards, tom lane
>



-- 
Sandeep Thakkar

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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-03 14:13  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Tom Lane @ 2016-11-03 14:13 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> On Wed, Nov 2, 2016 at 6:59 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Well, that should have failed for anyone.  Maybe you mean that it's
>> trying to symlink from a symlink?

> No, I mean the itsdir(fromname); is returning the non zero value and I
> thought it is because it thinks the fromname is a directory and not a file.
> Anyway, I observed that there is change in the itsdir() function that it
> now returns '2' for the symbolic links. Hence the error.

Yeah.  I have a query in to the tz mailing list about that, but no
answer yet.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-04 02:31  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Tom Lane @ 2016-11-04 02:31 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> Anyway, I observed that there is change in the itsdir() function that it
> now returns '2' for the symbolic links. Hence the error. Till previous
> release, it used to return '0' for symbolic links.  If hard links cannot be
> used and it fallsback to symbolic links, then itsdir() should return '0'
> for symbolic links. Isn't it?

After some back-and-forth with the IANA crew, I've pushed a patch that
I believe will fix this, but if you could try it in your environment that
would make me feel better.  Please check not only that the symlinks get
made, but that they point somewhere sane, because that aspect of it
seems to have been broken too :-(.

I pushed the fix to HEAD only for the moment, but if you prefer testing on
a back branch, the patch should apply fine there.

BTW, it would be a really good idea if you guys were running a buildfarm
member that represented this build environment accurately, because it's
clear that no one else, anywhere, is testing either PG or the upstream
tzcode releases in such an environment.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-04 08:18  Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Sandeep Thakkar @ 2016-11-04 08:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On Fri, Nov 4, 2016 at 8:01 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> > Anyway, I observed that there is change in the itsdir() function that it
> > now returns '2' for the symbolic links. Hence the error. Till previous
> > release, it used to return '0' for symbolic links.  If hard links cannot
> be
> > used and it fallsback to symbolic links, then itsdir() should return '0'
> > for symbolic links. Isn't it?
>
> After some back-and-forth with the IANA crew, I've pushed a patch that
> I believe will fix this, but if you could try it in your environment that
> would make me feel better.  Please check not only that the symlinks get
> made, but that they point somewhere sane, because that aspect of it
> seems to have been broken too :-(.
>
> I pushed the fix to HEAD only for the moment, but if you prefer testing on
> a back branch, the patch should apply fine there.
>
> With the patch, the build on 9.2 is now successful. Thanks! The patch
needs little change on 9.3 and 9.2. I have attached the patch for those 2
branches.
I used the -samefile option of find command to check that hard links (on
the other branches where we didn't see this issue) and symlinks (on 9.2)
match. I didn't see anything broken for symlinks.



> BTW, it would be a really good idea if you guys were running a buildfarm
> member that represented this build environment accurately, because it's
> clear that no one else, anywhere, is testing either PG or the upstream
> tzcode releases in such an environment.
>
> OK. Well, it's the 9.3/9.2 that we build on such an environment and except
this build error, we never observed any challenges since the first 9.2
release. Moreover, we also have another backup build farm where build setup
is different.



>                         regards, tom lane
>



-- 
Sandeep Thakkar

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

tz-9392.patch (application/octet-stream, 18.9K) download diff --git a/src/timezone/zic.c b/src/timezone/zic.c index 6121337..d24d4d2 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -11,9 +11,11 @@ #ifdef HAVE_GETOPT_H #include <getopt.h> #endif +#include <fcntl.h> #include <locale.h> #include <sys/stat.h> #include <time.h> +#include <unistd.h> extern int optind; extern char *optarg; @@ -44,14 +46,24 @@ typedef int64 zic_t; #define MKDIR_UMASK 0755 #endif #endif -#ifndef S_ISLNK -#define S_ISLNK(m) 0 +#ifndef AT_SYMLINK_FOLLOW +#define linkat(fromdir, from, todir, to, flag) \ + (itssymlink(from) ? (errno = ENOTSUP, -1) : link(from, to)) #endif +/* The maximum ptrdiff_t value, for pre-C99 platforms. */ +#ifndef PTRDIFF_MAX +static ptrdiff_t const PTRDIFF_MAX = MAXVAL(ptrdiff_t, TYPE_BIT(ptrdiff_t)); +#endif + +/* The type and printf format for line numbers. */ +typedef int lineno; +#define PRIdLINENO "d" + struct rule { const char *r_filename; - int r_linenum; + lineno r_linenum; const char *r_name; zic_t r_loyear; /* for example, 1986 */ @@ -73,7 +85,7 @@ struct rule zic_t r_stdoff; /* offset from standard time */ const char *r_abbrvar; /* variable part of abbreviation */ - int r_todo; /* a rule to do (used in outzone) */ + bool r_todo; /* a rule to do (used in outzone) */ zic_t r_temp; /* used in outzone */ }; @@ -88,7 +100,7 @@ struct rule struct zone { const char *z_filename; - int z_linenum; + lineno z_linenum; const char *z_name; zic_t z_gmtoff; @@ -99,7 +111,7 @@ struct zone zic_t z_stdoff; struct rule *z_rules; - int z_nrules; + ptrdiff_t z_nrules; struct rule z_untilrule; zic_t z_untiltime; @@ -131,20 +143,21 @@ static void inrule(char **fields, int nfields); static bool inzcont(char **fields, int nfields); static bool inzone(char **fields, int nfields); static bool inzsub(char **, int, bool); -static int itsdir(const char *name); +static bool itsdir(char const *); +static bool itssymlink(char const *); static bool is_alpha(char a); static char lowerit(char); static void mkdirs(char const *, bool); static void newabbr(const char *abbr); static zic_t oadd(zic_t t1, zic_t t2); -static void outzone(const struct zone * zp, int ntzones); +static void outzone(const struct zone * zp, ptrdiff_t ntzones); static zic_t rpytime(const struct rule * rp, zic_t wantedy); static void rulesub(struct rule * rp, const char *loyearp, const char *hiyearp, const char *typep, const char *monthp, const char *dayp, const char *timep); static zic_t tadd(zic_t t1, zic_t t2); -static bool yearistype(int year, const char *type); +static bool yearistype(zic_t year, const char *type); /* Bound on length of what %z can expand to. */ enum @@ -168,7 +181,7 @@ static int leapcnt; static bool leapseen; static zic_t leapminyear; static zic_t leapmaxyear; -static int linenum; +static lineno linenum; static int max_abbrvar_len = PERCENT_Z_LEN_BOUND; static int max_format_len; static zic_t max_year; @@ -177,10 +190,10 @@ static bool noise; static bool print_abbrevs; static zic_t print_cutoff; static const char *rfilename; -static int rlinenum; +static lineno rlinenum; static const char *progname; -static int timecnt; -static int timecnt_alloc; +static ptrdiff_t timecnt; +static ptrdiff_t timecnt_alloc; static int typecnt; /* @@ -265,24 +278,24 @@ static int typecnt; #define YR_ONLY 2 static struct rule *rules; -static int nrules; /* number of rules */ -static int nrules_alloc; +static ptrdiff_t nrules; /* number of rules */ +static ptrdiff_t nrules_alloc; static struct zone *zones; -static int nzones; /* number of zones */ -static int nzones_alloc; +static ptrdiff_t nzones; /* number of zones */ +static ptrdiff_t nzones_alloc; struct link { const char *l_filename; - int l_linenum; + lineno l_linenum; const char *l_from; const char *l_to; }; static struct link *links; -static int nlinks; -static int nlinks_alloc; +static ptrdiff_t nlinks; +static ptrdiff_t nlinks_alloc; struct lookup { @@ -429,17 +442,18 @@ ecpyalloc(char const * str) } static void * -growalloc(void *ptr, size_t itemsize, int nitems, int *nitems_alloc) +growalloc(void *ptr, size_t itemsize, ptrdiff_t nitems, ptrdiff_t * nitems_alloc) { if (nitems < *nitems_alloc) return ptr; else { - int nitems_max = INT_MAX - WORK_AROUND_QTBUG_53071; + ptrdiff_t nitems_max = PTRDIFF_MAX - WORK_AROUND_QTBUG_53071; + ptrdiff_t amax = nitems_max < SIZE_MAX ? nitems_max : SIZE_MAX; - if ((nitems_max - 1) / 3 * 2 < *nitems_alloc) - memory_exhausted(_("int overflow")); - *nitems_alloc = *nitems_alloc + (*nitems_alloc >> 1) + 1; + if ((amax - 1) / 3 * 2 < *nitems_alloc) + memory_exhausted(_("integer overflow")); + *nitems_alloc += (*nitems_alloc >> 1) + 1; return erealloc(ptr, size_product(*nitems_alloc, itemsize)); } } @@ -449,7 +463,7 @@ growalloc(void *ptr, size_t itemsize, int nitems, int *nitems_alloc) */ static void -eats(const char *name, int num, const char *rname, int rnum) +eats(char const * name, lineno num, char const * rname, lineno rnum) { filename = name; linenum = num; @@ -458,7 +472,7 @@ eats(const char *name, int num, const char *rname, int rnum) } static void -eat(const char *name, int num) +eat(char const * name, lineno num) { eats(name, num, NULL, -1); } @@ -471,10 +485,10 @@ verror(const char *string, va_list args) * "*" -v on BSD systems. */ if (filename) - fprintf(stderr, _("\"%s\", line %d: "), filename, linenum); + fprintf(stderr, _("\"%s\", line %" PRIdLINENO ": "), filename, linenum); vfprintf(stderr, string, args); if (rfilename != NULL) - fprintf(stderr, _(" (rule from \"%s\", line %d)"), + fprintf(stderr, _(" (rule from \"%s\", line %" PRIdLINENO ")"), rfilename, rlinenum); fprintf(stderr, "\n"); } @@ -565,9 +579,10 @@ static const char *yitcommand; int main(int argc, char *argv[]) { - int i; - int j; - int c; + int c, + k; + ptrdiff_t i, + j; #ifndef WIN32 umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); @@ -579,14 +594,14 @@ main(int argc, char *argv[]) _("wild compilation-time specification of zic_t")); return EXIT_FAILURE; } - for (i = 1; i < argc; ++i) - if (strcmp(argv[i], "--version") == 0) + for (k = 1; k < argc; k++) + if (strcmp(argv[k], "--version") == 0) { printf("zic %s\n", PG_VERSION); close_file(stdout, NULL, NULL); return EXIT_SUCCESS; } - else if (strcmp(argv[i], "--help") == 0) + else if (strcmp(argv[k], "--help") == 0) { usage(stdout, EXIT_SUCCESS); } @@ -674,8 +689,8 @@ main(int argc, char *argv[]) adjleap(); } - for (i = optind; i < argc; ++i) - infile(argv[i]); + for (k = optind; k < argc; k++) + infile(argv[k]); if (errors) return EXIT_FAILURE; associate(); @@ -725,7 +740,7 @@ componentcheck(char const * name, char const * component, enum { component_len_max = 14}; - size_t component_len = component_end - component; + ptrdiff_t component_len = component_end - component; if (component_len == 0) { @@ -743,8 +758,10 @@ componentcheck(char const * name, char const * component, if (0 < component_len && component_len <= 2 && component[0] == '.' && component_end[-1] == '.') { + int len = component_len; + error(_("file name '%s' contains '%.*s' component"), - name, (int) component_len, component); + name, len, component); return false; } if (noise) @@ -835,9 +852,9 @@ relname(char const * from, char const * to) for (i = 0; f[i] && f[i] == to[i]; i++) if (f[i] == '/') dir_len = i + 1; - for (; f[i]; i++) - dotdots += f[i] == '/' && f[i - 1] != '/'; - taillen = i - dir_len; + for (; to[i]; i++) + dotdots += to[i] == '/' && to[i - 1] != '/'; + taillen = strlen(f + dir_len); dotdotetcsize = 3 * dotdots + taillen + 1; if (dotdotetcsize <= linksize) { @@ -851,10 +868,19 @@ relname(char const * from, char const * to) } #endif /* HAVE_SYMLINK */ +/* Hard link FROM to TO, following any symbolic links. + Return 0 if successful, an error number otherwise. */ +static int +hardlinkerr(char const * from, char const * to) +{ + int r = linkat(AT_FDCWD, from, AT_FDCWD, to, AT_SYMLINK_FOLLOW); + + return r == 0 ? 0 : errno; +} + static void dolink(char const * fromfield, char const * tofield, bool staysymlink) { - int fromisdir; bool todirs_made = false; int link_errno; @@ -862,17 +888,14 @@ dolink(char const * fromfield, char const * tofield, bool staysymlink) * We get to be careful here since there's a fair chance of root running * us. */ - fromisdir = itsdir(fromfield); - if (fromisdir) + if (itsdir(fromfield)) { - char const *e = strerror(fromisdir < 0 ? errno : EPERM); - fprintf(stderr, _("%s: link from %s/%s failed: %s\n"), - progname, directory, fromfield, e); + progname, directory, fromfield, strerror(EPERM)); exit(EXIT_FAILURE); } if (staysymlink) - staysymlink = itsdir(tofield) == 2; + staysymlink = itssymlink(tofield); if (remove(tofield) == 0) todirs_made = true; else if (errno != ENOENT) @@ -883,13 +906,12 @@ dolink(char const * fromfield, char const * tofield, bool staysymlink) progname, directory, tofield, e); exit(EXIT_FAILURE); } - link_errno = (staysymlink ? ENOTSUP - : link(fromfield, tofield) == 0 ? 0 : errno); + link_errno = staysymlink ? ENOTSUP : hardlinkerr(fromfield, tofield); if (link_errno == ENOENT && !todirs_made) { mkdirs(tofield, true); todirs_made = true; - link_errno = link(fromfield, tofield) == 0 ? 0 : errno; + link_errno = hardlinkerr(fromfield, tofield); } if (link_errno != 0) { @@ -997,31 +1019,42 @@ static const zic_t early_time = (WORK_AROUND_GNOME_BUG_730332 ? BIG_BANG : MINVAL(zic_t, TIME_T_BITS_IN_FILE)); -/* Return 1 if NAME is a directory, 2 if a symbolic link, 0 if - something else, -1 (setting errno) if trouble. */ -static int +/* Return true if NAME is a directory. */ +static bool itsdir(char const * name) { struct stat st; - int res = lstat(name, &st); - + int res = stat(name, &st); +#ifdef S_ISDIR if (res == 0) + return S_ISDIR(st.st_mode) != 0; +#endif + if (res == 0 || errno == EOVERFLOW) { -#ifdef S_ISDIR - return S_ISDIR(st.st_mode) ? 1 : S_ISLNK(st.st_mode) ? 2 : 0; -#else size_t n = strlen(name); char *nameslashdot = emalloc(n + 3); bool dir; memcpy(nameslashdot, name, n); strcpy(&nameslashdot[n], &"/."[!(n && name[n - 1] != '/')]); - dir = lstat(nameslashdot, &st) == 0; + dir = stat(nameslashdot, &st) == 0 || errno == EOVERFLOW; free(nameslashdot); return dir; -#endif } - return -1; + return false; +} + +/* Return true if NAME is a symbolic link. */ +static bool +itssymlink(char const * name) +{ +#ifdef HAVE_SYMLINK + char c; + + return 0 <= readlink(name, &c, 1); +#else + return false; +#endif } /* @@ -1044,10 +1077,10 @@ associate(void) { struct zone *zp; struct rule *rp; - int base, + ptrdiff_t i, + j, + base, out; - int i, - j; if (nrules != 0) { @@ -1134,7 +1167,7 @@ infile(const char *name) const struct lookup *lp; int nfields; bool wantcont; - int num; + lineno num; char buf[BUFSIZ]; if (strcmp(name, "-") == 0) @@ -1185,7 +1218,7 @@ infile(const char *name) if (lp == NULL) error(_("input line of unknown type")); else - switch ((int) (lp->l_value)) + switch (lp->l_value) { case LC_RULE: inrule(fields, nfields); @@ -1312,7 +1345,7 @@ inrule(char **fields, int nfields) static bool inzone(char **fields, int nfields) { - int i; + ptrdiff_t i; if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { @@ -1337,8 +1370,8 @@ inzone(char **fields, int nfields) if (zones[i].z_name != NULL && strcmp(zones[i].z_name, fields[ZF_NAME]) == 0) { - error( - _("duplicate zone name %s (file \"%s\", line %d)"), + error(_("duplicate zone name %s" + " (file \"%s\", line %" PRIdLINENO ")"), fields[ZF_NAME], zones[i].z_filename, zones[i].z_linenum); @@ -1462,7 +1495,7 @@ inleap(char **fields, int nfields) { const char *cp; const struct lookup *lp; - int i, + zic_t i, j; /* PG: make year be int not zic_t to avoid sscanf portability issues */ @@ -1669,7 +1702,7 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp, lp = byword(cp, begin_years); rp->r_lowasnum = lp == NULL; if (!rp->r_lowasnum) - switch ((int) lp->l_value) + switch (lp->l_value) { case YR_MINIMUM: rp->r_loyear = ZIC_MIN; @@ -1694,7 +1727,7 @@ rulesub(struct rule * rp, const char *loyearp, const char *hiyearp, lp = byword(cp, end_years); rp->r_hiwasnum = lp == NULL; if (!rp->r_hiwasnum) - switch ((int) lp->l_value) + switch (lp->l_value) { case YR_MINIMUM: rp->r_hiyear = ZIC_MIN; @@ -1844,11 +1877,11 @@ static void writezone(const char *const name, const char *const string, char version) { FILE *fp; - int i, + ptrdiff_t i, j; int leapcnt32, leapi32; - int timecnt32, + ptrdiff_t timecnt32, timei32; int pass; static const struct tzhead tzh0; @@ -1856,7 +1889,7 @@ writezone(const char *const name, const char *const string, char version) bool dir_checked = false; zic_t one = 1; zic_t y2038_boundary = one << 31; - int nats = timecnt + WORK_AROUND_QTBUG_53071; + ptrdiff_t nats = timecnt + WORK_AROUND_QTBUG_53071; zic_t *ats = emalloc(size_product(nats, sizeof *ats + 1)); void *typesptr = ats + nats; unsigned char *types = typesptr; @@ -1871,8 +1904,8 @@ writezone(const char *const name, const char *const string, char version) * Optimize. */ { - int fromi; - int toi; + ptrdiff_t fromi, + toi; toi = 0; fromi = 0; @@ -1896,9 +1929,17 @@ writezone(const char *const name, const char *const string, char version) } timecnt = toi; } + if (noise && timecnt > 1200) - warning(_("pre-2014 clients may mishandle" - " more than 1200 transition times")); + { + if (timecnt > TZ_MAX_TIMES) + warning(_("reference clients mishandle" + " more than %d transition times"), + TZ_MAX_TIMES); + else + warning(_("pre-2014 clients may mishandle" + " more than 1200 transition times")); + } /* * Transfer. @@ -2001,23 +2042,25 @@ writezone(const char *const name, const char *const string, char version) } for (pass = 1; pass <= 2; ++pass) { - int thistimei, - thistimecnt; + ptrdiff_t thistimei, + thistimecnt, + thistimelim; int thisleapi, - thisleapcnt; - int thistimelim, + thisleapcnt, thisleaplim; int writetype[TZ_MAX_TYPES]; int typemap[TZ_MAX_TYPES]; int thistypecnt; char thischars[TZ_MAX_CHARS]; - char thischarcnt; + int thischarcnt; + bool toomanytimes; int indmap[TZ_MAX_CHARS]; if (pass == 1) { thistimei = timei32; thistimecnt = timecnt32; + toomanytimes = thistimecnt >> 31 >> 1 != 0; thisleapi = leapi32; thisleapcnt = leapcnt32; } @@ -2025,9 +2068,12 @@ writezone(const char *const name, const char *const string, char version) { thistimei = 0; thistimecnt = timecnt; + toomanytimes = thistimecnt >> 31 >> 31 >> 2 != 0; thisleapi = 0; thisleapcnt = leapcnt; } + if (toomanytimes) + error(_("too many transition times")); thistimelim = thistimei + thistimecnt; thisleaplim = thisleapi + thisleapcnt; for (i = 0; i < typecnt; ++i) @@ -2128,8 +2174,7 @@ writezone(const char *const name, const char *const string, char version) break; if (j == thischarcnt) { - strcpy(&thischars[(int) thischarcnt], - thisabbr); + strcpy(&thischars[thischarcnt], thisabbr); thischarcnt += strlen(thisabbr) + 1; } indmap[abbrinds[i]] = j; @@ -2476,13 +2521,13 @@ enum YEAR_BY_YEAR_ZONE = 1}; static int -stringzone(char *result, const struct zone * const zpfirst, const int zonecount) +stringzone(char *result, struct zone const * zpfirst, ptrdiff_t zonecount) { const struct zone *zp; struct rule *rp; struct rule *stdrp; struct rule *dstrp; - int i; + ptrdiff_t i; const char *abbrvar; int compat = 0; int c; @@ -2611,11 +2656,11 @@ stringzone(char *result, const struct zone * const zpfirst, const int zonecount) } static void -outzone(const struct zone * zpfirst, int zonecount) +outzone(const struct zone * zpfirst, ptrdiff_t zonecount) { const struct zone *zp; struct rule *rp; - int i, + ptrdiff_t i, j; bool usestart, useuntil; @@ -2637,7 +2682,7 @@ outzone(const struct zone * zpfirst, int zonecount) int compat; bool do_extend; char version; - int lastatmax = -1; + ptrdiff_t lastatmax = -1; max_abbr_len = 2 + max_format_len + max_abbrvar_len; max_envvar_len = 2 * max_abbr_len + 5 * 9; @@ -2806,7 +2851,7 @@ outzone(const struct zone * zpfirst, int zonecount) } for (;;) { - int k; + ptrdiff_t k; zic_t jtime, ktime = 0; zic_t offset; @@ -3101,30 +3146,52 @@ adjleap(void) } } +static char * +shellquote(char *b, char const * s) +{ + *b++ = '\''; + while (*s) + { + if (*s == '\'') + *b++ = '\'', *b++ = '\\', *b++ = '\''; + *b++ = *s++; + } + *b++ = '\''; + return b; +} + static bool -yearistype(int year, const char *type) +yearistype(zic_t year, const char *type) { - static char *buf; + char *buf; + char *b; int result; if (type == NULL || *type == '\0') return true; - buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type)); - sprintf(buf, "%s %d %s", yitcommand, year, type); + buf = emalloc(1 + 4 * strlen(yitcommand) + 2 + + INT_STRLEN_MAXIMUM(zic_t) +2 + 4 * strlen(type) + 2); + b = shellquote(buf, yitcommand); + *b++ = ' '; + b += sprintf(b, INT64_FORMAT, year); + *b++ = ' '; + b = shellquote(b, type); + *b = '\0'; result = system(buf); if (WIFEXITED(result)) - switch (WEXITSTATUS(result)) + { + int status = WEXITSTATUS(result); + + if (status <= 1) { - case 0: - return true; - case 1: - return false; + free(buf); + return status == 0; } + } error(_("Wild result from command execution")); fprintf(stderr, _("%s: command was '%s', result was %d\n"), progname, buf, result); - for (;;) - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } /* Is A a space character in the C locale? */ @@ -3358,7 +3425,7 @@ getfields(char *cp) else { error(_("Odd number of quotation marks")); - exit(1); + exit(EXIT_FAILURE); } } while (*cp && *cp != '#' && !is_space(*cp)); if (is_space(*cp)) @@ -3547,7 +3614,8 @@ newabbr(const char *string) /* Ensure that the directories of ARGNAME exist, by making any missing ones. If ANCESTORS, do this only for ARGNAME's ancestors; otherwise, - do it for ARGNAME too. Exit with failure if there is trouble. */ + do it for ARGNAME too. Exit with failure if there is trouble. + Do not consider an existing non-directory to be trouble. */ static void mkdirs(char const * argname, bool ancestors) { @@ -3579,7 +3647,7 @@ mkdirs(char const * argname, bool ancestors) { int err = errno; - if (err != EEXIST && itsdir(name) < 0) + if (err != EEXIST && !itsdir(name)) { error(_("%s: Cannot create directory %s: %s"), progname, name, strerror(err));
^ permalink raw reply [nested|flat] 10+ messages in thread

* Re: Compilation of timezone source with zic fails (on mountpoint)
@ 2016-11-04 14:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2016-11-04 14:48 UTC (permalink / raw)
  To: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>; +Cc: pgsql-bugs

Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> writes:
> On Fri, Nov 4, 2016 at 8:01 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> After some back-and-forth with the IANA crew, I've pushed a patch that
>> I believe will fix this, but if you could try it in your environment that
>> would make me feel better.

> With the patch, the build on 9.2 is now successful. Thanks!

Great, thanks for testing.  I'm pushed this to the back branches as well.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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


end of thread, other threads:[~2016-11-04 14:48 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-10-25 16:03 Compilation of timezone source with zic fails (on mountpoint) Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
2016-10-25 16:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-10-26 16:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-02 12:41   ` Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
2016-11-02 13:29     ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-03 07:18       ` Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
2016-11-03 14:13         ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-04 02:31         ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-04 08:18           ` Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
2016-11-04 14:48             ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox