Browse Source

push app in git

dev
serkus01 4 months ago
parent
commit
d1e3ca004e
100 changed files with 23703 additions and 2 deletions
  1. +5
    -0
      BuildInfo.txt
  2. +63
    -0
      Makefile
  3. +56
    -2
      README.md
  4. +70
    -0
      bin/dev
  5. +332
    -0
      bin/nitrogen
  6. +504
    -0
      do-plugins.escript
  7. +43
    -0
      docker/Dockerfile
  8. BIN
      erts-11.1.5/bin/beam.smp
  9. BIN
      erts-11.1.5/bin/ct_run
  10. BIN
      erts-11.1.5/bin/dialyzer
  11. BIN
      erts-11.1.5/bin/epmd
  12. +34
    -0
      erts-11.1.5/bin/erl
  13. BIN
      erts-11.1.5/bin/erl_call
  14. BIN
      erts-11.1.5/bin/erl_child_setup
  15. BIN
      erts-11.1.5/bin/erlc
  16. BIN
      erts-11.1.5/bin/erlexec
  17. BIN
      erts-11.1.5/bin/escript
  18. BIN
      erts-11.1.5/bin/heart
  19. BIN
      erts-11.1.5/bin/inet_gethost
  20. +182
    -0
      erts-11.1.5/bin/nodetool
  21. BIN
      erts-11.1.5/bin/run_erl
  22. +37
    -0
      erts-11.1.5/bin/start
  23. BIN
      erts-11.1.5/bin/to_erl
  24. BIN
      erts-11.1.5/bin/typer
  25. BIN
      erts-11.1.5/bin/yielding_c_fun
  26. +42
    -0
      erts-11.1.5/include/driver_int.h
  27. +636
    -0
      erts-11.1.5/include/erl_driver.h
  28. +170
    -0
      erts-11.1.5/include/erl_drv_nif.h
  29. +161
    -0
      erts-11.1.5/include/erl_fixed_size_int_types.h
  30. +38
    -0
      erts-11.1.5/include/erl_int_sizes_config.h
  31. +157
    -0
      erts-11.1.5/include/erl_memory_trace_parser.h
  32. +413
    -0
      erts-11.1.5/include/erl_nif.h
  33. +654
    -0
      erts-11.1.5/include/erl_nif_api_funcs.h
  34. +29
    -0
      erts-11.1.5/include/internal/README
  35. +52
    -0
      erts-11.1.5/include/internal/erl_errno.h
  36. +246
    -0
      erts-11.1.5/include/internal/erl_memory_trace_protocol.h
  37. +89
    -0
      erts-11.1.5/include/internal/erl_misc_utils.h
  38. +66
    -0
      erts-11.1.5/include/internal/erl_printf.h
  39. +59
    -0
      erts-11.1.5/include/internal/erl_printf_format.h
  40. +25
    -0
      erts-11.1.5/include/internal/erts_internal.mk
  41. +9168
    -0
      erts-11.1.5/include/internal/ethr_atomics.h
  42. +786
    -0
      erts-11.1.5/include/internal/ethr_mutex.h
  43. +231
    -0
      erts-11.1.5/include/internal/ethr_optimized_fallbacks.h
  44. +835
    -0
      erts-11.1.5/include/internal/ethread.h
  45. +40
    -0
      erts-11.1.5/include/internal/ethread.mk
  46. +290
    -0
      erts-11.1.5/include/internal/ethread_header_config.h
  47. +76
    -0
      erts-11.1.5/include/internal/ethread_inline.h
  48. +569
    -0
      erts-11.1.5/include/internal/gcc/ethr_atomic.h
  49. +244
    -0
      erts-11.1.5/include/internal/gcc/ethr_dw_atomic.h
  50. +214
    -0
      erts-11.1.5/include/internal/gcc/ethr_membar.h
  51. +365
    -0
      erts-11.1.5/include/internal/gcc/ethread.h
  52. +256
    -0
      erts-11.1.5/include/internal/i386/atomic.h
  53. +302
    -0
      erts-11.1.5/include/internal/i386/ethr_dw_atomic.h
  54. +115
    -0
      erts-11.1.5/include/internal/i386/ethr_membar.h
  55. +39
    -0
      erts-11.1.5/include/internal/i386/ethread.h
  56. +138
    -0
      erts-11.1.5/include/internal/i386/rwlock.h
  57. +100
    -0
      erts-11.1.5/include/internal/i386/spinlock.h
  58. +624
    -0
      erts-11.1.5/include/internal/libatomic_ops/ethr_atomic.h
  59. +568
    -0
      erts-11.1.5/include/internal/libatomic_ops/ethr_dw_atomic.h
  60. +76
    -0
      erts-11.1.5/include/internal/libatomic_ops/ethr_membar.h
  61. +46
    -0
      erts-11.1.5/include/internal/libatomic_ops/ethread.h
  62. +441
    -0
      erts-11.1.5/include/internal/ppc32/atomic.h
  63. +64
    -0
      erts-11.1.5/include/internal/ppc32/ethr_membar.h
  64. +33
    -0
      erts-11.1.5/include/internal/ppc32/ethread.h
  65. +157
    -0
      erts-11.1.5/include/internal/ppc32/rwlock.h
  66. +96
    -0
      erts-11.1.5/include/internal/ppc32/spinlock.h
  67. +170
    -0
      erts-11.1.5/include/internal/pthread/ethr_event.h
  68. +137
    -0
      erts-11.1.5/include/internal/sparc32/atomic.h
  69. +116
    -0
      erts-11.1.5/include/internal/sparc32/ethr_membar.h
  70. +38
    -0
      erts-11.1.5/include/internal/sparc32/ethread.h
  71. +146
    -0
      erts-11.1.5/include/internal/sparc32/rwlock.h
  72. +85
    -0
      erts-11.1.5/include/internal/sparc32/spinlock.h
  73. +21
    -0
      erts-11.1.5/include/internal/sparc64/ethread.h
  74. +143
    -0
      erts-11.1.5/include/internal/tile/atomic.h
  75. +36
    -0
      erts-11.1.5/include/internal/tile/ethr_membar.h
  76. +30
    -0
      erts-11.1.5/include/internal/tile/ethread.h
  77. +481
    -0
      erts-11.1.5/include/internal/win/ethr_atomic.h
  78. +155
    -0
      erts-11.1.5/include/internal/win/ethr_dw_atomic.h
  79. +68
    -0
      erts-11.1.5/include/internal/win/ethr_event.h
  80. +146
    -0
      erts-11.1.5/include/internal/win/ethr_membar.h
  81. +38
    -0
      erts-11.1.5/include/internal/win/ethread.h
  82. +21
    -0
      erts-11.1.5/include/internal/x86_64/ethread.h
  83. +29
    -0
      erts-11.1.5/lib/internal/README
  84. BIN
      erts-11.1.5/lib/internal/liberts_internal.a
  85. BIN
      erts-11.1.5/lib/internal/liberts_internal_r.a
  86. BIN
      erts-11.1.5/lib/internal/libethread.a
  87. BIN
      erts-11.1.5/lib/liberts.a
  88. BIN
      erts-11.1.5/lib/liberts_r.a
  89. +260
    -0
      erts-11.1.5/src/setuid_socket_wrap.c
  90. +29
    -0
      etc/app.config
  91. +69
    -0
      etc/simple_bridge.config
  92. +44
    -0
      etc/sync.config
  93. +29
    -0
      etc/vm.args
  94. +1340
    -0
      lib/asn1-5.0.14/c_src/asn1_erl_nif.c
  95. +14
    -0
      lib/asn1-5.0.14/ebin/asn1.app
  96. +22
    -0
      lib/asn1-5.0.14/ebin/asn1.appup
  97. BIN
      lib/asn1-5.0.14/ebin/asn1_db.beam
  98. BIN
      lib/asn1-5.0.14/ebin/asn1ct.beam
  99. BIN
      lib/asn1-5.0.14/ebin/asn1ct_check.beam
  100. BIN
      lib/asn1-5.0.14/ebin/asn1ct_constructed_ber_bin_v2.beam

+ 5
- 0
BuildInfo.txt View File

@@ -0,0 +1,5 @@
Nitrogen Version:
2.4.0

Built On (uname -v):
#1 SMP PREEMPT Tue Jan 26 22:44:25 +09 2021

+ 63
- 0
Makefile View File

@@ -0,0 +1,63 @@
.PHONY: fix-slim-release test

all: releases get-deps plugins compile

REBAR?=./rebar -q

cookie:
@echo Generating a default cookie in /etc/vm.args
@(echo -setcookie `openssl rand -base64 50 | head -n1 | sed -e 's/[^a-zA-Z0-9]//g'` >> etc/vm.args)

compile:
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Erlang in `which erl`"; $(REBAR) compile)

get-deps:
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Erlang in `which erl`"; $(REBAR) get-deps)

update-deps:
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Erlang in `which erl`"; $(REBAR) update-deps)

eunit: get-deps compile
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Erlang in `which erl`"; $(REBAR) skip_deps=true eunit)

releases:
make fix-slim-release

copy-static:
@(mkdir -p site/static/nitrogen)
@(cp -r lib/nitrogen_core/www/* site/static/nitrogen/)

plugins:
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH;escript do-plugins.escript)

## This is only applicable for slim releases
fix-slim-release:
@echo Fixing slim release to the version of Erlang installed on this machine
@(./fix-slim-release)

DEPS_PLT=$(CURDIR)/.deps_plt
DEPS=erts kernel stdlib sasl lib/nitrogen_core lib/simple_bridge lib/nprocreg lib/nitro_cache lib/rekt lib/qdate

$(DEPS_PLT):
@echo Building local plt at $(DEPS_PLT)
@echo
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Dialyzer in `which dialyzer`"; dialyzer --output_plt $(DEPS_PLT) --build_plt --apps $(DEPS) -r ./lib)


dialyzer: all $(DEPS_PLT)
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; echo "Using Dialyzer in `which dialyzer`"; dialyzer --fullpath --plt $(DEPS_PLT) -Wrace_conditions -r ./site/ebin)

update: update-deps copy-static compile
@(echo "*** CONGRATULATIONS ***")
@(echo "Your Nitrogen installation has been upgraded.")
@(echo "You may need to manually merge any changes that may have been made to")
@(echo "configuration files as well as the initialization modules:")
@(echo " site/src/nitrogen_sup.erl")
@(echo " site/src/nitrogen_PLATFORM.erl")
@(echo " site/src/nitrogen_app.erl")
@(echo "")

upgrade: update

clean:
@(export PATH=`pwd`/`echo erts-*/bin`:$$PATH; $(REBAR) clean)

+ 56
- 2
README.md View File

@@ -1,3 +1,57 @@
# SPA_portage
# About

ERL in corp app for fortage
This is an Erlang web application using the [Nitrogen Web
Framework](https://nitrogenproject.com).

# Building

You can rebuild the project by typing:

make

If this fails, it likely means that its a slim release and Erlang is not
installed on this machine. Please [install
Erlang](https://www.erlang-solutions.com/resources/download.html).

# Running

You can start the application with:

bin/nitrogen start

which will start it in daemon mode. You can attach to this started daemon
with:

bin/nitrogen attach

If you'd rather have an Erlang console right away, rather than starting a
daemon, type:

bin/nitrogen console

# Config

The rebar.config file controls dependencies and build parameters using the
popular [rebar](http://github.com/rebar/rebar) tool.

The `plugins.config` file controls how Nitrogen plugins are handled.

The files in the `etc` directory control application configuration, including
ports, webserver set up, and the like. Please see the files there for
configuration options, or view the Nitrogen documentation.

# Code

Dependency libraries (once being built) end up in the `lib` directory.

Source code can be found in `site/src`

Template code is in `site/templates`

Compiled Erlang modules (ebin files) go in `site/ebin`

# Live code reloading

By default Nitrogen comes with an application called [sync](http://github.com/rustyio/sync) which provides automatic code reloading when the related .erl file or .ebin file is updated. To use this, run the following on the Erlang shell:

sync:go().

+ 70
- 0
bin/dev View File

@@ -0,0 +1,70 @@
#!/usr/bin/env bash

RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)

RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
RUNNER_USER=

# Make sure this script is running as the appropriate user
if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
exec sudo -u $RUNNER_USER -i $0 $@
fi

# Make sure CWD is set to runner base dir
cd $RUNNER_BASE_DIR

# Extract the target node name from node.args
NAME_ARG=`grep -e '-[s]*name' $RUNNER_ETC_DIR/vm.args`
if [ -z "$NAME_ARG" ]; then
echo "vm.args needs to have either -name or -sname parameter."
exit 1
fi

# Learn how to specify node name for connection from remote nodes
if echo $NAME_ARG | grep -E "^-sname" > /dev/null ; then
NAME_PARAM="-sname"
NAME_HOST=""
else
NAME_PARAM="-name"
if echo $NAME_ARG | grep -E "(@.*)" > /dev/null ; then
NAME_HOST=${BASH_REMATCH[1]}
else
NAME_HOST=""
fi
fi

# Extract the target cookie
COOKIE_ARG=`grep -e '-setcookie' $RUNNER_ETC_DIR/vm.args`
if [ -z "$COOKIE_ARG" ]; then
echo "vm.args needs to have a -setcookie parameter."
exit 1
fi

# Identify the script name
SCRIPT=`basename $0`

# Parse out release and erts info
START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
ERTS_VSN=${START_ERL% *}
APP_VSN=${START_ERL#* }

# Add ERTS bin dir to our path.
ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin

# Setup command to control the node
if [ -x $ERTS_PATH/escript ]; then
NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
else
NODETOOL="escript $RUNNER_BASE_DIR/releases/*/nodetool $NAME_ARG $COOKIE_ARG"
fi

# Make sure the local node IS running
RES=`$NODETOOL ping`
if [ "$RES" != "pong" ]; then
echo "Node is not running!"
exit 1
fi

$NODETOOL rpc nitrogen_dev command $@

+ 332
- 0
bin/nitrogen View File

@@ -0,0 +1,332 @@
#!/bin/sh
# -*- tab-width:4;indent-tabs-mode:nil -*-
# ex: ts=4 sw=4 et

RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)

CALLER_DIR=$PWD

RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
# Note the trailing slash on $PIPE_DIR/
PIPE_DIR=/tmp/`whoami`/$RUNNER_BASE_DIR/
RUNNER_USER=

# Make sure this script is running as the appropriate user
if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
exec sudo -u $RUNNER_USER -i $0 $@
fi

# Identify the script name
SCRIPT=`basename $0`

# Parse out release and erts info
START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
ERTS_VSN=${START_ERL% *}
APP_VSN=${START_ERL#* }

# Use $CWD/vm.args if exists, otherwise releases/APP_VSN/vm.args, or else etc/vm.args
if [ -e "$CALLER_DIR/vm.args" ]; then
VMARGS_PATH=$CALLER_DIR/vm.args
USE_DIR=$CALLER_DIR
else
USE_DIR=$RUNNER_BASE_DIR
if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then
VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args"
else
VMARGS_PATH="$RUNNER_ETC_DIR/vm.args"
fi
fi

RUNNER_LOG_DIR=$USE_DIR/log
# Make sure log directory exists
mkdir -p $RUNNER_LOG_DIR

# Use releases/VSN/sys.config if it exists otherwise use etc/app.config
## THIS SECTION MODIFIED FROM STOCK REBAR TO READ ALL *.config FILES FROM DIRECTORY
if [ -e "$USE_DIR/sys.config" ]; then
CONFIG="-config $USE_DIR/sys.config"
else
if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then
CONFIG="-config $RUNNER_BASE_DIR/releases/$APP_VSN/sys.config"
else
## NITROGEN CHANGE: Ensure that all .config files get loaded in /etc
for f in `ls $RUNNER_ETC_DIR/*.config`; do CONFIG="$CONFIG -config $f"; done
fi
fi

# Extract the target node name from node.args
NAME_ARG=`egrep '^-s?name' $VMARGS_PATH`
if [ -z "$NAME_ARG" ]; then
echo "vm.args needs to have either -name or -sname parameter."
exit 1
fi

# Extract the name type and name from the NAME_ARG for REMSH
REMSH_TYPE=`echo $NAME_ARG | awk '{print $1}'`
REMSH_NAME=`echo $NAME_ARG | awk '{print $2}'`

# Note the `date +%s`, used to allow multiple remsh to the same node transparently
REMSH_NAME_ARG="$REMSH_TYPE remsh`date +%s`@`echo $REMSH_NAME | awk -F@ '{print $2}'`"
REMSH_REMSH_ARG="-remsh $REMSH_NAME"

# Extract the target cookie
COOKIE_ARG=`grep '^-setcookie' $VMARGS_PATH`
if [ -z "$COOKIE_ARG" ]; then
echo "vm.args needs to have a -setcookie parameter."
exit 1
fi

# Make sure CWD is set to the right dir
cd $USE_DIR

# Make sure log directory exists
mkdir -p $USE_DIR/log

RUNNER_SCRIPT_DATA=
if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data" ]; then
RUNNER_SCRIPT_DATA=`cat $RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data`
fi

if [ -z "$RUNNER_SCRIPT_DATA" ]; then
ROOTDIR=$RUNNER_BASE_DIR
ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/nodetool" ]; then
NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG"
else
NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
fi
## Not a slim release, so no slim arguments
SLIM_ARGS=
elif [ "$RUNNER_SCRIPT_DATA" = "slim" ]; then
# Setup system paths
SYSTEM_ERL_PATH=`which erl`
if [ ! -x "$SYSTEM_ERL_PATH" ]; then
echo "Failed to find erl. Is Erlang/OTP available in PATH?"
exit 1
fi
SYSTEM_HOME_BIN=${SYSTEM_ERL_PATH%/*}
## This is a check for OSX using the Erlang Solutions installer
if [ -d "$SYSTEM_HOME_BIN/../lib/erlang" ]; then
ROOTDIR=$SYSTEM_HOME_BIN/../lib/erlang
else
ROOTDIR=$SYSTEM_HOME_BIN/..
fi
ERTS_PATH=$ROOTDIR/erts-$ERTS_VSN/bin
unset SYSTEM_ERL_PATH
unset SYSTEM_HOME_BIN

LOCAL_ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG"
unset LOCAL_ERL_PATH

# Setup additional arguments for slim release
SLIM_ARGS="-boot_var RELTOOL_EXT_LIB $RUNNER_BASE_DIR/lib -sasl releases_dir \"$RUNNER_BASE_DIR/releases\""
else
echo "Unknown runner_script.data"
exit 1
fi

# Setup remote shell command to control node
REMSH="$ERTS_PATH/erl $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG"

# Check the first argument for instructions
case "$1" in
start|start_boot)
# Make sure there is not already a node running
RES=`$NODETOOL ping`
if [ "$RES" = "pong" ]; then
echo "Node is already running!"
exit 1
fi
case "$1" in
start)
shift
START_OPTION="console"
HEART_OPTION="start"
;;
start_boot)
shift
START_OPTION="console_boot"
HEART_OPTION="start_boot"
;;
esac
RUN_PARAM=$(printf "\'%s\' " "$@")
HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT $HEART_OPTION $RUN_PARAM"
export HEART_COMMAND
mkdir -p $PIPE_DIR
$ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT $START_OPTION $RUN_PARAM" 2>&1
;;

stop)
# Wait for the node to completely stop...
case `uname -s` in
Linux|Darwin|FreeBSD|DragonFly|NetBSD|OpenBSD)
# PID COMMAND
PID=`ps ax -o pid= -o command=|\
grep "\-boot $RUNNER_BASE_DIR/[r]eleases"|awk '{print $1}'`
;;
SunOS)
# PID COMMAND
PID=`ps -ef -o pid= -o args=|\
grep "\-boot $RUNNER_BASE_DIR/[r]eleases"|awk '{print $1}'`
;;
CYGWIN*)
# UID PID PPID TTY STIME COMMAND
PID=`ps -efW|grep "\-boot $RUNNER_BASE_DIR/[r]eleases"|awk '{print $2}'`
;;
esac
$NODETOOL stop
ES=$?
if [ "$ES" -ne 0 ]; then
exit $ES
fi
while `kill -0 $PID 2>/dev/null`;
do
sleep 1
done
;;

restart)
## Restart the VM without exiting the process
$NODETOOL restart
ES=$?
if [ "$ES" -ne 0 ]; then
exit $ES
fi
;;

reboot)
## Restart the VM completely (uses heart to restart it)
$NODETOOL reboot
ES=$?
if [ "$ES" -ne 0 ]; then
exit $ES
fi
;;

ping)
## See if the VM is alive
$NODETOOL ping
ES=$?
if [ "$ES" -ne 0 ]; then
exit $ES
fi
;;

attach)
# Make sure a node IS running
RES=`$NODETOOL ping`
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi

shift
exec $ERTS_PATH/to_erl $PIPE_DIR
;;

remote_console)
# Make sure a node IS running
RES=`$NODETOOL ping`
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi

shift
exec $REMSH
;;

upgrade)
if [ -z "$2" ]; then
echo "Missing upgrade package argument"
echo "Usage: $SCRIPT upgrade {package base name}"
echo "NOTE {package base name} MUST NOT include the .tar.gz suffix"
exit 1
fi

# Make sure a node IS running
RES=`$NODETOOL ping`
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi

node_name=`echo $NAME_ARG | awk '{print $2}'`
erlang_cookie=`echo $COOKIE_ARG | awk '{print $2}'`

$ERTS_PATH/escript $RUNNER_BASE_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2
;;

console|console_clean|console_boot)
# .boot file typically just $SCRIPT (ie, the app name)
# however, for debugging, sometimes start_clean.boot is useful.
# For e.g. 'setup', one may even want to name another boot script.
case "$1" in
console) BOOTFILE=$SCRIPT ;;
console_clean) BOOTFILE=start_clean ;;
console_boot)
shift
BOOTFILE="$1"
shift
;;
esac
# Setup beam-required vars
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\\///'`

## NITROGEN CHANGE: '-mode interactive' for dynamic code loading
CMD="$BINDIR/erlexec $SLIM_ARGS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode interactive $CONFIG -args_file $VMARGS_PATH"
export EMU
export ROOTDIR
export BINDIR
export PROGNAME

# Dump environment info for logging purposes
echo "Exec: $CMD" -- ${1+"$@"}
echo "Root: $ROOTDIR"

# Log the startup
logger -t "$SCRIPT[$$]" "Starting up"

# Start the VM
exec $CMD -- ${1+"$@"}
;;

foreground)
# start up the release in the foreground for use by runit
# or other supervision services

BOOTFILE=$SCRIPT
FOREGROUNDOPTIONS="-noinput +Bd"

# Setup beam-required vars
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
CMD="$BINDIR/erlexec $SLIM_ARGS $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE $CONFIG -args_file $VMARGS_PATH"
export EMU
export ROOTDIR
export BINDIR
export PROGNAME

# Dump environment info for logging purposes
echo "Exec: $CMD" -- ${1+"$@"}
echo "Root: $ROOTDIR"

# Start the VM
exec $CMD -- ${1+"$@"}
;;
*)
echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade}"
exit 1
;;
esac

exit 0

+ 504
- 0
do-plugins.escript View File

@@ -0,0 +1,504 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%% vim: ts=4 sw=4 et ft=erlang
%%
%% Coyright 2013 - Jesse Gumm
%%
%% MIT License
%%
%% About
%%
%% This little script assists the Nitrogen Web Framework by simplifying the
%% process of including custom elements, actions, or validators without having
%% to worry about including a different header for each, or manually copying
%% records from each element's header into the "records.hrl".
%%
%% Further, this copies the plugin static information (javascript, images, etc)
%% into the site/static/plugins/<pluginname> directory. Then one doesn't need
%% to copy that information for each upgrade.
%%
%% TO MAKE A PLUGIN WORK WITH THIS SCRIPT:
%%
%% 1) Make sure your plugin is able to be used as a rebar dependency
%% 2) Include a file "nitrogen.plugin" in the root of the plugin directory
%% 3) If you have any static resources (js, images) put them in a 'static'
%% directory
%% 4) If this is a custom element, action, or validator, or requires anything
%% else that should be included in a header, add them to (one or more) .hrl
%% files in 'include'
%% 5) From your Nitrogen app's directory, include your plugin as a rebar
%% dependency and run 'make'
%%
%% Sample Plugin Directory Structure:
%%
%% myplugin/
%% ebin/
%%
%% src/
%% element_myplugin.erl
%% myplugin.app.src
%%
%% include/
%% myplugin.hrl
%%
%% priv/
%% templates/
%% mytemplate.html
%%
%% static/
%% js/
%% myplugin.js
%% jquery-some-plugin.js
%% images/
%% some_image.png
%% css/
%% myplugin.css
%%
%%
%% When the plugin is processed, the following will be updated in your Nitrogen App
%%
%% site/
%% include/
%% plugins.hrl (will include a reference to all .hrl files from your plugin)
%% static/
%% plugins/
%% myplugin/
%% js/
%% myplugin.js
%% jquery-some-plugin.js
%% images/
%% some_image.png
%% css/
%% myplugin.css
%% templates/
%% plugins/
%% mytemplate.html
%%
%% (Note: The Erlang/Nitrogen Element code is not copied, it'll be loaded just
%% like any rebar dependency's code)

main([]) ->
io:format("Checking for Nitrogen Plugins\n"),
RebarConfig = get_config("rebar.config"),
PluginConfig = get_config("plugins.config"),
DepDirs = proplists:get_value(deps_dir, RebarConfig, ["lib"]),
{Includes,Statics,Templates} = lists:foldl(fun(Dir, {Inc, Stat, Temp}) ->
{ok, FoundIncludes, FoundStatics, FoundTemplates} = get_plugins(Dir),
{FoundIncludes ++ Inc, FoundStatics ++ Stat, FoundTemplates ++ Temp}
end, {[],[],[]}, DepDirs),
case {Includes, Statics, Templates} of
{[],[],[]} ->
io:format("No Nitrogen Plugins Found~n");
_ ->
io:format("Generating aggregate plugin header (plugins.hrl)~n"),
generate_plugin_include(PluginConfig, Includes),
io:format("Generating plugin static directories~n"),
generate_plugin_static(PluginConfig, Statics),
io:format("Generating plugin template directories~n"),
generate_plugin_templates(PluginConfig, Templates),
io:format("Plugin generation complete~n")
end.


get_plugins(DepDir) ->
Files = case file:list_dir(DepDir) of
{ok, F} -> F;
{error, _} -> []
end,
{Inc,Stat,Temp} = lists:foldl(fun(X,PluginInfo={Includes,Statics,Templates}) ->
PluginPath = filename:join(DepDir,X),
case analyze_path(PluginPath) of
undefined ->
%% Not a plugin, so just continue
PluginInfo;
{ok, FoundIncludes, FoundStatics, FoundTemplates} ->
{FoundIncludes++Includes, FoundStatics++Statics, FoundTemplates++Templates}
end
end,{[],[],[]},Files),
{ok, Inc, Stat, Temp}.
get_config(File) ->
case file:consult(File) of
{error, _} -> [];
{ok, Config} -> Config
end.

analyze_path(Path) ->
case is_dir_or_symlink_dir(Path) of
true ->
{ok, Files} = file:list_dir(Path),
case lists:member("nitrogen.plugin",Files) of
false ->
undefined;
true ->
io:format("Found a Nitrogen plugin in ~p~n",[Path]),
IncludeDir = filename:join(Path,include),
StaticDir = filename:join(Path,static),
PrivStaticDir = filename:join([Path,priv,static]),
TemplateDir = filename:join([Path,priv,templates]),

Includes = analyze_path_include(IncludeDir),
%% Originally, the plugin spec called for statics to be
%% located in the "static" dir, however, it's more
%% OTP-compliant to have statics to be located in
%% "priv/static", so we support both here with StaticDir
%% and PrivStaticDir
Statics = analyze_path_exists_only(StaticDir)
++ analyze_path_exists_only(PrivStaticDir),

Templates = analyze_path_exists_only(TemplateDir),
{ok, Includes, Statics, Templates}
end;
false -> undefined
end.

is_dir_or_symlink_dir(Path) ->
case filelib:is_dir(Path) of
true -> true;
false ->
case file:read_link(Path) of
{ok, _} -> true;
{error, _} -> false
end
end.

analyze_path_include(Path) ->
case filelib:is_dir(Path) of
false -> [];
true -> list_includes(Path)
end.
list_includes(Path) ->
{ok, Files} = file:list_dir(Path),
Includes = filter_non_includes(Files),
[filename:join(Path,Inc) || Inc <- Includes].

filter_non_includes([]) -> [];
filter_non_includes([File | Files]) ->
case re:run(File,"\.hrl$",[{capture,none}]) of
match -> [File | filter_non_includes(Files)];
nomatch -> filter_non_includes(Files)
end.

analyze_path_exists_only(Path) ->
case filelib:is_dir(Path) of
false -> [];
true -> [Path]
end.

generate_plugin_include(Config, Includes) ->
IncludeFile = proplists:get_value(plugins_hrl, Config, "site/include/plugins.hrl"),
HeaderLines = ["%% Automatically Generated by do-plugins.escript",
"%% Manually editing this file is not recommended."],
PluginLines = [includify(I) || I <- Includes],
PluginContents = string:join(HeaderLines ++ PluginLines,"\n"),
FinalContents = iolist_to_binary(PluginContents),
CurrentContents = get_current_include(IncludeFile),
case FinalContents == CurrentContents of
true -> io:format("No changes to ~p~n",[IncludeFile]);
false -> file:write_file(IncludeFile,PluginContents)
end.

get_current_include(File) ->
case file:read_file(File) of
{ok, Binary} -> Binary;
{error, _} -> <<>>
end.

includify("lib/" ++ Path) ->
"-include_lib(\"" ++ Path ++ "\").";
includify(Path) ->
"-include(\"" ++ filename:join("..",Path) ++ "\").".

generate_plugin_static(Config, Statics) ->
PluginStaticBase = proplists:get_value(static_dir, Config, "site/static/plugins"),
CopyMode = proplists:get_value(copy_mode, Config, copy),
clear_plugin_dir(PluginStaticBase),
filelib:ensure_dir(filename:join(PluginStaticBase,dummy)),
[generate_plugin_copy_worker(PluginStaticBase,CopyMode,Static) || Static <- Statics].

clear_plugin_dir(Dir) ->
rm_rf(Dir).

plugin_name_from_static_path(PluginStatic) ->
PluginStaticParts = filename:split(PluginStatic),
case lists:reverse(PluginStaticParts) of
["templates","priv",PluginName|_] -> PluginName;
["templates",PluginName|_] -> PluginName;
["static","priv",PluginName|_] -> PluginName;
["static",PluginName|_] -> PluginName
end.

generate_plugin_copy_worker(PluginBase, CopyMode, PluginStatic) ->
%% Split the Plugin Static Dir into parts and extract the name of the plugin
%% ie "lib/whatever/static" - the Plugin Name is "whatever"
PluginName = plugin_name_from_static_path(PluginStatic),
%% And we're going to copy it into our system's plugin static dir
%% (ie "site/static/plugins/whatever")
FinalDestination = filename:join(PluginBase,PluginName),

%% And let's copy or link them.
case CopyMode of
link ->
LinkPrefix = make_link_relative_prefix(FinalDestination),
file:make_symlink(filename:join([LinkPrefix,PluginStatic]),FinalDestination);
copy ->
%% We want to copy the contents of the Plugin's static dir,
%% So we're copying from /lib/whatever/static/*
PluginSource = filename:join(PluginStatic,"*"),

%% Make sure the dir exists to copy into
filelib:ensure_dir(filename:join(FinalDestination,dummy)),

%% And copy the directory
try cp_r([PluginSource],FinalDestination)
catch _:_ -> ok %% getting here usually just means that the source directory is empty
end;
Other ->
throw({invalid_copy_mode, Other})
end.

generate_plugin_templates(Config, Templates) ->
TemplateBase = proplists:get_value(template_dir, Config, "site/templates/plugins"),
CopyMode = proplists:get_value(copy_mode, Config, copy),
clear_plugin_dir(TemplateBase),
filelib:ensure_dir(filename:join(TemplateBase,dummy)),
[generate_plugin_copy_worker(TemplateBase, CopyMode, Template) || Template <- Templates].

%% Because the symlink is relative, we need to make sure it includes the
%% proper relative path prefix (ie, the right number of "../../../" to get us
%% back before linking
make_link_relative_prefix("./" ++ Path) ->
make_link_relative_prefix(Path);
make_link_relative_prefix(Path) ->
Parts = filename:split(Path),
Parts2 = lists:sublist(Parts, length(Parts)-1),
Parts3 = [relative_path_helper(Part) || Part <- Parts2],
filename:join(Parts3).

relative_path_helper(".") -> ".";
relative_path_helper("..") -> "";
relative_path_helper(_) -> "..".

%% -------------------------------------------------------------------------
%% ------------- File Actions (copied mostly from Rebar) -------------------
%% -------------------------------------------------------------------------


-define(CONSOLE(Str, Args), io:format(Str,Args)).
-define(FMT(Str,Args), lists:flatten(io_lib:format(Str,Args))).

rm_rf(Target) ->
case os:type() of
{unix, _} ->
EscTarget = escape_spaces(Target),
{ok, []} = sh(?FMT("rm -rf ~s", [EscTarget]),
[{use_stdout, false}, return_on_error]),
ok;
{win32, _} ->
Filelist = filelib:wildcard(Target),
Dirs = [F || F <- Filelist, filelib:is_dir(F)],
Files = Filelist -- Dirs,
ok = delete_each(Files),
ok = delete_each_dir_win32(Dirs),
ok
end.

delete_each([]) ->
ok;
delete_each([File | Rest]) ->
case file:delete(File) of
ok ->
delete_each(Rest);
{error, enoent} ->
delete_each(Rest);
{error, Reason} ->
ExitMsg = ?FMT("Error: Failed to delete file ~s: ~p\n", [File, Reason]),
exit(ExitMsg)
end.

delete_each_dir_win32([]) -> ok;
delete_each_dir_win32([Dir | Rest]) ->
{ok, []} = sh(?FMT("rd /q /s \"~s\"",
[filename:nativename(Dir)]),
[{use_stdout, false}, return_on_error]),
delete_each_dir_win32(Rest).



cp_r(Sources, Dest) ->
case os:type() of
{unix, _} ->
EscSources = [escape_spaces(Src) || Src <- Sources],
SourceStr = string:join(EscSources, " "),
{ok, []} = sh(?FMT("cp -R ~s \"~s\"",
[SourceStr, Dest]),
[{use_stdout, false}, return_on_error]),
ok;
{win32, _} ->
lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources),
ok
end.

%% Windows stuff
xcopy_win32(Source,Dest)->
{ok, R} = sh(
?FMT("xcopy \"~s\" \"~s\" /q /y /e 2> nul",
[filename:nativename(Source), filename:nativename(Dest)]),
[{use_stdout, false}, return_on_error]),
case length(R) > 0 of
%% when xcopy fails, stdout is empty and and error message is printed
%% to stderr (which is redirected to nul)
true -> ok;
false ->
{error, lists:flatten(
io_lib:format("Failed to xcopy from ~s to ~s~n",
[Source, Dest]))}
end.

cp_r_win32({true, SourceDir}, {true, DestDir}) ->
%% from directory to directory
SourceBase = filename:basename(SourceDir),
ok = case file:make_dir(filename:join(DestDir, SourceBase)) of
{error, eexist} -> ok;
Other -> Other
end,
ok = xcopy_win32(SourceDir, filename:join(DestDir, SourceBase));
cp_r_win32({false, Source} = S,{true, DestDir}) ->
%% from file to directory
cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))});
cp_r_win32({false, Source},{false, Dest}) ->
%% from file to file
{ok,_} = file:copy(Source, Dest),
ok;
cp_r_win32({true, SourceDir},{false,DestDir}) ->
IsFile = filelib:is_file(DestDir),
case IsFile of
true ->
%% From Directory to file? This shouldn't happen
{error,[{rebar_file_utils,cp_r_win32},
{directory_to_file_makes_no_sense,
{source,SourceDir},{dest,DestDir}}]};
false ->
%% Specifying a target directory that doesn't currently exist.
%% So Let's attempt to create this directory
%% Will not recursively create parent directories
ok = case file:make_dir(DestDir) of
{error, eexist} -> ok;
Other -> Other
end,
ok = xcopy_win32(SourceDir, DestDir)
end;
cp_r_win32(Source,Dest) ->
Dst = {filelib:is_dir(Dest), Dest},
lists:foreach(fun(Src) ->
ok = cp_r_win32({filelib:is_dir(Src), Src}, Dst)
end, filelib:wildcard(Source)),
ok.

%% Shell Command Stuff (from rebar_utils)
sh(Command0, Options0) ->
% ?CONSOLE("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [get_cwd(), Command0]),
% ?DEBUG("\topts: ~p\n", [Options0]),

DefaultOptions = [use_stdout, abort_on_error],
Options = [expand_sh_flag(V)
|| V <- proplists:compact(Options0 ++ DefaultOptions)],

ErrorHandler = proplists:get_value(error_handler, Options),
OutputHandler = proplists:get_value(output_handler, Options),

Command = patch_on_windows(Command0, proplists:get_value(env, Options, [])),
PortSettings = proplists:get_all_values(port_settings, Options) ++
[exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide],
Port = open_port({spawn, Command}, PortSettings),

case sh_loop(Port, OutputHandler, []) of
{ok, _Output} = Ok ->
Ok;
{error, {_Rc, _Output}=Err} ->
ErrorHandler(Command, Err)
end.

%%get_cwd() ->
%% {ok,Dir} = file:get_cwd(),
%% Dir.

patch_on_windows(Cmd, Env) ->
case os:type() of
{win32,nt} ->
"cmd /q /c "
++ lists:foldl(fun({Key, Value}, Acc) ->
expand_env_variable(Acc, Key, Value)
end, Cmd, Env);
_ ->
Cmd
end.

expand_env_variable(InStr, VarName, RawVarValue) ->
case string:chr(InStr, $$) of
0 ->
%% No variables to expand
InStr;
_ ->
VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", [global]),
%% Use a regex to match/replace:
%% Given variable "FOO": match $FOO\s | $FOOeol | ${FOO}
RegEx = io_lib:format("\\\$(~s(\\s|$)|{~s})", [VarName, VarName]),
ReOpts = [global, {return, list}],
re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
end.

sh_loop(Port, Fun, Acc) ->
receive
{Port, {data, {eol, Line}}} ->
sh_loop(Port, Fun, Fun(Line ++ "\n", Acc));
{Port, {data, {noeol, Line}}} ->
sh_loop(Port, Fun, Fun(Line, Acc));
{Port, {exit_status, 0}} ->
{ok, lists:flatten(lists:reverse(Acc))};
{Port, {exit_status, Rc}} ->
{error, {Rc, lists:flatten(lists:reverse(Acc))}}
end.

escape_spaces(Str) ->
re:replace(Str, " ", "\\\\ ", [global, {return, list}]).


log_and_abort(Message) ->
?CONSOLE("Aborting: ~s ~n",[Message]).


expand_sh_flag(return_on_error) ->
{error_handler,
fun(_Command, Err) ->
{error, Err}
end};
expand_sh_flag({abort_on_error, Message}) ->
{error_handler,
fun(Cmd,Err) ->
log_and_abort({Message,{Cmd,Err}})
end};
expand_sh_flag(abort_on_error) ->
expand_sh_flag({abort_on_error, error});
expand_sh_flag(use_stdout) ->
{output_handler,
fun(Line, Acc) ->
?CONSOLE("~s", [Line]),
[Line | Acc]
end};
expand_sh_flag({use_stdout, false}) ->
{output_handler,
fun(Line, Acc) ->
[Line | Acc]
end};
expand_sh_flag({cd, _CdArg} = Cd) ->
{port_settings, Cd};
expand_sh_flag({env, _EnvArg} = Env) ->
{port_settings, Env}.



+ 43
- 0
docker/Dockerfile View File

@@ -0,0 +1,43 @@
# This Dockerfile creates a gentoo stage3 container image. By default it
# creates a stage3-amd64 image. It utilizes a multi-stage build and requires
# docker-17.05.0 or later. It fetches a daily snapshot from the official
# sources and verifies its checksum as well as its gpg signature.

#create calculate conteiner

ARG BOOTSTRAP
FROM --platform=$BUILDPLATFORM ${BOOTSTRAP:-alpine:3.11} as builder

WORKDIR /gentoo

ARG ARCH=x86_64
ARG MICROARCH=amd64
ARG SUFFIX
ARG ROOTFS=rootfs.tar.xz 11-Mar-2021 10:34 212M

#ARG DIST="https://ftp-osl.osuosl.org/pub/gentoo/releases/${ARCH}/autobuilds"
ARG DIST="https://mirror.yandex.ru/calculate/container/"
ARG SIGNING_KEY="0xBB572E0E2D182910"

RUN echo "Building Gentoo Container image for ${ARCH} ${SUFFIX} fetching from ${DIST}" \
&& apk --no-cache add ca-certificates gnupg tar wget xz \
&& STAGE3PATH="$(wget -O- "${DIST}/latest-stage3-${MICROARCH}${SUFFIX}.txt" | tail -n 1 | cut -f 1 -d ' ')" \
&& echo "STAGE3PATH:" $STAGE3PATH \
&& STAGE3="$(basename ${STAGE3PATH})" \
&& wget -q "${DIST}/${STAGE3PATH}" "${DIST}/${STAGE3PATH}.CONTENTS.gz" "${DIST}/${STAGE3PATH}.DIGESTS.asc" \
&& gpg --list-keys \
&& echo "honor-http-proxy" >> ~/.gnupg/dirmngr.conf \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& gpg --keyserver hkps://keys.gentoo.org --recv-keys ${SIGNING_KEY} \
&& gpg --verify "${STAGE3}.DIGESTS.asc" \
&& awk '/# SHA512 HASH/{getline; print}' ${STAGE3}.DIGESTS.asc | sha512sum -c \
&& tar xpf "${STAGE3}" --xattrs-include='*.*' --numeric-owner \
&& ( sed -i -e 's/#rc_sys=""/rc_sys="docker"/g' etc/rc.conf 2>/dev/null || true ) \
&& echo 'UTC' > etc/timezone \
&& rm ${STAGE3}.DIGESTS.asc ${STAGE3}.CONTENTS.gz ${STAGE3}

FROM scratch

WORKDIR /
COPY --from=builder /gentoo/ /
CMD ["/bin/bash"]

BIN
erts-11.1.5/bin/beam.smp View File


BIN
erts-11.1.5/bin/ct_run View File


BIN
erts-11.1.5/bin/dialyzer View File


BIN
erts-11.1.5/bin/epmd View File


+ 34
- 0
erts-11.1.5/bin/erl View File

@@ -0,0 +1,34 @@
#!/bin/sh

## This script replaces the default "erl" in erts-VSN/bin. This is necessary
## as escript depends on erl and in turn, erl depends on having access to a
## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect
## of running escript -- the embedded node bypasses erl and uses erlexec directly
## (as it should).
##
## Note that this script makes the assumption that there is a start_clean.boot
## file available in $ROOTDIR/release/VSN.

# Determine the abspath of where this script is executing from.
ERTS_BIN_DIR=$(cd ${0%/*} && pwd)

# Now determine the root directory -- this script runs from erts-VSN/bin,
# so we simply need to strip off two dirs from the end of the ERTS_BIN_DIR
# path.
ROOTDIR=${ERTS_BIN_DIR%/*/*}

# Parse out release and erts info
START_ERL=`cat $ROOTDIR/releases/start_erl.data`
ERTS_VSN=${START_ERL% *}
APP_VSN=${START_ERL#* }

BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\\///'`
CMD="$BINDIR/erlexec"
export EMU
export ROOTDIR
export BINDIR
export PROGNAME

exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}

BIN
erts-11.1.5/bin/erl_call View File


BIN
erts-11.1.5/bin/erl_child_setup View File


BIN
erts-11.1.5/bin/erlc View File


BIN
erts-11.1.5/bin/erlexec View File


BIN
erts-11.1.5/bin/escript View File


BIN
erts-11.1.5/bin/heart View File


BIN
erts-11.1.5/bin/inet_gethost View File


+ 182
- 0
erts-11.1.5/bin/nodetool View File

@@ -0,0 +1,182 @@
#!/usr/bin/env escript
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% -------------------------------------------------------------------
%%
%% nodetool: Helper Script for interacting with live nodes
%%
%% -------------------------------------------------------------------
main(Args) ->
ok = start_epmd(),
%% Extract the args
{RestArgs, TargetNode} = process_args(Args, [], undefined),

%% any commands that don't need a running node
case RestArgs of
["chkconfig", File] ->
case file:consult(File) of
{ok, _} ->
io:format("ok\n"),
halt(0);
{error, {Line, Mod, Term}} ->
io:format(standard_error, ["Error on line ",
file:format_error({Line, Mod, Term}), "\n"], []),
halt(1);
{error, R} ->
io:format(standard_error, ["Error reading config file: ",
file:format_error(R), "\n"], []),
halt(1)
end;
_ ->
ok
end,

%% See if the node is currently running -- if it's not, we'll bail
case {net_kernel:hidden_connect_node(TargetNode),
net_adm:ping(TargetNode)} of
{true, pong} ->
ok;
{false,pong} ->
io:format("Failed to connect to node ~p .\n", [TargetNode]),
halt(1);
{_, pang} ->
io:format("Node ~p not responding to pings.\n", [TargetNode]),
halt(1)
end,

case RestArgs of
["getpid"] ->
io:format("~p\n",
[list_to_integer(rpc:call(TargetNode, os, getpid, []))]);
["ping"] ->
%% If we got this far, the node already responsed to a
%% ping, so just dump a "pong"
io:format("pong\n");
["stop"] ->
io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]);
["restart"] ->
io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]);
["reboot"] ->
io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]);
["rpc", Module, Function | RpcArgs] ->
case rpc:call(TargetNode,
list_to_atom(Module),
list_to_atom(Function),
[RpcArgs], 60000) of
ok ->
ok;
{badrpc, Reason} ->
io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
halt(1);
_ ->
halt(1)
end;
["rpc_infinity", Module, Function | RpcArgs] ->
case rpc:call(TargetNode,
list_to_atom(Module),
list_to_atom(Function),
[RpcArgs], infinity) of
ok ->
ok;
{badrpc, Reason} ->
io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
halt(1);
_ ->
halt(1)
end;
["rpcterms", Module, Function, ArgsAsString] ->
case rpc:call(TargetNode,
list_to_atom(Module),
list_to_atom(Function),
consult(ArgsAsString), 60000) of
{badrpc, Reason} ->
io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
halt(1);
Other ->
io:format("~p\n", [Other])
end;
Other ->
io:format("Other: ~p\n", [Other]),
io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms}\n")
end,
net_kernel:stop().

