summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-04-12 15:53:29 +0100
committerAndrew Clayton <a.clayton@nginx.com>2024-11-15 00:52:38 +0000
commit6c085cfaf4f2244af72d1f98517e2908129120c5 (patch)
treeafce4fb966b10986ba1b5817bc2c1bf69a5ace66
parenta35517901fb3c7d524739fc4fcf9e531d6404487 (diff)
downloadunit-skel_lm.tar.gz
unit-skel_lm.tar.bz2
Add a skeleton language module.skel_lm
Module is called 'skel'. Configure with $ ./configure skel Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--auto/help3
-rw-r--r--auto/modules/conf4
-rw-r--r--auto/modules/skel100
-rw-r--r--src/nxt_application.c3
-rw-r--r--src/nxt_application.h7
-rw-r--r--src/nxt_conf_validation.c12
-rw-r--r--src/nxt_main_process.c11
-rw-r--r--src/nxt_router.c1
-rw-r--r--src/skel/nxt_skel.c77
9 files changed, 218 insertions, 0 deletions
diff --git a/auto/help b/auto/help
index 94854762..2707d4d2 100644
--- a/auto/help
+++ b/auto/help
@@ -88,4 +88,7 @@ cat << END
run "./configure wasm-wasi-component --help" to see
available options
+ skel OPTIONS configure SKEL module
+ run "./configure skel --help" to see available options
+
END
diff --git a/auto/modules/conf b/auto/modules/conf
index ab4ed351..0909af34 100644
--- a/auto/modules/conf
+++ b/auto/modules/conf
@@ -41,6 +41,10 @@ case "$nxt_module" in
. auto/modules/wasm-wasi-component
;;
+ skel)
+ . auto/modules/skel
+ ;;
+
*)
echo
echo $0: error: invalid module \"$nxt_module\".
diff --git a/auto/modules/skel b/auto/modules/skel
new file mode 100644
index 00000000..386b61fa
--- /dev/null
+++ b/auto/modules/skel
@@ -0,0 +1,100 @@
+# Copyright (C) NGINX, Inc.
+
+
+shift
+
+if [ ! -f $NXT_AUTOCONF_DATA ]; then
+ echo
+ echo Please run common $0 before configuring module \"$nxt_module\".
+ echo
+ exit 1
+fi
+
+. $NXT_AUTOCONF_DATA
+
+$echo "configuring SKEL module"
+$echo "configuring SKEL module ..." >> $NXT_AUTOCONF_ERR
+
+NXT_SKEL=skel
+NXT_SKEL_MODULE=${NXT_SKEL_MODULE=${NXT_SKEL##*/}}
+
+NXT_SKEL_LDFLAGS=
+NXT_SKEL_ADDITIONAL_FLAGS=
+
+if grep ^$NXT_SKEL_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
+ $echo
+ $echo $0: error: duplicate \"$NXT_SKEL_MODULE\" module configured.
+ $echo
+ exit 1;
+fi
+
+$echo " + SKEL module: ${NXT_SKEL_MODULE}.unit.so"
+
+. auto/cc/deps
+
+$echo >> $NXT_MAKEFILE
+
+NXT_SKEL_MODULE_SRCS=" \
+ src/skel/nxt_skel.c \
+"
+
+# The skel module object files.
+
+nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
+
+for nxt_src in $NXT_SKEL_MODULE_SRCS; do
+
+ nxt_obj=${nxt_src%.c}-$NXT_SKEL_MODULE.o
+ nxt_dep=${nxt_src%.c}-$NXT_SKEL_MODULE.dep
+ nxt_dep_flags=`nxt_gen_dep_flags`
+ nxt_dep_post=`nxt_gen_dep_post`
+ nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
+
+ cat << END >> $NXT_MAKEFILE
+
+$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
+ \$(v)mkdir -p $NXT_BUILD_DIR/src/skel
+ \$(PP_CC) \$@
+ \$(v)\$(CC) -c \$(CFLAGS) $NXT_SKEL_ADDITIONAL_FLAGS \$(NXT_INCS) \\
+ $nxt_dep_flags \\
+ -o $NXT_BUILD_DIR/$nxt_obj $nxt_src
+ $nxt_dep_post
+
+-include $NXT_BUILD_DIR/$nxt_dep
+
+END
+
+done
+
+
+cat << END >> $NXT_MAKEFILE
+
+.PHONY: ${NXT_SKEL_MODULE}
+.PHONY: ${NXT_SKEL_MODULE}-install
+.PHONY: ${NXT_SKEL_MODULE}-uninstall
+
+all: ${NXT_SKEL_MODULE}
+
+${NXT_SKEL_MODULE}: $NXT_BUILD_DIR/lib/unit/modules/${NXT_SKEL_MODULE}.unit.so
+
+$NXT_BUILD_DIR/lib/unit/modules/${NXT_SKEL_MODULE}.unit.so: $nxt_objs
+ \$(PP_LD) \$@
+ \$(v)\$(NXT_MODULE_LINK) -o \$@ \\
+ $nxt_objs ${NXT_SKEL_LDFLAGS} $NXT_LD_OPT
+
+
+install: ${NXT_SKEL_MODULE}-install
+
+${NXT_SKEL_MODULE}-install: ${NXT_SKEL_MODULE} install-check
+ install -d \$(DESTDIR)$NXT_MODULESDIR
+ install -p $NXT_BUILD_DIR/lib/unit/modules/${NXT_SKEL_MODULE}.unit.so \\
+ \$(DESTDIR)$NXT_MODULESDIR/
+
+
+uninstall: ${NXT_SKEL_MODULE}-uninstall
+
+${NXT_SKEL_MODULE}-uninstall:
+ rm -f \$(DESTDIR)$NXT_MODULESDIR/${NXT_SKEL_MODULE}.unit.so
+ @rmdir -p \$(DESTDIR)$NXT_MODULESDIR 2>/dev/null || true
+
+END
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 629aa11c..3c423033 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -1114,6 +1114,9 @@ nxt_app_parse_type(u_char *p, size_t length)
} else if (nxt_str_eq(&str, "wasm", 4)) {
return NXT_APP_WASM;
+
+ } else if (nxt_str_eq(&str, "skel", 4)) {
+ return NXT_APP_SKEL;
}
return NXT_APP_UNKNOWN;
diff --git a/src/nxt_application.h b/src/nxt_application.h
index a3b4230a..3668697a 100644
--- a/src/nxt_application.h
+++ b/src/nxt_application.h
@@ -23,6 +23,7 @@ typedef enum {
NXT_APP_JAVA,
NXT_APP_WASM,
NXT_APP_WASM_WC,
+ NXT_APP_SKEL,
NXT_APP_UNKNOWN,
} nxt_app_type_t;
@@ -113,6 +114,11 @@ typedef struct {
} nxt_wasm_wc_app_conf_t;
+typedef struct {
+ char *module;
+} nxt_skel_app_conf_t;
+
+
struct nxt_common_app_conf_s {
nxt_str_t name;
nxt_str_t type;
@@ -143,6 +149,7 @@ struct nxt_common_app_conf_s {
nxt_java_app_conf_t java;
nxt_wasm_app_conf_t wasm;
nxt_wasm_wc_app_conf_t wasm_wc;
+ nxt_skel_app_conf_t skel;
} u;
nxt_conf_value_t *self;
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index a0b4992f..6c473055 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -1203,6 +1203,17 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_wasm_access_members[] = {
};
+static nxt_conf_vldt_object_t nxt_conf_vldt_skel_members[] = {
+ {
+ .name = nxt_string("module"),
+ .type = NXT_CONF_VLDT_STRING,
+ .flags = NXT_CONF_VLDT_REQUIRED,
+ },
+
+ NXT_CONF_VLDT_NEXT(nxt_conf_vldt_common_members)
+};
+
+
static nxt_conf_vldt_object_t nxt_conf_vldt_common_members[] = {
{
.name = nxt_string("type"),
@@ -2872,6 +2883,7 @@ nxt_conf_vldt_app(nxt_conf_validation_t *vldt, nxt_str_t *name,
{ nxt_conf_vldt_object, nxt_conf_vldt_java_members },
{ nxt_conf_vldt_object, nxt_conf_vldt_wasm_members },
{ nxt_conf_vldt_object, nxt_conf_vldt_wasm_wc_members },
+ { nxt_conf_vldt_object, nxt_conf_vldt_skel_members },
};
ret = nxt_conf_vldt_type(vldt, name, value, NXT_CONF_VLDT_OBJECT);
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index e942c1a8..97a19aee 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -391,6 +391,16 @@ static nxt_conf_map_t nxt_wasm_wc_app_conf[] = {
};
+static nxt_conf_map_t nxt_skel_app_conf[] = {
+ {
+ nxt_string("module"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, u.skel.module),
+ },
+
+};
+
+
static nxt_conf_app_map_t nxt_app_maps[] = {
{ nxt_nitems(nxt_external_app_conf), nxt_external_app_conf },
{ nxt_nitems(nxt_python_app_conf), nxt_python_app_conf },
@@ -400,6 +410,7 @@ static nxt_conf_app_map_t nxt_app_maps[] = {
{ nxt_nitems(nxt_java_app_conf), nxt_java_app_conf },
{ nxt_nitems(nxt_wasm_app_conf), nxt_wasm_app_conf },
{ nxt_nitems(nxt_wasm_wc_app_conf), nxt_wasm_wc_app_conf },
+ { nxt_nitems(nxt_skel_app_conf), nxt_skel_app_conf },
};
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 44ea823b..41e00513 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -288,6 +288,7 @@ static const nxt_str_t *nxt_app_msg_prefix[] = {
[NXT_APP_JAVA] = &empty_prefix,
[NXT_APP_WASM] = &empty_prefix,
[NXT_APP_WASM_WC] = &empty_prefix,
+ [NXT_APP_SKEL] = &empty_prefix,
};
diff --git a/src/skel/nxt_skel.c b/src/skel/nxt_skel.c
new file mode 100644
index 00000000..52e69eab
--- /dev/null
+++ b/src/skel/nxt_skel.c
@@ -0,0 +1,77 @@
+#include <nxt_main.h>
+#include <nxt_application.h>
+#include <nxt_unit.h>
+#include <nxt_unit_request.h>
+
+
+#define SKEL_VERSION "1.0"
+
+
+static uint32_t compat[] = {
+ NXT_VERNUM, NXT_DEBUG,
+};
+
+static nxt_unit_ctx_t *nxt_skel_unit_ctx;
+
+
+static void
+nxt_skel_request_handler(nxt_unit_request_info_t *req)
+{
+ printf("%s: \n", __func__);
+}
+
+
+static nxt_int_t
+nxt_skel_setup(nxt_task_t *task, nxt_process_t *process,
+ nxt_common_app_conf_t *conf)
+{
+ printf("%s: \n", __func__);
+
+ return NXT_OK;
+}
+
+
+static nxt_int_t
+nxt_skel_start(nxt_task_t *task, nxt_process_data_t *data)
+{
+ nxt_int_t ret;
+ nxt_unit_ctx_t *unit_ctx;
+ nxt_unit_init_t skel_init;
+ nxt_common_app_conf_t *conf;
+
+ printf("%s: \n", __func__);
+
+ conf = data->app;
+
+ ret = nxt_unit_default_init(task, &skel_init, conf);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ nxt_alert(task, "nxt_unit_default_init() failed");
+ return ret;
+ }
+
+ skel_init.callbacks.request_handler = nxt_skel_request_handler;
+
+ unit_ctx = nxt_unit_init(&skel_init);
+ if (nxt_slow_path(unit_ctx == NULL)) {
+ return NXT_ERROR;
+ }
+
+ nxt_skel_unit_ctx = unit_ctx;
+
+ nxt_unit_run(nxt_skel_unit_ctx);
+ nxt_unit_done(nxt_skel_unit_ctx);
+
+ exit(EXIT_SUCCESS);
+}
+
+
+NXT_EXPORT nxt_app_module_t nxt_app_module = {
+ sizeof(compat),
+ compat,
+ nxt_string("skel"),
+ SKEL_VERSION,
+ NULL,
+ 0,
+ nxt_skel_setup,
+ nxt_skel_start,
+};