Skip to content
Browse files

first attempt to run properly under cygwin

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@506 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 8cd9bf2 commit 28e4c7386f65447e4d48a0bcb027ae5418fb1163 @klacke committed Sep 8, 2003
Showing with 3,330 additions and 1,041 deletions.
  1. +14 −6 c_src/Makefile
  2. +3,110 −944 configure
  3. +35 −37 configure.in
  4. +3 −8 include.mk.in
  5. +8 −6 scripts/Install
  6. +3 −3 scripts/Makefile
  7. +4 −3 scripts/mangle
  8. +24 −10 scripts/yaws.ss
  9. +69 −6 src/yaws.erl
  10. +5 −5 src/yaws_compile.erl
  11. +7 −2 src/yaws_config.erl
  12. +13 −2 src/yaws_ctl.erl
  13. +10 −1 src/yaws_log.erl
  14. +24 −7 src/yaws_server.erl
  15. +1 −1 vsn.mk
View
20 c_src/Makefile
@@ -1,9 +1,17 @@
include ../include.mk
-PRIV_FILES= ../priv/setuid_drv.$(DLL)
+# don't c-compile anything on win32 (yet)
+# I don't know how to make linked in driver using gcc
-CFLAGS += -I${ERLDIR}/usr/include
+ifdef WIN32
+ PRIV_FILES=../priv/.foo
+else
+ PRIV_FILES= ../priv/setuid_drv.$(DLL)
+endif
+
+
+CFLAGS += -I"${ERLDIR}/usr/include"
#
# Targets
@@ -16,16 +24,16 @@ clean:
install:
install -d $(INSTALLPREFIX)/lib/yaws/priv
- install ../priv/setuid_drv.$(DLL) $(INSTALLPREFIX)/lib/yaws/priv
+ install $(PRIV_FILES) $(INSTALLPREFIX)/lib/yaws/priv
../priv/setuid_drv.$(DLL): setuid_drv.$(OBJ)
- $(LD_SHARED) $(OUT)$@ setuid_drv.$(OBJ) $(DLL_LIBS)
-
+ $(LD_SHARED) $(OUT) $@ setuid_drv.$(OBJ) $(DLL_LIBS)
setuid_drv.$(OBJ): setuid_drv.c
$(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER setuid_drv.c
-
+../priv/.foo:
+ touch ../priv/.foo
View
4,054 configure
3,110 additions, 944 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
72 configure.in
@@ -10,6 +10,8 @@ AC_DEFINE_UNQUOTED(CPU_VENDOR_OS, "$target")
AC_PATH_PROG(ERL, erl)
AC_PATH_PROG(ERLC, erlc)
+
+
AC_SUBST(ERL)
AC_SUBST(ERLC)
@@ -40,61 +42,54 @@ AC_DEFUN(BT_ERL_LIB_VSN,
])dnl
-
-
-
+dnl
+dnl I keep the cugwin dll code in case I later learn how to
+dnl compile a linked in driver on windows using gcc
+dnl
case "$target_os" in
*cygwin*)
- ERLDIR=`echo ${ERL} | sed 's/\/erts.*//'`
- ERL_DLL_LIB=`./scripts/ntpath.sh ${ERLDIR}/usr/lib/erl_dll.lib`
- AC_SUBST(ERL_DLL_LIB)
+
+
+ ERLDIR=`echo "${ERL}" | sed 's/\/bin\/*erl.*//'`
+ ERL_DLL_LIB="${ERLDIR}/usr/lib/erl_dll.lib"
+ AC_SUBST(ERL_DLL_LIB)
;;
*)
ERLDIR=`awk -F= '/ROOTDIR=/ { print [$]2; exit; }' $ERL`;;
esac
-if test ! -d $ERLDIR ; then
+if test ! -d "$ERLDIR" ; then
AC_MSG_ERROR([Broken Erlang installation, $ERLDIR does not exist!])
fi
AC_SUBST(ERLDIR)
+AC_SUBST(ERL_DLL_LIB)
+AC_PROG_CC
+AC_PROG_GCC_TRADITIONAL
-BT_ERL_LIB_VSN(erl_interface)
-
-ERL_INTERFACE_LIB=${ERLDIR}/lib/erl_interface-${ERL_INTERFACE_VSN}/lib
- case $target_os in
- *cygwin*)
- ERL_INTERFACE_LIBS=`./scripts/ntpath.sh "$ERL_INTERFACE_LIB/erl_interface.lib $ERL_INTERFACE_LIB/ei.lib"`;;
- *)
- ERL_INTERFACE_LIBS="-lerl_interface -lei ";;
- esac
-
-
+dnl ===============================================================
+dnl Checks for programs.
+dnl ===============================================================
-ERL_INTERFACE_INCLUDE=${ERLDIR}/lib/erl_interface-${ERL_INTERFACE_VSN}/include
-AC_SUBST(ERL_INTERFACE_LIB)dnl
-AC_SUBST(ERL_INTERFACE_LIBS)dnl
-AC_SUBST(ERL_INTERFACE_INCLUDE)dnl
+dnl
+dnl cygwin code here is broken and not used ....
+dnl
-dnl ===============================================================
-dnl Checks for programs.
-dnl ===============================================================
case "$target_os" in
*cygwin*)
WIN32=win32
- AC_DEFINE(WIN32)
- AC_SUBST(WIN32)
-
- STRIP=echo
- AC_SUBST(STRIP)
-
- OUT="/out:"
- AC_SUBST(OUT)
+ cat >> confdefs.h <<\EOF
+#define WIN32 1
+EOF
+ LD_SHARED="gcc -shared"
+ DLL=dll
+ DLL_LIBS="-lc \"$ERL_DLL_LIB\""
+
AC_SUBST(MATHLIB)
@@ -108,11 +103,7 @@ case "$target_os" in
AC_SUBST(OBJ)
;;
*)
- AC_PROG_CC
- AC_PROG_GCC_TRADITIONAL
- STRIP=strip
- AC_SUBST(STRIP)
LINKER=$CC
AC_SUBST(LINKER)
@@ -137,6 +128,9 @@ case "$target_os" in
;;
esac
+
+AC_SUBST(DLL_LIBS)
+
AC_PROG_MAKE_SET
AC_PROG_INSTALL
@@ -173,6 +167,10 @@ case "$target_os" in
AC_SUBST(LD_SHARED)
;;
*cygwin*)
+ AC_PATH_PROG(WERL, werl)
+ AC_SUBST(WERL)
+ AC_DEFINE(WIN32)
+ AC_SUBST(WIN32)
;;
*)
AC_MSG_RESULT(unknown)
View
11 include.mk.in
@@ -7,6 +7,7 @@ VARDIR = $(DESTDIR)@localstatedir@
INSTALLPREFIX = $(DESTDIR)$(PREFIX)
ERL=@ERL@
+WERL=@WERL@
ERLC=@ERLC@
EMULATOR=beam
@@ -33,20 +34,14 @@ DLL=@DLL@
OBJ=@OBJ@
OUT=@OUT@
FPIC=@FPIC@
-STRIP=@STRIP@
LIBS=@LIBS@
ERLDIR=@ERLDIR@
-ERL_INTERFACE_LIB=@ERL_INTERFACE_LIB@
-ERL_INTERFACE_LIBS=@ERL_INTERFACE_LIBS@
-ERL_INTERFACE_INCLUDE=@ERL_INTERFACE_INCLUDE@
LD_SHARED=@LD_SHARED@
-LDFLAGS +=-L$(ERL_INTERFACE_LIB)
-
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
@@ -82,10 +77,10 @@ APPSCRIPT = '$$vsn=shift; $$mods=""; while(@ARGV){ $$_=shift; s/^([A-Z].*)$$/\'\
cp $< $@
../ebin/%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o ../ebin $<
+ "$(ERLC)" $(ERLC_FLAGS) -o ../ebin $<
%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) $<
+ "$(ERLC)" $(ERLC_FLAGS) $<
View
14 scripts/Install
@@ -4,7 +4,8 @@
prefix=$1
installprefix=$2
erl=$3
-etcdir=$4
+werl=$4
+etcdir=$5
. ../vsn.mk
y=yaws-${YAWS_VSN}
@@ -16,16 +17,17 @@ mangle ()
{
d=$1
e=$2
- from=$3
- to=$4
+ w=$3
+ from=$4
+ to=$5
install -d `dirname $to`
- sed -e "s;%yawsdir%;$d;g" -e "s;%erl%;$e;" $from > $to
+ sed -e "s;%yawsdir%;$d;g" -e "s;%erl%;$e;" -e "s;%werl%;$w;" $from > $to
}
-mangle ${prefix}/lib/yaws ${erl} yaws.ss ${installprefix}/bin/yaws
+mangle ${prefix}/lib/yaws "${erl}" "${werl}" yaws.ss ${installprefix}/bin/yaws
install -d ${installprefix}/lib/yaws/examples/ebin
install -d ${installprefix}/lib/yaws/examples/include
chmod +x ${installprefix}/bin/yaws
@@ -35,7 +37,7 @@ else
t=${etcdir}/yaws.conf
fi
-mangle ${prefix}/lib/yaws ${erl} yaws.conf.template ${t}
+mangle ${prefix}/lib/yaws "${erl}" "${werl}" yaws.conf.template ${t}
if [ -f /etc/gentoo-release ]; then
View
6 scripts/Makefile
@@ -4,14 +4,14 @@ include ../include.mk
all debug: ../bin/yaws
../bin/yaws: yaws.ss
- @sh ./mangle `pwd`/.. $(ERL) yaws.ss ../bin/yaws
+ sh -x ./mangle `pwd`/.. "$(ERL)" "$(WERL)" yaws.ss ../bin/yaws
@chmod +x ../bin/yaws
local_install: ../bin/yaws
@if [ -f $$HOME/yaws.conf ]; \
then echo "$$HOME/yaws.conf already exists "; \
else \
- sh ./mangle `pwd`/.. $(ERL) yaws.conf.template.local ${HOME}/yaws.conf; echo "installed yaws.conf in $$HOME "; fi
+ sh ./mangle `pwd`/.. "$(ERL)" "$(WERL)" yaws.conf.template.local ${HOME}/yaws.conf; echo "installed yaws.conf in $$HOME "; fi
install -d $$HOME/bin
cp ../bin/yaws $$HOME/bin/yaws
@@ -22,7 +22,7 @@ clean:
install: all .foo
.foo:
- sh -x ./Install $(PREFIX) $(INSTALLPREFIX) $(ERL) $(ETCDIR)
+ sh -x ./Install $(PREFIX) $(INSTALLPREFIX) "$(ERL)" "$(WERL)" $(ETCDIR)
View
7 scripts/mangle
@@ -2,9 +2,10 @@
d=$1
e=$2
-s=$3
-t=$4
+w=$3
+s=$4
+t=$5
install -d `dirname $t`
-sed -e "s;%yawsdir%;$d;g" -e "s;%erl%;$e;" $s > $t
+sed -e "s;%yawsdir%;$d;g" -e "s;%erl%;$e;" -e "s;%werl%;$w;" $s > $t
View
34 scripts/yaws.ss
@@ -1,8 +1,16 @@
#!/bin/sh
-yawsdir=%yawsdir%
-erl=%erl%
+yawsdir="%yawsdir%"
+erl="%erl%"
+case `uname` in
+ CYGWIN*)
+ yawsdir=`cygpath --windows $yawsdir`
+ werl="%werl%"
+ delim=\\;;
+ *)
+ delim=/
+esac
ENV_PGM=`which env`
@@ -12,6 +20,7 @@ help()
{
echo "usage: server modes ... "
echo " yaws -i -- interactive (no daemon) mode"
+ echo " yaws -w -- cygwin interactive (werl) "
echo " yaws -D -- daemon mode"
echo " yaws -d -- debug mode"
echo " yaws -c file -- set config file"
@@ -56,6 +65,11 @@ do
interactive="true";
debug=" -yaws debug ";
daemon="";;
+ -w)
+ interactive="true";
+ debug=" -yaws debug ";
+ daemon="";
+ erl=$werl;;
-D)
daemon=" -detached ";;
-d)
@@ -76,19 +90,19 @@ do
runmod=" -runmod $1 "
shift;;
-h)
- exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl hup;
+ exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl hup;
exit 0;;
-s)
- exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl stop;
+ exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stop;
exit 0;;
-S)
- exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl status;
+ exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status;
exit 0;;
-load)
- exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl load $*;
+ exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl load $*;
exit 0;;
-v)
- exec $erl -noshell -pa ${yawsdir}/ebin -s yaws printversion;
+ exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws printversion;
exit 0;;
-sname)
sname=" -sname $1 "
@@ -99,7 +113,7 @@ do
ID=`id -u`
mkdir /tmp/yaws 2> /dev/null
mkdir /tmp/yaws/${ID} 2> /dev/null
- out=`exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl check $*`
+ out=`exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl check $*`
if [ "$out" = "ok" ]; then
echo "$1" ok
exit 0
@@ -119,10 +133,10 @@ if [ -z "$heart" ] || [ -z "$daemon" ]; then
HEART_COMMAND="";
else
## ............................this line
- export HEART_COMMAND="${ENV_PGM} HEART=true $erl ${daemon} ${heart} -pa ${yawsdir}/ebin ${sname} ${debug} -s yaws $trace $conf $runmod $mnesia";
+ export HEART_COMMAND="${ENV_PGM} HEART=true \"$erl\" ${daemon} ${heart} -pa ${yawsdir}${delim}ebin ${sname} ${debug} -s yaws $trace $conf $runmod $mnesia";
fi
## keep this line in sync with ....^
-exec $erl ${daemon} ${heart} -pa ${yawsdir}/ebin ${sname} ${debug} -s yaws $trace $conf $runmod $mnesia
+exec "$erl" ${daemon} ${heart} -pa ${yawsdir}${delim}ebin ${sname} ${debug} -s yaws $trace $conf $runmod $mnesia
View
75 src/yaws.erl
@@ -1175,14 +1175,20 @@ setuser(User) ->
end.
getuid() ->
- erl_ddll:load_driver(filename:dirname(code:which(?MODULE)) ++
- "/../priv/", "setuid_drv"),
- P = open_port({spawn, "setuid_drv g"},[]),
- receive
- {P, {data, "ok " ++ IntList}} ->
- {ok, IntList}
+ case os:type() of
+ {win32, _} ->
+ {ok, "XXX"};
+ _ ->
+ erl_ddll:load_driver(filename:dirname(code:which(?MODULE)) ++
+ "/../priv/", "setuid_drv"),
+ P = open_port({spawn, "setuid_drv g"},[]),
+ receive
+ {P, {data, "ok " ++ IntList}} ->
+ {ok, IntList}
+ end
end.
+
idu(User) ->
erl_ddll:load_driver(filename:dirname(code:which(?MODULE)) ++
"/../priv/", "setuid_drv"),
@@ -1200,3 +1206,60 @@ user_to_home(User) ->
{P, {data, "ok " ++ Home}} ->
Home
end.
+
+
+tmp_dir() ->
+ case os:type() of
+ {win32,_} ->
+ "c:/winnt/temp";
+ _ ->
+ "/tmp"
+ end.
+
+
+% Try to create a tmp directory in the current directory.
+% In case of any problem terminate yaws.
+%
+create_tmp_dir() ->
+ ErrorMessage = "TEMP, and TMP variables undefined. ",
+ Dir = case file:get_cwd() of
+ {ok, CurDir} ->
+ CurDir ++ "/tmp";
+ Err ->
+ io:format(
+ ErrorMessage++"Canont access current directory; error: ~p~n",
+ [Err]),
+ init:stop()
+ end,
+ case file:make_dir(Dir) of
+ ok -> Dir;
+ {error, eexist} ->
+ case file:read_file_info("tmp") of
+ {ok, FI} when FI#file_info.type==directory ->
+ Dir;
+ _ ->
+ io:format(
+ ErrorMessage++"Canont access directory ~p~n",
+ [Dir]),
+ init:stop()
+ end;
+ Error ->
+ io:format(
+ ErrorMessage++"Canont create directory ~p, Error: ~p~n",
+ [Dir,Error]),
+ init:stop()
+ end.
+
+%
+% String represeting temporary directory that
+% can be used for format functions (io,io_lib).
+% WIN32 path can contain $~, so they are doubled.
+%
+tmp_dir_fstr() ->
+ lists:foldr(fun($~, Str) -> [$~, $~ | Str];
+ (C , Str) -> [C | Str]
+ end,
+ [],
+ tmp_dir()).
+
+
View
10 src/yaws_compile.erl
@@ -245,11 +245,11 @@ new_out_file(Line, C, GC) ->
Other
end,
Module = [$m | integer_to_list(Mnum)],
- OutFile = lists:flatten(
- io_lib:format(
- "/tmp/yaws/~s/~s.erl",[GC#gconf.uid, Module])),
-
- %% "/tmp/yaws/" ++ Module ++ ".erl",
+ OutFile =
+ lists:flatten(
+ io_lib:format(
+ "~s/yaws/~s/~s.erl",[yaws:tmp_dir(), GC#gconf.uid, Module])),
+
?Debug("Writing outout file~s~n", [OutFile]),
{ok, Out} = file:open(OutFile, [write]),
View
9 src/yaws_config.erl
@@ -333,8 +333,13 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
end;
["username", '=' , Uname] ->
- fload(FD, globals, GC#gconf{username = Uname},
- C, Cs, Lno+1, Next);
+ case os:type() of
+ {win32, _} ->
+ {error, "username feature not supported on win32"};
+ _ ->
+ fload(FD, globals, GC#gconf{username = Uname},
+ C, Cs, Lno+1, Next)
+ end;
['<', "server", Server, '>'] -> %% first server
fload(FD, server, GC, #sconf{servername = Server},
View
15 src/yaws_ctl.erl
@@ -15,15 +15,25 @@
-include_lib("kernel/include/file.hrl").
-include_lib("yaws/include/yaws.hrl").
-include_lib("yaws/include/yaws_api.hrl").
-
+-include("yaws_debug.hrl").
ctl_file("0") ->
"/var/run/yaws.ctl";
ctl_file(Id) ->
- io_lib:format("/tmp/yaws.ctl.~s",[Id]).
+ Tmp = yaws:tmp_dir_fstr(),
+ io_lib:format(Tmp ++ "/yaws.ctl.~s",[Id]).
start(Top, Id) ->
+ case catch start0(Top, Id) of
+ {'EXIT', Reason} ->
+ error_logger:format("Faild to start ctl : ~p~n", [Reason]),
+ Top ! {self(), {error, Reason}};
+ Other ->
+ Other
+ end.
+
+start0(Top, Id) ->
case gen_tcp:listen(0, [{packet, 2},
{active, false},
binary,
@@ -33,6 +43,7 @@ start(Top, Id) ->
case inet:sockname(L) of
{ok, {_, Port}} ->
F = ctl_file(Id),
+ ?Debug("Ctlfile : ~s~n", [F]),
file:write_file(F, io_lib:format("~w", [Port])),
{ok, FI} = file:read_file_info(F),
M = FI#file_info.mode,
View
11 src/yaws_log.erl
@@ -123,7 +123,16 @@ handle_call({setdir, Dir, Sconfs}, _From, State)
L = lists:zf(
fun(SC) ->
- A = filename:join([Dir, SC#sconf.servername ++ ".access"]),
+ FileName = case os:type() of
+ {win32,_ } ->
+ lists:map(fun($:) -> $.;
+ (C ) -> C
+ end,
+ SC#sconf.servername);
+ _ ->
+ SC#sconf.servername
+ end,
+ A = filename:join([Dir, FileName ++ ".access"]),
case file:open(A, [write, raw, append]) of
{ok, Fd} ->
{true, #alog{servername = SC#sconf.servername,
View
31 src/yaws_server.erl
@@ -229,14 +229,20 @@ init2(Gconf, Sconfs, RunMod, FirstTime) ->
{CTL, ok} ->
ok;
{CTL, {error, R}} ->
+ error_logger:format("CTL failed ~p~n", [R]),
exit(R)
end;
true ->
ok
end,
- file:make_dir("/tmp/yaws"),
- set_writeable("/tmp/yaws"),
+ Tdir0 = yaws:tmp_dir()++"/yaws/" ,
+ file:make_dir(Tdir0),
+ set_writeable(Tdir0),
+ Tdir = Tdir0 ++ Gconf#gconf.uid,
+ file:make_dir(Tdir0),
+ set_writeable(Tdir0),
+
case (catch yaws_log:uid_change(Gconf)) of
ok ->
ok;
@@ -386,17 +392,26 @@ add_yaws_auth(Dirs, A) ->
do_listen(SC) ->
case SC#sconf.ssl of
undefined ->
- {nossl, gen_tcp:listen(SC#sconf.port, opts(SC))};
+ {nossl, gen_tcp_listen(SC#sconf.port, opts(SC))};
SSL ->
{ssl, ssl:listen(SC#sconf.port, ssl_opts(SC, SSL))}
end.
+gen_tcp_listen(Port, Opts) ->
+ ?Debug("Listen ~p:~p~n", [Port, Opts]),
+ gen_tcp:listen(Port, Opts).
+
+
set_writeable(Dir) ->
set_dir_mode(Dir, 8#777).
set_dir_mode(Dir, Mode) ->
- {ok, FI} = file:read_file_info(Dir),
- file:write_file_info(Dir, FI#file_info{mode = Mode}).
+ case file:read_file_info(Dir) of
+ {ok, FI} ->
+ file:write_file_info(Dir, FI#file_info{mode = Mode});
+ Err ->
+ error_logger:format("Failed to read_file_info(~s)~n", [Dir])
+ end.
gserv(_, []) ->
@@ -449,7 +464,7 @@ gserv(GC, Group0) ->
setup_tdir(GC) ->
- Tdir = "/tmp/yaws/" ++ GC#gconf.uid,
+ Tdir = yaws:tmp_dir()++"/yaws/" ++ GC#gconf.uid,
file:make_dir(Tdir),
set_dir_mode(Tdir, 8#700),
case file:list_dir(Tdir) of
@@ -598,6 +613,7 @@ filter_false(L) ->
do_accept(GS) when GS#gs.ssl == nossl ->
+ ?Debug("wait in accept ... ~n",[]),
gen_tcp:accept(GS#gs.l);
do_accept(GS) when GS#gs.ssl == ssl ->
ssl:accept(GS#gs.l).
@@ -1565,7 +1581,8 @@ del_old_files([]) ->
del_old_files([{_FileAtom, spec, _Mtime1, Spec, _}]) ->
lists:foreach(
fun({mod, _, _, _, Mod, _Func}) ->
- F="/tmp/yaws/" ++ yaws:to_list(Mod) ++ ".erl",
+
+ F=yaws:tmp_dir()++"/yaws/" ++ yaws:to_list(Mod) ++ ".erl",
code:purge(Mod),
code:purge(Mod),
file:delete(F);
View
2 vsn.mk
@@ -1 +1 @@
-YAWS_VSN=1.30
+YAWS_VSN=1.31

0 comments on commit 28e4c73

Please sign in to comment.
Something went wrong with that request. Please try again.