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

Commite2f21ff

Browse files
committed
Add fallback implementation for setenv()
This fixes the code compilation on Windows with MSVC and Kerberos, asa missing implementation of setenv() causes a compilation failure of theGSSAPI code. This was only reproducible when building the code withKerberos, something that buildfarm animal hamerkop has fixed recently.This issue only happens on 12 and 13, as this code has been introducedinb0b39f7. HEAD is already able to compile properly thanks to7ca37fb, and this commit is a minimal cherry-pick of it.Thanks to Tom Lane for the discussion.Discussion:https://postgr.es/m/YLDtm5WGjPxm6ua4@paquier.xyzBackpatch-through: 12
1 parentfe6f632 commite2f21ff

File tree

8 files changed

+80
-3
lines changed

8 files changed

+80
-3
lines changed

‎configure

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15858,12 +15858,29 @@ case $host_os in
1585815858
# Windows uses a specialised env handler
1585915859
mingw*)
1586015860

15861+
$as_echo "#define HAVE_SETENV 1" >>confdefs.h
15862+
15863+
1586115864
$as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
1586215865

15866+
ac_cv_func_setenv=yes
1586315867
ac_cv_func_unsetenv=yes
1586415868
;;
1586515869
*)
15866-
ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv"
15870+
ac_fn_c_check_func "$LINENO" "setenv" "ac_cv_func_setenv"
15871+
if test "x$ac_cv_func_setenv" = xyes; then :
15872+
$as_echo "#define HAVE_SETENV 1" >>confdefs.h
15873+
15874+
else
15875+
case " $LIBOBJS " in
15876+
*" setenv.$ac_objext "* ) ;;
15877+
*) LIBOBJS="$LIBOBJS setenv.$ac_objext"
15878+
;;
15879+
esac
15880+
15881+
fi
15882+
15883+
ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv"
1586715884
if test "x$ac_cv_func_unsetenv" = xyes; then :
1586815885
$as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
1586915886

‎configure.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,11 +1747,13 @@ fi
17471747
case $host_os in
17481748
# Windows uses a specialised env handler
17491749
mingw*)
1750+
AC_DEFINE(HAVE_SETENV, 1, [Define to 1 because replacement version used.])
17501751
AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
1752+
ac_cv_func_setenv=yes
17511753
ac_cv_func_unsetenv=yes
17521754
;;
17531755
*)
1754-
AC_REPLACE_FUNCS([unsetenv])
1756+
AC_REPLACE_FUNCS([setenvunsetenv])
17551757
;;
17561758
esac
17571759

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@
473473
/* Define to 1 if you have the <security/pam_appl.h> header file. */
474474
#undef HAVE_SECURITY_PAM_APPL_H
475475

476+
/* Define to 1 if you have the `setenv' function. */
477+
#undef HAVE_SETENV
478+
476479
/* Define to 1 if you have the `setproctitle' function. */
477480
#undef HAVE_SETPROCTITLE
478481

‎src/include/port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ extern size_t strnlen(const char *str, size_t maxlen);
429429
externlongrandom(void);
430430
#endif
431431

432+
#ifndefHAVE_SETENV
433+
externintsetenv(constchar*name,constchar*value,intoverwrite);
434+
#endif
435+
432436
#ifndefHAVE_UNSETENV
433437
externvoidunsetenv(constchar*name);
434438
#endif

‎src/include/port/win32_port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ extern void _dosmaperr(unsigned long);
462462

463463
/* in port/win32env.c */
464464
externintpgwin32_putenv(constchar*);
465+
externintpgwin32_setenv(constchar*name,constchar*value,intoverwrite);
465466
externvoidpgwin32_unsetenv(constchar*);
466467

467468
/* in port/win32security.c */
@@ -472,6 +473,7 @@ extern intpgwin32_is_admin(void);
472473
externBOOLAddUserToTokenDacl(HANDLEhToken);
473474

474475
#defineputenv(x) pgwin32_putenv(x)
476+
#definesetenv(x,y,z) pgwin32_setenv(x,y,z)
475477
#defineunsetenv(x) pgwin32_unsetenv(x)
476478

477479
/* Things that exist in MinGW headers, but need to be added to MSVC */

‎src/port/setenv.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* setenv.c
4+
* setenv() emulation for machines without it
5+
*
6+
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* src/port/setenv.c
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
16+
#include"c.h"
17+
18+
19+
int
20+
setenv(constchar*name,constchar*value,intoverwrite)
21+
{
22+
char*envstr;
23+
24+
/* Error conditions, per POSIX */
25+
if (name==NULL||name[0]=='\0'||strchr(name,'=')!=NULL||
26+
value==NULL)
27+
{
28+
errno=EINVAL;
29+
return-1;
30+
}
31+
32+
/* No work if variable exists and we're not to replace it */
33+
if (overwrite==0&&getenv(name)!=NULL)
34+
return0;
35+
36+
/*
37+
* Add or replace the value using putenv(). This will leak memory if the
38+
* same variable is repeatedly redefined, but there's little we can do
39+
* about that when sitting atop putenv().
40+
*/
41+
envstr= (char*)malloc(strlen(name)+strlen(value)+2);
42+
if (!envstr)/* not much we can do if no memory */
43+
return-1;
44+
45+
sprintf(envstr,"%s=%s",name,value);
46+
47+
returnputenv(envstr);
48+
}

‎src/tools/msvc/Mkvcbuild.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ sub mkvcbuild
101101
dirent.c dlopen.c getopt.c getopt_long.c link.c
102102
pread.c pwrite.c pg_bitutils.c
103103
pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
104-
pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c
104+
pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.csetenv.csystem.c
105105
sprompt.c strerror.c tar.c thread.c
106106
win32env.c win32error.c win32security.c win32setlocale.c);
107107

‎src/tools/msvc/Solution.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ sub GenerateFiles
341341
HAVE_RL_FILENAME_QUOTING_FUNCTION=>undef,
342342
HAVE_RL_RESET_SCREEN_SIZE=>undef,
343343
HAVE_SECURITY_PAM_APPL_H=>undef,
344+
HAVE_SETENV=>undef,
344345
HAVE_SETPROCTITLE=>undef,
345346
HAVE_SETPROCTITLE_FAST=>undef,
346347
HAVE_SETSID=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp