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

Commit2c8118e

Browse files
committed
Use printf's %m format instead of strerror(errno) in more places
Most callers of strerror() are removed from the backend code. Theremaining callers require special handling with a saved errno from aprevious system call. The frontend code still needs strerror() whereerror states need to be handled outside of fprintf.Note that pg_regress is not changed to use %m as the TAP output mayclobber errno, since those functions call fprintf() and friends beforeevaluating the format string.Support for %m in src/port/snprintf.c has been added ind6c55de,hence all the stable branches currently supported include it.Author: Dagfinn Ilmari MannsåkerDiscussion:https://postgr.es/m/87sf13jhuw.fsf@wibble.ilmari.org
1 parent3045324 commit2c8118e

File tree

24 files changed

+158
-192
lines changed

24 files changed

+158
-192
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,12 +1375,12 @@ PostmasterMain(int argc, char *argv[])
13751375

13761376
/* Make PID file world readable */
13771377
if (chmod(external_pid_file,S_IRUSR |S_IWUSR |S_IRGRP |S_IROTH)!=0)
1378-
write_stderr("%s: could not change permissions of external PID file \"%s\": %s\n",
1379-
progname,external_pid_file,strerror(errno));
1378+
write_stderr("%s: could not change permissions of external PID file \"%s\": %m\n",
1379+
progname,external_pid_file);
13801380
}
13811381
else
1382-
write_stderr("%s: could not write external PID file \"%s\": %s\n",
1383-
progname,external_pid_file,strerror(errno));
1382+
write_stderr("%s: could not write external PID file \"%s\": %m\n",
1383+
progname,external_pid_file);
13841384

13851385
on_proc_exit(unlink_external_pid_file,0);
13861386
}
@@ -1589,8 +1589,8 @@ checkControlFile(void)
15891589
{
15901590
write_stderr("%s: could not find the database system\n"
15911591
"Expected to find it in the directory \"%s\",\n"
1592-
"but could not open file \"%s\": %s\n",
1593-
progname,DataDir,path,strerror(errno));
1592+
"but could not open file \"%s\": %m\n",
1593+
progname,DataDir,path);
15941594
ExitPostmaster(2);
15951595
}
15961596
FreeFile(fp);
@@ -6277,24 +6277,21 @@ read_backend_variables(char *id, Port **port, BackgroundWorker **worker)
62776277
fp=AllocateFile(id,PG_BINARY_R);
62786278
if (!fp)
62796279
{
6280-
write_stderr("could not open backend variables file \"%s\": %s\n",
6281-
id,strerror(errno));
6280+
write_stderr("could not open backend variables file \"%s\": %m\n",id);
62826281
exit(1);
62836282
}
62846283

62856284
if (fread(&param,sizeof(param),1,fp)!=1)
62866285
{
6287-
write_stderr("could not read from backend variables file \"%s\": %s\n",
6288-
id,strerror(errno));
6286+
write_stderr("could not read from backend variables file \"%s\": %m\n",id);
62896287
exit(1);
62906288
}
62916289

62926290
/* Release file */
62936291
FreeFile(fp);
62946292
if (unlink(id)!=0)
62956293
{
6296-
write_stderr("could not remove file \"%s\": %s\n",
6297-
id,strerror(errno));
6294+
write_stderr("could not remove file \"%s\": %m\n",id);
62986295
exit(1);
62996296
}
63006297
#else

‎src/backend/postmaster/syslogger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ write_syslogger_file(const char *buffer, int count, int destination)
11731173
* to our input pipe which would result in a different sort of looping.
11741174
*/
11751175
if (rc!=count)
1176-
write_stderr("could not write to log file: %s\n",strerror(errno));
1176+
write_stderr("could not write to log file: %m\n");
11771177
}
11781178

11791179
#ifdefWIN32

‎src/backend/utils/misc/guc.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,10 +1799,9 @@ SelectConfigFiles(const char *userDoption, const char *progname)
17991799