process_args([], Acc, TargetNode) ->
{lists:reverse(Acc), TargetNode};
process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) ->
erlang:set_cookie(node(), list_to_atom(Cookie)),
process_args(Rest, Acc, TargetNode);
process_args(["-name", TargetName | Rest], Acc, _) ->
ThisNode = append_node_suffix(TargetName, "_maint_"),
{ok, _} = net_kernel:start([ThisNode, longnames]),
process_args(Rest, Acc, nodename(TargetName));
process_args(["-sname", TargetName | Rest], Acc, _) ->
ThisNode = append_node_suffix(TargetName, "_maint_"),
{ok, _} = net_kernel:start([ThisNode, shortnames]),
process_args(Rest, Acc, nodename(TargetName));
process_args([Arg | Rest], Acc, Opts) ->
process_args(Rest, [Arg | Acc], Opts).


start_epmd() ->
[] = os:cmd(epmd_path() ++ " -daemon"),
ok.

epmd_path() ->
ErtsBinDir = filename:dirname(escript:script_name()),
Name = "epmd",
case os:find_executable(Name, ErtsBinDir) of
false ->
case os:find_executable(Name) of
false ->
io:format("Could not find epmd.~n"),
halt(1);
GlobalEpmd ->
GlobalEpmd
end;
Epmd ->
Epmd
end.


nodename(Name) ->
case string:tokens(Name, "@") of
[_Node, _Host] ->
list_to_atom(Name);
[Node] ->
[_, Host] = string:tokens(atom_to_list(node()), "@"),
list_to_atom(lists:concat([Node, "@", Host]))
end.

append_node_suffix(Name, Suffix) ->
case string:tokens(Name, "@") of
[Node, Host] ->
list_to_atom(lists:concat([Node, Suffix, os:getpid(), "@", Host]));
[Node] ->
list_to_atom(lists:concat([Node, Suffix, os:getpid()]))
end.


%%
%% Given a string or binary, parse it into a list of terms, ala file:consult/0
%%
consult(Str) when is_list(Str) ->
consult([], Str, []);
consult(Bin) when is_binary(Bin)->
consult([], binary_to_list(Bin), []).

consult(Cont, Str, Acc) ->
case erl_scan:tokens(Cont, Str, 0) of
{done, Result, Remaining} ->
case Result of
{ok, Tokens, _} ->
{ok, Term} = erl_parse:parse_term(Tokens),
consult([], Remaining, [Term | Acc]);
{eof, _Other} ->
lists:reverse(Acc);
{error, Info, _} ->
{error, Info}
end;
{more, Cont1} ->
consult(Cont1, eof, Acc)
end.

BIN
erts-11.1.5/bin/run_erl View File


+ 37
- 0
erts-11.1.5/bin/start View File

@@ -0,0 +1,37 @@
#!/bin/sh
#
# %CopyrightBegin%
#
# Copyright Ericsson AB 1996-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%
#
# This program invokes the erlang emulator by calling run_erl.
# It should only be used at an embedded target system.
# It should be modified to give the correct flags to erl (via start_erl),
# e.g -mode embedded -sname XXX
#
# Usage: start [Data]
#
ROOTDIR=/usr/lib64/erlang

if [ -z "$RELDIR" ]
then
RELDIR=$ROOTDIR/releases
fi

START_ERL_DATA=${1:-$RELDIR/start_erl.data}

$ROOTDIR/bin/run_erl -daemon /tmp/ $ROOTDIR/log "exec $ROOTDIR/bin/start_erl $ROOTDIR $RELDIR $START_ERL_DATA"

BIN
erts-11.1.5/bin/to_erl View File


BIN
erts-11.1.5/bin/typer View File


BIN
erts-11.1.5/bin/yielding_c_fun View File


+ 42
- 0
erts-11.1.5/include/driver_int.h View File

@@ -0,0 +1,42 @@
/*
* %CopyrightBegin%
*
* Copyright Ericsson AB 1997-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%
*/
/*
* System dependant driver declarations
*/

#ifndef __DRIVER_INT_H__
#define __DRIVER_INT_H__

#ifdef HAVE_SYS_UIO_H
#include <sys/types.h>
#include <sys/uio.h>

typedef struct iovec SysIOVec;

#else

typedef struct {
char* iov_base;
int iov_len;
} SysIOVec;

#endif

#endif

+ 636
- 0
erts-11.1.5/include/erl_driver.h View File

@@ -0,0 +1,636 @@
/*
* %CopyrightBegin%
*
* Copyright Ericsson AB 1999-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%
*/

/*
* Include file for erlang driver writers.
*/

#ifndef __ERL_DRIVER_H__
#define __ERL_DRIVER_H__

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#define ERL_DRV_DEPRECATED_FUNC
#ifdef __GNUC__
# if __GNUC__ >= 3
# undef ERL_DRV_DEPRECATED_FUNC
# define ERL_DRV_DEPRECATED_FUNC __attribute__((deprecated))
# endif
#endif

#include "erl_drv_nif.h"

#include <stdlib.h>

#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_)
#ifndef STATIC_ERLANG_DRIVER
/* Windows dynamic drivers, everything is different... */
#define ERL_DRIVER_TYPES_ONLY
#define WIN32_DYNAMIC_ERL_DRIVER
#endif
#endif

#ifndef EXTERN
# ifdef __cplusplus
# define EXTERN extern "C"
# else
# define EXTERN extern
# endif
#endif

#define ERL_DRV_READ ((int)ERL_NIF_SELECT_READ)
#define ERL_DRV_WRITE ((int)ERL_NIF_SELECT_WRITE)
#define ERL_DRV_USE ((int)ERL_NIF_SELECT_STOP)
#define ERL_DRV_USE_NO_CALLBACK (ERL_DRV_USE | (ERL_DRV_USE << 1))

/* Old deprecated */
#define DO_READ ERL_DRV_READ
#define DO_WRITE ERL_DRV_WRITE

#define ERL_DRV_EXTENDED_MARKER (0xfeeeeeed)
#define ERL_DRV_EXTENDED_MAJOR_VERSION 3
#define ERL_DRV_EXTENDED_MINOR_VERSION 3

/*
* The emulator will refuse to load a driver with a major version
* lower than ERL_DRV_MIN_REQUIRED_MAJOR_VERSION_ON_LOAD. The load
* may however fail if user have not removed use of deprecated
* symbols.
*
* The ERL_DRV_MIN_REQUIRED_MAJOR_VERSION_ON_LOAD have to allow
* loading of drivers built at least two major OTP releases
* ago.
*
* Bump of major version to 3 happened in OTP 17. That is, in
* OTP 19 we can increase ERL_DRV_MIN_REQUIRED_MAJOR_VERSION_ON_LOAD
* to 3.
*/
#define ERL_DRV_MIN_REQUIRED_MAJOR_VERSION_ON_LOAD 2

/*
* The emulator will refuse to load a driver with different major
* version than the one used by the emulator.
*/


/* Values for set_port_control_flags() */

#define PORT_CONTROL_FLAG_BINARY (1 << 0)
#define PORT_CONTROL_FLAG_HEAVY (1 << 1)

/* Values for get_port_flags() */

#define PORT_FLAG_BINARY (1 << 0)
#define PORT_FLAG_LINE (1 << 1)


#define ERL_DRV_FLAG_USE_PORT_LOCKING (1 << 0)
#define ERL_DRV_FLAG_SOFT_BUSY (1 << 1)
#define ERL_DRV_FLAG_NO_BUSY_MSGQ (1 << 2)
#define ERL_DRV_FLAG_USE_INIT_ACK (1 << 3)

/*
* Integer types
*/

typedef ErlNapiUInt64 ErlDrvUInt64;
typedef ErlNapiSInt64 ErlDrvSInt64;
typedef ErlNapiUInt ErlDrvUInt;
typedef ErlNapiSInt ErlDrvSInt;
typedef ErlNapiUInt ErlDrvTermData;

#if defined(__WIN32__) || defined(_WIN32)
typedef ErlDrvUInt ErlDrvSizeT;
typedef ErlDrvSInt ErlDrvSSizeT;
#else
typedef size_t ErlDrvSizeT;
typedef ssize_t ErlDrvSSizeT;
#endif

/*
* A binary as seen in a driver. Note that a binary should never be
* altered by the driver when it has been sent to Erlang.
*/

typedef struct erl_drv_binary {
ErlDrvSInt orig_size; /* total length of binary */
char orig_bytes[1]; /* the data (char instead of byte!) */
} ErlDrvBinary;


/*
* Note: These types are incomplete to catch type errors easier.
*/

typedef struct _erl_drv_data* ErlDrvData; /* Data to be used by the driver itself. */
#ifndef ERL_SYS_DRV
typedef struct _erl_drv_event* ErlDrvEvent; /* An event to be selected on. */
#endif
typedef struct _erl_drv_port* ErlDrvPort; /* A port descriptor. */
typedef struct _erl_drv_port* ErlDrvThreadData; /* Thread data. */

typedef struct {
unsigned long megasecs;
unsigned long secs;
unsigned long microsecs;
} ErlDrvNowData;

typedef ErlDrvSInt64 ErlDrvTime;

#define ERL_DRV_TIME_ERROR ((ErlDrvSInt64) ERTS_NAPI_TIME_ERROR__)

typedef enum {
ERL_DRV_SEC = ERTS_NAPI_SEC__,
ERL_DRV_MSEC = ERTS_NAPI_MSEC__,
ERL_DRV_USEC = ERTS_NAPI_USEC__,
ERL_DRV_NSEC = ERTS_NAPI_NSEC__
} ErlDrvTimeUnit;

/*
* Error codes that can be return from driver.
*/

/*
* Exception code from open_port/2 will be {'EXIT',{einval,Where}}.
*/
#define ERL_DRV_ERROR_GENERAL ((ErlDrvData) -1)

/*
* Exception code from open_port/2 will be {'EXIT',{Errno,Where}},
* where Errno is a textual representation of the errno variable
* (e.g. eacces if errno is EACCES).
*/
#define ERL_DRV_ERROR_ERRNO ((ErlDrvData) -2)

/*
* Exception code from open_port/2 will be {'EXIT',{badarg,Where}}.
*/
#define ERL_DRV_ERROR_BADARG ((ErlDrvData) -3)

typedef struct erl_io_vec {
int vsize; /* length of vectors */
ErlDrvSizeT size; /* total size in bytes */
SysIOVec* iov;
ErlDrvBinary** binv;
} ErlIOVec;

/*
* erl driver thread types
*/

typedef struct ErlDrvTid_ *ErlDrvTid;
typedef struct ErlDrvMutex_ ErlDrvMutex;
typedef struct ErlDrvCond_ ErlDrvCond;
typedef struct ErlDrvRWLock_ ErlDrvRWLock;
typedef int ErlDrvTSDKey;

/*
*
*/
typedef struct erl_drv_port_data_lock * ErlDrvPDL;

/*
* This structure defines a driver.
*/

