Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- fix for non-portable use of setenv

  • Loading branch information...
commit e4b70f28fdc45c65a9aa6fc6da56224fcd45cffe 1 parent d78ee6a
jconway authored
Showing with 32 additions and 4 deletions.
  1. +15 −1 pg_userfuncs.c
  2. +16 −3 plr.c
  3. +1 −0  plr.h
16 pg_userfuncs.c
View
@@ -33,6 +33,7 @@
#include "plr.h"
#include "miscadmin.h"
+#include "utils/memutils.h"
extern char **environ;
@@ -373,8 +374,21 @@ Datum
plr_set_rhome(PG_FUNCTION_ARGS)
{
char *rhome = PG_TEXT_GET_STR(PG_GETARG_TEXT_P(0));
+ size_t rh_len = strlen(rhome);
- setenv("R_HOME", rhome, 1);
+ if (rh_len)
+ {
+ char *rhenv;
+ MemoryContext oldcontext;
+
+ /* Needs to live until/unless we explicitly delete it */
+ oldcontext = MemoryContextSwitchTo(TopMemoryContext);
+ rhenv = palloc(8 + rh_len);
+ MemoryContextSwitchTo(oldcontext);
+
+ sprintf(rhenv, "R_HOME=%s", rhome);
+ putenv(rhenv);
+ }
PG_RETURN_TEXT_P(PG_STR_GET_TEXT("OK"));
}
19 plr.c
View
@@ -315,9 +315,22 @@ plr_init(void)
r_home = getenv("R_HOME");
if (r_home == NULL)
{
- /* see if this is a compiled in default R_HOME */
- if (strlen(R_HOME_DEFAULT))
- setenv("R_HOME", R_HOME_DEFAULT, 0);
+ size_t rh_len = strlen(R_HOME_DEFAULT);
+
+ /* see if there is a compiled in default R_HOME */
+ if (rh_len)
+ {
+ char *rhenv;
+ MemoryContext oldcontext;
+
+ /* Needs to live until/unless we explicitly delete it */
+ oldcontext = MemoryContextSwitchTo(TopMemoryContext);
+ rhenv = palloc(8 + rh_len);
+ MemoryContextSwitchTo(oldcontext);
+
+ sprintf(rhenv, "R_HOME=%s", R_HOME_DEFAULT);
+ putenv(rhenv);
+ }
else
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1  plr.h
View
@@ -36,6 +36,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <setjmp.h>
+#include <stdlib.h>
#include <sys/stat.h>
#include "R.h"
Please sign in to comment.
Something went wrong with that request. Please try again.