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

Commiteeece9e

Browse files
committed
Unify calling conventions for postgres/postmaster sub-main functions
There was a wild mix of calling conventions: Some were declared toreturn void and didn't return, some returned an int exit code, someclaimed to return an exit code, which the callers checked, butactually never returned, and so on.Now all of these functions are declared to return void and decoratedwith attribute noreturn and don't return. That's easiest, and mostcode already worked that way.
1 parentc7d47ab commiteeece9e

File tree

23 files changed

+60
-63
lines changed

23 files changed

+60
-63
lines changed

‎src/backend/main/main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ main(int argc, char *argv[])
173173

174174
#ifdefEXEC_BACKEND
175175
if (argc>1&&strncmp(argv[1],"--fork",6)==0)
176-
exit(SubPostmasterMain(argc,argv));
176+
SubPostmasterMain(argc,argv);/* does not return */
177177
#endif
178178

179179
#ifdefWIN32
@@ -189,14 +189,13 @@ main(int argc, char *argv[])
189189

190190
if (argc>1&&strcmp(argv[1],"--boot")==0)
191191
AuxiliaryProcessMain(argc,argv);/* does not return */
192-
193-
if (argc>1&&strcmp(argv[1],"--describe-config")==0)
194-
exit(GucInfoMain());
195-
196-
if (argc>1&&strcmp(argv[1],"--single")==0)
197-
exit(PostgresMain(argc,argv,get_current_username(progname)));
198-
199-
exit(PostmasterMain(argc,argv));
192+
elseif (argc>1&&strcmp(argv[1],"--describe-config")==0)
193+
GucInfoMain();/* does not return */
194+
elseif (argc>1&&strcmp(argv[1],"--single")==0)
195+
PostgresMain(argc,argv,get_current_username(progname));/* does not return */
196+
else
197+
PostmasterMain(argc,argv);/* does not return */
198+
abort();/* should not get here */
200199
}
201200

202201

‎src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ intAutovacuumLauncherPid = 0;
269269
staticpid_tavlauncher_forkexec(void);
270270
staticpid_tavworker_forkexec(void);
271271
#endif
272-
NON_EXEC_STATICvoidAutoVacWorkerMain(intargc,char*argv[]);
273-
NON_EXEC_STATICvoidAutoVacLauncherMain(intargc,char*argv[]);
272+
NON_EXEC_STATICvoidAutoVacWorkerMain(intargc,char*argv[]) __attribute__((noreturn));
273+
NON_EXEC_STATICvoidAutoVacLauncherMain(intargc,char*argv[]) __attribute__((noreturn));
274274

275275
staticOiddo_start_worker(void);
276276
staticvoidlauncher_determine_sleep(boolcanlaunch,boolrecursing,

‎src/backend/postmaster/pgarch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static Latch mainloop_latch;
101101
staticpid_tpgarch_forkexec(void);
102102
#endif
103103

104-
NON_EXEC_STATICvoidPgArchiverMain(intargc,char*argv[]);
104+
NON_EXEC_STATICvoidPgArchiverMain(intargc,char*argv[]) __attribute__((noreturn));
105105
staticvoidpgarch_exit(SIGNAL_ARGS);
106106
staticvoidArchSigHupHandler(SIGNAL_ARGS);
107107
staticvoidArchSigTermHandler(SIGNAL_ARGS);

‎src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static instr_time total_func_time;
243243
staticpid_tpgstat_forkexec(void);
244244
#endif
245245

246-
NON_EXEC_STATICvoidPgstatCollectorMain(intargc,char*argv[]);
246+
NON_EXEC_STATICvoidPgstatCollectorMain(intargc,char*argv[]) __attribute__((noreturn));
247247
staticvoidpgstat_exit(SIGNAL_ARGS);
248248
staticvoidpgstat_beshutdown_hook(intcode,Datumarg);
249249
staticvoidpgstat_sighup_handler(SIGNAL_ARGS);

‎src/backend/postmaster/postmaster.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ static void LogChildExit(int lev, const char *procname,
343343
intpid,intexitstatus);
344344
staticvoidPostmasterStateMachine(void);
345345
staticvoidBackendInitialize(Port*port);
346-
staticintBackendRun(Port*port);
347-
staticvoidExitPostmaster(intstatus);
346+
staticvoidBackendRun(Port*port) __attribute__((noreturn));
347+
staticvoidExitPostmaster(intstatus) __attribute__((noreturn));
348348
staticintServerLoop(void);
349349
staticintBackendStartup(Port*port);
350350
staticintProcessStartupPacket(Port*port,boolSSLdone);
@@ -491,7 +491,7 @@ HANDLEPostmasterHandle;
491491
/*
492492
* Postmaster main entry point
493493
*/
494-
int
494+
void
495495
PostmasterMain(intargc,char*argv[])
496496
{
497497
intopt;
@@ -1125,7 +1125,7 @@ PostmasterMain(int argc, char *argv[])
11251125
*/
11261126
ExitPostmaster(status!=STATUS_OK);
11271127

1128-
return0;/* not reached */
1128+
abort();/* not reached */
11291129
}
11301130

11311131

@@ -3295,7 +3295,7 @@ BackendStartup(Port *port)
32953295
BackendInitialize(port);
32963296

32973297
/* And run the backend */
3298-
proc_exit(BackendRun(port));
3298+
BackendRun(port);
32993299
}
33003300
#endif/* EXEC_BACKEND */
33013301