18001800
if (configdir&&stat(configdir,&stat_buf)!=0)
18011801
{
1802-
write_stderr("%s: could not access directory \"%s\": %s\n",
1802+
write_stderr("%s: could not access directory \"%s\": %m\n",
18031803
progname,
1804-
configdir,
1805-
strerror(errno));
1804+
configdir);
18061805
if (errno==ENOENT)
18071806
write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
18081807
return false;
@@ -1851,8 +1850,8 @@ SelectConfigFiles(const char *userDoption, const char *progname)
18511850
*/
18521851
if (stat(ConfigFileName,&stat_buf)!=0)
18531852
{
1854-
write_stderr("%s: could not access the server configuration file \"%s\": %s\n",
1855-
progname,ConfigFileName,strerror(errno));
1853+
write_stderr("%s: could not access the server configuration file \"%s\": %m\n",
1854+
progname,ConfigFileName);
18561855
free(configdir);
18571856
return false;
18581857
}

‎src/bin/initdb/findtimezone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ scan_available_timezones(char *tzdir, char *tzdirsub, struct tztry *tt,
680680
if (stat(tzdir,&statbuf)!=0)
681681
{
682682
#ifdefDEBUG_IDENTIFY_TIMEZONE
683-
fprintf(stderr,"could not stat \"%s\": %s\n",
684-
tzdir,strerror(errno));
683+
fprintf(stderr,"could not stat \"%s\": %m\n",
684+
tzdir);
685685
#endif
686686
tzdir[tzdir_orig_len]='\0';
687687
continue;

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ get_pgpid(bool is_status_request)
254254
write_stderr(_("%s: directory \"%s\" does not exist\n"),progname,
255255
pg_data);
256256
else
257-
write_stderr(_("%s: could not access directory \"%s\": %s\n"),progname,
258-
pg_data,strerror(errno));
257+
write_stderr(_("%s: could not access directory \"%s\": %m\n"),progname,
258+
pg_data);
259259

260260
/*
261261
* The Linux Standard Base Core Specification 3.1 says this should
@@ -280,8 +280,8 @@ get_pgpid(bool is_status_request)
280280
return0;
281281
else
282282
{
283-
write_stderr(_("%s: could not open PID file \"%s\": %s\n"),
284-
progname,pid_file,strerror(errno));
283+
write_stderr(_("%s: could not open PID file \"%s\": %m\n"),
284+
progname,pid_file);
285285
exit(1);
286286
}
287287
}
@@ -454,8 +454,8 @@ start_postmaster(void)
454454
if (pm_pid<0)
455455
{
456456
/* fork failed */
457-
write_stderr(_("%s: could not start server: %s\n"),
458-
progname,strerror(errno));
457+
write_stderr(_("%s: could not start server: %m\n"),
458+
progname);
459459
exit(1);
460460
}
461461
if (pm_pid>0)
@@ -474,8 +474,8 @@ start_postmaster(void)
474474
#ifdefHAVE_SETSID
475475
if (setsid()<0)
476476
{
477-
write_stderr(_("%s: could not start server due to setsid() failure: %s\n"),
478-
progname,strerror(errno));
477+
write_stderr(_("%s: could not start server due to setsid() failure: %m\n"),
478+
progname);
479479
exit(1);
480480
}
481481
#endif
@@ -496,8 +496,8 @@ start_postmaster(void)
496496
(void)execl("/bin/sh","/bin/sh","-c",cmd, (char*)NULL);
497497

498498
/* exec failed */
499-
write_stderr(_("%s: could not start server: %s\n"),
500-
progname,strerror(errno));
499+
write_stderr(_("%s: could not start server: %m\n"),
500+
progname);
501501
exit(1);
502502

503503
return0;/* keep dumb compilers quiet */
@@ -544,8 +544,8 @@ start_postmaster(void)
544544
*/
545545
if (errno!=ENOENT)
546546
{
547-
write_stderr(_("%s: could not open log file \"%s\": %s\n"),
548-
progname,log_file,strerror(errno));
547+
write_stderr(_("%s: could not open log file \"%s\": %m\n"),
548+
progname,log_file);
549549
exit(1);
550550
}
551551
}
@@ -851,8 +851,8 @@ trap_sigint_during_startup(SIGNAL_ARGS)
851851
if (postmasterPID!=-1)
852852
{
853853
if (kill(postmasterPID,SIGINT)!=0)
854-
write_stderr(_("%s: could not send stop signal (PID: %d): %s\n"),
855-
progname, (int)postmasterPID,strerror(errno));
854+
write_stderr(_("%s: could not send stop signal (PID: %d): %m\n"),
855+
progname, (int)postmasterPID);
856856
}
857857

858858
/*
@@ -1035,8 +1035,7 @@ do_stop(void)
10351035

10361036
if (kill(pid,sig)!=0)
10371037
{
1038-
write_stderr(_("%s: could not send stop signal (PID: %d): %s\n"),progname, (int)pid,
1039-
strerror(errno));
1038+
write_stderr(_("%s: could not send stop signal (PID: %d): %m\n"),progname, (int)pid);
10401039
exit(1);
10411040
}
10421041

@@ -1103,8 +1102,7 @@ do_restart(void)
11031102
{
11041103
if (kill(pid,sig)!=0)
11051104
{
1106-
write_stderr(_("%s: could not send stop signal (PID: %d): %s\n"),progname, (int)pid,
1107-
strerror(errno));
1105+
write_stderr(_("%s: could not send stop signal (PID: %d): %m\n"),progname, (int)pid);
11081106
exit(1);
11091107
}
11101108

@@ -1159,8 +1157,8 @@ do_reload(void)
11591157

11601158
if (kill(pid,sig)!=0)
11611159
{
1162-
write_stderr(_("%s: could not send reload signal (PID: %d): %s\n"),
1163-
progname, (int)pid,strerror(errno));
1160+
write_stderr(_("%s: could not send reload signal (PID: %d): %m\n"),
1161+
progname, (int)pid);
11641162
exit(1);
11651163
}
11661164

@@ -1207,25 +1205,25 @@ do_promote(void)
12071205

12081206
if ((prmfile=fopen(promote_file,"w"))==NULL)
12091207
{
1210-
write_stderr(_("%s: could not create promote signal file \"%s\": %s\n"),
1211-
progname,promote_file,strerror(errno));
1208+
write_stderr(_("%s: could not create promote signal file \"%s\": %m\n"),
1209+
progname,promote_file);
12121210
exit(1);
12131211
}
12141212
if (fclose(prmfile))
12151213
{
1216-
write_stderr(_("%s: could not write promote signal file \"%s\": %s\n"),
1217-
progname,promote_file,strerror(errno));
1214+
write_stderr(_("%s: could not write promote signal file \"%s\": %m\n"),
1215+
progname,promote_file);
12181216
exit(1);
12191217
}
12201218

12211219
sig=SIGUSR1;
12221220
if (kill(pid,sig)!=0)
12231221
{
1224-
write_stderr(_("%s: could not send promote signal (PID: %d): %s\n"),
1225-
progname, (int)pid,strerror(errno));
1222+
write_stderr(_("%s: could not send promote signal (PID: %d): %m\n"),
1223+
progname, (int)pid);
12261224
if (unlink(promote_file)!=0)
1227-
write_stderr(_("%s: could not remove promote signal file \"%s\": %s\n"),
1228-
progname,promote_file,strerror(errno));
1225+
write_stderr(_("%s: could not remove promote signal file \"%s\": %m\n"),
1226+
progname,promote_file);
12291227
exit(1);
12301228
}
12311229

@@ -1280,25 +1278,25 @@ do_logrotate(void)
12801278

12811279
if ((logrotatefile=fopen(logrotate_file,"w"))==NULL)
12821280
{
1283-
write_stderr(_("%s: could not create log rotation signal file \"%s\": %s\n"),
1284-
progname,logrotate_file,strerror(errno));
1281+
write_stderr(_("%s: could not create log rotation signal file \"%s\": %m\n"),
1282+
progname,logrotate_file);
12851283
exit(1);
12861284
}
12871285
if (fclose(logrotatefile))
12881286
{
1289-
write_stderr(_("%s: could not write log rotation signal file \"%s\": %s\n"),
1290-
progname,logrotate_file,strerror(errno));
1287+
write_stderr(_("%s: could not write log rotation signal file \"%s\": %m\n"),
1288+
progname,logrotate_file);
12911289
exit(1);
12921290
}
12931291

12941292
sig=SIGUSR1;
12951293
if (kill(pid,sig)!=0)
12961294
{
1297-
write_stderr(_("%s: could not send log rotation signal (PID: %d): %s\n"),
1298-
progname, (int)pid,strerror(errno));
1295+
write_stderr(_("%s: could not send log rotation signal (PID: %d): %m\n"),
1296+
progname, (int)pid);
12991297
if (unlink(logrotate_file)!=0)
1300-
write_stderr(_("%s: could not remove log rotation signal file \"%s\": %s\n"),
1301-
progname,logrotate_file,strerror(errno));
1298+
write_stderr(_("%s: could not remove log rotation signal file \"%s\": %m\n"),
1299+
progname,logrotate_file);
13021300
exit(1);
13031301
}
13041302

@@ -1396,8 +1394,8 @@ do_kill(pid_t pid)
13961394
{
13971395
if (kill(pid,sig)!=0)
13981396
{
1399-
write_stderr(_("%s: could not send signal %d (PID: %d): %s\n"),
1400-
progname,sig, (int)pid,strerror(errno));
1397+
write_stderr(_("%s: could not send signal %d (PID: %d): %m\n"),
1398+
progname,sig, (int)pid);
14011399
exit(1);
14021400
}
14031401
}

‎src/bin/pg_dump/compress_gzip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Gzip_getc(CompressFileHandle *CFH)
292292
if (ret==EOF)
293293
{
294294
if (!gzeof(gzfp))
295-
pg_fatal("could not read from input file: %s",strerror(errno));
295+
pg_fatal("could not read from input file: %m");
296296
else
297297
pg_fatal("could not read from input file: end of file");
298298
}

‎src/bin/pg_dump/compress_none.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ read_none(void *ptr, size_t size, size_t *rsize, CompressFileHandle *CFH)
9494

9595
ret=fread(ptr,1,size,fp);
9696
if (ret!=size&& !feof(fp))
97-
pg_fatal("could not read from input file: %s",
98-
strerror(errno));
97+
pg_fatal("could not read from input file: %m");
9998

10099
if (rsize)
101100
*rsize=ret;
@@ -137,7 +136,7 @@ getc_none(CompressFileHandle *CFH)
137136
if (ret==EOF)
138137
{
139138
if (!feof(fp))
140-
pg_fatal("could not read from input file: %s",strerror(errno));
139+
pg_fatal("could not read from input file: %m");
141140
else
142141
pg_fatal("could not read from input file: end of file");
143142
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp