Skip to content

Commit

Permalink
Merge branch 'lukas/kernel/ttysl-nif/OTP-18211/OTP-18231/OTP-17932'
Browse files Browse the repository at this point in the history
* lukas/kernel/ttysl-nif/OTP-18211/OTP-18231/OTP-17932: (34 commits)
  kernel: Fix loading of prim_tty nif in embedded mode
  erts: Fix so that prim_tty can be reloaded
  ct: Fix peer compilation from unicode path
  kernel: Fix remote shell edlin expand for jcl remote shells
  stdlib: Fix escript SUITE
  stdlib: Polish testcase failures
  ssh: Fix to be compatible with new group interface
  erts: Handle can be null for statically linked nifs
  erts: Clear fallback flag when stopping select
  erts: Fix building of debuginfo on windows
  stdlib: Add shell:start_interactive/0,1
  stdlib: Add shell session configuration
  stdlib: Add shell_slogan stdlib configuration
  erts: Reset tty when child_setup exits
  stdlib: Fix group handling of eof for -noshell
  kernel: Introduce terminal io:getopts option
  kernel: Change -noshell and -noinput to use user_drv
  kernel: Use prim_tty wcwidth for tty testing
  erts: Re-Implement shell using nif
  kernel: Rewrite user_drv group handling to use records
  ...
  • Loading branch information
garazdawi committed Aug 31, 2022
2 parents 0d27112 + 945b37f commit 7151c97
Show file tree
Hide file tree
Showing 73 changed files with 4,358 additions and 6,048 deletions.
7 changes: 7 additions & 0 deletions .github/dockerfiles/Dockerfile.ubuntu-base
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ RUN apt-get install -y git && \
done && \
rm -rf ~/.kerl

## We use tmux to test terminals
RUN apt-get install -y libevent-dev libutf8proc-dev && \
cd /tmp && wget https://github.com/tmux/tmux/releases/download/3.2a/tmux-3.2a.tar.gz && \
tar xvzf tmux-3.2a.tar.gz && cd tmux-3.2a && \
./configure --enable-static --enable-utf8proc && \
make && make install

ENV LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

ARG USER=gitpod
Expand Down
21 changes: 14 additions & 7 deletions .github/scripts/build-macos.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/sh

export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN)
export ERL_TOP=`pwd`
export RELEASE_ROOT=$ERL_TOP/release
export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
export ERL_TOP="$(pwd)"
export ERLC_USE_SERVER=true
export RELEASE_ROOT="$ERL_TOP/release"
BUILD_DOCS=false

./otp_build configure \
--disable-dynamic-ssl-lib
if [ "$1" = "build_docs" ]; then
BUILD_DOCS=true
shift
fi

./otp_build configure $*
./otp_build boot -a
./otp_build release -a $RELEASE_ROOT
make release_docs DOC_TARGETS=chunks
./otp_build release -a "$RELEASE_ROOT"
if $BUILD_DOCS; then
make release_docs DOC_TARGETS=chunks
fi
10 changes: 3 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
tar -xzf ./otp_src.tar.gz
export PATH=$PWD/wxWidgets/release/bin:$PATH
cd otp
$GITHUB_WORKSPACE/.github/scripts/build-macos.sh
$GITHUB_WORKSPACE/.github/scripts/build-macos.sh build_docs --disable-dynamic-ssl-lib
tar -czf otp_macos_$(cat OTP_VERSION)_x86-64.tar.gz -C release .
- name: Test Erlang
Expand All @@ -152,6 +152,7 @@ jobs:
runs-on: macos-12
needs: pack
steps:
- uses: actions/checkout@v2
- name: Download source archive
uses: actions/download-artifact@v2
with:
Expand All @@ -161,12 +162,7 @@ jobs:
run: |
tar -xzf ./otp_src.tar.gz
cd otp
export ERL_TOP=`pwd`
export MAKEFLAGS="-j$(($(nproc) + 2)) -O"
export ERLC_USE_SERVER=true
./otp_build configure --xcomp-conf=./xcomp/erl-xcomp-arm64-ios.conf --without-ssl
./otp_build boot -a
./otp_build release -a
$GITHUB_WORKSPACE/.github/scripts/build-macos.sh --xcomp-conf=./xcomp/erl-xcomp-arm64-ios.conf --without-ssl
- name: Package .xcframework
run: |
Expand Down
4 changes: 2 additions & 2 deletions HOWTO/INSTALL-WIN32.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ This is the short story though, for the experienced and impatient:
<http://www.erlang.org/download.html>) and unpack with `tar`
to the windows disk for example to: /mnt/c/src/