@@ -3539,7 +3539,7 @@ BackendInitialize(Port *port)
35393539
*Shouldn't return at all.
35403540
*If PostgresMain() fails, return status.
35413541
*/
3542-
staticint
3542+
staticvoid
35433543
BackendRun(Port*port)
35443544
{
35453545
char**av;
@@ -3610,7 +3610,7 @@ BackendRun(Port *port)
36103610
*/
36113611
MemoryContextSwitchTo(TopMemoryContext);
36123612

3613-
return (PostgresMain(ac,av,port->user_name));
3613+
PostgresMain(ac,av,port->user_name);
36143614
}
36153615

36163616

@@ -3960,7 +3960,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
39603960
* have been inherited by fork() on Unix. Remaining arguments go to the
39613961
* subprocess FooMain() routine.
39623962
*/
3963-
int
3963+
void
39643964
SubPostmasterMain(intargc,char*argv[])
39653965
{
39663966
Portport;
@@ -4111,7 +4111,7 @@ SubPostmasterMain(int argc, char *argv[])
41114111
CreateSharedMemoryAndSemaphores(false,0);
41124112

41134113
/* And run the backend */
4114-
proc_exit(BackendRun(&port));
4114+
BackendRun(&port);/* does not return */
41154115
}
41164116
if (strcmp(argv[1],"--forkboot")==0)
41174117
{
@@ -4127,8 +4127,7 @@ SubPostmasterMain(int argc, char *argv[])
41274127
/* Attach process to shared data structures */
41284128
CreateSharedMemoryAndSemaphores(false,0);
41294129

4130-
AuxiliaryProcessMain(argc-2,argv+2);
4131-
proc_exit(0);
4130+
AuxiliaryProcessMain(argc-2,argv+2);/* does not return */
41324131
}
41334132
if (strcmp(argv[1],"--forkavlauncher")==0)
41344133
{
@@ -4144,8 +4143,7 @@ SubPostmasterMain(int argc, char *argv[])
41444143
/* Attach process to shared data structures */
41454144
CreateSharedMemoryAndSemaphores(false,0);
41464145

4147-
AutoVacLauncherMain(argc-2,argv+2);
4148-
proc_exit(0);
4146+
AutoVacLauncherMain(argc-2,argv+2);/* does not return */
41494147
}
41504148
if (strcmp(argv[1],"--forkavworker")==0)
41514149
{
@@ -4161,8 +4159,7 @@ SubPostmasterMain(int argc, char *argv[])
41614159
/* Attach process to shared data structures */
41624160
CreateSharedMemoryAndSemaphores(false,0);
41634161

4164-
AutoVacWorkerMain(argc-2,argv+2);
4165-
proc_exit(0);
4162+
AutoVacWorkerMain(argc-2,argv+2);/* does not return */
41664163
}
41674164
if (strcmp(argv[1],"--forkarch")==0)
41684165
{
@@ -4171,8 +4168,7 @@ SubPostmasterMain(int argc, char *argv[])
41714168

41724169
/* Do not want to attach to shared memory */
41734170

4174-
PgArchiverMain(argc,argv);
4175-
proc_exit(0);
4171+
PgArchiverMain(argc,argv);/* does not return */
41764172
}
41774173
if (strcmp(argv[1],"--forkcol")==0)
41784174
{
@@ -4181,8 +4177,7 @@ SubPostmasterMain(int argc, char *argv[])
41814177

41824178
/* Do not want to attach to shared memory */
41834179

4184-
PgstatCollectorMain(argc,argv);
4185-
proc_exit(0);
4180+
PgstatCollectorMain(argc,argv);/* does not return */
41864181
}
41874182
if (strcmp(argv[1],"--forklog")==0)
41884183
{
@@ -4191,11 +4186,10 @@ SubPostmasterMain(int argc, char *argv[])
41914186

41924187
/* Do not want to attach to shared memory */
41934188

4194-
SysLoggerMain(argc,argv);
4195-
proc_exit(0);
4189+
SysLoggerMain(argc,argv);/* does not return */
41964190
}
41974191