typedef struct erl_drv_entry {
int (*init)(void); /* called at system start up for statically
linked drivers, and after loading for
dynamically loaded drivers */

#ifndef ERL_SYS_DRV
ErlDrvData (*start)(ErlDrvPort port, char *command);
/* called when open_port/2 is invoked.
return value -1 means failure. */
#else
ErlDrvData (*start)(ErlDrvPort port, char *command, SysDriverOpts* opts);
/* special options, only for system driver */
#endif
void (*stop)(ErlDrvData drv_data);
/* called when port is closed, and when the
emulator is halted. */
void (*output)(ErlDrvData drv_data, char *buf, ErlDrvSizeT len);
/* called when we have output from erlang to
the port */
void (*ready_input)(ErlDrvData drv_data, ErlDrvEvent event);
/* called when we have input from one of
the driver's handles */
void (*ready_output)(ErlDrvData drv_data, ErlDrvEvent event);
/* called when output is possible to one of
the driver's handles */
char *driver_name; /* name supplied as command
in open_port XXX ? */
void (*finish)(void); /* called before unloading the driver -
DYNAMIC DRIVERS ONLY */
void *handle; /* Reserved -- Used by emulator internally */
ErlDrvSSizeT (*control)(ErlDrvData drv_data, unsigned int command,
char *buf, ErlDrvSizeT len, char **rbuf,
ErlDrvSizeT rlen); /* "ioctl" for drivers - invoked by
port_control/3 */
void (*timeout)(ErlDrvData drv_data); /* Handling of timeout in driver */
void (*outputv)(ErlDrvData drv_data, ErlIOVec *ev);
/* called when we have output from erlang
to the port */
void (*ready_async)(ErlDrvData drv_data, ErlDrvThreadData thread_data);
void (*flush)(ErlDrvData drv_data);
/* called when the port is about to be
closed, and there is data in the
driver queue that needs to be flushed
before 'stop' can be called */
ErlDrvSSizeT (*call)(ErlDrvData drv_data,
unsigned int command, char *buf, ErlDrvSizeT len,
char **rbuf, ErlDrvSizeT rlen,
unsigned int *flags); /* Works mostly like 'control',
a synchronous
call into the driver. */
void (*unused_event_callback)(void);
int extended_marker; /* ERL_DRV_EXTENDED_MARKER */
int major_version; /* ERL_DRV_EXTENDED_MAJOR_VERSION */
int minor_version; /* ERL_DRV_EXTENDED_MINOR_VERSION */
int driver_flags; /* ERL_DRV_FLAGs */
void *handle2; /* Reserved -- Used by emulator internally */
void (*process_exit)(ErlDrvData drv_data, ErlDrvMonitor *monitor);
/* Called when a process monitor fires */
void (*stop_select)(ErlDrvEvent event, void* reserved);
/* Called on behalf of driver_select when
it is safe to release 'event'. A typical
unix driver would call close(event) */
void (*emergency_close)(ErlDrvData drv_data);
/* called when the port is closed abruptly.
specifically when erl_crash_dump is called. */
/* When adding entries here, dont forget to pad in obsolete/driver.h */
} ErlDrvEntry;

/*
* This macro is used to name a dynamic driver's init function in
* a way that doesn't lead to conflicts. This is crucial when using
* operating systems that has one namespace for all symbols
* (e.g. VxWorks). Example: if you have an dynamic driver C source
* file named echo_drv.c, you use the macro like this:
*
* DRIVER_INIT(echo_drv)
* {
* ....
* }
*
* This function will be called by the Erlang I/O system when the driver is loaded.
* It must initialize a ErlDrvEntry structure and return a pointer to it.
*/

#ifdef STATIC_ERLANG_DRIVER
# define ERLANG_DRIVER_NAME(NAME) NAME ## _driver_init
# define ERL_DRIVER_EXPORT
#else
# define ERLANG_DRIVER_NAME(NAME) driver_init
# if defined(__GNUC__) && __GNUC__ >= 4
# define ERL_DRIVER_EXPORT __attribute__ ((visibility("default")))
# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550)
# define ERL_DRIVER_EXPORT __global
# else
# define ERL_DRIVER_EXPORT
# endif
#endif

#ifndef ERL_DRIVER_TYPES_ONLY

#define DRIVER_INIT(DRIVER_NAME) \
ERL_DRIVER_EXPORT ErlDrvEntry* ERLANG_DRIVER_NAME(DRIVER_NAME)(void); \
ERL_DRIVER_EXPORT ErlDrvEntry* ERLANG_DRIVER_NAME(DRIVER_NAME)(void)

#define ERL_DRV_BUSY_MSGQ_DISABLED (~((ErlDrvSizeT) 0))
#define ERL_DRV_BUSY_MSGQ_READ_ONLY ((ErlDrvSizeT) 0)
#define ERL_DRV_BUSY_MSGQ_LIM_MAX (ERL_DRV_BUSY_MSGQ_DISABLED - 1)
#define ERL_DRV_BUSY_MSGQ_LIM_MIN ((ErlDrvSizeT) 1)

/*
* These are the functions available for driver writers.
*/
EXTERN void erl_drv_busy_msgq_limits(ErlDrvPort port,
ErlDrvSizeT *low,
ErlDrvSizeT *high);

EXTERN int driver_select(ErlDrvPort port, ErlDrvEvent event, int mode, int on);

EXTERN int driver_output(ErlDrvPort port, char *buf, ErlDrvSizeT len);
EXTERN int driver_output2(ErlDrvPort port, char *hbuf, ErlDrvSizeT hlen,
char *buf, ErlDrvSizeT len);
EXTERN int driver_output_binary(ErlDrvPort port, char *hbuf, ErlDrvSizeT hlen,
ErlDrvBinary* bin,
ErlDrvSizeT offset, ErlDrvSizeT len);
EXTERN int driver_outputv(ErlDrvPort port, char* hbuf, ErlDrvSizeT hlen,
ErlIOVec *ev, ErlDrvSizeT skip);
EXTERN ErlDrvSizeT driver_vec_to_buf(ErlIOVec *ev, char *buf, ErlDrvSizeT len);
EXTERN int driver_set_timer(ErlDrvPort port, unsigned long time);
EXTERN int driver_cancel_timer(ErlDrvPort port);
EXTERN int driver_read_timer(ErlDrvPort port, unsigned long *time_left);

/*
* Inform runtime system about lengthy work.
*/
EXTERN int erl_drv_consume_timeslice(ErlDrvPort port, int percent);

/*
* Get plain-text error message from within a driver
*/
EXTERN char* erl_errno_id(int error);

/*
* The following functions are used to initiate a close of a port
* from a driver.
*/
EXTERN int driver_failure_eof(ErlDrvPort port);
EXTERN int driver_failure_atom(ErlDrvPort port, char *string);
EXTERN int driver_failure_posix(ErlDrvPort port, int error);
EXTERN int driver_failure(ErlDrvPort port, int error);
EXTERN int driver_exit (ErlDrvPort port, int err);


/*
* Port Data Lock
*/

EXTERN ErlDrvPDL driver_pdl_create(ErlDrvPort);
EXTERN void driver_pdl_lock(ErlDrvPDL);
EXTERN void driver_pdl_unlock(ErlDrvPDL);
EXTERN ErlDrvSInt driver_pdl_get_refc(ErlDrvPDL);
EXTERN ErlDrvSInt driver_pdl_inc_refc(ErlDrvPDL);
EXTERN ErlDrvSInt driver_pdl_dec_refc(ErlDrvPDL);

/*
* Process monitors
*/
EXTERN int
driver_monitor_process(ErlDrvPort port, ErlDrvTermData process,
ErlDrvMonitor *monitor);
EXTERN int
driver_demonitor_process(ErlDrvPort port, const ErlDrvMonitor *monitor);
EXTERN ErlDrvTermData
driver_get_monitored_process(ErlDrvPort port, const ErlDrvMonitor *monitor);
EXTERN int driver_compare_monitors(const ErlDrvMonitor *monitor1,
const ErlDrvMonitor *monitor2);

/*
* Port attributes
*/
EXTERN void set_busy_port(ErlDrvPort port, int on);
EXTERN void set_port_control_flags(ErlDrvPort port, int flags);

EXTERN int get_port_flags(ErlDrvPort port);


/* Binary interface */

/*
* NOTE: DO NOT overwrite a binary with new data (if the data is delivered);
* since the binary is a shared object it MUST be written once.
*/

EXTERN ErlDrvBinary* driver_alloc_binary(ErlDrvSizeT size);
EXTERN ErlDrvBinary* driver_realloc_binary(ErlDrvBinary *bin, ErlDrvSizeT size);
EXTERN void driver_free_binary(ErlDrvBinary *bin);

/* Referenc count on driver binaries */
EXTERN ErlDrvSInt driver_binary_get_refc(ErlDrvBinary *dbp);
EXTERN ErlDrvSInt driver_binary_inc_refc(ErlDrvBinary *dbp);
EXTERN ErlDrvSInt driver_binary_dec_refc(ErlDrvBinary *dbp);

/* Allocation interface */
EXTERN void *driver_alloc(ErlDrvSizeT size);
EXTERN void *driver_realloc(void *ptr, ErlDrvSizeT size);
EXTERN void driver_free(void *ptr);

/* Queue interface */
EXTERN int driver_enq(ErlDrvPort port, char* buf, ErlDrvSizeT len);
EXTERN int driver_pushq(ErlDrvPort port, char* buf, ErlDrvSizeT len);
EXTERN ErlDrvSizeT driver_deq(ErlDrvPort port, ErlDrvSizeT size);
EXTERN ErlDrvSizeT driver_sizeq(ErlDrvPort port);
EXTERN int driver_enq_bin(ErlDrvPort port, ErlDrvBinary *bin, ErlDrvSizeT offset,
ErlDrvSizeT len);
EXTERN int driver_pushq_bin(ErlDrvPort port, ErlDrvBinary *bin, ErlDrvSizeT offset,
ErlDrvSizeT len);

EXTERN ErlDrvSizeT driver_peekqv(ErlDrvPort port, ErlIOVec *ev);
EXTERN SysIOVec* driver_peekq(ErlDrvPort port, int *vlen);
EXTERN int driver_enqv(ErlDrvPort port, ErlIOVec *ev, ErlDrvSizeT skip);
EXTERN int driver_pushqv(ErlDrvPort port, ErlIOVec *ev, ErlDrvSizeT skip);

/*
* Add and remove driver entries.
*/
EXTERN void add_driver_entry(ErlDrvEntry *de);
EXTERN int remove_driver_entry(ErlDrvEntry *de);

/*
* System info
*/
EXTERN void driver_system_info(ErlDrvSysInfo *sip, size_t si_size);

/*
* erl driver thread functions.
*/

