このTagsの登録数:1件 表示 : 1 - 1 / 1
apxsだけでとりあえずモジュールの雛形ができたのでちょっといじって mod_hello ができちゃった。つぎはどういう仕組みでこれが動いてるかしらべよう。
雛形作成 coji-note:~/progs/mod_p2p coji$ ../apache/bin/apxs -g -n hello Creating [DIR] hello Creating [FILE] hello/Makefile Creating [FILE] hello/modules.mk Creating [FILE] hello/mod_hello.c Creating [FILE] hello/.deps
モジュールのコンパイル・インストール ~/progs/mod_p2p/hello $ ../apache/bin/apxs -c -i mod_hello.c /opt/local/share/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -g -O2 -I/Users/coji/progs/apache/include -I/opt/local/include/apr-1 -I/opt/local/include/apr-1 -I/opt/local/include -c -o mod_hello.lo mod_hello.c && touch mod_hello.slo /opt/local/share/apr-1/build/libtool --silent --mode=link gcc -o mod_hello.la -rpath /Users/coji/progs/apache/modules -module -avoid-version mod_hello.lo /Users/coji/progs/apache/build/instdso.sh SH_LIBTOOL='/opt/local/share/apr-1/build/libtool' mod_hello.la /Users/coji/progs/apache/modules /opt/local/share/apr-1/build/libtool --mode=install cp mod_hello.la /Users/coji/progs/apache/modules/ cp .libs/mod_hello.so /Users/coji/progs/apache/modules/mod_hello.so cp .libs/mod_hello.lai /Users/coji/progs/apache/modules/mod_hello.la cp .libs/mod_hello.a /Users/coji/progs/apache/modules/mod_hello.a ranlib /Users/coji/progs/apache/modules/mod_hello.a chmod 644 /Users/coji/progs/apache/modules/mod_hello.a ---------------------------------------------------------------------- Libraries have been installed in: /Users/coji/progs/apache/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable during execution See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /Users/coji/progs/apache/modules/mod_hello.so
モジュールのインストールとhttpd.conf への追加 ~/progs/mod_p2p/hello $ ../apache/bin/apxs -i -a mod_hello.c /Users/coji/progs/apache/build/instdso.sh SH_LIBTOOL='/opt/local/share/apr-1/build/libtool' mod_hello.c /Users/coji/progs/apache/modules /opt/local/share/apr-1/build/libtool --mode=install cp mod_hello.c /Users/coji/progs/apache/modules/ cp mod_hello.c /Users/coji/progs/apache/modules/mod_hello.c Warning! dlname not found in /Users/coji/progs/apache/modules/mod_hello.c. Assuming installing a .so rather than a libtool archive. chmod 755 /Users/coji/progs/apache/modules/mod_hello.so [activating module `hello' in /Users/coji/progs/apache/conf/httpd.conf]
mod_hello.c はこれ。 #include "httpd.h" #include "http_config.h" #include "http_protocol.h" #include "ap_config.h" /* The sample content handler */ static int hello_handler(request_rec *r) { if (strcmp(r->handler, "hello")) { return DECLINED; } r->content_type = "text/html"; if (!r->header_only) ap_rputs("Hello, world\n", r); return OK; } static void hello_register_hooks(apr_pool_t *p) { ap_hook_handler(hello_handler, NULL, NULL, APR_HOOK_MIDDLE); } /* Dispatch list for API hooks */ module AP_MODULE_DECLARE_DATA hello_module = { STANDARD20_MODULE_STUFF, NULL, /* create per-dir config structures */ NULL, /* merge per-dir config structures */ NULL, /* create per-server config structures */ NULL, /* merge per-server config structures */ NULL, /* table of config file commands */ hello_register_hooks /* register hooks */ };
httpd.confにはこう書いた SetHandler hello Order allow,deny Allow from all
溝口浩二(31歳) 東京在住 最近は動画中継職人。コードもたまに書いてます。 ドワンゴ、ニワンゴ所属
詳細検索
apxsだけでとりあえずモジュールの雛形ができたのでちょっといじって mod_hello ができちゃった。
つぎはどういう仕組みでこれが動いてるかしらべよう。
雛形作成
モジュールのコンパイル・インストール
モジュールのインストールとhttpd.conf への追加
mod_hello.c はこれ。
httpd.confにはこう書いた