From 3e692f3912f8cbb3c446479651f45201313424ad Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 Jun 2015 12:39:57 -0600 Subject: [PATCH] apps/examples/thttpd now uses the Union File System if BINFS is selected for CGI binaris --- examples/thttpd/Kconfig | 1 + examples/thttpd/content/Makefile.binfs | 49 ++++++++++--- examples/thttpd/content/hello/hello.c | 4 -- examples/thttpd/content/index/index.c | 86 ----------------------- examples/thttpd/content/netstat/netstat.c | 4 -- examples/thttpd/content/tasks/tasks.c | 4 -- examples/thttpd/thttpd_main.c | 56 +++++++++++---- examples/unionfs/unionfs_main.c | 2 +- netutils/thttpd/Kconfig | 9 +-- 9 files changed, 88 insertions(+), 127 deletions(-) delete mode 100644 examples/thttpd/content/index/index.c diff --git a/examples/thttpd/Kconfig b/examples/thttpd/Kconfig index 42ec1381f..0cef2e149 100644 --- a/examples/thttpd/Kconfig +++ b/examples/thttpd/Kconfig @@ -6,6 +6,7 @@ config EXAMPLES_THTTPD bool "THTTPD web server example" default n + depends on FS_ROMFS ---help--- Enable the THTTPD web server example diff --git a/examples/thttpd/content/Makefile.binfs b/examples/thttpd/content/Makefile.binfs index 3ba8b4af3..67e09b2c8 100644 --- a/examples/thttpd/content/Makefile.binfs +++ b/examples/thttpd/content/Makefile.binfs @@ -43,8 +43,14 @@ CONFIG_THTTPD_CGI_STACKSIZE ?= 2048 PRIORITY = $(CONFIG_THTTPD_CGI_PRIORITY) STACKSIZE = $(CONFIG_THTTPD_CGI_STACKSIZE) +THTTPD_DIR = $(APPDIR)/examples/thttpd +CONTENT_DIR = $(THTTPD_DIR)/content +ROMFS_DIR = $(CONTENT_DIR)/romfs +ROMFS_IMG = $(CONTENT_DIR)/romfs.img +ROMFS_HDR = $(CONTENT_DIR)/romfs.h + ASRCS = -CSRCS = index.c hello.c netstat.c tasks.c +CSRCS = hello.c netstat.c tasks.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) @@ -68,8 +74,8 @@ else INSTALL_DIR = $(BIN_DIR) endif -ROOTDEPPATH = --dep-path index --dep-path hello --dep-path netstat --dep-path tasks -VPATH = index:hello:netstat:tasks +ROOTDEPPATH = --dep-path hello --dep-path netstat --dep-path tasks +VPATH = hello:netstat:tasks all: .built .PHONY: context headers binaries depend clean @@ -80,16 +86,38 @@ $(AOBJS): %$(OBJEXT): %.S $(COBJS) $(MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -.built: $(OBJS) +# Create the romfs directory + +$(ROMFS_DIR): + @mkdir -p $(ROMFS_DIR) + +# Populate the romfs directory + +$(ROMFS_DIR)/index.html : $(CONTENT_DIR)/index.html + @cp -a $< $@ || { echo "cp of index.html failed"; exit 1; } + +$(ROMFS_DIR)/style.css : $(CONTENT_DIR)/style.css + @cp -a $< $@ || { echo "cp of $< failed"; exit 1; } + +populate: $(ROMFS_DIR) $(ROMFS_DIR)/index.html $(ROMFS_DIR)/style.css + +# Create the romfs.img file from the populated romfs directory + +$(ROMFS_IMG): populate + @genromfs -f $@ -d $(ROMFS_DIR) -V "THTTPDTEST" + +# Create the romfs.h header file from the romfs.img file + +$(ROMFS_HDR) : $(ROMFS_IMG) + @(cd $(CONTENT_DIR); xxd -i romfs.img | sed -e "s/^unsigned/static const unsigned/g" >$@) + +.built: $(ROMFS_HDR) $(OBJS) $(call ARCHIVE, $(BIN), $(OBJS)) @touch .built binaries: .built -headers: - -$(BUILTIN_REGISTRY)$(DELIM)index_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,index.cgi,$(PRIORITY),$(STACKSIZE),index_main) +headers: $(ROMFS_HDR) $(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat: $(DEPCONFIG) Makefile $(call REGISTER,hello,$(PRIORITY),$(STACKSIZE),hello_main) @@ -100,7 +128,7 @@ $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat: $(DEPCONFIG) Makefile $(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat: $(DEPCONFIG) Makefile $(call REGISTER,tasks,$(PRIORITY),$(STACKSIZE),tasks_main) -context: $(BUILTIN_REGISTRY)$(DELIM)index_main.bdat $(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat $(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat +context: $(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat $(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat .depend: Makefile $(SRCS) @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep @@ -109,6 +137,9 @@ context: $(BUILTIN_REGISTRY)$(DELIM)index_main.bdat $(BUILTIN_REGISTRY)$(DELIM)h depend: .depend clean: + $(call DELFILE$(ROMFS_HDR)) + $(call DELFILE, $(ROMFS_IMG)) + @rm -rf $(ROMFS_DIR) $(call DELFILE, .built) $(call CLEAN) diff --git a/examples/thttpd/content/hello/hello.c b/examples/thttpd/content/hello/hello.c index a2b821b94..e46f49c45 100644 --- a/examples/thttpd/content/hello/hello.c +++ b/examples/thttpd/content/hello/hello.c @@ -66,11 +66,7 @@ int main(int argc, char *argv[]) "\r\n" "\r\n" "
\r\n" -#ifdef CONFIG_THTTPD_BINFS - "\r\n" -#else "\r\n" -#endif "\r\n" "\r\n" "\r\n" diff --git a/examples/thttpd/content/index/index.c b/examples/thttpd/content/index/index.c deleted file mode 100644 index c4ff595c9..000000000 --- a/examples/thttpd/content/index/index.c +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - * examples/thttpd/content/index/index.c - * Generates index.cgi file - * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#ifdef CONFIG_THTTPD_BINFS -int index_main(int argc, char *argv[]) -#else -int main(int argc, char *argv[]) -#endif -{ - fprintf(stderr, "index.cgi requested from: %s\n", getenv("REMOTE_ADDR")); - - puts( - "\r\n" - "\r\n" - " \r\n" - " NuttX examples/thttpd\r\n" - " \r\n" - " \r\n" - "\r\n" - "

\r\n" - " These web pages are served by a port of THTTPD\r\n" - " running on top of NuttX.\r\n" - "

\r\n" - "

\r\n" - " Click on the links below to exercise THTTPD's CGI capability under NuttX.\r\n" - " Clicking the links will execute the CGI program from a built-in program\r\n" - " residing in a BINFS file system.\r\n" - "

\r\n" - " \r\n" - "
  • Front page
  • \r\n" - "
  • Say Hello
  • \r\n" - "
  • Tasks
  • \r\n" - "
  • Network status
  • \r\n" - " \r\n" - " \r\n" - "\r\n" - ); - - return 0; -} diff --git a/examples/thttpd/content/netstat/netstat.c b/examples/thttpd/content/netstat/netstat.c index 5131117c5..b07f22c2b 100644 --- a/examples/thttpd/content/netstat/netstat.c +++ b/examples/thttpd/content/netstat/netstat.c @@ -121,11 +121,7 @@ int main(int argc, char *argv[]) "\r\n" "\r\n" "
    \r\n" -#ifdef CONFIG_THTTPD_BINFS - "\r\n" -#else "\r\n" -#endif "\r\n" "\r\n" "\r\n" diff --git a/examples/thttpd/content/tasks/tasks.c b/examples/thttpd/content/tasks/tasks.c index 80143926b..198668519 100644 --- a/examples/thttpd/content/tasks/tasks.c +++ b/examples/thttpd/content/tasks/tasks.c @@ -182,11 +182,7 @@ int main(int argc, char *argv[]) "\r\n" "\r\n" "
    \r\n" -#ifdef CONFIG_THTTPD_BINFS - "\r\n" -#else "\r\n" -#endif "\r\n" "\r\n" "\r\n" diff --git a/examples/thttpd/thttpd_main.c b/examples/thttpd/thttpd_main.c index e3f306704..1434b01c0 100644 --- a/examples/thttpd/thttpd_main.c +++ b/examples/thttpd/thttpd_main.c @@ -65,6 +65,7 @@ #endif #ifdef CONFIG_THTTPD_BINFS +# include # include #endif @@ -72,8 +73,9 @@ # include #endif +#include "content/romfs.h" + #ifdef CONFIG_THTTPD_NXFLAT -# include "content/romfs.h" # include "content/symtab.h" #endif @@ -108,19 +110,23 @@ #endif #ifdef CONFIG_THTTPD_BINFS -# ifndef CONFIG_FS_BINFS +# ifndef CONFIG_BUILTIN # error "You must select CONFIG_BUILTIN=y in your configuration file" # endif # ifndef CONFIG_FS_BINFS # error "You must select CONFIG_FS_BINFS=y in your configuration file" # endif + +# ifndef CONFIG_FS_UNIONFS +# error "CONFIG_FS_UNIONFS=y is required in this configuration" +# endif #endif + /* Ethernet specific configuration */ #ifdef CONFIG_NET_ETHERNET - - /* Otherwise, use the standard Ethernet device name */ + /* Use the standard Ethernet device name */ # define NET_DEVNAME "eth0" @@ -153,7 +159,16 @@ #define SECTORSIZE 512 #define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE) #define ROMFSDEV "/dev/ram0" -#define MOUNTPT CONFIG_THTTPD_PATH + +#ifdef CONFIG_THTTPD_BINFS +# define ROMFS_MOUNTPT "/mnt/tmp1" +# define ROMFS_PREFIX NULL +# define BINFS_MOUNTPT "/mnt/tmp2" +# define BINFS_PREFIX "cgi-bin" +# define UNIONFS_MOUNTPT CONFIG_THTTPD_PATH +#else +# define ROMFS_MOUNTPT CONFIG_THTTPD_PATH +#endif /**************************************************************************** * Private Data @@ -249,6 +264,7 @@ int thttp_main(int argc, char *argv[]) printf("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret); exit(2); } +#endif /* Create a ROM disk for the ROMFS filesystem */ @@ -258,26 +274,29 @@ int thttp_main(int argc, char *argv[]) if (ret < 0) { printf("ERROR: romdisk_register failed: %d\n", ret); +#ifdef CONFIG_THTTPD_NXFLAT nxflat_uninitialize(); +#endif exit(1); } /* Mount the ROMFS file system */ printf("Mounting ROMFS filesystem at target=%s with source=%s\n", - MOUNTPT, ROMFSDEV); + ROMFS_MOUNTPT, ROMFSDEV); - ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL); + ret = mount(ROMFSDEV, ROMFS_MOUNTPT, "romfs", MS_RDONLY, NULL); if (ret < 0) { printf("ERROR: mount(%s,%s,romfs) failed: %d\n", - ROMFSDEV, MOUNTPT, errno); + ROMFSDEV, ROMFS_MOUNTPT, errno); +#ifdef CONFIG_THTTPD_NXFLAT nxflat_uninitialize(); - } #endif + } #ifdef CONFIG_THTTPD_BINFS - /* Initialize the NXFLAT binary loader */ + /* Initialize the BINFS binary loader */ printf("Initializing the Built-In binary loader\n"); @@ -290,12 +309,23 @@ int thttp_main(int argc, char *argv[]) /* Mount the BINFS file system */ - printf("Mounting BINFS filesystem at target=%s\n", MOUNTPT); + printf("Mounting BINFS filesystem at %s\n", BINFS_MOUNTPT); - ret = mount(NULL, MOUNTPT, "binfs", MS_RDONLY, NULL); + ret = mount(NULL, BINFS_MOUNTPT, "binfs", MS_RDONLY, NULL); if (ret < 0) { - printf("ERROR: mount(NULL,%s,binfs) failed: %d\n", MOUNTPT, errno); + printf("ERROR: mount(NULL,%s,binfs) failed: %d\n", BINFS_MOUNTPT, errno); + } + + /* Now create and mount the union file system */ + + printf("Creating UNIONFS filesystem at %s\n", UNIONFS_MOUNTPT); + + ret = unionfs_mount(ROMFS_MOUNTPT, ROMFS_PREFIX, BINFS_MOUNTPT, BINFS_PREFIX, + UNIONFS_MOUNTPT); + if (ret < 0) + { + printf("ERROR: Failed to create the union file system at %s: %d\n", UNIONFS_MOUNTPT, ret); } #endif diff --git a/examples/unionfs/unionfs_main.c b/examples/unionfs/unionfs_main.c index 59bd442eb..c05879acf 100644 --- a/examples/unionfs/unionfs_main.c +++ b/examples/unionfs/unionfs_main.c @@ -192,7 +192,7 @@ int unionfs_main(int argc, char *argv[]) CONFIG_EXAMPLES_UNIONFS_MOUNTPT); if (ret < 0) { - printf("ERROR: Failed to crate the union file system 1: %d\n", ret); + printf("ERROR: Failed to create the union file system: %d\n", ret); return EXIT_FAILURE; } diff --git a/netutils/thttpd/Kconfig b/netutils/thttpd/Kconfig index 42562a460..0b27283b4 100644 --- a/netutils/thttpd/Kconfig +++ b/netutils/thttpd/Kconfig @@ -56,22 +56,19 @@ endchoice config THTTPD_PATH string "Path to the server content" - default "/mnt/www" if NXFLAT - default "/bin" if FS_BINFS + default "/mnt/www" ---help--- Server working directory. Default: "/mnt/www" config THTTPD_CGI_PATH string "Path to CGI content" - default "/mnt/www/cgi-bin" if NXFLAT - default "/bin" if FS_BINFS + default "/mnt/www/cgi-bin" ---help--- Path to CGI executables. Default: "/mnt/www/cgi-bin" config THTTPD_CGI_PATTERN string "CGI match pattern" - default "/mnt/www/cgi-bin/*" if NXFLAT - default "/bin/*" if FS_BINFS + default "/mnt/www/cgi-bin/*" ---help--- Only CGI programs matching this pattern will be executed. In fact, if this value is not defined then no CGI logic will be built.