From 228e70bb5fe44ead9cd389c83421a59e7a4eaad8 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 17 Aug 2012 09:04:00 +0200 Subject: [PATCH] Native version of lighttpd The port of lighttpd at 'ports/src/app/lighttpd' executes the web server directly (w/o using Noux). It is accompanied by the lighttpd.run script. At the current stage, lighttpd is starting up but fails because of an unsupport fcntl call. --- ports/ports/lighttpd.inc | 8 +- ports/ports/lighttpd.mk | 1 + ports/run/lighttpd.run | 133 ++++++++++++++++++ .../disable_gethostbyaddr_fcntl.patch | 75 ++++++++++ ports/src/app/lighttpd/plugin-static.h | 4 + ports/src/app/lighttpd/target.inc | 25 ++++ ports/src/app/lighttpd/target.mk | 5 + 7 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 ports/run/lighttpd.run create mode 100644 ports/src/app/lighttpd/disable_gethostbyaddr_fcntl.patch create mode 100644 ports/src/app/lighttpd/plugin-static.h create mode 100644 ports/src/app/lighttpd/target.inc create mode 100644 ports/src/app/lighttpd/target.mk diff --git a/ports/ports/lighttpd.inc b/ports/ports/lighttpd.inc index 2e33ec5dc..615a1810a 100644 --- a/ports/ports/lighttpd.inc +++ b/ports/ports/lighttpd.inc @@ -1,2 +1,6 @@ -LIGHTTPD_VERSION = 1.4.31 -LIGHTTPD = lighttpd-$(LIGHTTPD_VERSION) +LIGHTTPD_MAIN := 1 +LIGHTTPD_MAJOR := 4 +LIGHTTPD_MINOR := 31 +LIGHTTPD_VERSION := $(LIGHTTPD_MAIN).$(LIGHTTPD_MAJOR).$(LIGHTTPD_MINOR) +LIGHTTPD := lighttpd-$(LIGHTTPD_VERSION) + diff --git a/ports/ports/lighttpd.mk b/ports/ports/lighttpd.mk index 60e8b8479..09bd4a1f6 100644 --- a/ports/ports/lighttpd.mk +++ b/ports/ports/lighttpd.mk @@ -18,3 +18,4 @@ $(DOWNLOAD_DIR)/$(LIGHTTPD_TGZ): $(CONTRIB_DIR)/$(LIGHTTPD): $(DOWNLOAD_DIR)/$(LIGHTTPD_TGZ) $(VERBOSE)tar xfz $< -C $(CONTRIB_DIR) && touch $@ + $(VERBOSE)patch -N -p1 < src/app/lighttpd/disable_gethostbyaddr_fcntl.patch diff --git a/ports/run/lighttpd.run b/ports/run/lighttpd.run new file mode 100644 index 000000000..95f685fe1 --- /dev/null +++ b/ports/run/lighttpd.run @@ -0,0 +1,133 @@ +# +# \brief Example for running lighttpd +# \author Norman Feske +# \date 2012-08-16 +# + +set build_components { + core init + drivers/pci + drivers/nic + drivers/timer + server/ram_fs + app/lighttpd +} + +build $build_components + +create_boot_directory + +append config { + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec pci] config { + + + + } + +append config { + + + + + + + + + + + + + +# lighttpd configuration +server.port = 80 +server.document-root = "/website" +server.event-handler = "select" +server.network-backend = "write" +index-file.names = ( + "index.xhtml", "index.html", "index.htm" +) +mimetype.assign = ( + ".html" => "text/html", + ".htm" => "text/html" +) + + + + + + + + Hello + + +

Hello Genode!