4198-
return1;/* shouldn't get here */
4192+
abort();/* shouldn't get here */
41994193
}
42004194
#endif/* EXEC_BACKEND */
42014195

‎src/backend/postmaster/syslogger.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static volatile sig_atomic_t rotation_requested = false;
139139
staticpid_tsyslogger_forkexec(void);
140140
staticvoidsyslogger_parseArgs(intargc,char*argv[]);
141141
#endif
142+
NON_EXEC_STATICvoidSysLoggerMain(intargc,char*argv[]) __attribute__((noreturn));
142143
staticvoidprocess_pipe_input(char*logbuffer,int*bytes_in_logbuffer);
143144
staticvoidflush_pipe_input(char*logbuffer,int*bytes_in_logbuffer);
144145
staticvoidopen_csvlogfile(void);

‎src/backend/replication/walsender.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static void WalSndLastCycleHandler(SIGNAL_ARGS);
120120

121121
/* Prototypes for private functions */
122122
staticboolHandleReplicationCommand(constchar*cmd_string);
123-
staticintWalSndLoop(void);
123+
staticvoidWalSndLoop(void) __attribute__((noreturn));
124124
staticvoidInitWalSnd(void);
125125
staticvoidWalSndHandshake(void);
126126
staticvoidWalSndKill(intcode,Datumarg);
@@ -135,7 +135,7 @@ static void WalSndKeepalive(char *msgbuf);
135135

136136

137137
/* Main entry point for walsender process */
138-
int
138+
void
139139
WalSenderMain(void)
140140
{
141141
MemoryContextwalsnd_context;
@@ -192,7 +192,7 @@ WalSenderMain(void)
192192
SyncRepInitConfig();
193193

194194
/* Main loop of walsender */
195-
returnWalSndLoop();
195+
WalSndLoop();
196196
}
197197

198198
/*
@@ -706,7 +706,7 @@ ProcessStandbyHSFeedbackMessage(void)
706706
}
707707

708708
/* Main loop of walsender process */
709-
staticint
709+
staticvoid
710710
WalSndLoop(void)
711711
{
712712
char*output_message;
@@ -882,7 +882,7 @@ WalSndLoop(void)
882882
whereToSendOutput=DestNone;
883883

884884
proc_exit(0);
885-
return1;/* keep the compiler quiet */
885+
abort();/* keep the compiler quiet */
886886
}
887887

888888
/* Initialize a per-walsender data structure for this walsender process */

‎src/backend/tcop/postgres.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
35073507
* for the session.
35083508
* ----------------------------------------------------------------
35093509
*/
3510-
int
3510+
void
35113511
PostgresMain(intargc,char*argv[],constchar*username)
35123512
{
35133513
constchar*dbname;
@@ -3721,7 +3721,10 @@ PostgresMain(int argc, char *argv[], const char *username)
37213721

37223722
/* If this is a WAL sender process, we're done with initialization. */
37233723
if (am_walsender)
3724-
proc_exit(WalSenderMain());
3724+
{
3725+
WalSenderMain();/* does not return */
3726+
abort();
3727+
}
37253728

37263729
/*
37273730
* process any libraries that should be preloaded at backend start (this
@@ -4199,7 +4202,7 @@ PostgresMain(int argc, char *argv[], const char *username)
41994202
/* can't get here because the above loop never exits */
42004203
Assert(false);
42014204

4202-
return1;/* keep compiler quiet */
4205+
abort();/* keep compiler quiet */
42034206
}
42044207

42054208

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void printMixedStruct(mixedStruct *structToPrint);
4343
staticbooldisplayStruct(mixedStruct*structToDisplay);
4444

4545

46-
int
46+
void
4747
GucInfoMain(void)
4848
{
4949
structconfig_generic**guc_vars;
@@ -64,7 +64,7 @@ GucInfoMain(void)
6464
printMixedStruct(var);
6565
}
6666

67-
return0;
67+
exit(0);
6868
}
6969

7070

‎src/include/bootstrap/bootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern Form_pg_attribute attrtypes[MAXATTR];
4040
externintnumattr;
4141

4242

43-
externvoidAuxiliaryProcessMain(intargc,char*argv[]);
43+
externvoidAuxiliaryProcessMain(intargc,char*argv[]) __attribute__((noreturn));
4444

