Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8aaf88b

Browse files
Fix Y2038 issues with MyStartTime.
Several places treat MyStartTime as a "long", which is only 32 bitswide on some platforms. In reality, MyStartTime is a pg_time_t,i.e., a signed 64-bit integer. This will lead to interesting bugson the aforementioned systems in 2038 when signed 32-bit integersare no longer sufficient to store Unix time (e.g., "pg_ctl start"hanging). To fix, ensure that MyStartTime is handled as a 64-bitvalue everywhere. (Of course, users will need to ensure thattime_t is 64 bits wide on their system, too.)Co-authored-by: Max JohnsonDiscussion:https://postgr.es/m/CO1PR07MB905262E8AC270FAAACED66008D682%40CO1PR07MB9052.namprd07.prod.outlook.comBackpatch-through: 12
1 parent0f0e253 commit8aaf88b

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

‎contrib/postgres_fdw/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ process_pgfdw_appname(const char *appname)
522522
appendStringInfoString(&buf,application_name);
523523
break;
524524
case'c':
525-
appendStringInfo(&buf,"%lx.%x",(long) (MyStartTime),MyProcPid);
525+
appendStringInfo(&buf,"%"INT64_MODIFIER"x.%x",MyStartTime,MyProcPid);
526526
break;
527527
case'C':
528528
appendStringInfoString(&buf,cluster_name);

‎src/backend/utils/error/csvlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ write_csvlog(ErrorData *edata)
122122
appendStringInfoChar(&buf,',');
123123

124124
/* session id */
125-
appendStringInfo(&buf,"%lx.%x", (long)MyStartTime,MyProcPid);
125+
appendStringInfo(&buf,"%"INT64_MODIFIER"x.%x",MyStartTime,MyProcPid);
126126
appendStringInfoChar(&buf,',');
127127

128128
/* Line number */

‎src/backend/utils/error/elog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,12 +2939,12 @@ log_status_format(StringInfo buf, const char *format, ErrorData *edata)
29392939
{
29402940
charstrfbuf[128];
29412941

2942-
snprintf(strfbuf,sizeof(strfbuf)-1,"%lx.%x",
2943-
(long) (MyStartTime),MyProcPid);
2942+
snprintf(strfbuf,sizeof(strfbuf)-1,"%"INT64_MODIFIER"x.%x",
2943+
MyStartTime,MyProcPid);
29442944
appendStringInfo(buf,"%*s",padding,strfbuf);
29452945
}
29462946
else
2947-
appendStringInfo(buf,"%lx.%x",(long) (MyStartTime),MyProcPid);
2947+
appendStringInfo(buf,"%"INT64_MODIFIER"x.%x",MyStartTime,MyProcPid);
29482948
break;
29492949
case'p':
29502950
if (padding!=0)

‎src/backend/utils/error/jsonlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ write_jsonlog(ErrorData *edata)
170170
}
171171

172172
/* Session id */
173-
appendJSONKeyValueFmt(&buf,"session_id", true,"%lx.%x",
174-
(long)MyStartTime,MyProcPid);
173+
appendJSONKeyValueFmt(&buf,"session_id", true,"%"INT64_MODIFIER"x.%x",
174+
MyStartTime,MyProcPid);
175175

176176
/* Line number */
177177
appendJSONKeyValueFmt(&buf,"line_num", false,"%ld",log_line_number);

‎src/backend/utils/init/miscinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,10 @@ CreateLockFile(const char *filename, bool amPostmaster,
13831383
* both datadir and socket lockfiles; although more stuff may get added to
13841384
* the datadir lockfile later.
13851385
*/
1386-
snprintf(buffer,sizeof(buffer),"%d\n%s\n%ld\n%d\n%s\n",
1386+
snprintf(buffer,sizeof(buffer),"%d\n%s\n"INT64_FORMAT"\n%d\n%s\n",
13871387
amPostmaster ? (int)my_pid :-((int)my_pid),
13881388
DataDir,
1389-
(long)MyStartTime,
1389+
MyStartTime,
13901390
PostPortNumber,
13911391
socketDir);
13921392

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint)
618618
* Allow 2 seconds slop for possible cross-process clock skew.
619619
*/
620620
pmpid=atol(optlines[LOCK_FILE_LINE_PID-1]);
621-
pmstart=atol(optlines[LOCK_FILE_LINE_START_TIME-1]);
621+
pmstart=atoll(optlines[LOCK_FILE_LINE_START_TIME-1]);
622622
if (pmstart >=start_time-2&&
623623
#ifndefWIN32
624624
pmpid==pm_pid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp