aboutsummaryrefslogtreecommitdiffstats
path: root/erts/etc/common/erlc.c
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2017-04-21 14:49:18 +0200
committerDan Gudmundsson <[email protected]>2017-04-24 14:14:39 +0200
commitfab97e165a79db10b7b560be5aefc7489982bced (patch)
tree45aa6c78ee53704e1c43edf9fe27f3fc2eb7ee8c /erts/etc/common/erlc.c
parent739bca3fc267c55d84c8f5c193d16c0b2a7eee13 (diff)
downloadotp-fab97e165a79db10b7b560be5aefc7489982bced.tar.gz
otp-fab97e165a79db10b7b560be5aefc7489982bced.tar.bz2
otp-fab97e165a79db10b7b560be5aefc7489982bced.zip
Rename argv[0] from beam to invoking program name
Allows ps and htop to display the invoking program/script name instead of beam[.smp].
Diffstat (limited to 'erts/etc/common/erlc.c')
-rw-r--r--erts/etc/common/erlc.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c
index b54cb31bef..2abeff33a3 100644
--- a/erts/etc/common/erlc.c
+++ b/erts/etc/common/erlc.c
@@ -72,6 +72,9 @@ static int pause_after_execution = 0;
static char* process_opt(int* pArgc, char*** pArgv, int offset);
static void error(char* format, ...);
static void* emalloc(size_t size);
+#ifdef HAVE_COPYING_PUTENV
+static void efree(void *p);
+#endif
static char* strsave(char* string);
static void push_words(char* src);
static int run_erlang(char* name, char** argv);
@@ -147,6 +150,28 @@ get_env(char *key)
}
static void
+set_env(char *key, char *value)
+{
+#ifdef __WIN32__
+ WCHAR wkey[MAXPATHLEN];
+ WCHAR wvalue[MAXPATHLEN];
+ MultiByteToWideChar(CP_UTF8, 0, key, -1, wkey, MAXPATHLEN);
+ MultiByteToWideChar(CP_UTF8, 0, value, -1, wvalue, MAXPATHLEN);
+ if (!SetEnvironmentVariableW(wkey, wvalue))
+ error("SetEnvironmentVariable(\"%s\", \"%s\") failed!", key, value);
+#else
+ size_t size = strlen(key) + 1 + strlen(value) + 1;
+ char *str = emalloc(size);
+ sprintf(str, "%s=%s", key, value);
+ if (putenv(str) != 0)
+ error("putenv(\"%s\") failed!", str);
+#ifdef HAVE_COPYING_PUTENV
+ efree(str);
+#endif
+#endif
+}
+
+static void
free_env_val(char *value)
{
#ifdef __WIN32__
@@ -188,6 +213,11 @@ int main(int argc, char** argv)
error("Value of environment variable ERLC_EMULATOR is too large");
/*
+ * Add scriptname to env
+ */
+ set_env("ESCRIPT_NAME", argv[0]);
+
+ /*
* Allocate the argv vector to be used for arguments to Erlang.
* Arrange for starting to pushing information in the middle of
* the array, to allow easy adding of emulator options (like -pa)
@@ -499,6 +529,13 @@ erealloc(void *p, size_t size)
}
#endif
+#ifdef HAVE_COPYING_PUTENV
+static void
+efree(void *p)
+{
+ free(p);
+}
+#endif
static char*
strsave(char* string)
{