4545
externvoiderr_out(void);
4646

‎src/include/pgstat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ extern void pgstat_reset_all(void);
749749
externvoidallow_immediate_pgstat_restart(void);
750750

751751
#ifdefEXEC_BACKEND
752-
externvoidPgstatCollectorMain(intargc,char*argv[]);
752+
externvoidPgstatCollectorMain(intargc,char*argv[]) __attribute__((noreturn));
753753
#endif
754754

755755

‎src/include/postmaster/autovacuum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ extern void AutoVacWorkerFailed(void);
5252
externvoidAutoVacuumUpdateDelay(void);
5353

5454
#ifdefEXEC_BACKEND
55-
externvoidAutoVacLauncherMain(intargc,char*argv[]);
56-
externvoidAutoVacWorkerMain(intargc,char*argv[]);
55+
externvoidAutoVacLauncherMain(intargc,char*argv[]) __attribute__((noreturn));
56+
externvoidAutoVacWorkerMain(intargc,char*argv[]) __attribute__((noreturn));
5757
externvoidAutovacuumWorkerIAm(void);
5858
externvoidAutovacuumLauncherIAm(void);
5959
#endif

‎src/include/postmaster/bgwriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ extern intCheckPointTimeout;
2525
externintCheckPointWarning;
2626
externdoubleCheckPointCompletionTarget;
2727

28-
externvoidBackgroundWriterMain(void);
29-
externvoidCheckpointerMain(void);
28+
externvoidBackgroundWriterMain(void) __attribute__((noreturn));
29+
externvoidCheckpointerMain(void) __attribute__((noreturn));
3030

3131
externvoidRequestCheckpoint(intflags);
3232
externvoidCheckpointWriteDelay(intflags,doubleprogress);

‎src/include/postmaster/pgarch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
externintpgarch_start(void);
2121

2222
#ifdefEXEC_BACKEND
23-
externvoidPgArchiverMain(intargc,char*argv[]);
23+
externvoidPgArchiverMain(intargc,char*argv[]) __attribute__((noreturn));
2424
#endif
2525

2626
#endif/* _PGARCH_H */

‎src/include/postmaster/postmaster.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ extern intpostmaster_alive_fds[2];
4646

4747
externconstchar*progname;
4848

49-
externintPostmasterMain(intargc,char*argv[]);
49+
externvoidPostmasterMain(intargc,char*argv[]) __attribute__((noreturn));
5050
externvoidClosePostmasterPorts(boolam_syslogger);
5151

5252
externintMaxLivePostmasterChildren(void);
5353

5454
#ifdefEXEC_BACKEND
5555
externpid_tpostmaster_forkexec(intargc,char*argv[]);
56-
externintSubPostmasterMain(intargc,char*argv[]);
56+
externvoidSubPostmasterMain(intargc,char*argv[]) __attribute__((noreturn));
5757

5858
externSizeShmemBackendArraySize(void);
5959
externvoidShmemBackendArrayAllocation(void);

‎src/include/postmaster/startup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define_STARTUP_H
1414

1515
externvoidHandleStartupProcInterrupts(void);
16-
externvoidStartupProcessMain(void);
16+
externvoidStartupProcessMain(void) __attribute__((noreturn));
1717
externvoidPreRestoreCommand(void);
1818
externvoidPostRestoreCommand(void);
1919
externboolIsPromoteTriggered(void);

‎src/include/postmaster/syslogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extern intSysLogger_Start(void);
8484
externvoidwrite_syslogger_file(constchar*buffer,intcount,intdest);
8585

8686
#ifdefEXEC_BACKEND
87-
externvoidSysLoggerMain(intargc,char*argv[]);
87+
externvoidSysLoggerMain(intargc,char*argv[]) __attribute__((noreturn));
8888
#endif
8989

9090
#endif/* _SYSLOGGER_H */

‎src/include/postmaster/walwriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
/* GUC options */
1616
externintWalWriterDelay;
1717

18-
externvoidWalWriterMain(void);
18+
externvoidWalWriterMain(void) __attribute__((noreturn));
1919

2020
#endif/* _WALWRITER_H */

‎src/include/replication/walreceiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef void (*walrcv_disconnect_type) (void);
109109
externPGDLLIMPORTwalrcv_disconnect_typewalrcv_disconnect;
110110

111111
/* prototypes for functions in walreceiver.c */
112-
externvoidWalReceiverMain(void);
112+
externvoidWalReceiverMain(void) __attribute__((noreturn));
113113

114114
/* prototypes for functions in walreceiverfuncs.c */
115115
externSizeWalRcvShmemSize(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp