From 5b9265ad19d6596a8b599eccc64accb67e3c664e Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Mon, 21 Nov 2016 11:48:54 +0000 Subject: Remove vestiges of watchdog support in heart Hardware watchdog support was removed from heart in R13A, but there were still some vestiges in the code and the documentation. - Remove mentions of the HW_WD_DISABLE variable, as it's no longer used. - Remove the HEART_BEAT_BOOT_DELAY variable, as it was only used for the hardware watchdog. --- erts/etc/common/heart.c | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/heart.c b/erts/etc/common/heart.c index d67b997d6d..bc353e384e 100644 --- a/erts/etc/common/heart.c +++ b/erts/etc/common/heart.c @@ -48,13 +48,10 @@ * * HEART_BEATING * - * This program expects a heart beat messages. If it does not receive a - * heart beat message from Erlang within heart_beat_timeout seconds, it - * reboots the system. The variable heart_beat_timeout is exported (so - * that it can be set from the shell in VxWorks, as is the variable - * heart_beat_report_delay). When using Solaris, the system is rebooted - * by executing the command stored in the environment variable - * HEART_COMMAND. + * This program expects a heart beat message. If it does not receive a + * heart beat message from Erlang within heart_beat_timeout seconds, it + * reboots the system. The system is rebooted by executing the command + * stored in the environment variable HEART_COMMAND. * * BLOCKING DESCRIPTORS * @@ -149,27 +146,17 @@ struct msg { /* Maybe interesting to change */ /* Times in seconds */ -#define HEART_BEAT_BOOT_DELAY 60 /* 1 minute */ #define SELECT_TIMEOUT 5 /* Every 5 seconds we reset the watchdog timer */ /* heart_beat_timeout is the maximum gap in seconds between two - consecutive heart beat messages from Erlang, and HEART_BEAT_BOOT_DELAY - is the the extra delay that wd_keeper allows for, to give heart a - chance to reboot in the "normal" way before the hardware watchdog - enters the scene. heart_beat_report_delay is the time allowed for reporting - before rebooting under VxWorks. */ + consecutive heart beat messages from Erlang. */ int heart_beat_timeout = 60; -int heart_beat_report_delay = 30; -int heart_beat_boot_delay = HEART_BEAT_BOOT_DELAY; /* All current platforms have a process identifier that fits in an unsigned long and where 0 is an impossible or invalid value */ unsigned long heart_beat_kill_pid = 0; -#define VW_WD_TIMEOUT (heart_beat_timeout+heart_beat_report_delay+heart_beat_boot_delay) -#define SOL_WD_TIMEOUT (heart_beat_timeout+heart_beat_boot_delay) - /* reasons for reboot */ #define R_TIMEOUT (1) #define R_CLOSED (2) @@ -297,7 +284,6 @@ free_env_val(char *value) static void get_arguments(int argc, char** argv) { int i = 1; int h; - int w; unsigned long p; while (i < argc) { @@ -313,15 +299,6 @@ static void get_arguments(int argc, char** argv) { i++; } break; - case 'w': - if (strcmp(argv[i], "-wt") == 0) - if (sscanf(argv[i+1],"%i",&w) ==1) - if ((w > 10) && (w <= 65535)) { - heart_beat_boot_delay = w; - fprintf(stderr,"heart_beat_boot_delay = %d\n",w); - i++; - } - break; case 'p': if (strcmp(argv[i], "-pid") == 0) if (sscanf(argv[i+1],"%lu",&p) ==1){ @@ -347,7 +324,7 @@ static void get_arguments(int argc, char** argv) { } i++; } - debugf("arguments -ht %d -wt %d -pid %lu\n",h,w,p); + debugf("arguments -ht %d -pid %lu\n",h,p); } int main(int argc, char **argv) { @@ -674,11 +651,6 @@ void win_system(char *command) */ static void do_terminate(int erlin_fd, int reason) { - /* - When we get here, we have HEART_BEAT_BOOT_DELAY secs to finish - (plus heart_beat_report_delay if under VxWorks), so we don't need - to call wd_reset(). - */ int ret = 0, tmo=0; char *tmo_env; -- cgit v1.2.3 From 1d8dbc7123245a536df6bb09e891d3a075fb70ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kan=20Mattsson?= Date: Thu, 22 Dec 2016 09:57:21 +0100 Subject: escript: Handle symbolic link to a standalone escript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code has been rearranged to make use of the actual path "get_default_emulator(scriptname)" to the escript instead of the given one "get_default_emulator(argv[0])". TL;DR Assume a source system with some Erlang applications (app1, app2 etc.) and an escript called "mytool". When generating a standalone target system (with reltool for example), the escript(s) are located in the same top bin directory as "erl". See mytool* below. In such a system the original "mytool" escript is given the extension ".escript" and the file with the same name as the original escript is a copy of the "escript" executable. One purpose of the escript executable is to determine which "erl" to use to start the system. In a standalone system we want it to find the runtime system bundled with the escript(s). This is done by analyzing the path in order to find the "erl" located in the same directory as the escript. A dilemma here is that we do not want to put the top bin directory in the execution path (PATH env var) as we then would cause other Erlang applications to make use of our bundled run-time system. One way of solving this is to choose some suitable bin directory in the execution path (such as /user/local/bin) and put a symbolic link there to our mytool executable. Unfortunately this did not work as the escript executable (in this case called mytool) would try to find "erl" in /usr/local/bin and when it did not find such a file it resorted to use the command "erl" which would find some (unwanted) "erl" in the execution path. My fix solves that problem. ├── bin/ │   ├── erl* (dyn_erl.c) │   ├── mytool* (escript.c) │   ├── mytool.escript* (original mytool escript) │   └── start_clean.boot ├── erts-vsn/ │   └── bin/ │   ├── beam* │   ├── beam.smp* │   ├── erl* │   ├── erl_child_setup* │   ├── erlexec* │   └── inet_gethost* └── lib/ ├── app1-vsn ├── app2-vsn └── ... --- erts/etc/common/escript.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 71c278881c..4134a3ff36 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -428,14 +428,6 @@ main(int argc, char** argv) argv[argc] = NULL; #endif - emulator = env = get_env("ESCRIPT_EMULATOR"); - if (emulator == NULL) { - emulator = get_default_emulator(argv[0]); - } - - if (strlen(emulator) >= PMAX) - error("Value of environment variable ESCRIPT_EMULATOR is too large"); - /* * Allocate the argv vector to be used for arguments to Erlang. * Arrange for starting to pushing information in the middle of @@ -446,21 +438,10 @@ main(int argc, char** argv) eargv_base = (char **) emalloc(eargv_size*sizeof(char*)); eargv = eargv_base; eargc = 0; - push_words(emulator); eargc_base = eargc; eargv = eargv + eargv_size/2; eargc = 0; - free_env_val(env); - - /* - * Push initial arguments. - */ - - PUSH("+B"); - PUSH2("-boot", "start_clean"); - PUSH("-noshell"); - /* Determine basename of the executable */ for (basename = argv[0]+strlen(argv[0]); basename > argv[0] && !(IS_DIRSEP(basename[-1])); @@ -510,6 +491,27 @@ main(int argc, char** argv) efree(absname); } + /* Determine path to emulator */ + emulator = env = get_env("ESCRIPT_EMULATOR"); + + if (emulator == NULL) { + emulator = get_default_emulator(scriptname); + } + + if (strlen(emulator) >= PMAX) + error("Value of environment variable ESCRIPT_EMULATOR is too large"); + + /* + * Push initial arguments. + */ + + push_words(emulator); + free_env_val(env); + + PUSH("+B"); + PUSH2("-boot", "start_clean"); + PUSH("-noshell"); + /* * Read options from the %%! row in the script and add them as args */ -- cgit v1.2.3 From 7c06ca6231b812965305522284dd9f2653ced98d Mon Sep 17 00:00:00 2001 From: Andrew Dryga Date: Tue, 14 Feb 2017 11:30:41 +0200 Subject: Fixed typos in erts --- erts/etc/common/inet_gethost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c index bc4893b0eb..ccafd95e51 100644 --- a/erts/etc/common/inet_gethost.c +++ b/erts/etc/common/inet_gethost.c @@ -2717,7 +2717,7 @@ BOOL close_mesq(MesQ *q) LeaveCriticalSection(&(q->crit)); return FALSE; } - /* Noone else is supposed to use this object any more */ + /* No one else is supposed to use this object any more */ LeaveCriticalSection(&(q->crit)); DeleteCriticalSection(&(q->crit)); CloseHandle(q->data_present); -- cgit v1.2.3 From 455132374162a06df39e1bff4780610ef8e86870 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 6 Mar 2017 16:58:54 +0100 Subject: erts: Only show debug consoles if ERL_CONSOLE_MODE is defined --- erts/etc/common/erlexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 2b2e0e480a..ee59759940 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -1044,7 +1044,7 @@ int main(int argc, char **argv) start_epmd(epmd_prog); #if (! defined(__WIN32__)) && defined(DEBUG) - if (start_detached) { + if (start_detached && get_env("ERL_CONSOLE_MODE")) { /* Start the emulator within an xterm. * Move up all arguments and insert * "xterm -e " first. -- cgit v1.2.3 From 6a4d4b43914a5898671e7f9dea7988771450af0f Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Thu, 2 Mar 2017 17:36:48 +0100 Subject: Remove typer application The application now has an own repo, https://github.com/erlang/typer --- erts/etc/common/Makefile.in | 11 +- erts/etc/common/typer.c | 455 -------------------------------------------- 2 files changed, 2 insertions(+), 464 deletions(-) delete mode 100644 erts/etc/common/typer.c (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index cb053a1b7c..d3af634729 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -143,7 +143,7 @@ MC_OUTPUTS=$(OBJDIR)/erlsrv_logmess.h $(OBJDIR)/erlsrv_logmess.res MT_FLAG="-MD" endif INET_GETHOST = $(BINDIR)/inet_gethost.exe -INSTALL_EMBEDDED_PROGS += $(BINDIR)/typer.exe $(BINDIR)/dialyzer.exe $(BINDIR)/erlc.exe $(BINDIR)/start_erl.exe $(BINDIR)/escript.exe $(BINDIR)/ct_run.exe +INSTALL_EMBEDDED_PROGS += $(BINDIR)/dialyzer.exe $(BINDIR)/erlc.exe $(BINDIR)/start_erl.exe $(BINDIR)/escript.exe $(BINDIR)/ct_run.exe INSTALL_SRC = $(WINETC)/start_erl.c $(WINETC)/Nmakefile.start_erl ERLEXECDIR=. INSTALL_LIBS = @@ -176,7 +176,7 @@ ENTRY_OBJ= ERLSRV_OBJECTS= MC_OUTPUTS= INET_GETHOST = $(BINDIR)/inet_gethost@EXEEXT@ -INSTALL_EMBEDDED_PROGS += $(BINDIR)/typer@EXEEXT@ $(BINDIR)/dialyzer@EXEEXT@ \ +INSTALL_EMBEDDED_PROGS += $(BINDIR)/dialyzer@EXEEXT@ \ $(BINDIR)/erlc@EXEEXT@ $(BINDIR)/escript@EXEEXT@ $(BINDIR)/ct_run@EXEEXT@ \ $(BINDIR)/run_erl $(BINDIR)/to_erl $(BINDIR)/dyn_erl INSTALL_EMBEDDED_DATA = $(UXETC)/start.src $(UXETC)/start_erl.src @@ -242,7 +242,6 @@ endif rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/safe_string.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/run_erl.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/to_erl.o - rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/typer.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/ct_run.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/vxcall.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/erl.o @@ -433,12 +432,6 @@ $(BINDIR)/dialyzer@EXEEXT@: $(OBJDIR)/dialyzer.o $(ERTS_LIB) $(OBJDIR)/dialyzer.o: dialyzer.c $(RC_GENERATED) $(V_CC) $(CFLAGS) -o $@ -c dialyzer.c -$(BINDIR)/typer@EXEEXT@: $(OBJDIR)/typer.o $(ERTS_LIB) - $(ld_verbose)$(PURIFY) $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/typer.o -L$(OBJDIR) $(LIBS) $(ERTS_INTERNAL_LIBS) - -$(OBJDIR)/typer.o: typer.c $(RC_GENERATED) - $(V_CC) $(CFLAGS) -o $@ -c typer.c - $(BINDIR)/escript@EXEEXT@: $(OBJDIR)/escript.o $(ERTS_LIB) $(ld_verbose)$(PURIFY) $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/escript.o -L$(OBJDIR) $(LIBS) $(ERTS_INTERNAL_LIBS) diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c deleted file mode 100644 index 77a95ccded..0000000000 --- a/erts/etc/common/typer.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - * %CopyrightBegin% - * - * Copyright Ericsson AB 2006-2016. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * %CopyrightEnd% - */ -/* - * Purpose: Typer front-end. - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -#endif - -#include - -#define NO 0 -#define YES 1 - -#define ASIZE(a) (sizeof(a)/sizeof(a[0])) - -static int debug = 0; /* Bit flags for debug printouts. */ - -static char** eargv_base; /* Base of vector. */ -static char** eargv; /* First argument for erl. */ - -static int eargc; /* Number of arguments in eargv. */ - -#ifdef __WIN32__ -# define QUOTE(s) possibly_quote(s) -# define IS_DIRSEP(c) ((c) == '/' || (c) == '\\') -# define ERL_NAME "erl.exe" -#else -# define QUOTE(s) s -# define IS_DIRSEP(c) ((c) == '/') -# define ERL_NAME "erl" -#endif - -#define UNSHIFT(s) eargc++, eargv--; eargv[0] = QUOTE(s) -#define PUSH(s) eargv[eargc++] = QUOTE(s) -#define PUSH2(s, t) PUSH(s); PUSH(t) -#define PUSH3(s, t, u) PUSH2(s, t); PUSH(u) - -/* - * Local functions. - */ - -static void error(char* format, ...); -static void* emalloc(size_t size); -static char* strsave(char* string); -static void push_words(char* src); -static int run_erlang(char* name, char** argv); -static char* get_default_emulator(char* progname); -#ifdef __WIN32__ -static char* possibly_quote(char* arg); -static void* erealloc(void *p, size_t size); -#endif - -/* - * Supply a strerror() function if libc doesn't. - */ -#ifndef HAVE_STRERROR - -extern int sys_nerr; - -#ifndef SYS_ERRLIST_DECLARED -extern const char * const sys_errlist[]; -#endif /* !SYS_ERRLIST_DECLARED */ - -char *strerror(int errnum) -{ - static char *emsg[1024]; - - if (errnum != 0) { - if (errnum > 0 && errnum < sys_nerr) - sprintf((char *) &emsg[0], "(%s)", sys_errlist[errnum]); - else - sprintf((char *) &emsg[0], "errnum = %d ", errnum); - } - else { - emsg[0] = '\0'; - } - return (char *) &emsg[0]; -} -#endif /* !HAVE_STRERROR */ - -#ifdef __WIN32__ -int wmain(int argc, wchar_t **wcargv) -{ - char** argv; -#else -int -main(int argc, char** argv) -{ -#endif - int eargv_size; - int eargc_base; /* How many arguments in the base of eargv. */ - char* emulator; - int need_shell = 0; - -#ifdef __WIN32__ - int i; - int len; - /* Convert argv to utf8 */ - argv = emalloc((argc+1) * sizeof(char*)); - for (i=0; i 1 && strcmp(argv[1], "-smp") == 0) { - PUSH("-smpauto"); - argc--, argv++; - } - - PUSH("+B"); - PUSH2("-boot", "start_clean"); - PUSH3("-run", "typer", "start"); - PUSH("-extra"); - - /* - * Push everything except --shell. - */ - - while (argc > 1) { - if (strcmp(argv[1], "--shell") == 0) { - need_shell = 1; - } else { - PUSH(argv[1]); - } - argc--, argv++; - } - - if (!need_shell) { - UNSHIFT("-noinput"); - } - - /* - * Move up the commands for invoking the emulator and adjust eargv - * accordingly. - */ - - while (--eargc_base >= 0) { - UNSHIFT(eargv_base[eargc_base]); - } - - /* - * Invoke Erlang with the collected options. - */ - - PUSH(NULL); - return run_erlang(eargv[0], eargv); -} - -static void -push_words(char* src) -{ - char sbuf[MAXPATHLEN]; - char* dst; - - dst = sbuf; - while ((*dst++ = *src++) != '\0') { - if (isspace((int)*src)) { - *dst = '\0'; - PUSH(strsave(sbuf)); - dst = sbuf; - do { - src++; - } while (isspace((int)*src)); - } - } - if (sbuf[0]) - PUSH(strsave(sbuf)); -} -#ifdef __WIN32__ -wchar_t *make_commandline(char **argv) -{ - static wchar_t *buff = NULL; - static int siz = 0; - int num = 0, len; - char **arg; - wchar_t *p; - - if (*argv == NULL) { - return L""; - } - for (arg = argv; *arg != NULL; ++arg) { - num += strlen(*arg)+1; - } - if (!siz) { - siz = num; - buff = (wchar_t *) emalloc(siz*sizeof(wchar_t)); - } else if (siz < num) { - siz = num; - buff = (wchar_t *) erealloc(buff,siz*sizeof(wchar_t)); - } - p = buff; - num=0; - for (arg = argv; *arg != NULL; ++arg) { - len = MultiByteToWideChar(CP_UTF8, 0, *arg, -1, p, siz); - p+=(len-1); - *p++=L' '; - } - *(--p) = L'\0'; - - if (debug) { - printf("Processed command line:%S\n",buff); - } - return buff; -} - -int my_spawnvp(char **argv) -{ - STARTUPINFOW siStartInfo; - PROCESS_INFORMATION piProcInfo; - DWORD ec; - - memset(&siStartInfo,0,sizeof(STARTUPINFOW)); - siStartInfo.cb = sizeof(STARTUPINFOW); - siStartInfo.dwFlags = STARTF_USESTDHANDLES; - siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); - - if (!CreateProcessW(NULL, - make_commandline(argv), - NULL, - NULL, - TRUE, - 0, - NULL, - NULL, - &siStartInfo, - &piProcInfo)) { - return -1; - } - CloseHandle(piProcInfo.hThread); - - WaitForSingleObject(piProcInfo.hProcess,INFINITE); - if (!GetExitCodeProcess(piProcInfo.hProcess,&ec)) { - return 0; - } - return (int) ec; -} -#endif /* __WIN32__ */ - - -static int -run_erlang(char* progname, char** argv) -{ -#ifdef __WIN32__ - int status; -#endif - - if (debug) { - int i = 0; - while (argv[i] != NULL) - printf(" %s", argv[i++]); - printf("\n"); - } - -#ifdef __WIN32__ - /* - * Alas, we must wait here for the program to finish. - * Otherwise, the shell from which we were executed will think - * we are finished and print a prompt and read keyboard input. - */ - - status = my_spawnvp(argv)/*_spawnvp(_P_WAIT,progname,argv)*/; - if (status == -1) { - fprintf(stderr, "typer: Error executing '%s': %d", progname, - GetLastError()); - } - return status; -#else - execvp(progname, argv); - error("Error %d executing \'%s\'.", errno, progname); - return 2; -#endif -} - -static void -error(char* format, ...) -{ - char sbuf[1024]; - va_list ap; - - va_start(ap, format); - erts_vsnprintf(sbuf, sizeof(sbuf), format, ap); - va_end(ap); - fprintf(stderr, "typer: %s\n", sbuf); - exit(1); -} - -static void* -emalloc(size_t size) -{ - void *p = malloc(size); - if (p == NULL) - error("Insufficient memory"); - return p; -} - -#ifdef __WIN32__ -static void * -erealloc(void *p, size_t size) -{ - void *res = realloc(p, size); - if (res == NULL) - error("Insufficient memory"); - return res; -} -#endif - -static char* -strsave(char* string) -{ - char* p = emalloc(strlen(string)+1); - strcpy(p, string); - return p; -} - -static int -file_exists(char *progname) -{ -#ifdef __WIN32__ - wchar_t wcsbuf[MAXPATHLEN]; - MultiByteToWideChar(CP_UTF8, 0, progname, -1, wcsbuf, MAXPATHLEN); - return (_waccess(wcsbuf, 0) != -1); -#else - return (access(progname, 1) != -1); -#endif -} - -static char* -get_default_emulator(char* progname) -{ - char sbuf[MAXPATHLEN]; - char* s; - - if (strlen(progname) >= sizeof(sbuf)) - return ERL_NAME; - - strcpy(sbuf, progname); - for (s = sbuf+strlen(sbuf); s >= sbuf; s--) { - if (IS_DIRSEP(*s)) { - strcpy(s+1, ERL_NAME); - if(file_exists(sbuf)) - return strsave(sbuf); - break; - } - } - return ERL_NAME; -} - -#ifdef __WIN32__ -static char* -possibly_quote(char* arg) -{ - int mustQuote = NO; - int n = 0; - char* s; - char* narg; - - if (arg == NULL) { - return arg; - } - - /* - * Scan the string to find out if it needs quoting and return - * the original argument if not. - */ - - for (s = arg; *s; s++, n++) { - switch(*s) { - case ' ': - mustQuote = YES; - continue; - case '"': - mustQuote = YES; - n++; - continue; - case '\\': - if(s[1] == '"') - n++; - continue; - default: - continue; - } - } - if (!mustQuote) { - return arg; - } - - /* - * Insert the quotes and put a backslash in front of every quote - * inside the string. - */ - - s = narg = emalloc(n+2+1); - for (*s++ = '"'; *arg; arg++, s++) { - if (*arg == '"' || (*arg == '\\' && arg[1] == '"')) { - *s++ = '\\'; - } - *s = *arg; - } - if (s[-1] == '\\') { - *s++ ='\\'; - } - *s++ = '"'; - *s = '\0'; - return narg; -} -#endif /* __WIN32__ */ -- cgit v1.2.3 From f0c4d095e0d9be054181785f5c9ca34b52aa2995 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Tue, 11 Apr 2017 19:15:05 +0200 Subject: Suggested stack size options for dirty schedulers --- erts/etc/common/erlexec.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index ee59759940..362817e94c 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -141,6 +141,8 @@ static char *pluss_val_switches[] = { "wt", "ws", "ss", + "ssdcpu", + "ssdio", "pp", "ub", NULL -- cgit v1.2.3 From 8c665562272bac669ea400638d379f21495636af Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 3 Apr 2017 16:19:47 +0200 Subject: erts: Rebuild etc executables if config.h changes --- erts/etc/common/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index d3af634729..f656eebc46 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -360,7 +360,7 @@ Install.ini: ../$(TARGET)/Install.src ../../vsn.mk $(TARGET)/Makefile else -RC_GENERATED = +RC_GENERATED = $(ERL_TOP)/erts/$(TARGET)/config.h endif #--------------------------------------------------------- # End of windows specific targets. -- cgit v1.2.3 From 030e6ef2efaad12d485cec1727c4b68c09c6c584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 12 Apr 2017 15:19:23 +0200 Subject: Add back TypEr to the main OTP repository It turned out that the dependencies between Dialyzer and TypEr makes it impractical to have TypEr in a separate repository. Add it back to the OTP repository, but put the Erlang module 'typer' in the dialyzer application. --- erts/etc/common/Makefile.in | 11 +- erts/etc/common/typer.c | 455 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 464 insertions(+), 2 deletions(-) create mode 100644 erts/etc/common/typer.c (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index d3af634729..7634583462 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -143,7 +143,7 @@ MC_OUTPUTS=$(OBJDIR)/erlsrv_logmess.h $(OBJDIR)/erlsrv_logmess.res MT_FLAG="-MD" endif INET_GETHOST = $(BINDIR)/inet_gethost.exe -INSTALL_EMBEDDED_PROGS += $(BINDIR)/dialyzer.exe $(BINDIR)/erlc.exe $(BINDIR)/start_erl.exe $(BINDIR)/escript.exe $(BINDIR)/ct_run.exe +INSTALL_EMBEDDED_PROGS += $(BINDIR)/typer.exe $(BINDIR)/dialyzer.exe $(BINDIR)/erlc.exe $(BINDIR)/start_erl.exe $(BINDIR)/escript.exe $(BINDIR)/ct_run.exe INSTALL_SRC = $(WINETC)/start_erl.c $(WINETC)/Nmakefile.start_erl ERLEXECDIR=. INSTALL_LIBS = @@ -176,7 +176,7 @@ ENTRY_OBJ= ERLSRV_OBJECTS= MC_OUTPUTS= INET_GETHOST = $(BINDIR)/inet_gethost@EXEEXT@ -INSTALL_EMBEDDED_PROGS += $(BINDIR)/dialyzer@EXEEXT@ \ +INSTALL_EMBEDDED_PROGS += $(BINDIR)/typer@EXEEXT@ $(BINDIR)/dialyzer@EXEEXT@ \ $(BINDIR)/erlc@EXEEXT@ $(BINDIR)/escript@EXEEXT@ $(BINDIR)/ct_run@EXEEXT@ \ $(BINDIR)/run_erl $(BINDIR)/to_erl $(BINDIR)/dyn_erl INSTALL_EMBEDDED_DATA = $(UXETC)/start.src $(UXETC)/start_erl.src @@ -238,6 +238,7 @@ endif rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/reclaim.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/run_erl.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/to_erl.o + rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/typer.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/dyn_erl.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/safe_string.o rm -f $(ERL_TOP)/erts/obj*/$(TARGET)/run_erl.o @@ -432,6 +433,12 @@ $(BINDIR)/dialyzer@EXEEXT@: $(OBJDIR)/dialyzer.o $(ERTS_LIB) $(OBJDIR)/dialyzer.o: dialyzer.c $(RC_GENERATED) $(V_CC) $(CFLAGS) -o $@ -c dialyzer.c +$(BINDIR)/typer@EXEEXT@: $(OBJDIR)/typer.o $(ERTS_LIB) + $(ld_verbose)$(PURIFY) $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/typer.o -L$(OBJDIR) $(LIBS) $(ERTS_INTERNAL_LIBS) + +$(OBJDIR)/typer.o: typer.c $(RC_GENERATED) + $(V_CC) $(CFLAGS) -o $@ -c typer.c + $(BINDIR)/escript@EXEEXT@: $(OBJDIR)/escript.o $(ERTS_LIB) $(ld_verbose)$(PURIFY) $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/escript.o -L$(OBJDIR) $(LIBS) $(ERTS_INTERNAL_LIBS) diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c new file mode 100644 index 0000000000..77a95ccded --- /dev/null +++ b/erts/etc/common/typer.c @@ -0,0 +1,455 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2006-2016. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + */ +/* + * Purpose: Typer front-end. + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "sys.h" +#ifdef __WIN32__ +#include +#endif + +#include + +#define NO 0 +#define YES 1 + +#define ASIZE(a) (sizeof(a)/sizeof(a[0])) + +static int debug = 0; /* Bit flags for debug printouts. */ + +static char** eargv_base; /* Base of vector. */ +static char** eargv; /* First argument for erl. */ + +static int eargc; /* Number of arguments in eargv. */ + +#ifdef __WIN32__ +# define QUOTE(s) possibly_quote(s) +# define IS_DIRSEP(c) ((c) == '/' || (c) == '\\') +# define ERL_NAME "erl.exe" +#else +# define QUOTE(s) s +# define IS_DIRSEP(c) ((c) == '/') +# define ERL_NAME "erl" +#endif + +#define UNSHIFT(s) eargc++, eargv--; eargv[0] = QUOTE(s) +#define PUSH(s) eargv[eargc++] = QUOTE(s) +#define PUSH2(s, t) PUSH(s); PUSH(t) +#define PUSH3(s, t, u) PUSH2(s, t); PUSH(u) + +/* + * Local functions. + */ + +static void error(char* format, ...); +static void* emalloc(size_t size); +static char* strsave(char* string); +static void push_words(char* src); +static int run_erlang(char* name, char** argv); +static char* get_default_emulator(char* progname); +#ifdef __WIN32__ +static char* possibly_quote(char* arg); +static void* erealloc(void *p, size_t size); +#endif + +/* + * Supply a strerror() function if libc doesn't. + */ +#ifndef HAVE_STRERROR + +extern int sys_nerr; + +#ifndef SYS_ERRLIST_DECLARED +extern const char * const sys_errlist[]; +#endif /* !SYS_ERRLIST_DECLARED */ + +char *strerror(int errnum) +{ + static char *emsg[1024]; + + if (errnum != 0) { + if (errnum > 0 && errnum < sys_nerr) + sprintf((char *) &emsg[0], "(%s)", sys_errlist[errnum]); + else + sprintf((char *) &emsg[0], "errnum = %d ", errnum); + } + else { + emsg[0] = '\0'; + } + return (char *) &emsg[0]; +} +#endif /* !HAVE_STRERROR */ + +#ifdef __WIN32__ +int wmain(int argc, wchar_t **wcargv) +{ + char** argv; +#else +int +main(int argc, char** argv) +{ +#endif + int eargv_size; + int eargc_base; /* How many arguments in the base of eargv. */ + char* emulator; + int need_shell = 0; + +#ifdef __WIN32__ + int i; + int len; + /* Convert argv to utf8 */ + argv = emalloc((argc+1) * sizeof(char*)); + for (i=0; i 1 && strcmp(argv[1], "-smp") == 0) { + PUSH("-smpauto"); + argc--, argv++; + } + + PUSH("+B"); + PUSH2("-boot", "start_clean"); + PUSH3("-run", "typer", "start"); + PUSH("-extra"); + + /* + * Push everything except --shell. + */ + + while (argc > 1) { + if (strcmp(argv[1], "--shell") == 0) { + need_shell = 1; + } else { + PUSH(argv[1]); + } + argc--, argv++; + } + + if (!need_shell) { + UNSHIFT("-noinput"); + } + + /* + * Move up the commands for invoking the emulator and adjust eargv + * accordingly. + */ + + while (--eargc_base >= 0) { + UNSHIFT(eargv_base[eargc_base]); + } + + /* + * Invoke Erlang with the collected options. + */ + + PUSH(NULL); + return run_erlang(eargv[0], eargv); +} + +static void +push_words(char* src) +{ + char sbuf[MAXPATHLEN]; + char* dst; + + dst = sbuf; + while ((*dst++ = *src++) != '\0') { + if (isspace((int)*src)) { + *dst = '\0'; + PUSH(strsave(sbuf)); + dst = sbuf; + do { + src++; + } while (isspace((int)*src)); + } + } + if (sbuf[0]) + PUSH(strsave(sbuf)); +} +#ifdef __WIN32__ +wchar_t *make_commandline(char **argv) +{ + static wchar_t *buff = NULL; + static int siz = 0; + int num = 0, len; + char **arg; + wchar_t *p; + + if (*argv == NULL) { + return L""; + } + for (arg = argv; *arg != NULL; ++arg) { + num += strlen(*arg)+1; + } + if (!siz) { + siz = num; + buff = (wchar_t *) emalloc(siz*sizeof(wchar_t)); + } else if (siz < num) { + siz = num; + buff = (wchar_t *) erealloc(buff,siz*sizeof(wchar_t)); + } + p = buff; + num=0; + for (arg = argv; *arg != NULL; ++arg) { + len = MultiByteToWideChar(CP_UTF8, 0, *arg, -1, p, siz); + p+=(len-1); + *p++=L' '; + } + *(--p) = L'\0'; + + if (debug) { + printf("Processed command line:%S\n",buff); + } + return buff; +} + +int my_spawnvp(char **argv) +{ + STARTUPINFOW siStartInfo; + PROCESS_INFORMATION piProcInfo; + DWORD ec; + + memset(&siStartInfo,0,sizeof(STARTUPINFOW)); + siStartInfo.cb = sizeof(STARTUPINFOW); + siStartInfo.dwFlags = STARTF_USESTDHANDLES; + siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); + siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); + + if (!CreateProcessW(NULL, + make_commandline(argv), + NULL, + NULL, + TRUE, + 0, + NULL, + NULL, + &siStartInfo, + &piProcInfo)) { + return -1; + } + CloseHandle(piProcInfo.hThread); + + WaitForSingleObject(piProcInfo.hProcess,INFINITE); + if (!GetExitCodeProcess(piProcInfo.hProcess,&ec)) { + return 0; + } + return (int) ec; +} +#endif /* __WIN32__ */ + + +static int +run_erlang(char* progname, char** argv) +{ +#ifdef __WIN32__ + int status; +#endif + + if (debug) { + int i = 0; + while (argv[i] != NULL) + printf(" %s", argv[i++]); + printf("\n"); + } + +#ifdef __WIN32__ + /* + * Alas, we must wait here for the program to finish. + * Otherwise, the shell from which we were executed will think + * we are finished and print a prompt and read keyboard input. + */ + + status = my_spawnvp(argv)/*_spawnvp(_P_WAIT,progname,argv)*/; + if (status == -1) { + fprintf(stderr, "typer: Error executing '%s': %d", progname, + GetLastError()); + } + return status; +#else + execvp(progname, argv); + error("Error %d executing \'%s\'.", errno, progname); + return 2; +#endif +} + +static void +error(char* format, ...) +{ + char sbuf[1024]; + va_list ap; + + va_start(ap, format); + erts_vsnprintf(sbuf, sizeof(sbuf), format, ap); + va_end(ap); + fprintf(stderr, "typer: %s\n", sbuf); + exit(1); +} + +static void* +emalloc(size_t size) +{ + void *p = malloc(size); + if (p == NULL) + error("Insufficient memory"); + return p; +} + +#ifdef __WIN32__ +static void * +erealloc(void *p, size_t size) +{ + void *res = realloc(p, size); + if (res == NULL) + error("Insufficient memory"); + return res; +} +#endif + +static char* +strsave(char* string) +{ + char* p = emalloc(strlen(string)+1); + strcpy(p, string); + return p; +} + +static int +file_exists(char *progname) +{ +#ifdef __WIN32__ + wchar_t wcsbuf[MAXPATHLEN]; + MultiByteToWideChar(CP_UTF8, 0, progname, -1, wcsbuf, MAXPATHLEN); + return (_waccess(wcsbuf, 0) != -1); +#else + return (access(progname, 1) != -1); +#endif +} + +static char* +get_default_emulator(char* progname) +{ + char sbuf[MAXPATHLEN]; + char* s; + + if (strlen(progname) >= sizeof(sbuf)) + return ERL_NAME; + + strcpy(sbuf, progname); + for (s = sbuf+strlen(sbuf); s >= sbuf; s--) { + if (IS_DIRSEP(*s)) { + strcpy(s+1, ERL_NAME); + if(file_exists(sbuf)) + return strsave(sbuf); + break; + } + } + return ERL_NAME; +} + +#ifdef __WIN32__ +static char* +possibly_quote(char* arg) +{ + int mustQuote = NO; + int n = 0; + char* s; + char* narg; + + if (arg == NULL) { + return arg; + } + + /* + * Scan the string to find out if it needs quoting and return + * the original argument if not. + */ + + for (s = arg; *s; s++, n++) { + switch(*s) { + case ' ': + mustQuote = YES; + continue; + case '"': + mustQuote = YES; + n++; + continue; + case '\\': + if(s[1] == '"') + n++; + continue; + default: + continue; + } + } + if (!mustQuote) { + return arg; + } + + /* + * Insert the quotes and put a backslash in front of every quote + * inside the string. + */ + + s = narg = emalloc(n+2+1); + for (*s++ = '"'; *arg; arg++, s++) { + if (*arg == '"' || (*arg == '\\' && arg[1] == '"')) { + *s++ = '\\'; + } + *s = *arg; + } + if (s[-1] == '\\') { + *s++ ='\\'; + } + *s++ = '"'; + *s = '\0'; + return narg; +} +#endif /* __WIN32__ */ -- cgit v1.2.3 From f30d131bd979e29b68fb7d9ff515c61a246201f4 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Tue, 21 Mar 2017 13:40:08 +0100 Subject: erts: Deprecate the non-smp emulators --- erts/etc/common/erlexec.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index ee59759940..b29190e4d9 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -203,8 +203,8 @@ void error(char* format, ...); * Local functions. */ -#if !defined(ERTS_HAVE_SMP_EMU) -static void usage_notsup(const char *switchname); +#if !defined(ERTS_HAVE_SMP_EMU) || !defined(ERTS_HAVE_PLAIN_EMU) +static void usage_notsup(const char *switchname, const char *alt); #endif static char **build_args_from_env(char *env_var); static char **build_args_from_string(char *env_var); @@ -487,8 +487,7 @@ int main(int argc, char **argv) cpuinfo = erts_cpu_info_create(); /* '-smp auto' is default */ #ifdef ERTS_HAVE_SMP_EMU - if (erts_get_cpu_configured(cpuinfo) > 1) - emu_type |= EMU_TYPE_SMP; + emu_type |= EMU_TYPE_SMP; #endif #if defined(__WIN32__) && defined(WIN32_ALWAYS_DEBUG) @@ -520,12 +519,11 @@ int main(int argc, char **argv) i++; smp_auto: emu_type_passed |= EMU_TYPE_SMP; -#ifdef ERTS_HAVE_SMP_EMU - if (erts_get_cpu_configured(cpuinfo) > 1) - emu_type |= EMU_TYPE_SMP; - else +#if defined(ERTS_HAVE_PLAIN_EMU) && !defined(ERTS_HAVE_SMP_EMU) + emu_type &= ~EMU_TYPE_SMP; +#else + emu_type |= EMU_TYPE_SMP; #endif - emu_type &= ~EMU_TYPE_SMP; } else if (strcmp(argv[i+1], "enable") == 0) { i++; @@ -534,14 +532,18 @@ int main(int argc, char **argv) #ifdef ERTS_HAVE_SMP_EMU emu_type |= EMU_TYPE_SMP; #else - usage_notsup("-smp enable"); + usage_notsup("-smp enable", ""); #endif } else if (strcmp(argv[i+1], "disable") == 0) { i++; smp_disable: - emu_type_passed |= EMU_TYPE_SMP; + emu_type_passed &= ~EMU_TYPE_SMP; +#ifdef ERTS_HAVE_PLAIN_EMU emu_type &= ~EMU_TYPE_SMP; +#else + usage_notsup("-smp disable", " Use \"+S 1\" instead."); +#endif } else { smp: @@ -550,7 +552,7 @@ int main(int argc, char **argv) #ifdef ERTS_HAVE_SMP_EMU emu_type |= EMU_TYPE_SMP; #else - usage_notsup("-smp"); + usage_notsup("-smp", ""); #endif } } else if (strcmp(argv[i], "-smpenable") == 0) { @@ -1183,14 +1185,14 @@ usage_aux(void) #ifdef __WIN32__ "[-start_erl [datafile]] " #endif - "[-smp " + "[-smp [auto" #ifdef ERTS_HAVE_SMP_EMU - "[enable|" + "|enable" #endif - "auto|disable" -#ifdef ERTS_HAVE_SMP_EMU - "]" +#ifdef ERTS_HAVE_PLAIN_EMU + "|disable" #endif + "]" "] " "[-make] [-man [manopts] MANPAGE] [-x] [-emu_args] [-start_epmd BOOLEAN] " "[-args_file FILENAME] [+A THREADS] [+a SIZE] [+B[c|d|i]] [+c [BOOLEAN]] " @@ -1212,11 +1214,11 @@ usage(const char *switchname) usage_aux(); } -#if !defined(ERTS_HAVE_SMP_EMU) +#if !defined(ERTS_HAVE_SMP_EMU) || !defined(ERTS_HAVE_PLAIN_EMU) static void -usage_notsup(const char *switchname) +usage_notsup(const char *switchname, const char *alt) { - fprintf(stderr, "Argument \'%s\' not supported.\n", switchname); + fprintf(stderr, "Argument \'%s\' not supported.%s\n", switchname, alt); usage_aux(); } #endif -- cgit v1.2.3 From fab97e165a79db10b7b560be5aefc7489982bced Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Fri, 21 Apr 2017 14:49:18 +0200 Subject: Rename argv[0] from beam to invoking program name Allows ps and htop to display the invoking program/script name instead of beam[.smp]. --- erts/etc/common/ct_run.c | 40 ++++++++++++++++++++++++++++++++++++++++ erts/etc/common/dialyzer.c | 39 +++++++++++++++++++++++++++++++++++++++ erts/etc/common/erlc.c | 37 +++++++++++++++++++++++++++++++++++++ erts/etc/common/erlexec.c | 8 ++++++-- erts/etc/common/escript.c | 30 +++++++++++++++++++++++++++++- erts/etc/common/typer.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 189 insertions(+), 3 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/ct_run.c b/erts/etc/common/ct_run.c index acdfa8c8b8..898c8ccde0 100644 --- a/erts/etc/common/ct_run.c +++ b/erts/etc/common/ct_run.c @@ -82,6 +82,9 @@ static int eargc; /* Number of arguments in eargv. */ 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); @@ -119,6 +122,30 @@ char *strerror(int errnum) } #endif /* !HAVE_STRERROR */ + +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 +} + + #ifdef __WIN32__ int wmain(int argc, wchar_t **wcargv) { @@ -154,6 +181,11 @@ int main(int argc, char** argv) emulator = get_default_emulator(argv[0]); + /* + * 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 @@ -458,6 +490,14 @@ erealloc(void *p, size_t size) } #endif +#ifdef HAVE_COPYING_PUTENV +static void +efree(void *p) +{ + free(p); +} +#endif + static char* strsave(char* string) { diff --git a/erts/etc/common/dialyzer.c b/erts/etc/common/dialyzer.c index 6ba3605422..829984ef3f 100644 --- a/erts/etc/common/dialyzer.c +++ b/erts/etc/common/dialyzer.c @@ -64,6 +64,9 @@ static int eargc; /* Number of arguments in eargv. */ 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,29 @@ free_env_val(char *value) #endif } +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 +} + + #ifdef __WIN32__ int wmain(int argc, wchar_t **wcargv) { @@ -180,6 +206,11 @@ int main(int argc, char** argv) if (strlen(emulator) >= MAXPATHLEN) error("Value of environment variable DIALYZER_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 @@ -434,6 +465,14 @@ erealloc(void *p, size_t size) } #endif +#ifdef HAVE_COPYING_PUTENV +static void +efree(void *p) +{ + free(p); +} +#endif + static char* strsave(char* string) { 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); @@ -146,6 +149,28 @@ get_env(char *key) #endif } +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) { @@ -187,6 +212,11 @@ int main(int argc, char** argv) if (strlen(emulator) >= MAXPATHLEN) 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 @@ -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) { diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index ee59759940..a1c6bb223b 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -583,8 +583,12 @@ int main(int argc, char **argv) erts_snprintf(tmpStr, sizeof(tmpStr), "%s" DIRSEP "%s" BINARY_EXT, bindir, emu); emu = strsave(tmpStr); - add_Eargs(emu); /* Will be argv[0] -- necessary! */ - + s = get_env("ESCRIPT_NAME"); + if(s) { + add_Eargs(s); /* argv[0] = scriptname*/ + } else { + add_Eargs(progname); /* argv[0] = erl or cerl */ + } /* * Add the bindir to the path (unless it is there already). */ diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 4134a3ff36..c28e45a044 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -155,6 +155,29 @@ free_env_val(char *value) efree(value); #endif } + +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 +} + /* * Find absolute path to this program */ @@ -548,7 +571,12 @@ main(int argc, char** argv) while (--eargc_base >= 0) { UNSHIFT(eargv_base[eargc_base]); } - + + /* + * Add scriptname to env + */ + set_env("ESCRIPT_NAME", scriptname); + /* * Invoke Erlang with the collected options. */ diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c index 77a95ccded..644c90a795 100644 --- a/erts/etc/common/typer.c +++ b/erts/etc/common/typer.c @@ -64,6 +64,9 @@ static int eargc; /* Number of arguments in eargv. */ 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); @@ -101,6 +104,29 @@ char *strerror(int errnum) } #endif /* !HAVE_STRERROR */ +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 +} + + #ifdef __WIN32__ int wmain(int argc, wchar_t **wcargv) { @@ -129,6 +155,10 @@ main(int argc, char** argv) #endif emulator = get_default_emulator(argv[0]); + /* + * Add scriptname to env + */ + set_env("ESCRIPT_NAME", argv[0]); /* * Allocate the argv vector to be used for arguments to Erlang. @@ -353,6 +383,14 @@ erealloc(void *p, size_t size) } #endif +#ifdef HAVE_COPYING_PUTENV +static void +efree(void *p) +{ + free(p); +} +#endif + static char* strsave(char* string) { -- cgit v1.2.3 From 83e20c62057ebc1d8064bf57b01be560cd244e1d Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 4 May 2017 15:42:21 +0200 Subject: Update copyright year --- erts/etc/common/Makefile.in | 2 +- erts/etc/common/ct_run.c | 2 +- erts/etc/common/dialyzer.c | 2 +- erts/etc/common/erlc.c | 2 +- erts/etc/common/erlexec.c | 2 +- erts/etc/common/escript.c | 2 +- erts/etc/common/inet_gethost.c | 2 +- erts/etc/common/typer.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index b4fa0d4c79..583426460e 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2016. All Rights Reserved. +# Copyright Ericsson AB 1996-2017. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/erts/etc/common/ct_run.c b/erts/etc/common/ct_run.c index 898c8ccde0..6639c83778 100644 --- a/erts/etc/common/ct_run.c +++ b/erts/etc/common/ct_run.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2010-2016. All Rights Reserved. + * Copyright Ericsson AB 2010-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/dialyzer.c b/erts/etc/common/dialyzer.c index 829984ef3f..c8d977f6de 100644 --- a/erts/etc/common/dialyzer.c +++ b/erts/etc/common/dialyzer.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2006-2016. All Rights Reserved. + * Copyright Ericsson AB 2006-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index 2abeff33a3..cbbd2a37cd 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1997-2016. All Rights Reserved. + * Copyright Ericsson AB 1997-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index f11ec2320a..f73c4ef1ca 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2016. All Rights Reserved. + * Copyright Ericsson AB 1996-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index c28e45a044..630e241882 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2007-2016. All Rights Reserved. + * Copyright Ericsson AB 2007-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c index ccafd95e51..b746487668 100644 --- a/erts/etc/common/inet_gethost.c +++ b/erts/etc/common/inet_gethost.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2016. All Rights Reserved. + * Copyright Ericsson AB 1998-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c index 644c90a795..6bae9f96b7 100644 --- a/erts/etc/common/typer.c +++ b/erts/etc/common/typer.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2006-2016. All Rights Reserved. + * Copyright Ericsson AB 2006-2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 6166106ff9ff9d62b5d5966dbdb03e189e2a2bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 12 May 2017 14:52:19 +0200 Subject: Teach erlexec the -emu_type option Add the option -emu_type to start an emulator of a certain type. For exampe, "-emu_type lcnt" will start beam.lcnt.smp. Any string will be accepted after -emu_type. If there is no corresponding emulator, there will be an error similar to: erlexec: The emulator '.../bin/x86_64-unknown-linux-gnu/beam.foo.smp' does not exist. On Windows, there is an undocumented option "-debug". Remove that option, because -emu_type can be used instead. --- erts/etc/common/erlexec.c | 105 ++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 68 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index f73c4ef1ca..70520eea15 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -184,17 +184,6 @@ static char *plusz_val_switches[] = { #endif #define SMP_SUFFIX ".smp" -#define DEBUG_SUFFIX ".debug" -#define EMU_TYPE_SUFFIX_LENGTH strlen(DEBUG_SUFFIX) - -/* - * Define flags for different memory architectures. - */ -#define EMU_TYPE_SMP 0x0001 - -#ifdef __WIN32__ -#define EMU_TYPE_DEBUG 0x0004 -#endif void usage(const char *switchname); static void usage_format(char *format, ...); @@ -221,7 +210,7 @@ static void *erealloc(void *p, size_t size); static void efree(void *p); static char* strsave(char* string); static int is_one_of_strings(char *str, char *strs[]); -static char *write_str(char *to, char *from); +static char *write_str(char *to, const char *from); static void get_home(void); static void add_epmd_port(void); #ifdef __WIN32__ @@ -255,9 +244,8 @@ static int verbose = 0; /* If non-zero, print some extra information. */ static int start_detached = 0; /* If non-zero, the emulator should be * started detached (in the background). */ -static int emu_type = 0; /* If non-zero, start beam.ARCH or beam.ARCH.exe - * instead of beam or beam.exe, where ARCH is defined by flags. */ -static int emu_type_passed = 0; /* Types explicitly set */ +static int start_smp_emu = 0; /* Start the smp emulator. */ +static const char* emu_type = 0; /* Type of emulator (lcnt, valgrind, etc) */ #ifdef __WIN32__ static char *start_emulator_program = NULL; /* For detachec mode - @@ -352,11 +340,11 @@ free_env_val(char *value) } /* - * Add the architecture suffix to the program name if needed, - * except on Windows, where we insert it just before ".DLL". + * Add the type and architecture suffix to the program name if needed. + * On Windows, we insert it just before ".DLL". */ static char* -add_extra_suffixes(char *prog, int type) +add_extra_suffixes(char *prog) { char *res; char *p; @@ -366,16 +354,10 @@ add_extra_suffixes(char *prog, int type) int dll = 0; #endif - if (!type) { - return prog; - } - len = strlen(prog); - /* Worst-case allocation */ - p = emalloc(len + - EMU_TYPE_SUFFIX_LENGTH + - + 1); + /* Allocate enough extra space for suffixes */ + p = emalloc(len + 100); res = p; p = write_str(p, prog); @@ -392,13 +374,11 @@ add_extra_suffixes(char *prog, int type) } #endif -#ifdef __WIN32__ - if (type & EMU_TYPE_DEBUG) { - p = write_str(p, DEBUG_SUFFIX); - type &= ~(EMU_TYPE_DEBUG); + if (emu_type) { + p = write_str(p, "."); + p = write_str(p, emu_type); } -#endif - if (type == EMU_TYPE_SMP) { + if (start_smp_emu) { p = write_str(p, SMP_SUFFIX); } #ifdef __WIN32__ @@ -489,12 +469,11 @@ int main(int argc, char **argv) cpuinfo = erts_cpu_info_create(); /* '-smp auto' is default */ #ifdef ERTS_HAVE_SMP_EMU - emu_type |= EMU_TYPE_SMP; + start_smp_emu = 1; #endif #if defined(__WIN32__) && defined(WIN32_ALWAYS_DEBUG) - emu_type_passed |= EMU_TYPE_DEBUG; - emu_type |= EMU_TYPE_DEBUG; + emu_type = "debug"; #endif /* We need to do this before the ordinary processing. */ @@ -519,57 +498,42 @@ int main(int argc, char **argv) if (strcmp(argv[i+1], "auto") == 0) { i++; - smp_auto: - emu_type_passed |= EMU_TYPE_SMP; -#if defined(ERTS_HAVE_PLAIN_EMU) && !defined(ERTS_HAVE_SMP_EMU) - emu_type &= ~EMU_TYPE_SMP; -#else - emu_type |= EMU_TYPE_SMP; -#endif - } - else if (strcmp(argv[i+1], "enable") == 0) { + } else if (strcmp(argv[i+1], "enable") == 0) { i++; smp_enable: - emu_type_passed |= EMU_TYPE_SMP; -#ifdef ERTS_HAVE_SMP_EMU - emu_type |= EMU_TYPE_SMP; -#else + ; +#if !defined(ERTS_HAVE_SMP_EMU) usage_notsup("-smp enable", ""); #endif - } - else if (strcmp(argv[i+1], "disable") == 0) { + } else if (strcmp(argv[i+1], "disable") == 0) { i++; smp_disable: - emu_type_passed &= ~EMU_TYPE_SMP; #ifdef ERTS_HAVE_PLAIN_EMU - emu_type &= ~EMU_TYPE_SMP; + start_smp_emu = 0; #else usage_notsup("-smp disable", " Use \"+S 1\" instead."); #endif - } - else { + } else { smp: - - emu_type_passed |= EMU_TYPE_SMP; -#ifdef ERTS_HAVE_SMP_EMU - emu_type |= EMU_TYPE_SMP; -#else + ; +#if !defined(ERTS_HAVE_SMP_EMU) usage_notsup("-smp", ""); #endif } } else if (strcmp(argv[i], "-smpenable") == 0) { goto smp_enable; } else if (strcmp(argv[i], "-smpauto") == 0) { - goto smp_auto; + ; } else if (strcmp(argv[i], "-smpdisable") == 0) { goto smp_disable; -#ifdef __WIN32__ - } else if (strcmp(argv[i], "-debug") == 0) { - emu_type_passed |= EMU_TYPE_DEBUG; - emu_type |= EMU_TYPE_DEBUG; -#endif } else if (strcmp(argv[i], "-extra") == 0) { break; + } else if (strcmp(argv[i], "-emu_type") == 0) { + if (i + 1 >= argc) { + usage(argv[i]); + } + emu_type = argv[i+1]; + i++; } } i++; @@ -582,7 +546,7 @@ int main(int argc, char **argv) if (strcmp(malloc_lib, "libc") != 0) usage("+MYm"); } - emu = add_extra_suffixes(emu, emu_type); + emu = add_extra_suffixes(emu); emu_name = strsave(emu); erts_snprintf(tmpStr, sizeof(tmpStr), "%s" DIRSEP "%s" BINARY_EXT, bindir, emu); emu = strsave(tmpStr); @@ -1176,7 +1140,11 @@ int main(int argc, char **argv) { execv(emu, Eargsp); } - error("Error %d executing \'%s\'.", errno, emu); + if (errno == ENOENT) { + error("The emulator \'%s\' does not exist.", emu); + } else { + error("Error %d executing \'%s\'.", errno, emu); + } return 1; #endif } @@ -1376,7 +1344,7 @@ is_one_of_strings(char *str, char *strs[]) return 0; } -static char *write_str(char *to, char *from) +static char *write_str(char *to, const char *from) { while (*from) *(to++) = *(from++); @@ -1903,6 +1871,7 @@ read_args_file(char *filename) #undef SAVE_CHAR } + typedef struct { char **argv; int argc; -- cgit v1.2.3 From 13f07042fd333c9bc137e142c4dc24b7d5cbe909 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 23 May 2017 12:43:33 +0200 Subject: Revert setting default argv0 name Changing argv[0] from emu name to progname if ESCRIPT_NAME was not set caused to many failing scripts, revert that part of the change. See 86f6a9856 --- erts/etc/common/erlexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 70520eea15..51ed2d0dff 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -555,7 +555,7 @@ int main(int argc, char **argv) if(s) { add_Eargs(s); /* argv[0] = scriptname*/ } else { - add_Eargs(progname); /* argv[0] = erl or cerl */ + add_Eargs(emu); /* argv[0] = erl or cerl */ } /* * Add the bindir to the path (unless it is there already). -- cgit v1.2.3 From 68de330d763fb450a763a2d56e63dbe009e12703 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Mon, 22 May 2017 15:49:15 +0200 Subject: Fix erlang system lookup from escript bug introduced in PR #1293 Erlang system found in PATH was used even when explicitly pointing out the escript binary in another Erlang system. --- erts/etc/common/escript.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 630e241882..80cc25b040 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -433,7 +433,7 @@ main(int argc, char** argv) char* emulator; char* env; char* basename; - char* absname; + char* def_emu_lookup_path; char scriptname[PMAX]; char** last_opt; char** first_opt; @@ -480,6 +480,7 @@ main(int argc, char** argv) #else if (strcmp(basename, "escript") == 0) { #endif + def_emu_lookup_path = argv[0]; /* * Locate all options before the script name. */ @@ -498,27 +499,24 @@ main(int argc, char** argv) argc--; argv++; } else { + char *absname = find_prog(argv[0]); #ifdef __WIN32__ - int len; -#endif - absname = find_prog(argv[0]); -#ifdef __WIN32__ - len = strlen(absname); + int len = strlen(absname); if (len >= 4 && _stricmp(absname+len-4, ".exe") == 0) { absname[len-4] = '\0'; } #endif - erts_snprintf(scriptname, sizeof(scriptname), "%s.escript", absname); - efree(absname); + efree(absname); + def_emu_lookup_path = scriptname; } /* Determine path to emulator */ emulator = env = get_env("ESCRIPT_EMULATOR"); if (emulator == NULL) { - emulator = get_default_emulator(scriptname); + emulator = get_default_emulator(def_emu_lookup_path); } if (strlen(emulator) >= PMAX) -- cgit v1.2.3 From 385b18de6fd72672ed7d6736b30f56d6691d4433 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Tue, 23 May 2017 16:38:43 +0200 Subject: escript: Do not split path to Erlang system into multiple words escript failed to start Erlang systems with spaces in the absolute path (when absolute path was used). --- erts/etc/common/escript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 80cc25b040..7f0af77a4c 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -526,7 +526,7 @@ main(int argc, char** argv) * Push initial arguments. */ - push_words(emulator); + PUSH(emulator); free_env_val(env); PUSH("+B"); -- cgit v1.2.3 From 4d484afced06366cbeac0cfb15ad8bb14ee46fba Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sun, 2 Jul 2017 09:15:26 +0200 Subject: escript.c: remove dead code --- erts/etc/common/escript.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 7f0af77a4c..9cd5dd3fab 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -74,7 +74,6 @@ static void error(char* format, ...); static void* emalloc(size_t size); static void efree(void *p); static char* strsave(char* string); -static void push_words(char* src); static int run_erlang(char* name, char** argv); static char* get_default_emulator(char* progname); #ifdef __WIN32__ @@ -583,26 +582,6 @@ main(int argc, char** argv) return run_erlang(eargv[0], eargv); } -static void -push_words(char* src) -{ - char sbuf[PMAX]; - char* dst; - - dst = sbuf; - while ((*dst++ = *src++) != '\0') { - if (isspace((int)*src)) { - *dst = '\0'; - PUSH(strsave(sbuf)); - dst = sbuf; - do { - src++; - } while (isspace((int)*src)); - } - } - if (sbuf[0]) - PUSH(strsave(sbuf)); -} #ifdef __WIN32__ wchar_t *make_commandline(char **argv) { -- cgit v1.2.3 From f3fa8288287072195baa791ee11d5480d3cd45ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Thu, 22 Jun 2017 13:22:13 +0200 Subject: Allow toggling lock counting at runtime The implementation is still hidden behind ERTS_ENABLE_LOCK_COUNT, and all categories are still enabled by default, but the actual counting can be toggled at will. OTP-13170 --- erts/etc/common/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index 583426460e..4bcbb288b3 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -57,7 +57,7 @@ ERTS_INCL = -I$(ERL_TOP)/erts/include \ CC = @CC@ WFLAGS = @WFLAGS@ CFLAGS = @CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSDIR) -I$(EMUDIR) \ - $(ERTS_INCL) -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\" + -I$(COMSYSDIR) $(ERTS_INCL) -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\" LD = @LD@ LIBS = @LIBS@ LDFLAGS = @LDFLAGS@ @@ -77,6 +77,7 @@ endif BINDIR = $(ERL_TOP)/bin/$(TARGET) OBJDIR = $(ERL_TOP)/erts/obj$(TYPEMARKER)/$(TARGET) EMUDIR = $(ERL_TOP)/erts/emulator/beam +COMSYSDIR = $(ERL_TOP)/erts/emulator/sys/common EMUOSDIR = $(ERL_TOP)/erts/emulator/@ERLANG_OSTYPE@ SYSDIR = $(ERL_TOP)/erts/emulator/sys/@ERLANG_OSTYPE@ DRVDIR = $(ERL_TOP)/erts/emulator/drivers/@ERLANG_OSTYPE@ -- cgit v1.2.3 From 4ac0e889944d9529e7904e61700e1205d166ca19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Tue, 11 Jul 2017 15:08:23 +0200 Subject: Fix building debug emulator on windows CFLAGS weren't updated to include the sys/common directory for this build target. --- erts/etc/common/Makefile.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index 4bcbb288b3..5b1b9119ce 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -70,10 +70,12 @@ endif ifeq ($(TARGET),win32) ifeq ($(TYPE),debug) CFLAGS = $(subst -O2,-g,@CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSDIR) \ - -I$(EMUDIR) $(ERTS_INCL) -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\") + -I$(EMUDIR) -I$(COMSYSDIR) $(ERTS_INCL) \ + -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\") LDFLAGS += -g endif endif + BINDIR = $(ERL_TOP)/bin/$(TARGET) OBJDIR = $(ERL_TOP)/erts/obj$(TYPEMARKER)/$(TARGET) EMUDIR = $(ERL_TOP)/erts/emulator/beam -- cgit v1.2.3 From eaad1be9619109483d85549889c2bf3244d6cfe4 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 12 Jul 2017 11:37:11 +0200 Subject: erts: Remove usage of sys.h from etc tools --- erts/etc/common/Makefile.in | 11 ++++---- erts/etc/common/ct_run.c | 11 +------- erts/etc/common/dialyzer.c | 10 +------ erts/etc/common/erlc.c | 14 +--------- erts/etc/common/erlexec.c | 25 +++++++---------- erts/etc/common/escript.c | 10 +------ erts/etc/common/etc_common.h | 65 ++++++++++++++++++++++++++++++++++++++++++++ erts/etc/common/typer.c | 10 +------ 8 files changed, 86 insertions(+), 70 deletions(-) create mode 100644 erts/etc/common/etc_common.h (limited to 'erts/etc/common') diff --git a/erts/etc/common/Makefile.in b/erts/etc/common/Makefile.in index 5b1b9119ce..1f35cef669 100644 --- a/erts/etc/common/Makefile.in +++ b/erts/etc/common/Makefile.in @@ -56,7 +56,7 @@ ERTS_INCL = -I$(ERL_TOP)/erts/include \ CC = @CC@ WFLAGS = @WFLAGS@ -CFLAGS = @CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSDIR) -I$(EMUDIR) \ +CFLAGS = @CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSOSDIR) -I$(EMUDIR) -I. \ -I$(COMSYSDIR) $(ERTS_INCL) -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\" LD = @LD@ LIBS = @LIBS@ @@ -69,9 +69,9 @@ endif ifeq ($(TARGET),win32) ifeq ($(TYPE),debug) -CFLAGS = $(subst -O2,-g,@CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSDIR) \ - -I$(EMUDIR) -I$(COMSYSDIR) $(ERTS_INCL) \ - -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\") +CFLAGS = $(subst -O2,-g,@CFLAGS@ @DEFS@ $(TYPE_FLAGS) @WFLAGS@ -I$(SYSOSDIR) \ + -I$(EMUDIR) -I$(COMSYSDIR) $(ERTS_INCL) \ + -DOTP_SYSTEM_VERSION=\"$(SYSTEM_VSN)\") LDFLAGS += -g endif endif @@ -81,7 +81,8 @@ OBJDIR = $(ERL_TOP)/erts/obj$(TYPEMARKER)/$(TARGET) EMUDIR = $(ERL_TOP)/erts/emulator/beam COMSYSDIR = $(ERL_TOP)/erts/emulator/sys/common EMUOSDIR = $(ERL_TOP)/erts/emulator/@ERLANG_OSTYPE@ -SYSDIR = $(ERL_TOP)/erts/emulator/sys/@ERLANG_OSTYPE@ +SYSDIR = $(ERL_TOP)/erts/emulator/sys/common +SYSOSDIR = $(ERL_TOP)/erts/emulator/sys/@ERLANG_OSTYPE@ DRVDIR = $(ERL_TOP)/erts/emulator/drivers/@ERLANG_OSTYPE@ UXETC = ../unix WINETC = ../win32 diff --git a/erts/etc/common/ct_run.c b/erts/etc/common/ct_run.c index 6639c83778..efa7ac3493 100644 --- a/erts/etc/common/ct_run.c +++ b/erts/etc/common/ct_run.c @@ -20,16 +20,7 @@ /* * Purpose: Common Test front-end. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -#endif - -#include +#include "etc_common.h" #define NO 0 #define YES 1 diff --git a/erts/etc/common/dialyzer.c b/erts/etc/common/dialyzer.c index c8d977f6de..0e74eb065b 100644 --- a/erts/etc/common/dialyzer.c +++ b/erts/etc/common/dialyzer.c @@ -20,16 +20,8 @@ /* * Purpose: Dialyzer front-end. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -#endif -#include +#include "etc_common.h" #define NO 0 #define YES 1 diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index cbbd2a37cd..8cfd98bcc4 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -20,19 +20,7 @@ /* * Purpose: Common compiler front-end. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -/* FIXE ME config_win32.h? */ -#define HAVE_STRERROR 1 -#define snprintf _snprintf -#endif - -#include +#include "etc_common.h" #define NO 0 #define YES 1 diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 51ed2d0dff..48abf77533 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -23,14 +23,9 @@ * additions required for Windows NT. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "etc_common.h" -#include "sys.h" #include "erl_driver.h" -#include -#include #include "erl_misc_utils.h" #ifdef __WIN32__ @@ -886,8 +881,8 @@ int main(int argc, char **argv) case 'c': argv[i][0] = '-'; if (argv[i][2] == '\0' && i+1 < argc) { - if (sys_strcmp(argv[i+1], "true") == 0 - || sys_strcmp(argv[i+1], "false") == 0) { + if (strcmp(argv[i+1], "true") == 0 + || strcmp(argv[i+1], "false") == 0) { add_Eargs(argv[i]); add_Eargs(argv[i+1]); i++; @@ -2195,18 +2190,18 @@ static WCHAR *utf8_to_utf16(unsigned char *bytes) res = target = emalloc((num + 1) * sizeof(WCHAR)); while (*bytes) { if (((*bytes) & ((unsigned char) 0x80)) == 0) { - unipoint = (Uint) *bytes; + unipoint = (unsigned int) *bytes; ++bytes; } else if (((*bytes) & ((unsigned char) 0xE0)) == 0xC0) { unipoint = - (((Uint) ((*bytes) & ((unsigned char) 0x1F))) << 6) | - ((Uint) (bytes[1] & ((unsigned char) 0x3F))); + (((unsigned int) ((*bytes) & ((unsigned char) 0x1F))) << 6) | + ((unsigned int) (bytes[1] & ((unsigned char) 0x3F))); bytes += 2; } else if (((*bytes) & ((unsigned char) 0xF0)) == 0xE0) { unipoint = - (((Uint) ((*bytes) & ((unsigned char) 0xF))) << 12) | - (((Uint) (bytes[1] & ((unsigned char) 0x3F))) << 6) | - ((Uint) (bytes[2] & ((unsigned char) 0x3F))); + (((unsigned int) ((*bytes) & ((unsigned char) 0xF))) << 12) | + (((unsigned int) (bytes[1] & ((unsigned char) 0x3F))) << 6) | + ((unsigned int) (bytes[2] & ((unsigned char) 0x3F))); if (unipoint > 0xFFFF) { unipoint = (unsigned int) '?'; } @@ -2225,7 +2220,7 @@ static WCHAR *utf8_to_utf16(unsigned char *bytes) static int put_utf8(WCHAR ch, unsigned char *target, int sz, int *pos) { - Uint x = (Uint) ch; + unsigned int x = (unsigned int) ch; if (x < 0x80) { if (*pos >= sz) { return -1; diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 9cd5dd3fab..8241675200 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -20,16 +20,8 @@ /* * Purpose: escript front-end. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -#endif -#include +#include "etc_common.h" static int debug = 0; /* Bit flags for debug printouts. */ diff --git a/erts/etc/common/etc_common.h b/erts/etc/common/etc_common.h new file mode 100644 index 0000000000..3f26064a9e --- /dev/null +++ b/erts/etc/common/etc_common.h @@ -0,0 +1,65 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2017. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * %CopyrightEnd% + */ +/* + * Purpose: common includes for all etc programs + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#if !defined(__WIN32__) +# include +# include +# include +# include +# include +#else +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include +#include +#include + +/* + * Make sure that MAXPATHLEN is defined. + */ +#ifndef MAXPATHLEN +# ifdef PATH_MAX +# define MAXPATHLEN PATH_MAX +# else +# define MAXPATHLEN 2048 +# endif +#endif + +#include "erl_printf.h" + +#ifdef __WIN32__ +/* FIXE ME config_win32.h? */ +#define HAVE_STRERROR 1 +#define snprintf _snprintf +#endif diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c index 6bae9f96b7..b64cbb4a92 100644 --- a/erts/etc/common/typer.c +++ b/erts/etc/common/typer.c @@ -20,16 +20,8 @@ /* * Purpose: Typer front-end. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "sys.h" -#ifdef __WIN32__ -#include -#endif -#include +#include "etc_common.h" #define NO 0 #define YES 1 -- cgit v1.2.3 From a69339d9f8c73d2a0a2369289b464db00c479302 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 12 Jul 2017 14:56:09 +0200 Subject: erts: Remove ERTS_SMP and USE_THREAD defines This refactor was done using the unifdef tool like this: for file in $(find erts/ -name *.[ch]); do unifdef -t -f defile -o $file $file; done where defile contained: #define ERTS_SMP 1 #define USE_THREADS 1 #define DDLL_SMP 1 #define ERTS_HAVE_SMP_EMU 1 #define SMP 1 #define ERL_BITS_REENTRANT 1 #define ERTS_USE_ASYNC_READY_Q 1 #define FDBLOCK 1 #undef ERTS_POLL_NEED_ASYNC_INTERRUPT_SUPPORT #define ERTS_POLL_ASYNC_INTERRUPT_SUPPORT 0 #define ERTS_POLL_USE_WAKEUP_PIPE 1 #define ERTS_POLL_USE_UPDATE_REQUESTS_QUEUE 1 #undef ERTS_HAVE_PLAIN_EMU #undef ERTS_SIGNAL_STATE --- erts/etc/common/erlexec.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 48abf77533..55a55b658c 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -189,9 +189,7 @@ void error(char* format, ...); * Local functions. */ -#if !defined(ERTS_HAVE_SMP_EMU) || !defined(ERTS_HAVE_PLAIN_EMU) static void usage_notsup(const char *switchname, const char *alt); -#endif static char **build_args_from_env(char *env_var); static char **build_args_from_string(char *env_var); static void initial_argv_massage(int *argc, char ***argv); @@ -463,9 +461,7 @@ int main(int argc, char **argv) */ cpuinfo = erts_cpu_info_create(); /* '-smp auto' is default */ -#ifdef ERTS_HAVE_SMP_EMU start_smp_emu = 1; -#endif #if defined(__WIN32__) && defined(WIN32_ALWAYS_DEBUG) emu_type = "debug"; @@ -497,23 +493,13 @@ int main(int argc, char **argv) i++; smp_enable: ; -#if !defined(ERTS_HAVE_SMP_EMU) - usage_notsup("-smp enable", ""); -#endif } else if (strcmp(argv[i+1], "disable") == 0) { i++; smp_disable: -#ifdef ERTS_HAVE_PLAIN_EMU - start_smp_emu = 0; -#else usage_notsup("-smp disable", " Use \"+S 1\" instead."); -#endif } else { smp: ; -#if !defined(ERTS_HAVE_SMP_EMU) - usage_notsup("-smp", ""); -#endif } } else if (strcmp(argv[i], "-smpenable") == 0) { goto smp_enable; @@ -1155,12 +1141,7 @@ usage_aux(void) "[-start_erl [datafile]] " #endif "[-smp [auto" -#ifdef ERTS_HAVE_SMP_EMU "|enable" -#endif -#ifdef ERTS_HAVE_PLAIN_EMU - "|disable" -#endif "]" "] " "[-make] [-man [manopts] MANPAGE] [-x] [-emu_args] [-start_epmd BOOLEAN] " @@ -1183,14 +1164,12 @@ usage(const char *switchname) usage_aux(); } -#if !defined(ERTS_HAVE_SMP_EMU) || !defined(ERTS_HAVE_PLAIN_EMU) static void usage_notsup(const char *switchname, const char *alt) { fprintf(stderr, "Argument \'%s\' not supported.%s\n", switchname, alt); usage_aux(); } -#endif static void usage_format(char *format, ...) -- cgit v1.2.3 From 7cbd315c3feccbfd67d369a79f299d62035a2c57 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 11 Sep 2017 15:15:22 +0200 Subject: erts: non-smp removal cleanup in erlexec --- erts/etc/common/erlexec.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 55a55b658c..6b194e25da 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -237,7 +237,7 @@ static int verbose = 0; /* If non-zero, print some extra information. */ static int start_detached = 0; /* If non-zero, the emulator should be * started detached (in the background). */ -static int start_smp_emu = 0; /* Start the smp emulator. */ +static int start_smp_emu = 1; /* Start the smp emulator. */ static const char* emu_type = 0; /* Type of emulator (lcnt, valgrind, etc) */ #ifdef __WIN32__ @@ -460,8 +460,6 @@ int main(int argc, char **argv) * Construct the path of the executable. */ cpuinfo = erts_cpu_info_create(); - /* '-smp auto' is default */ - start_smp_emu = 1; #if defined(__WIN32__) && defined(WIN32_ALWAYS_DEBUG) emu_type = "debug"; @@ -1140,10 +1138,6 @@ usage_aux(void) #ifdef __WIN32__ "[-start_erl [datafile]] " #endif - "[-smp [auto" - "|enable" - "]" - "] " "[-make] [-man [manopts] MANPAGE] [-x] [-emu_args] [-start_epmd BOOLEAN] " "[-args_file FILENAME] [+A THREADS] [+a SIZE] [+B[c|d|i]] [+c [BOOLEAN]] " "[+C MODE] [+h HEAP_SIZE_OPTION] [+K BOOLEAN] " -- cgit v1.2.3 From c4015fbe39a2b76f9746f91eb705a59ac59b06f4 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 14:05:12 +0200 Subject: dialyzer: Do not load .erlang Use 'no_dot_erlang' start script for tools. Options and paths should be stated on the command line. --- erts/etc/common/dialyzer.c | 2 +- erts/etc/common/typer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/dialyzer.c b/erts/etc/common/dialyzer.c index 0e74eb065b..b45d5c7ca7 100644 --- a/erts/etc/common/dialyzer.c +++ b/erts/etc/common/dialyzer.c @@ -255,7 +255,7 @@ int main(int argc, char** argv) } PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-run", "dialyzer", "plain_cl"); PUSH("-extra"); diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c index b64cbb4a92..f13135d883 100644 --- a/erts/etc/common/typer.c +++ b/erts/etc/common/typer.c @@ -177,7 +177,7 @@ main(int argc, char** argv) } PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-run", "typer", "start"); PUSH("-extra"); -- cgit v1.2.3 From 20824528602d921716ed373ee266175e62c09421 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 13:55:57 +0200 Subject: escript: Do not load .erlang Previously you could not opt out on loading .erlang, change the default to not load the resource file. The escript author can invoke c:erlangrc(PathList) to find and load .erlang if needed. --- erts/etc/common/escript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 8241675200..d739d21f12 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -521,7 +521,7 @@ main(int argc, char** argv) free_env_val(env); PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH("-noshell"); /* -- cgit v1.2.3 From b93f1cd08c540c27ac49b8078fbb3102029979f8 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 14:09:05 +0200 Subject: erlc: Do not load .erlang Use 'no_dot_erlang' start script for tools. Options and paths should be stated on the command line, via a Makefile, rebar.config etc. --- erts/etc/common/erlc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index 8cfd98bcc4..aa99c69100 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -234,7 +234,7 @@ int main(int argc, char** argv) PUSH("+A0"); PUSH("-noinput"); PUSH2("-mode", "minimal"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-s", "erl_compile", "compile_cmdline"); PUSH("-extra"); -- cgit v1.2.3 From 988f5f5e8061ce2e135a314ca782788eda478a06 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Tue, 30 May 2017 16:35:18 +0200 Subject: erts: Move all I/O polling to a seperate thread --- erts/etc/common/erlexec.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 6b194e25da..d61a3cbf95 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -810,6 +810,28 @@ int main(int argc, char **argv) add_Eargs(argv[i+1]); i++; break; + case 'I': + if (argv[i][2] == 'O' && (argv[i][3] == 't' || argv[i][3] == 'p')) { + if (argv[i][4] != '\0') + goto the_default; + argv[i][0] = '-'; + add_Eargs(argv[i]); + add_Eargs(argv[i+1]); + i++; + break; + } + if (argv[i][2] == 'O' && argv[i][3] == 'P' && + (argv[i][4] == 't' || argv[i][4] == 'p')) { + if (argv[i][5] != '\0') + goto the_default; + argv[i][0] = '-'; + add_Eargs(argv[i]); + add_Eargs(argv[i+1]); + i++; + break; + } + usage(argv[i]); + break; case 'S': if (argv[i][2] == 'P') { if (argv[i][3] != '\0') -- cgit v1.2.3 From b7a5e370d7a7a1b6cfc9c96cb56d7acfc0fa944b Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 13 Oct 2017 14:23:50 +0200 Subject: erts: Use PROFILE dir as home on windows Instead of using C:\Windows we use the profile path as the home path on windows. The profile path normally resolves to C:\Users\%USERNAME%. This fixes an issue where the default path to the .erlang.cookie was not the same for jinterface as for erl. --- erts/etc/common/erlexec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 51ed2d0dff..eaa94cd5e4 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -36,6 +36,7 @@ #ifdef __WIN32__ # include "erl_version.h" # include "init_file.h" +# include #endif #define NO 0 @@ -1541,17 +1542,16 @@ static void get_parameters(int argc, char** argv) static void get_home(void) { - int len; - char tmpstr[MAX_PATH+1]; + wchar_t *profile; char* homedrive; char* homepath; homedrive = get_env("HOMEDRIVE"); homepath = get_env("HOMEPATH"); if (!homedrive || !homepath) { - if (len = GetWindowsDirectory(tmpstr,MAX_PATH)) { - home = emalloc(len+1); - strcpy(home,tmpstr); + if (SHGetKnownFolderPath(&FOLDERID_Profile, 0, NULL, &profile) == S_OK) { + home = utf16_to_utf8(profile); + /* CoTaskMemFree(profile); */ } else error("HOMEDRIVE or HOMEPATH is not set and GetWindowsDir failed"); } else { -- cgit v1.2.3 From 80c8a01cf69dcf571eb28519e3f90c5bde9919cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Tue, 21 Nov 2017 10:38:48 +0100 Subject: Ensure that bindir is first in $PATH on startup erlexec adds $ROOT/erts-/bin and $ROOT/bin first in $PATH on startup, but didn't do so if they were in the $PATH already, which meant that the bindir didn't point to the current release after a downgrade. --- erts/etc/common/erlexec.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index eaa94cd5e4..860e721beb 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -558,19 +558,44 @@ int main(int argc, char **argv) } else { add_Eargs(emu); /* argv[0] = erl or cerl */ } - /* - * Add the bindir to the path (unless it is there already). - */ + + /* Add the bindir to the front of the PATH, and remove all subsequent + * occurrences to avoid ballooning it on repeated up/downgrades. */ s = get_env("PATH"); - if (!s) { - erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP "%s" DIRSEP "bin", bindir, rootdir); - } else if (strstr(s, bindir) == NULL) { - erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP "%s", bindir, - rootdir, s); + + if (s == NULL) { + erts_snprintf(tmpStr, sizeof(tmpStr), + "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP, bindir, rootdir); + } else if (strstr(s, rootdir) == NULL) { + erts_snprintf(tmpStr, sizeof(tmpStr), + "%s" PATHSEP "%s" DIRSEP "bin" PATHSEP "%s", bindir, rootdir, s); } else { - erts_snprintf(tmpStr, sizeof(tmpStr), "%s", s); + const char *bindir_slug, *bindir_slug_index; + int bindir_slug_length; + const char *in_index; + char *out_index; + + erts_snprintf(tmpStr, sizeof(tmpStr), "%s" PATHSEP, bindir); + + bindir_slug = strsave(tmpStr); + bindir_slug_length = strlen(bindir_slug); + + out_index = &tmpStr[bindir_slug_length]; + in_index = s; + + while ((bindir_slug_index = strstr(in_index, bindir_slug))) { + int block_length = (bindir_slug_index - in_index); + + memcpy(out_index, in_index, block_length); + + in_index = bindir_slug_index + bindir_slug_length; + out_index += block_length; + } + + strcpy(out_index, in_index); } + free_env_val(s); set_env("PATH", tmpStr); -- cgit v1.2.3 From 443b2e0fabe9dfbe78d7fe857b29e74f7533da39 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 23 Jan 2018 22:26:44 +0100 Subject: erts: Add migration options "acnl" and "acfml" acnl: Abandon Carrier Nr Limit acfml: Abandon Carrier Free block Min Limit --- erts/etc/common/erlexec.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 2b2e0e480a..864b16ce0e 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -84,6 +84,8 @@ static char *plusM_au_alloc_switches[] = { "as", "asbcst", "acul", + "acnl", + "acfml", "e", "t", "lmbcs", -- cgit v1.2.3 From ee6d1b9a61d8f2f087f0f3bf3ea2b933b5c3a93a Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 13 Feb 2018 10:14:22 +0100 Subject: Stop returning V4MAPPED addresses --- erts/etc/common/inet_gethost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c index b746487668..4fc7a93348 100644 --- a/erts/etc/common/inet_gethost.c +++ b/erts/etc/common/inet_gethost.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2017. All Rights Reserved. + * Copyright Ericsson AB 1998-2018. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1770,7 +1770,7 @@ static int worker_loop(void) } #elif defined(HAVE_GETIPNODEBYNAME) /*#ifdef HAVE_GETADDRINFO */ DEBUGF(5,("Starting getipnodebyname(%s)",data)); - he = getipnodebyname(data, AF_INET6, AI_DEFAULT, &error_num); + he = getipnodebyname(data, AF_INET6, 0, &error_num); if (he) { free_he = 1; error_num = 0; -- cgit v1.2.3 From f278cee87dd7ef929a64b411b4e83c3d7028687a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Fri, 23 Mar 2018 13:15:08 +0100 Subject: Add +sbwt/+swt analogues for dirty schedulers Sharing these settings for all schedulers can degrade performance, so it makes sense to be able to configure them separately. This also changes the default busy-wait time to "short" for both kinds of dirty schedulers. --- erts/etc/common/erlexec.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index f7774c6e2e..cf6d1bacca 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -129,6 +129,8 @@ static char *plusM_other_switches[] = { /* +s arguments with values */ static char *pluss_val_switches[] = { "bt", + "bwtdcpu", + "bwtdio", "bwt", "cl", "ct", @@ -136,6 +138,8 @@ static char *pluss_val_switches[] = { "fwi", "tbt", "wct", + "wtdcpu", + "wtdio", "wt", "ws", "ss", -- cgit v1.2.3 From 573a5abd9d6b1668b49376b489b187780c7125c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Tue, 27 Mar 2018 13:14:40 +0200 Subject: erts: Rewrite memory instrumentation This commit replaces the old memory instrumentation with a new implementation that scans carriers instead of wrapping erts_alloc/erts_free. The old implementation could not extract information without halting the emulator, had considerable runtime overhead, and the memory maps it produced were noisy and lacked critical information. Since the new implementation walks through existing data structures there's no longer a need to start the emulator with special flags to get information about carrier utilization/fragmentation. Memory fragmentation is also easier to diagnose as it's presented on a per-carrier basis which eliminates the need to account for "holes" between mmap segments. To help track allocations, each allocation can now be tagged with what it is and who allocated it at the cost of one extra word per allocation. This is controlled on a per-allocator basis with the +Matags option, and is enabled by default for binary_alloc and driver_alloc (which is also used by NIFs). --- erts/etc/common/erlexec.c | 1 + 1 file changed, 1 insertion(+) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index cf6d1bacca..21a3f40c97 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -79,6 +79,7 @@ static const char plusM_au_allocs[]= { static char *plusM_au_alloc_switches[] = { "as", "asbcst", + "atags", "acul", "acnl", "acfml", -- cgit v1.2.3 From 05b1c13e36ec49891e89593b25e668e983a4fc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Tue, 24 Apr 2018 13:30:00 +0200 Subject: heart: Use ntohs instead of manual conversion Multiplying a signed char by 256 is undefined behavior and caused problems on some platforms when the length was long enough. We could cast it to an unsigned int to make it work, but it's best not to reinvent the wheel. Fixes OTP-15034 --- erts/etc/common/heart.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/heart.c b/erts/etc/common/heart.c index 01ef840b5d..aaaffbca79 100644 --- a/erts/etc/common/heart.c +++ b/erts/etc/common/heart.c @@ -847,11 +847,8 @@ write_message(fd, mp) int fd; struct msg *mp; { - int len; - char* tmp; + int len = ntohs(mp->len); - tmp = (char*) &(mp->len); - len = (*tmp * 256) + *(tmp+1); if ((len == 0) || (len > MSG_BODY_SIZE)) { return MSG_HDR_SIZE; } /* cc68k wants (char *) */ -- cgit v1.2.3 From 35fb6f2e11db0454c634772137f748dc81bcca63 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Thu, 24 May 2018 09:59:47 +0200 Subject: Fix use-after-free on Windows in escript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit 385b18de6fd72672ed7d6736b30f56d6691d4433, the emulator path was not copied anymore before pushing it to the args vector (before it was done within the `push_words` function. Since on Windows `free_env_val` is not a NOP as it is on Unix systems, the string is freed and afterwards used, leading to strange errors like this: escript: Error executing 'àyI': 2 This is fixed by removing the `free_env_val` call. --- erts/etc/common/escript.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index d739d21f12..c84e63ad7c 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -138,15 +138,6 @@ get_env(char *key) #endif } -static void -free_env_val(char *value) -{ -#ifdef __WIN32__ - if (value) - efree(value); -#endif -} - static void set_env(char *key, char *value) { @@ -422,7 +413,6 @@ main(int argc, char** argv) int eargv_size; int eargc_base; /* How many arguments in the base of eargv. */ char* emulator; - char* env; char* basename; char* def_emu_lookup_path; char scriptname[PMAX]; @@ -504,7 +494,7 @@ main(int argc, char** argv) } /* Determine path to emulator */ - emulator = env = get_env("ESCRIPT_EMULATOR"); + emulator = get_env("ESCRIPT_EMULATOR"); if (emulator == NULL) { emulator = get_default_emulator(def_emu_lookup_path); @@ -518,7 +508,6 @@ main(int argc, char** argv) */ PUSH(emulator); - free_env_val(env); PUSH("+B"); PUSH2("-boot", "no_dot_erlang"); -- cgit v1.2.3 From 5ca92e2eac1e84fd22f60e7abc3aa2b0ff1cb42b Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Mon, 18 Jun 2018 14:51:18 +0200 Subject: Update copyright year --- erts/etc/common/erlexec.c | 2 +- erts/etc/common/escript.c | 2 +- erts/etc/common/heart.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 21a3f40c97..0cb01fd4ef 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2017. All Rights Reserved. + * Copyright Ericsson AB 1996-2018. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index c84e63ad7c..078937e676 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2007-2017. All Rights Reserved. + * Copyright Ericsson AB 2007-2018. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/erts/etc/common/heart.c b/erts/etc/common/heart.c index 8f1e89b638..bd218ff725 100644 --- a/erts/etc/common/heart.c +++ b/erts/etc/common/heart.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2016. All Rights Reserved. + * Copyright Ericsson AB 1996-2018. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3