diff options
| author | Robert Haas <rhaas@postgresql.org> | 2017-03-31 20:35:51 -0400 |
|---|---|---|
| committer | Robert Haas <rhaas@postgresql.org> | 2017-03-31 20:43:32 -0400 |
| commit | 2113ac4cbb12b815804e8873d761cade9ddf49b9 (patch) | |
| tree | 26eafa3c03cb8108f45192c4df4a6fcdcd5f716e /doc/src | |
| parent | c281cd5fe178c946dc23eae4d4642be5ddbe3eb4 (diff) | |
Don't use bgw_main even to specify in-core bgworker entrypoints.
On EXEC_BACKEND builds, this can fail if ASLR is in use.
Backpatch to 9.5. On master, completely remove the bgw_main field
completely, since there is no situation in which it is safe for an
EXEC_BACKEND build. On 9.6 and 9.5, leave the field intact to avoid
breaking things for third-party code that doesn't care about working
under EXEC_BACKEND. Prior to 9.5, there are no in-core bgworker
entrypoints.
Petr Jelinek, reviewed by me.
Discussion: http://postgr.es/m/09d8ad33-4287-a09b-a77f-77f8761adb5e@2ndquadrant.com
Diffstat (limited to 'doc/src')
| -rw-r--r-- | doc/src/sgml/bgworker.sgml | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml index 07f9f1081c3..b4223230819 100644 --- a/doc/src/sgml/bgworker.sgml +++ b/doc/src/sgml/bgworker.sgml @@ -54,9 +54,8 @@ typedef struct BackgroundWorker int bgw_flags; BgWorkerStartTime bgw_start_time; int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */ - bgworker_main_type bgw_main; - char bgw_library_name[BGW_MAXLEN]; /* only if bgw_main is NULL */ - char bgw_function_name[BGW_MAXLEN]; /* only if bgw_main is NULL */ + char bgw_library_name[BGW_MAXLEN]; + char bgw_function_name[BGW_MAXLEN]; Datum bgw_main_arg; char bgw_extra[BGW_EXTRALEN]; int bgw_notify_pid; @@ -131,26 +130,12 @@ typedef struct BackgroundWorker </para> <para> - <structfield>bgw_main</structfield> is a pointer to the function to run when - the process is started. This field can only safely be used to launch - functions within the core server, because shared libraries may be loaded - at different starting addresses in different backend processes. This will - happen on all platforms when the library is loaded using any mechanism - other than <xref linkend="guc-shared-preload-libraries">. Even when that - mechanism is used, address space layout variations will still occur on - Windows, and when <literal>EXEC_BACKEND</> is used. Therefore, most users - of this API should set this field to NULL. If it is non-NULL, it takes - precedence over <structfield>bgw_library_name</> and - <structfield>bgw_function_name</>. - </para> - - <para> <structfield>bgw_library_name</structfield> is the name of a library in which the initial entry point for the background worker should be sought. The named library will be dynamically loaded by the worker process and <structfield>bgw_function_name</structfield> will be used to identify the - function to be called. If loading a function from the core code, - <structfield>bgw_main</> should be set instead. + function to be called. If loading a function from the core code, this must + be set to "postgres". </para> <para> @@ -161,13 +146,10 @@ typedef struct BackgroundWorker <para> <structfield>bgw_main_arg</structfield> is the <type>Datum</> argument - to the background worker main function. Regardless of whether that - function is specified via <structfield>bgw_main</> or via the combination - of <function>bgw_library_name</> and <function>bgw_function_name</>, - this main function should take a single argument of type <type>Datum</> - and return <type>void</>. <structfield>bgw_main_arg</structfield> will be - passed as the argument. In addition, the global variable - <literal>MyBgworkerEntry</literal> + to the background worker main function. This main function should take a + single argument of type <type>Datum</> and return <type>void</>. + <structfield>bgw_main_arg</structfield> will be passed as the argument. + In addition, the global variable <literal>MyBgworkerEntry</literal> points to a copy of the <structname>BackgroundWorker</structname> structure passed at registration time; the worker may find it helpful to examine this structure. @@ -215,7 +197,7 @@ typedef struct BackgroundWorker <para> Signals are initially blocked when control reaches the - <structfield>bgw_main</> function, and must be unblocked by it; this is to + background worker's main function, and must be unblocked by it; this is to allow the process to customize its signal handlers, if necessary. Signals can be unblocked in the new process by calling <function>BackgroundWorkerUnblockSignals</> and blocked by calling |