EXTERN ErlDrvMutex *erl_drv_mutex_create(char *name);
EXTERN void erl_drv_mutex_destroy(ErlDrvMutex *mtx);
EXTERN int erl_drv_mutex_trylock(ErlDrvMutex *mtx);
EXTERN void erl_drv_mutex_lock(ErlDrvMutex *mtx);
EXTERN void erl_drv_mutex_unlock(ErlDrvMutex *mtx);
EXTERN ErlDrvCond *erl_drv_cond_create(char *name);
EXTERN void erl_drv_cond_destroy(ErlDrvCond *cnd);
EXTERN void erl_drv_cond_signal(ErlDrvCond *cnd);
EXTERN void erl_drv_cond_broadcast(ErlDrvCond *cnd);
EXTERN void erl_drv_cond_wait(ErlDrvCond *cnd, ErlDrvMutex *mtx);
EXTERN ErlDrvRWLock *erl_drv_rwlock_create(char *name);
EXTERN void erl_drv_rwlock_destroy(ErlDrvRWLock *rwlck);
EXTERN int erl_drv_rwlock_tryrlock(ErlDrvRWLock *rwlck);
EXTERN void erl_drv_rwlock_rlock(ErlDrvRWLock *rwlck);
EXTERN void erl_drv_rwlock_runlock(ErlDrvRWLock *rwlck);
EXTERN int erl_drv_rwlock_tryrwlock(ErlDrvRWLock *rwlck);
EXTERN void erl_drv_rwlock_rwlock(ErlDrvRWLock *rwlck);
EXTERN void erl_drv_rwlock_rwunlock(ErlDrvRWLock *rwlck);
EXTERN int erl_drv_tsd_key_create(char *name, ErlDrvTSDKey *key);
EXTERN void erl_drv_tsd_key_destroy(ErlDrvTSDKey key);
EXTERN void erl_drv_tsd_set(ErlDrvTSDKey key, void *data);
EXTERN void *erl_drv_tsd_get(ErlDrvTSDKey key);
EXTERN ErlDrvThreadOpts *erl_drv_thread_opts_create(char *name);
EXTERN void erl_drv_thread_opts_destroy(ErlDrvThreadOpts *opts);
EXTERN int erl_drv_thread_create(char *name,
ErlDrvTid *tid,
void * (*func)(void *),
void *args,
ErlDrvThreadOpts *opts);
EXTERN ErlDrvTid erl_drv_thread_self(void);
EXTERN int erl_drv_equal_tids(ErlDrvTid tid1, ErlDrvTid tid2);
EXTERN void erl_drv_thread_exit(void *resp);
EXTERN int erl_drv_thread_join(ErlDrvTid, void **respp);

EXTERN char* erl_drv_mutex_name(ErlDrvMutex *mtx);
EXTERN char* erl_drv_cond_name(ErlDrvCond *cnd);
EXTERN char* erl_drv_rwlock_name(ErlDrvRWLock *rwlck);
EXTERN char* erl_drv_thread_name(ErlDrvTid tid);

/*
* Misc.
*/
EXTERN int null_func(void);

#endif /* !ERL_DRIVER_TYPES_ONLY */

/* Constants for return flags from the 'port_call' callback */
#define DRIVER_CALL_KEEP_BUFFER 0x1

/* ErlDrvTerm is the type to use for casts when building
* terms that should be sent to connected process,
* for instance a tuple on the form {tcp, Port, [Tag|Binary]}
*
* ErlDrvTerm spec[] = {
* ERL_DRV_ATOM, driver_mk_atom("tcp"),
* ERL_DRV_PORT, driver_mk_port(drv->ix),
* ERL_DRV_INT, REPLY_TAG,
* ERL_DRV_BINARY, (ErlDrvTerm)bin, 50, 0,
* ERL_DRV_LIST, 2,
* ERL_DRV_TUPLE, 3,
* }
*
*/

#define TERM_DATA(x) ((ErlDrvTermData) (x))

/* Possible types to send from driver Argument type */
#define ERL_DRV_NIL ((ErlDrvTermData) 1) /* None */
#define ERL_DRV_ATOM ((ErlDrvTermData) 2) /* driver_mk_atom(string) */
#define ERL_DRV_INT ((ErlDrvTermData) 3) /* ErlDrvSInt */
#define ERL_DRV_PORT ((ErlDrvTermData) 4) /* driver_mk_port(ix) */
#define ERL_DRV_BINARY ((ErlDrvTermData) 5) /* ErlDrvBinary*,
* ErlDrvUInt size,
* ErlDrvUInt offs */
#define ERL_DRV_STRING ((ErlDrvTermData) 6) /* char*, ErlDrvUInt */
#define ERL_DRV_TUPLE ((ErlDrvTermData) 7) /* ErlDrvUInt */
#define ERL_DRV_LIST ((ErlDrvTermData) 8) /* ErlDrvUInt */
#define ERL_DRV_STRING_CONS ((ErlDrvTermData) 9) /* char*, ErlDrvUInt */
#define ERL_DRV_PID ((ErlDrvTermData) 10) /* driver_connected,... */

#define ERL_DRV_FLOAT ((ErlDrvTermData) 11) /* double * */
#define ERL_DRV_EXT2TERM ((ErlDrvTermData) 12) /* char *, ErlDrvUInt */
#define ERL_DRV_UINT ((ErlDrvTermData) 13) /* ErlDrvUInt */
#define ERL_DRV_BUF2BINARY ((ErlDrvTermData) 14) /* char *, ErlDrvUInt */
#define ERL_DRV_INT64 ((ErlDrvTermData) 15) /* ErlDrvSInt64 * */
#define ERL_DRV_UINT64 ((ErlDrvTermData) 16) /* ErlDrvUInt64 * */

#define ERL_DRV_MAP ((ErlDrvTermData) 17) /* ErlDrvUInt */

#ifndef ERL_DRIVER_TYPES_ONLY

/* make terms for driver_output_term and driver_send_term */
EXTERN ErlDrvTermData driver_mk_atom(char*);
EXTERN ErlDrvTermData driver_mk_port(ErlDrvPort);
EXTERN ErlDrvTermData driver_connected(ErlDrvPort);
EXTERN ErlDrvTermData driver_caller(ErlDrvPort);
extern const ErlDrvTermData driver_term_nil;
EXTERN ErlDrvTermData driver_mk_term_nil(void);
EXTERN ErlDrvPort driver_create_port(ErlDrvPort creator_port,
ErlDrvTermData connected, /* pid */
char* name, /* driver name */
ErlDrvData drv_data);

/*
* driver_output_term() is deprecated, and scheduled for removal in
* OTP-R17. Use erl_drv_output_term() instead. For more information
* see the erl_driver(3) documentation.
*/
EXTERN int driver_output_term(ErlDrvPort ix,
ErlDrvTermData* data,
int len) ERL_DRV_DEPRECATED_FUNC;
/*
* driver_send_term() is deprecated, and scheduled for removal in
* OTP-R17. Use erl_drv_send_term() instead. For more information
* see the erl_driver(3) documentation.
*/
EXTERN int driver_send_term(ErlDrvPort ix,
ErlDrvTermData to,
ErlDrvTermData* data,
int len) ERL_DRV_DEPRECATED_FUNC;

/* output term data to the port owner */
EXTERN int erl_drv_output_term(ErlDrvTermData port,
ErlDrvTermData* data,
int len);
/* output term data to a specific process */
EXTERN int erl_drv_send_term(ErlDrvTermData port,
ErlDrvTermData to,
ErlDrvTermData* data,
int len);

/* Async IO functions */
EXTERN unsigned int driver_async_port_key(ErlDrvPort port);

EXTERN long driver_async(ErlDrvPort ix,
unsigned int* key,
void (*async_invoke)(void*),
void* async_data,
void (*async_free)(void*));

/* Locks the driver in the machine "forever", there is
no unlock function. Note that this is almost never useful, as an open
port towards the driver locks it until the port is closed, why unexpected
unloading "never" happens. */
EXTERN int driver_lock_driver(ErlDrvPort ix);

/* Get the current 'now' timestamp (analogue to erlang:now()) */
EXTERN int driver_get_now(ErlDrvNowData *now) ERL_DRV_DEPRECATED_FUNC;

/* Erlang Monotonic Time */
EXTERN ErlDrvTime erl_drv_monotonic_time(ErlDrvTimeUnit time_unit);
/* Time offset between Erlang Monotonic Time and Erlang System Time */
EXTERN ErlDrvTime erl_drv_time_offset(ErlDrvTimeUnit time_unit);
/* Time unit conversion */
EXTERN ErlDrvTime erl_drv_convert_time_unit(ErlDrvTime val,
ErlDrvTimeUnit from,
ErlDrvTimeUnit to);

/* These were removed from the ANSI version, now they're back. */

EXTERN void *driver_dl_open(char *);
EXTERN void *driver_dl_sym(void *, char *);
EXTERN int driver_dl_close(void *);
EXTERN char *driver_dl_error(void);

/* environment */
EXTERN int erl_drv_putenv(const char *key, char *value);
EXTERN int erl_drv_getenv(const char *key, char *value, size_t *value_size);

/* spawn start init ack */
EXTERN void erl_drv_init_ack(ErlDrvPort ix, ErlDrvData res);

/* set the pid seen in port_info */
EXTERN void erl_drv_set_os_pid(ErlDrvPort ix, ErlDrvSInt pid);

#endif /* !ERL_DRIVER_TYPES_ONLY */

#ifdef WIN32_DYNAMIC_ERL_DRIVER
# include "erl_win_dyn_driver.h"
#endif

#endif

/* also in global.h, but driver's can't include global.h */
void dtrace_drvport_str(ErlDrvPort port, char *port_buf);

+ 170
- 0
erts-11.1.5/include/erl_drv_nif.h View File

@@ -0,0 +1,170 @@
/*
* %CopyrightBegin%
*
* Copyright Ericsson AB 2010-2020. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");