Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- fix for non-portable use of setenv

  • Loading branch information...
commit 29895d05f20700b8a360eb59c0684b7f7809e7d8 1 parent 748a174
authored September 08, 2007
16  pg_userfuncs.c
@@ -33,6 +33,7 @@
33 33
 #include "plr.h"
34 34
 
35 35
 #include "miscadmin.h"
  36
+#include "utils/memutils.h"
36 37
 
37 38
 extern char **environ;
38 39
 
@@ -357,8 +358,21 @@ Datum
357 358
 plr_set_rhome(PG_FUNCTION_ARGS)
358 359
 {
359 360
 	char		   *rhome = PG_TEXT_GET_STR(PG_GETARG_TEXT_P(0));
  361
+	size_t			rh_len = strlen(rhome);
360 362
 
361  
-	setenv("R_HOME", rhome, 1);
  363
+	if (rh_len)
  364
+	{
  365
+		char			   *rhenv;
  366
+		MemoryContext		oldcontext;
  367
+
  368
+		/* Needs to live until/unless we explicitly delete it */
  369
+		oldcontext = MemoryContextSwitchTo(TopMemoryContext);
  370
+		rhenv = palloc(8 + rh_len);
  371
+		MemoryContextSwitchTo(oldcontext);
  372
+
  373
+		sprintf(rhenv, "R_HOME=%s", rhome);
  374
+		putenv(rhenv);
  375
+	}
362 376
 
363 377
 	PG_RETURN_TEXT_P(PG_STR_GET_TEXT("OK"));
364 378
 }
19  plr.c
@@ -317,9 +317,22 @@ plr_init(void)
317 317
 	r_home = getenv("R_HOME");
318 318
 	if (r_home == NULL)
319 319
 	{
320  
-		/* see if this is a compiled in default R_HOME */
321  
-		if (strlen(R_HOME_DEFAULT))
322  
-			setenv("R_HOME", R_HOME_DEFAULT, 0);
  320
+		size_t		rh_len = strlen(R_HOME_DEFAULT);
  321
+
  322
+		/* see if there is a compiled in default R_HOME */
  323
+		if (rh_len)
  324
+		{
  325
+			char	   *rhenv;
  326
+			MemoryContext		oldcontext;
  327
+
  328
+			/* Needs to live until/unless we explicitly delete it */
  329
+			oldcontext = MemoryContextSwitchTo(TopMemoryContext);
  330
+			rhenv = palloc(8 + rh_len);
  331
+			MemoryContextSwitchTo(oldcontext);
  332
+
  333
+			sprintf(rhenv, "R_HOME=%s", R_HOME_DEFAULT);
  334
+			putenv(rhenv);
  335
+		}
323 336
 		else
324 337
 			ereport(ERROR,
325 338
 					(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1  plr.h
@@ -36,6 +36,7 @@
36 36
 #include <unistd.h>
37 37
 #include <fcntl.h>
38 38
 #include <setjmp.h>
  39
+#include <stdlib.h>
39 40
 #include <sys/stat.h>
40 41
 
41 42
 #define ELOG_H

0 notes on commit 29895d0

Please sign in to comment.
Something went wrong with that request. Please try again.