* [9fans] Things about werc + Plan 9 httpd
@ 2014-01-22 3:46 cherry
0 siblings, 0 replies; only message in thread
From: cherry @ 2014-01-22 3:46 UTC (permalink / raw)
To: werc9, Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 2377 bytes --]
Hello,
As I recently played werc on Plan 9, I would like to share a couple of
things I found.
First, in the Docs page (
http://werc.cat-v.org/docs/web-server-setup/plan-9-httpd), it says
> you will need to replace the ‘%($“extraHeaders%)’ in lib/headers.tpl with
‘% echo $"extraHeaders’ no clue why.
The reason is %(...%) invokes "echo -n", and when the variable is empty (in
many cases $extraHeaders is), it calls write() with zero length, which, if
writes to a pipe, causes the other end of the pipe read()'s zero byte (as
pipe(3) says, write boundary is preserved), and it may think it's got to
the end. For example, cat, /sys/src/cmd/cat.c:10
while((n=read(f, buf, (long)sizeof buf))>0)
$“extraHeaders is used in bin/werc.rc:140
template $headers $master_template | awk_buffer
which also suffers the same problem. I have played many different ways to
work around it, and my current solution (I believe covering all cases) is
to wrap echo as
fn echo { builtin echo $* | cat }
so when it is echoing nothing, "cat" will consume the zero-length write().
Any comment or idea? I don't have p9p so I don't know why there is no such
problem. Probably unix's pipe implemented differently.
Second, in the same Docs page, the werc-wrapper's arguments seem not
matched with httpd's magic. Is it outdated? Or I missed anything? The
following works for me:
SERVER_NAME=$*(2)
REQUEST_URI=`{echo $*(22)}
if(~ $#REQUEST_URI 0)
REQUEST_URI=/
REQUEST_METHOD=$*(20)
PLAN9=/
Another thing is about remapping the root directory. Httpd does not handle
it, so we put all stuff into a sub directory, but many werc generated links
are still pointing to something under the root, e.g. the side-bar, and even
css. Certainly a way is to hack werc. My alternative approach is generating
rewriting rules mapping every first-level directories, putting it into a
script starting httpd, like,
echo /w @/magic/werc-wrap > /tmp/rewrite
echo / @/w >> /tmp/rewrite
for(i in `{ls -p $sitedir})
echo /$i @/w/$i >> /tmp/rewrite
bind /tmp/rewrite /sys/lib/httpd.rewrite
Kill httpd | rc
ip/httpd/httpd
A problem is adding new stuff to the root requires a restart of httpd, but
this happens probably not very often.
Hope this is useful, and sorry for a long email.
Thanks,
- cherry
[-- Attachment #2: Type: text/html, Size: 2715 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-01-22 3:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-22 3:46 [9fans] Things about werc + Plan 9 httpd cherry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).