* Install mingw-gcc, and make: `sudo apt install g++-mingw-w64 gcc-mingw-w64 make`
* Install mingw-gcc, and make: `sudo apt update && sudo apt install g++-mingw-w64 gcc-mingw-w64 make`

* `$ cd UNPACK_DIR`

Expand Down Expand Up @@ -150,7 +150,7 @@ the different tools:
Install into `C:/OpenSSL-Win64` (or `C:/OpenSSL-Win32`)

* wxWidgets (optional)
You need this to build wx and use gui's in debugger and observer.
You need this to build wx to use gui's in debugger and observer.

We recommend v3.1.4 or later.
Unpack into `c:/opt/local64/pgm/wxWidgets-3.1.4`
Expand Down
4 changes: 1 addition & 3 deletions erts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ local_setup:
cp $(ERL_TOP)/bin/$(TARGET)/erlc.exe $(ERL_TOP)/bin/erlc.exe; \
cp $(ERL_TOP)/bin/$(TARGET)/erl.exe $(ERL_TOP)/bin/erl.exe; \
cp $(ERL_TOP)/bin/$(TARGET)/erl_call.exe $(ERL_TOP)/bin/erl_call.exe; \
cp $(ERL_TOP)/bin/$(TARGET)/werl.exe $(ERL_TOP)/bin/werl.exe; \
cp $(ERL_TOP)/bin/$(TARGET)/escript.exe $(ERL_TOP)/bin/escript.exe; \
chmod 755 $(ERL_TOP)/bin/erl.exe $(ERL_TOP)/bin/erlc.exe \
$(ERL_TOP)/bin/werl.exe; \
chmod 755 $(ERL_TOP)/bin/erl.exe $(ERL_TOP)/bin/erlc.exe; \
make_local_ini.sh $(ERL_TOP); \
cp $(ERL_TOP)/bin/erl.ini $(ERL_TOP)/bin/$(TARGET)/erl.ini; \
else \
Expand Down
4 changes: 2 additions & 2 deletions erts/doc/src/erl_cmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ $ <input>erl \
to implement an Alternative Carrier for the Erlang
Distribution</seeguide>.</p>
</item>
<tag><c><![CDATA[-noinput]]></c></tag>
<tag><marker id="noinput"/><c><![CDATA[-noinput]]></c></tag>
<item>
<p>Ensures that the Erlang runtime system never tries to read
any input. Implies <c><![CDATA[-noshell]]></c>.</p>
</item>
<tag><c><![CDATA[-noshell]]></c></tag>
<tag><marker id="noshell"/><c><![CDATA[-noshell]]></c></tag>
<item>
<p>Starts an Erlang runtime system with no shell. This flag
makes it possible to have the Erlang runtime system as a
Expand Down
3 changes: 1 addition & 2 deletions erts/doc/src/erlsrv_cmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@
<item>
<p>The location of the Erlang emulator.
The default is the <c><![CDATA[erl.exe]]></c> located in the same
directory as <c>erlsrv.exe</c>. Do not specify
<c><![CDATA[werl.exe]]></c> as this emulator, it will not work.</p>
directory as <c>erlsrv.exe</c>.</p>
<p>If the system uses release handling, this is to be set to a
program similar to <c><![CDATA[start_erl.exe]]></c>.</p>
</item>
Expand Down
8 changes: 3 additions & 5 deletions erts/emulator/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ RUN_OBJS += \
LTTNG_OBJS = $(OBJDIR)/erlang_lttng.o

NIF_OBJS = \
$(OBJDIR)/prim_tty_nif.o \
$(OBJDIR)/erl_tracer_nif.o \
$(OBJDIR)/prim_buffer_nif.o \
$(OBJDIR)/prim_file_nif.o \
Expand All @@ -1139,10 +1140,8 @@ ifeq ($(TARGET),win32)
DRV_OBJS = \
$(OBJDIR)/registry_drv.o \
$(OBJDIR)/inet_drv.o \
$(OBJDIR)/ram_file_drv.o \
$(OBJDIR)/ttsl_drv.o
$(OBJDIR)/ram_file_drv.o
OS_OBJS = \
$(OBJDIR)/win_con.o \
$(OBJDIR)/dll_sys.o \
$(OBJDIR)/driver_tab.o \
$(OBJDIR)/sys_float.o \
Expand All @@ -1166,8 +1165,7 @@ OS_OBJS = \

DRV_OBJS = \
$(OBJDIR)/inet_drv.o \
$(OBJDIR)/ram_file_drv.o \
$(OBJDIR)/ttsl_drv.o
$(OBJDIR)/ram_file_drv.o
endif

ifneq ($(STATIC_NIFS),no)
Expand Down
103 changes: 90 additions & 13 deletions erts/emulator/beam/bif.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#endif

#include <stddef.h> /* offsetof() */
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#define WANT_NONBLOCKING
#include "sys.h"
#include "erl_vm.h"
#include "erl_sys_driver.h"
Expand Down Expand Up @@ -4180,27 +4184,100 @@ BIF_RETTYPE erts_debug_display_1(BIF_ALIST_1)
BIF_RET(res);
}


BIF_RETTYPE display_string_1(BIF_ALIST_1)
BIF_RETTYPE display_string_2(BIF_ALIST_2)
{
Process* p = BIF_P;
Eterm string = BIF_ARG_1;
Sint len = erts_unicode_list_to_buf_len(string);
Eterm string = BIF_ARG_2;
Sint len;
Sint written;
byte *str;
int res;
byte *temp_alloc = NULL;

if (len < 0) {
BIF_ERROR(p, BADARG);
#ifdef __WIN32__
HANDLE fd;
if (ERTS_IS_ATOM_STR("stdout", BIF_ARG_1)) {
fd = GetStdHandle(STD_OUTPUT_HANDLE);
} else if (ERTS_IS_ATOM_STR("stderr", BIF_ARG_1)) {
fd = GetStdHandle(STD_ERROR_HANDLE);
}
#else
int fd;
if (ERTS_IS_ATOM_STR("stdout", BIF_ARG_1)) {
fd = fileno(stdout);
} else if (ERTS_IS_ATOM_STR("stderr", BIF_ARG_1)) {
fd = fileno(stderr);
}
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCSTI)
else if (ERTS_IS_ATOM_STR("stdin", BIF_ARG_1)) {
fd = open("/proc/self/fd/0",0);
}
#endif
#endif
else {
BIF_ERROR(p, BADARG);
}
if (is_list(string) || is_nil(string)) {
len = erts_unicode_list_to_buf_len(string);
if (len < 0) BIF_ERROR(p, BADARG);
str = temp_alloc = (byte *) erts_alloc(ERTS_ALC_T_TMP, sizeof(char)*len);
res = erts_unicode_list_to_buf(string, str, len, &written);
if (res != 0 || written != len)
erts_exit(ERTS_ERROR_EXIT, "%s:%d: Internal error (%d)\n", __FILE__, __LINE__, res);
} else if (is_binary(string)) {
Uint bitoffs, bitsize;
ERTS_GET_BINARY_BYTES(string, str, bitoffs, bitsize);
if (bitsize % 8 != 0) BIF_ERROR(p, BADARG);
len = binary_size(string);
if (bitoffs != 0) {
str = erts_get_aligned_binary_bytes(string, &temp_alloc);
}
} else {
BIF_ERROR(p, BADARG);
}
str = (byte *) erts_alloc(ERTS_ALC_T_TMP, sizeof(char)*(len + 1));
res = erts_unicode_list_to_buf(string, str, len, &written);
if (res != 0 || written != len)
erts_exit(ERTS_ERROR_EXIT, "%s:%d: Internal error (%d)\n", __FILE__, __LINE__, res);
str[len] = '\0';
erts_fprintf(stderr, "%s", str);
erts_free(ERTS_ALC_T_TMP, (void *) str);

#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCSTI)
if (ERTS_IS_ATOM_STR("stdin", BIF_ARG_1)) {
for (int i = 0; i < len; i++) {
if (ioctl(fd, TIOCSTI, str+i) < 0) {
fprintf(stderr,"failed to write to %s (%s)\r\n", "/proc/self/fd/0",
strerror(errno));
close(fd);
goto error;
}
}
close(fd);
} else
#endif
{
#ifdef __WIN32__
if (!WriteFile(fd, str, len, &written, NULL)) {
goto error;
}
#else
written = 0;
do {
res = write(fd, str+written, len-written);
if (res < 0 && errno != ERRNO_BLOCK && errno != EINTR)
goto error;
written += res;
} while (written < len);
#endif
}
if (temp_alloc)
erts_free(ERTS_ALC_T_TMP, (void *) temp_alloc);
BIF_RET(am_true);

error: {
#ifdef __WIN32__
char *errnostr = last_error();
#else
char *errnostr = erl_errno_id(errno);
#endif
BIF_P->fvalue = am_atom_put(errnostr, strlen(errnostr));
erts_free(ERTS_ALC_T_TMP, (void *) str);
BIF_ERROR(p, BADARG | EXF_HAS_EXT_INFO);
}
}

BIF_RETTYPE display_nl_0(BIF_ALIST_0)
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/bif.tab
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bif erlang:crc32_combine/3
bif erlang:date/0
bif erlang:delete_module/1
bif erlang:display/1
bif erlang:display_string/1
bif erlang:display_string/2
bif erlang:display_nl/0
ubif erlang:element/2
bif erlang:erase/0
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/break.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ do_break(void)
/* check if we're in console mode and, if so,
halt immediately if break is called */
mode = erts_read_env("ERL_CONSOLE_MODE");
if (mode && sys_strcmp(mode, "window") != 0)
if (mode && sys_strcmp(mode, "detached") == 0)
erts_exit(0, "");
erts_free_read_env(mode);
#endif /* __WIN32__ */
Expand Down
1 change: 1 addition & 0 deletions erts/emulator/beam/erl_dirty_bif.tab
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dirty-io erts_debug:dirty_io/2
dirty-cpu erts_debug:lcnt_control/2
dirty-cpu erts_debug:lcnt_collect/0
dirty-cpu erts_debug:lcnt_clear/0
dirty-cpu erlang:display_string/2

# --- TEST of Dirty BIF functionality ---
# Functions below will execute on dirty schedulers when emulator has
Expand Down
1 change: 0 additions & 1 deletion erts/emulator/beam/erl_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,6 @@ static void close_dynlib(struct erl_module_nif* lib)
{
ASSERT(lib != NULL);
ASSERT(lib->mod == NULL);
ASSERT(lib->handle != NULL);
ASSERT(erts_refc_read(&lib->dynlib_refc,0) == 0);

if (lib->entry.unload != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ extern erts_tsd_key_t erts_is_crash_dumping_key;
static unsigned long zero_value = 0, one_value = 1;
# define SET_BLOCKING(fd) { if (ioctlsocket((fd), FIONBIO, &zero_value) != 0) fprintf(stderr, "Error setting socket to non-blocking: %d\n", WSAGetLastError()); }
# define SET_NONBLOCKING(fd) ioctlsocket((fd), FIONBIO, &one_value)

# define ERRNO_BLOCK EAGAIN /* We use the posix way for windows */
# else
# ifdef NB_FIONBIO /* Old BSD */
# include <sys/ioctl.h>
Expand Down
Loading

0 comments on commit 7151c97

Please sign in to comment.