diff mbox

example/webserver: pick up the www_dir from the environment

Message ID 1447857896-11510-1-git-send-email-anders.roxell@linaro.org
State New
Headers show

Commit Message

Anders Roxell Nov. 18, 2015, 2:44 p.m. UTC
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 example/webserver/httpd.c  | 7 ++++---
 scripts/start_webserver.sh | 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)

Comments

Anders Roxell Nov. 18, 2015, 2:55 p.m. UTC | #1
urgh!
ignore

On 18 November 2015 at 15:44, Anders Roxell <anders.roxell@linaro.org> wrote:
> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> ---
>  example/webserver/httpd.c  | 7 ++++---
>  scripts/start_webserver.sh | 2 ++
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/example/webserver/httpd.c b/example/webserver/httpd.c
> index d4e37fa..98753a4 100644
> --- a/example/webserver/httpd.c
> +++ b/example/webserver/httpd.c
> @@ -14,9 +14,6 @@ void httpd_main(uint32_t addr);
>  int sigreceived = 0;
>  static uint32_t myaddr;
>
> -/* Set www_dir to point to your web directory. */
> -static const char *www_dir = "/home/hjokinen/Dropbox/kolumbus-web";
> -
>  /* Table of concurrent connections */
>  #define NUM_CONNECTIONS 16
>  static struct {
> @@ -62,6 +59,8 @@ static int sendf(int fd, const char *fmt, ...)
>  /* Send one file. */
>  static void get_file(int s, char *url)
>  {
> +       /* Set www_dir to point to your web directory. */
> +       char *www_dir = NULL;
>         char bufo[512];
>         int n, w;
>
> @@ -88,6 +87,8 @@ static void get_file(int s, char *url)
>                 else if (!strcmp(p2, "js")) mime = "text/javascript";
>         }
>
> +       www_dir = getenv("www_dir");
> +
>         snprintf(bufo, sizeof(bufo), "%s/%s", www_dir, p);
>         FILE *f = fopen(bufo, "rb");
>
> diff --git a/scripts/start_webserver.sh b/scripts/start_webserver.sh
> index ac9b66d..ced4ac1 100755
> --- a/scripts/start_webserver.sh
> +++ b/scripts/start_webserver.sh
> @@ -7,6 +7,8 @@ fi
>  intf=$1
>  echo Starting Web Server on interface $intf
>
> +www_dir="${www_dir:-"/var/www/"}"
> +export www_dir
>  ./example/webserver/webserver -i $intf -c 2 &
>
>  sleep 1
> --
> 2.1.4
>
diff mbox

Patch

diff --git a/example/webserver/httpd.c b/example/webserver/httpd.c
index d4e37fa..98753a4 100644
--- a/example/webserver/httpd.c
+++ b/example/webserver/httpd.c
@@ -14,9 +14,6 @@  void httpd_main(uint32_t addr);
 int sigreceived = 0;
 static uint32_t myaddr;
 
-/* Set www_dir to point to your web directory. */
-static const char *www_dir = "/home/hjokinen/Dropbox/kolumbus-web";
-
 /* Table of concurrent connections */
 #define NUM_CONNECTIONS 16
 static struct {
@@ -62,6 +59,8 @@  static int sendf(int fd, const char *fmt, ...)
 /* Send one file. */
 static void get_file(int s, char *url)
 {
+	/* Set www_dir to point to your web directory. */
+	char *www_dir = NULL;
 	char bufo[512];
 	int n, w;
 
@@ -88,6 +87,8 @@  static void get_file(int s, char *url)
 		else if (!strcmp(p2, "js")) mime = "text/javascript";
 	}
 
+	www_dir = getenv("www_dir");
+
 	snprintf(bufo, sizeof(bufo), "%s/%s", www_dir, p);
 	FILE *f = fopen(bufo, "rb");
 
diff --git a/scripts/start_webserver.sh b/scripts/start_webserver.sh
index ac9b66d..ced4ac1 100755
--- a/scripts/start_webserver.sh
+++ b/scripts/start_webserver.sh
@@ -7,6 +7,8 @@  fi
 intf=$1
 echo Starting Web Server on interface $intf
 
+www_dir="${www_dir:-"/var/www/"}"
+export www_dir
 ./example/webserver/webserver -i $intf -c 2 &
 
 sleep 1