+ I am bold ;-) + + +
+
+
+
+
+ + + + + + + + + } + +append config { +
} + +install_config $config + + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init timer ld.lib.so nic_drv ram_fs + libc.lib.so libm.lib.so libc_fs.lib.so libc_log.lib.so + lwip.lib.so zlib.lib.so libcrypto.lib.so libssl.lib.so + lighttpd +} + +# platform-specific modules +lappend_if [have_spec pci] boot_modules pci_drv + +build_boot_image $boot_modules + +append_if [have_spec x86] qemu_args " -net nic,model=e1000 " +append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " + +append qemu_args " -net user -redir tcp:5555::80 " +append qemu_args " -nographic -serial mon:stdio " + +run_genode_until forever diff --git a/ports/src/app/lighttpd/disable_gethostbyaddr_fcntl.patch b/ports/src/app/lighttpd/disable_gethostbyaddr_fcntl.patch new file mode 100644 index 000000000..ec1cb1f4c --- /dev/null +++ b/ports/src/app/lighttpd/disable_gethostbyaddr_fcntl.patch @@ -0,0 +1,75 @@ +--- a/contrib/lighttpd-1.4.31/src/fdevent_poll.c.orig ++++ b/contrib/lighttpd-1.4.31/src/fdevent_poll.c +@@ -193,7 +193,7 @@ int fdevent_poll_init(fdevents *ev) { + int fdevent_poll_init(fdevents *ev) { + UNUSED(ev); + +- log_error_write(srv, __FILE__, __LINE__, ++ log_error_write(ev->srv, __FILE__, __LINE__, + "s", "poll is not supported, try to set server.event-handler = \"select\""); + + return -1; +--- a/contrib/lighttpd-1.4.31/src/http-header-glue.c.orig ++++ b/contrib/lighttpd-1.4.31/src/http-header-glue.c +@@ -175,6 +175,7 @@ int http_response_redirect_to_directory(server *srv, connection *con) { + break; + #endif + case AF_INET: ++#if 0 + if (NULL == (he = gethostbyaddr((char *)&our_addr.ipv4.sin_addr, sizeof(struct in_addr), AF_INET))) { + log_error_write(srv, __FILE__, __LINE__, + "SdS", "NOTICE: gethostbyaddr failed: ", +@@ -184,6 +185,8 @@ int http_response_redirect_to_directory(server *srv, connection *con) { + } else { + buffer_append_string(o, he->h_name); + } ++#endif ++ buffer_append_string(o, inet_ntoa(our_addr.ipv4.sin_addr)); + break; + default: + log_error_write(srv, __FILE__, __LINE__, +--- a/contrib/lighttpd-1.4.31/src/network.c.orig ++++ b/contrib/lighttpd-1.4.31/src/network.c +@@ -301,6 +301,7 @@ static int network_server_init(server *srv, buffer *host_token, specific_config + if (host == NULL) { + srv_socket->addr.ipv4.sin_addr.s_addr = htonl(INADDR_ANY); + } else { ++#if 0 + struct hostent *he; + if (NULL == (he = gethostbyname(host))) { + log_error_write(srv, __FILE__, __LINE__, +@@ -320,6 +321,7 @@ static int network_server_init(server *srv, buffer *host_token, specific_config + } + + memcpy(&(srv_socket->addr.ipv4.sin_addr.s_addr), he->h_addr_list[0], he->h_length); ++#endif + } + srv_socket->addr.ipv4.sin_port = htons(port); + +--- a/contrib/lighttpd-1.4.31/src/fdevent.c.orig ++++ b/contrib/lighttpd-1.4.31/src/fdevent.c +@@ -198,16 +198,23 @@ void * fdevent_get_context(fdevents *ev, int fd) { + } + + int fdevent_fcntl_set(fdevents *ev, int fd) { ++#if 0 + #ifdef FD_CLOEXEC + /* close fd on exec (cgi) */ + fcntl(fd, F_SETFD, FD_CLOEXEC); + #endif +- if ((ev) && (ev->fcntl_set)) return ev->fcntl_set(ev, fd); ++ if ((ev) && (ev->fcntl_set)){ ++ fprintf(stderr, "call ev->fcntl_set(ev, %d)\n", fd); ++ return ev->fcntl_set(ev, fd); ++ } + #ifdef O_NONBLOCK ++ fprintf(stderr, "call fcntl(ev, %d)\n", fd); + return fcntl(fd, F_SETFL, O_NONBLOCK | O_RDWR); + #else + return 0; + #endif ++#endif ++ return 0; + } + + diff --git a/ports/src/app/lighttpd/plugin-static.h b/ports/src/app/lighttpd/plugin-static.h new file mode 100644 index 000000000..6eb196623 --- /dev/null +++ b/ports/src/app/lighttpd/plugin-static.h @@ -0,0 +1,4 @@ +PLUGIN_INIT(mod_indexfile) +PLUGIN_INIT(mod_dirlisting) +PLUGIN_INIT(mod_staticfile) +PLUGIN_INIT(mod_access) diff --git a/ports/src/app/lighttpd/target.inc b/ports/src/app/lighttpd/target.inc new file mode 100644 index 000000000..5d423cc9b --- /dev/null +++ b/ports/src/app/lighttpd/target.inc @@ -0,0 +1,25 @@ +include $(REP_DIR)/ports/lighttpd.inc +LIGHTTPD_DIR = $(REP_DIR)/contrib/$(LIGHTTPD) + +FILTER_OUT = lempar.c lighttpd-angel.c lemon.c +SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIGHTTPD_DIR)/src/*.c))) + +vpath %.c $(LIGHTTPD_DIR)/src + +CC_OPT += -DHAVE_SOCKLEN_T -DHAVE_SYSLOG_H -DHAVE_STDINT_H -DUSE_POLL +CC_OPT += -DHAVE_SYS_WAIT_H -DHAVE_SYS_UN_H -DHAVE_MMAP -DHAVE_SELECT +CC_OPT += -DHAVE_WRITEV -DUSE_WRITEV +CC_OPT += -DSBIN_DIR="\"/sbin\"" +CC_OPT += -DPACKAGE_NAME="\"lighttpd\"" +CC_OPT += -DLIGHTTPD_VERSION_ID='($(LIGHTTPD_MAIN) << 16 | $(LIGHTTPD_MAJOR) << 8 | $(LIGHTTPD_MINOR))' +CC_OPT += -DPACKAGE_VERSION="\"$(LIGHTTPD_MAIN).$(LIGHTTPD_MAJOR).$(LIGHTTPD_MINOR)\"" +CC_OPT += -DLIBRARY_DIR="\"/lib\"" +CC_OPT += -DLIGHTTPD_STATIC + +CC_WARN = -Wall -Wno-unused-variable -Wno-unused-function + +INC_DIR += $(PRG_DIR) +INC_DIR += $(LIGHTTPD_DIR)/src + +LIBS += cxx env libc libm +LIBS += libcrypto libssl zlib config_args diff --git a/ports/src/app/lighttpd/target.mk b/ports/src/app/lighttpd/target.mk new file mode 100644 index 000000000..7542df2f8 --- /dev/null +++ b/ports/src/app/lighttpd/target.mk @@ -0,0 +1,5 @@ +TARGET = lighttpd + +include $(REP_DIR)/src/app/lighttpd/target.inc + +LIBS += cxx env libc libm libc_log libc_fs libc_lwip_nic_dhcp