diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 30e17bd1d1e07..d0c09852639b8 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -45,7 +45,7 @@ * *------------------------------------------------------------------------- */ - +#define PG_INITDB #include "postgres_fe.h" #include @@ -757,7 +757,7 @@ static char * get_id(void) { const char *username; - +#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) #ifndef WIN32 if (geteuid() == 0) /* 0 is root's uid */ { @@ -766,10 +766,12 @@ get_id(void) exit(1); } #endif - username = get_user_name_or_exit(progname); return pg_strdup(username); +#else + return pg_strdup(WASM_USERNAME); +#endif // wasm } static char * @@ -2587,8 +2589,13 @@ setup_bin_paths(const char *argv0) strlcpy(full_path, progname, sizeof(full_path)); if (ret == -1) +#if defined(__EMSCRIPTEN__) || defined(__wasi__) + printf("# WARNING: program \"%s\" is needed by %s but was not found in the same directory as \"%s\"\n", + "postgres", progname, full_path); +#else pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"", "postgres", progname, full_path); +#endif // wasm else pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s", "postgres", full_path, progname); @@ -3024,7 +3031,9 @@ initialize_data_directory(void) /* Select suitable configuration settings */ set_null_conf(); +#if !defined(__EMSCRIPTEN__) && !defined(__wasi__) test_config_settings(); +#endif // wasm /* Now create all the text config files */ setup_config(); diff --git a/src/common/exec.c b/src/common/exec.c index 0bee19c1e539f..ccc89f3f9719d 100644 --- a/src/common/exec.c +++ b/src/common/exec.c @@ -22,7 +22,7 @@ * This should be harmless everywhere else. */ #define _DARWIN_BETTER_REALPATH - +#define PG_EXEC #ifndef FRONTEND #include "postgres.h" #else @@ -411,7 +411,6 @@ pclose_check(FILE *stream) { int exitstatus; char *reason; - exitstatus = pclose(stream); if (exitstatus == 0) diff --git a/src/port/path.c b/src/port/path.c index 330b3f90332b0..73c474b4d742a 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -598,6 +598,15 @@ get_progname(const char *argv0) if (strlen(progname) > sizeof(EXE) - 1 && pg_strcasecmp(progname + strlen(progname) - (sizeof(EXE) - 1), EXE) == 0) progname[strlen(progname) - (sizeof(EXE) - 1)] = '\0'; +#elif defined(__EMSCRIPTEN__) + /* remove .js and make log a commment */ + if (progname && strlen(progname)>4) { + for (int i=strlen(progname)-2;i>2;i--) + progname[i] = progname[i-2]; + progname[0]= '#'; + progname[1]= ' '; + progname[strlen(progname)-1] = '\0'; + } #endif return progname;