Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stX46-00H9no-SP for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Sep 2024 18:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1stX46-00CkAU-8p for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Sep 2024 18:48:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stX45-00Ck9v-RF for pgsql-hackers@lists.postgresql.org; Wed, 25 Sep 2024 18:48:41 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1stX43-0012LB-3n for pgsql-hackers@postgresql.org; Wed, 25 Sep 2024 18:48:40 +0000 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-82aa7c3b3dbso8294339f.2 for ; Wed, 25 Sep 2024 11:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727290118; x=1727894918; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=POL5TsC+5owmqE47sX1prxd7bJM4tryBiNAA8Bb5vhs=; b=VDO9KHtw9x8LWAtnbSuK0ENGMk1SmBDJxY8vEL/pNLl6ubjQ937aRSUR3C2al9m6XO +aGVixzBpQnu5k4aLZZIFUvGXNmDvIu9Bdif2HFgSm5yYb6qKFFjxXWa8m9GlpW2zIfV y2Q1U0cy6iq/B22W/R9GAINTXTsMhZwJ45WsduYno7ayd1MYoQ6GWBQlhOpDSTNv9NoS gMgV1+A8wFc4/N/yu2k7CXyvl+5DEjF8xU1wAFAnhpO7UzUpoV5PeigkeMr005v0lejL Wq3hifOKj4NoOJZKUDC6KbgFcZGfNvrTRwu/fkXhAlYsWdkaVUv6Wa9+dy0ifnxfxyC1 vFWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727290118; x=1727894918; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=POL5TsC+5owmqE47sX1prxd7bJM4tryBiNAA8Bb5vhs=; b=D77zdV42SNQiXM5kfXZ2GW1l4PC4o91knQ99xsYvj0mX4Yu9o1ZMUP7YApcJB4ASIM JLOtbT0FBt4xgMWV/pdjWEVW6C/KiZ5tCn+tndUUqr5xeGF3959IYaLXD1jzI0DxIjRN VhSENTcFV5RisaE0EppQaPp69wu1vCX9qMMg/0CffDe7OI81oO6IMQiHEEJa+PATqxaS GJXJwNlAqN1fPjEwhqfAu7oMmrNO2T/LcBwVDXs0lN6HRxFNVJi7fuZB6y5oyUDdXNdx 1fFdoqy4nroRGrMS6ZWEfgR+WUksqi2dzgCM8iQCQvDQVhqPMgEfSL4cp/1GdEQQAetx aVwQ== X-Forwarded-Encrypted: i=1; AJvYcCUsGwJbssUmS/j1Cb6CArCM5tXatPeCzqlUTCOyR7AhN0RzrDRY0qjf4Am3El9chEUs3kUIPiSp6APchL7v@postgresql.org X-Gm-Message-State: AOJu0Ywhtb762JtcSuPYuB8QmmMwptckYIUHUa6mFAnB+jD7qKVsoeq7 rvWoZ4NX9EFIeHlihUBA2MivAm5CPs0kPam/idyM5ushXBgEqFEuIlJZ6A== X-Google-Smtp-Source: AGHT+IH4YqQrxgGT5FUJ4pdeiJMosDAYM8t9xW4wNp7JXoc/vtjXW7CJM+pJSQ4+GP4Z6uYBftiaQg== X-Received: by 2002:a05:6602:2dd3:b0:82a:ab20:f4bf with SMTP id ca18e2360f4ac-83247cfb2e8mr433119139f.1.1727290117798; Wed, 25 Sep 2024 11:48:37 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8323f5fab37sm121913439f.25.2024.09.25.11.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 11:48:37 -0700 (PDT) Date: Wed, 25 Sep 2024 13:48:35 -0500 From: Nathan Bossart To: Max Johnson Cc: "tgl@sss.pgh.pa.us" , "pgsql-hackers@postgresql.org" Subject: Re: pg_ctl/miscinit: print "MyStartTime" as a long long instead of long to avoid 2038 problem. Message-ID: References: <3486094.1727210681@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IYHC+qFES9m7f43e" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --IYHC+qFES9m7f43e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 25, 2024 at 03:17:45PM +0000, Max Johnson wrote: > I have amended my patch to reflect the changes that were discussed and > have verified on my system that it works the same as before. I have also > fixed a typo and changed the name of the patch to more accurately reflect > what it does now. Please let me know if there is anything else you'd like > me to do. Thanks! I went through all the other uses of MyStartTime and fixed those as needed, too. Please let me know what you think. -- nathan --IYHC+qFES9m7f43e Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fix_mystarttime_y2k38_bugs.patch" diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index 630b304338..da16fc78d4 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -522,7 +522,8 @@ process_pgfdw_appname(const char *appname) appendStringInfoString(&buf, application_name); break; case 'c': - appendStringInfo(&buf, "%lx.%x", (long) (MyStartTime), MyProcPid); + appendStringInfo(&buf, INT64_HEX_FORMAT ".%x", + MyStartTime, MyProcPid); break; case 'C': appendStringInfoString(&buf, cluster_name); diff --git a/src/backend/utils/error/csvlog.c b/src/backend/utils/error/csvlog.c index 855e130a97..acdffb6d06 100644 --- a/src/backend/utils/error/csvlog.c +++ b/src/backend/utils/error/csvlog.c @@ -120,7 +120,7 @@ write_csvlog(ErrorData *edata) appendStringInfoChar(&buf, ','); /* session id */ - appendStringInfo(&buf, "%lx.%x", (long) MyStartTime, MyProcPid); + appendStringInfo(&buf, INT64_HEX_FORMAT ".%x", MyStartTime, MyProcPid); appendStringInfoChar(&buf, ','); /* Line number */ diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 5cbb5b5416..70e4c30df3 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -2944,12 +2944,13 @@ log_status_format(StringInfo buf, const char *format, ErrorData *edata) { char strfbuf[128]; - snprintf(strfbuf, sizeof(strfbuf) - 1, "%lx.%x", - (long) (MyStartTime), MyProcPid); + snprintf(strfbuf, sizeof(strfbuf) - 1, INT64_HEX_FORMAT ".%x", + MyStartTime, MyProcPid); appendStringInfo(buf, "%*s", padding, strfbuf); } else - appendStringInfo(buf, "%lx.%x", (long) (MyStartTime), MyProcPid); + appendStringInfo(buf, INT64_HEX_FORMAT ".%x", + MyStartTime, MyProcPid); break; case 'p': if (padding != 0) diff --git a/src/backend/utils/error/jsonlog.c b/src/backend/utils/error/jsonlog.c index bd0124869d..492383a89e 100644 --- a/src/backend/utils/error/jsonlog.c +++ b/src/backend/utils/error/jsonlog.c @@ -168,8 +168,8 @@ write_jsonlog(ErrorData *edata) } /* Session id */ - appendJSONKeyValueFmt(&buf, "session_id", true, "%lx.%x", - (long) MyStartTime, MyProcPid); + appendJSONKeyValueFmt(&buf, "session_id", true, INT64_HEX_FORMAT ".%x", + MyStartTime, MyProcPid); /* Line number */ appendJSONKeyValueFmt(&buf, "line_num", false, "%ld", log_line_number); diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 537d92c0cf..ef60f41b8c 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -1372,10 +1372,10 @@ CreateLockFile(const char *filename, bool amPostmaster, * both datadir and socket lockfiles; although more stuff may get added to * the datadir lockfile later. */ - snprintf(buffer, sizeof(buffer), "%d\n%s\n%ld\n%d\n%s\n", + snprintf(buffer, sizeof(buffer), "%d\n%s\n" INT64_FORMAT "\n%d\n%s\n", amPostmaster ? (int) my_pid : -((int) my_pid), DataDir, - (long) MyStartTime, + MyStartTime, PostPortNumber, socketDir); diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index e7e878c22f..d6bb2c3311 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -618,7 +618,7 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint) * Allow 2 seconds slop for possible cross-process clock skew. */ pmpid = atol(optlines[LOCK_FILE_LINE_PID - 1]); - pmstart = atol(optlines[LOCK_FILE_LINE_START_TIME - 1]); + pmstart = atoll(optlines[LOCK_FILE_LINE_START_TIME - 1]); if (pmstart >= start_time - 2 && #ifndef WIN32 pmpid == pm_pid diff --git a/src/include/c.h b/src/include/c.h index dc1841346c..400c527397 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -547,6 +547,8 @@ typedef unsigned long long int uint64; /* snprintf format strings to use for 64-bit integers */ #define INT64_FORMAT "%" INT64_MODIFIER "d" #define UINT64_FORMAT "%" INT64_MODIFIER "u" +#define INT64_HEX_FORMAT "%" INT64_MODIFIER "x" +#define UINT64_HEX_FORMAT "%" INT64_MODIFIER "x" /* * 128-bit signed and unsigned integers diff --git a/src/test/modules/test_radixtree/test_radixtree.c b/src/test/modules/test_radixtree/test_radixtree.c index 1d9165a3a2..3e6863f660 100644 --- a/src/test/modules/test_radixtree/test_radixtree.c +++ b/src/test/modules/test_radixtree/test_radixtree.c @@ -23,8 +23,6 @@ /* uncomment to use shared memory for the tree */ /* #define TEST_SHARED_RT */ -#define UINT64_HEX_FORMAT "%" INT64_MODIFIER "X" - /* Convenient macros to test results */ #define EXPECT_TRUE(expr) \ do { \ --IYHC+qFES9m7f43e--