Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Dept of second thoughts -- instead of recommending setting of

R_SESSION_TMPDIR, which is potentially a concurrency issue, add an exit
callback using Postgres on_proc_exit() function. The callback function
then calls Rstd_CleanUp(), and all is good.
  • Loading branch information...
commit 00c7a66e9f09c654999bde886464821127ca6e4f 1 parent d6a911e
postgres authored
Showing with 41 additions and 15 deletions.
  1. +2 −15 doc/plr.sgml
  2. +17 −0 plr.c
  3. +22 −0 plr.h
View
17 doc/plr.sgml
@@ -107,21 +107,8 @@ CREATE LANGUAGE plr HANDLER plr_call_handler;
<tip>
<para>
R_HOME must be defined in the environment of the user under which
- PostgreSQL is started (a.k.a. the administrative user), <emphasis>before
- </emphasis> the postmaster is started. Otherwise PL/R will refuse to load.
- </para>
- <para>
- Additionally, R_SESSION_TMPDIR may be defined in the environment of
- the administrative user, also <emphasis>before</emphasis> the postmaster
- is started. R_SESSION_TMPDIR must specify an existing directory, owned by
- the administrative user. The R interpreter uses this directory as it
- performs its tasks. If this environment variable is not defined, the R
- interpreter will create its own temporary directories (e.g. /tmp/Rtmp12345,
- where 12345 is the pid of the process creating the directory). A normal
- command line R session would remove this directory when it exists. However
- PL/R has no way to know when a PostgreSQL session might end, therefore
- these temporary directories will accumulate until removed manually
- or by your OS.
+ PostgreSQL is started, <emphasis>before</emphasis> the postmaster
+ is started. Otherwise PL/R will refuse to load.
</para>
</tip>
View
17 plr.c
@@ -31,6 +31,7 @@
* plr.c - Language handler and support functions
*/
#include "plr.h"
+#include "storage/ipc.h"
/*
* Global data
@@ -221,6 +222,18 @@ load_r_cmd(const char *cmd)
}
/*
+ * plr_cleanup() - Let the embedded interpreter clean up after itself
+ *
+ * DO NOT make this static --- it has to be registered as an on_proc_exit()
+ * callback
+ */
+void
+plr_cleanup(void)
+{
+ Rstd_CleanUp(SA_NOSAVE, 0, FALSE);
+}
+
+/*
* plr_init() - Initialize all that's safe to do in the postmaster
*
* DO NOT make this static --- it has to be callable by preload
@@ -247,6 +260,10 @@ plr_init(void)
rargc = sizeof(rargv)/sizeof(rargv[0]);
Rf_initEmbeddedR(rargc, rargv);
+
+ /* arrange for automatic cleanup at proc_exit */
+ on_proc_exit(plr_cleanup, 0);
+
plr_pm_init_done = true;
}
View
22 plr.h
@@ -128,6 +128,27 @@ extern SEXP R_ParseVector(SEXP, int, int *);
#define PARSE_ERROR 3
#define PARSE_EOF 4
+
+/*
+ * See the no-exported header file ${R_HOME}/src/include/Startup.h
+ */
+/* Startup Actions */
+typedef enum {
+ SA_NORESTORE,/* = 0 */
+ SA_RESTORE,
+ SA_DEFAULT,/* was === SA_RESTORE */
+ SA_NOSAVE,
+ SA_SAVE,
+ SA_SAVEASK,
+ SA_SUICIDE
+} SA_TYPE;
+
+/*
+ * See the no-exported header file ${R_HOME}/src/unix/Runix.h
+ */
+extern void Rstd_CleanUp(SA_TYPE saveact, int status, int runLast);
+
+
/* convert C string to text pointer */
#define PG_TEXT_GET_STR(textp_) \
DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
@@ -284,6 +305,7 @@ extern int Rf_initEmbeddedR(int argc, char **argv);
/* PL/R language handler */
extern Datum plr_call_handler(PG_FUNCTION_ARGS);
+extern void plr_cleanup(void);
extern void plr_init(void);
extern void plr_load_modules(MemoryContext plr_SPI_context);
extern void load_r_cmd(const char *cmd);
Please sign in to comment.
Something went wrong with that request. Please try again.