Skip to content

Commit 037f970

Browse files
committed
PGL_* fencing
1 parent eef7567 commit 037f970

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

src/backend/tcop/postgres.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,17 @@ int client_connection_check_interval = 0;
105105
/* flags for non-system relation kinds to restrict use */
106106
int restrict_nonsystem_relation_kind;
107107

108-
#if (defined(__EMSCRIPTEN__) || defined(__wasi__)) && !defined(PATCH_MAIN)
109-
int cma_rsize = 0;
108+
#if (defined(__EMSCRIPTEN__) || defined(__wasi__))
109+
#if !defined(PGL_MAIN)
110+
volatile int cma_rsize = 0;
111+
#endif // PGL_MAIN
110112
bool quote_all_identifiers = false;
111-
#endif
113+
FILE* SOCKET_FILE = NULL;
114+
int SOCKET_DATA = 0;
115+
#endif // WASM
116+
117+
118+
112119

113120
/* ----------------
114121
* private typedefs etc
@@ -4081,7 +4088,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
40814088
#endif
40824089
}
40834090

4084-
#if !defined(PATCH_MAIN)
4091+
#if !defined(PGL_MAIN)
40854092
/*
40864093
* PostgresSingleUserMain
40874094
* Entry point for single user mode. argc/argv are the command line
@@ -4977,7 +4984,7 @@ PostgresMain(const char *dbname, const char *username)
49774984
}
49784985
} /* end of input-reading loop */
49794986
}
4980-
#endif /* PATCH_MAIN */
4987+
#endif /* PGL_MAIN */
49814988
/*
49824989
* Throw an error if we're a WAL sender process.
49834990
*

src/include/port/wasm_common.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,48 +100,42 @@ extern int pg_valid_server_encoding_id_private(int encoding);
100100
#define proc_exit(arg) pg_proc_exit(arg)
101101

102102

103+
104+
105+
#if defined(PGL_MAIN)
106+
#warning "PGL_MAIN"
103107
/*
104108
* popen is routed via pg_popen to stderr or a IDB_PIPE_* file
105109
* link a pclose replacement when we are in exec.c ( PG_EXEC defined )
106110
*/
107111

112+
extern FILE * pg_popen(const char *command, const char *type);
113+
#define popen(command, mode) pg_popen(command, mode)
108114

109-
#if defined(PG_EXEC)
115+
extern int pg_pclose(FILE *stream);
110116
#define pclose(stream) pg_pclose(stream)
111-
#include <stdio.h> // FILE
112-
113-
EMSCRIPTEN_KEEPALIVE FILE*
114-
SOCKET_FILE = NULL;
115117

116-
EMSCRIPTEN_KEEPALIVE int
117-
SOCKET_DATA = 0;
118-
119-
EMSCRIPTEN_KEEPALIVE FILE*
120-
IDB_PIPE_FP = NULL;
118+
#endif
121119

122-
EMSCRIPTEN_KEEPALIVE int
123-
IDB_STAGE = 0;
120+
#if defined(PGL_INITDB_MAIN)
124121

125-
int pg_pclose(FILE *stream);
126122

127-
int pg_pclose(FILE *stream) {
128-
if (IDB_STAGE==1)
129-
fprintf(stderr,"# pg_pclose(%s) 133:" __FILE__ "\n" , IDB_PIPE_BOOT);
130-
if (IDB_STAGE==2)
131-
fprintf(stderr,"# pg_pclose(%s) 135:" __FILE__ "\n" , IDB_PIPE_SINGLE);
132-
133-
if (IDB_PIPE_FP) {
134-
fflush(IDB_PIPE_FP);
135-
fclose(IDB_PIPE_FP);
136-
IDB_PIPE_FP = NULL;
137-
}
138-
return 0;
139-
}
140123

124+
// to override chmod()
125+
#include <sys/stat.h>
141126

142-
#endif // PG_EXEC
127+
extern int pg_chmod(const char * path, int mode_t);
128+
// initdb chmod is not supported by wasi, so just don't use it anywhere
129+
// #if defined(__wasi__)
130+
#define chmod(path, mode) pg_chmod(path, mode)
131+
//#endif
143132

133+
#endif
144134

135+
extern FILE* IDB_PIPE_FP;
136+
extern int IDB_STAGE;
137+
extern FILE* SOCKET_FILE;
138+
extern int SOCKET_DATA;
145139

146140
/*
147141
* OpenPipeStream : another kind of pipe open in fd.c

0 commit comments

Comments
 (0)