<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yoichi Kawasaki&#039;s Web &#187; linux</title>
	<atom:link href="http://yk55.com/blog/tags/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://yk55.com/blog</link>
	<description>the place to organize and record my ideas ...</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:16:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) -->	<item>
		<title>Segmentation fault(11) &#8211; Apache2 and libphp5.so on Ubuntu</title>
		<link>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/</link>
		<comments>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 15:32:11 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Environment Setup]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=434</guid>
		<description><![CDATA[Ubuntu10.04.1LTSでApache2、PHP5.3がうまく動いてくれない。 同一バージョンのApache、PHPを依存ライブラリをほぼ同じにしてdebian Lennyで試してみると問題なく動作する。 どうにもこうにもならないので後々のためにとりあえず記録だけ残しておく。 1. PROBLEM: Apache2 Segmentation fault(11) [Sun Nov 28 17:42:48 2010] [notice] Apache/2.2.2 (Unix) PHP/5.3.3 configured -- resuming normal operations [Sun Nov 28 17:42:48 2010] [notice] child pid 13032 exit signal Segmentation fault (11) [Sun Nov 28 17:42:49 2010] [notice] child pid 13033 exit signal Segmentation fault (11) [Sun Nov 28 17:42:52 [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu10.04.1LTSでApache2、PHP5.3がうまく動いてくれない。 同一バージョンのApache、PHPを依存ライブラリをほぼ同じにしてdebian Lennyで試してみると問題なく動作する。 どうにもこうにもならないので後々のためにとりあえず記録だけ残しておく。 </p>
<p><h2><strong>1. PROBLEM: Apache2 Segmentation fault(11)</strong></h2>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[Sun Nov 28 17:42:48 2010] [notice] Apache/2.2.2 (Unix) PHP/5.3.3 configured -- resuming normal operations<br />
[Sun Nov 28 17:42:48 2010] [notice] child pid 13032 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:49 2010] [notice] child pid 13033 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:52 2010] [notice] child pid 13034 exit signal Segmentation fault (11)<br />
[Sun Nov 28 17:42:56 2010] [notice] child pid 13035 exit signal Segmentation fault (11)</div></div>
<p><h2><strong>2. Environments</strong></h2>
<p><h4><strong>Installations: apache-2.2.2</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tar zxf httpd-2.2.2.tar.gz<br />
cd httpd-2.2.2<br />
<br />
CC=&quot;gcc&quot; OPTIM=&quot;-O2&quot; \<br />
&nbsp;./configure \<br />
&nbsp;--prefix=/home/apache-2.2.2 \<br />
&nbsp;--with-layout=Apache \<br />
&nbsp;--enable-rewrite \<br />
&nbsp;--disable-userdir \<br />
&nbsp;--enable-auth_dbm \<br />
&nbsp;--enable-usertrack \<br />
&nbsp;--enable-=so \<br />
&nbsp;--enable-proxy \<br />
&nbsp;--enable-proxy-http \<br />
&nbsp;--enable-proxy-connect \<br />
&nbsp;--enable-speling \<br />
&nbsp;--enable-headers \<br />
&nbsp;--enable-expires \<br />
&nbsp;--enable-setenvif \<br />
&nbsp;--enable-cache \<br />
&nbsp;--enable-disk-cache \<br />
&nbsp;--enable-mem-cache \<br />
&nbsp;--enable-info \<br />
&nbsp;--enable-rule=SHARED_CORE \<br />
&nbsp;--verbose<br />
<br />
make <br />
sudo make install<br />
sudo ln -s /home/apache-2.2.2 /home/apache</div></div>
<p><h4><strong>Installations: PHP-5.3.3</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tar zxvf php-5.3.3.tar.gz<br />
cd php-5.3.3<br />
./configure \<br />
&nbsp; &nbsp; --with-apxs2=/home/apache/bin/apxs \<br />
&nbsp; &nbsp; --with-mysql=/home/mysql \<br />
&nbsp; &nbsp; --with-curl=/usr/lib \<br />
&nbsp; &nbsp; --with-zlib \<br />
&nbsp; &nbsp; --enable-mbstring \<br />
&nbsp; &nbsp; --enable-mbregex \<br />
<br />
make<br />
sudo make install</div></div>
<p><h4><strong>Linux distribution Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ lsb_release -a <br />
No LSB modules are available.<br />
Distributor ID: Ubuntu<br />
Description: &nbsp; &nbsp;Ubuntu 10.04.1 LTS<br />
Release: &nbsp; &nbsp; &nbsp; &nbsp;10.04<br />
Codename: &nbsp; &nbsp; &nbsp; lucid</div></div>
<p><h4><strong>Apache Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ /home/apache/bin/apachectl -V<br />
<br />
Server version: Apache/2.2.2<br />
Server built: &nbsp; Apr &nbsp;4 2010 10:26:51<br />
Server's Module Magic Number: 20051115:2<br />
Server loaded: &nbsp;APR 1.2.7, APR-Util 1.2.7<br />
Compiled using: APR 1.2.7, APR-Util 1.2.7<br />
Architecture: &nbsp; 32-bit<br />
Server MPM: &nbsp; &nbsp; Prefork<br />
&nbsp; threaded: &nbsp; &nbsp; no<br />
&nbsp; &nbsp; forked: &nbsp; &nbsp; yes (variable process count)<br />
Server compiled with....<br />
&nbsp;-D APACHE_MPM_DIR=&quot;server/mpm/prefork&quot; &nbsp; &nbsp; &lt;--- サーバは MPM/Prefork<br />
&nbsp;-D APR_HAS_SENDFILE<br />
&nbsp;-D APR_HAS_MMAP<br />
&nbsp;-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)<br />
&nbsp;-D APR_USE_SYSVSEM_SERIALIZE<br />
&nbsp;-D APR_USE_PTHREAD_SERIALIZE<br />
&nbsp;-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT<br />
&nbsp;-D APR_HAS_OTHER_CHILD<br />
&nbsp;-D AP_HAVE_RELIABLE_PIPED_LOGS<br />
&nbsp;-D DYNAMIC_MODULE_LIMIT=128<br />
&nbsp;-D HTTPD_ROOT=&quot;/home/apache-2.2.2&quot;<br />
&nbsp;-D SUEXEC_BIN=&quot;/home/apache-2.2.2/bin/suexec&quot;<br />
&nbsp;-D DEFAULT_PIDLOG=&quot;logs/httpd.pid&quot;<br />
&nbsp;-D DEFAULT_SCOREBOARD=&quot;logs/apache_runtime_status&quot;<br />
&nbsp;-D DEFAULT_LOCKFILE=&quot;logs/accept.lock&quot;<br />
&nbsp;-D DEFAULT_ERRORLOG=&quot;logs/error_log&quot;<br />
&nbsp;-D AP_TYPES_CONFIG_FILE=&quot;conf/mime.types&quot;<br />
&nbsp;-D SERVER_CONFIG_FILE=&quot;conf/httpd.conf&quot;</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ /home/apache/bin/apachectl -M<br />
<br />
Loaded Modules:<br />
&nbsp;core_module (static)<br />
&nbsp;authn_file_module (static)<br />
&nbsp;authn_default_module (static)<br />
&nbsp;authz_host_module (static)<br />
&nbsp;authz_groupfile_module (static)<br />
&nbsp;authz_user_module (static)<br />
&nbsp;authz_default_module (static)<br />
&nbsp;auth_basic_module (static)<br />
&nbsp;cache_module (static)<br />
&nbsp;disk_cache_module (static)<br />
&nbsp;mem_cache_module (static)<br />
&nbsp;include_module (static)<br />
&nbsp;filter_module (static)<br />
&nbsp;log_config_module (static)<br />
&nbsp;env_module (static)<br />
&nbsp;expires_module (static)<br />
&nbsp;headers_module (static)<br />
&nbsp;usertrack_module (static)<br />
&nbsp;setenvif_module (static)<br />
&nbsp;proxy_module (static)<br />
&nbsp;proxy_connect_module (static)<br />
&nbsp;proxy_ftp_module (static)<br />
&nbsp;proxy_http_module (static)<br />
&nbsp;proxy_ajp_module (static)<br />
&nbsp;proxy_balancer_module (static)<br />
&nbsp;mpm_prefork_module (static)<br />
&nbsp;http_module (static)<br />
&nbsp;mime_module (static)<br />
&nbsp;status_module (static)<br />
&nbsp;autoindex_module (static)<br />
&nbsp;asis_module (static)<br />
&nbsp;info_module (static)<br />
&nbsp;cgi_module (static)<br />
&nbsp;negotiation_module (static)<br />
&nbsp;dir_module (static)<br />
&nbsp;actions_module (static)<br />
&nbsp;speling_module (static)<br />
&nbsp;alias_module (static)<br />
&nbsp;rewrite_module (static)<br />
&nbsp;so_module (static)<br />
&nbsp;php5_module (shared)<br />
Syntax OK</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ldd /home/apache/bin/httpd &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; linux-gate.so.1 =&gt; &nbsp;(0x00ed3000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libm.so.6 =&gt; /lib/tls/i686/cmov/libm.so.6 (0x006c4000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libaprutil-1.so.0 =&gt; /home/apache-2.2.2/lib/libaprutil-1.so.0 (0x00586000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libexpat.so.1 =&gt; /lib/libexpat.so.1 (0x0087a000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libapr-1.so.0 =&gt; /home/apache-2.2.2/lib/libapr-1.so.0 (0x00f91000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; librt.so.1 =&gt; /lib/tls/i686/cmov/librt.so.1 (0x0093b000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypt.so.1 =&gt; /lib/tls/i686/cmov/libcrypt.so.1 (0x005ce000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libpthread.so.0 =&gt; /lib/tls/i686/cmov/libpthread.so.0 (0x00115000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libdl.so.2 =&gt; /lib/tls/i686/cmov/libdl.so.2 (0x00964000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00413000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; /lib/ld-linux.so.2 (0x00d4f000)</div></div>
<p><h4><strong>PHP Info</strong></h4>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ php -i <br />
<br />
phpinfo()<br />
PHP Version =&gt; 5.3.3<br />
<br />
System =&gt; Linux ubuntu-xps 2.6.32-26-generic #47-Ubuntu SMP Wed Nov 17 15:59:05 UTC 2010 i686<br />
Build Date =&gt; Nov 28 2010 19:21:06<br />
Configure Command =&gt; &nbsp;'./configure' &nbsp;'--with-apxs2=/home/apache/bin/apxs' '--with-mysql=/home/mysql' '--with-curl=/usr/lib' '--with-zlib' '--enable-mbstring' '--enable-mbregex'<br />
Server API =&gt; Command Line Interface<br />
Virtual Directory Support =&gt; disabled<br />
Configuration File (php.ini) Path =&gt; /usr/local/lib<br />
Loaded Configuration File =&gt; (none)<br />
Scan this dir for additional .ini files =&gt; (none)<br />
Additional .ini files parsed =&gt; (none)<br />
PHP API =&gt; 20090626<br />
PHP Extension =&gt; 20090626<br />
Zend Extension =&gt; 220090626<br />
Zend Extension Build =&gt; API220090626,NTS<br />
PHP Extension Build =&gt; API20090626,NTS<br />
Debug Build =&gt; no<br />
Thread Safety =&gt; disabled<br />
Zend Memory Manager =&gt; enabled<br />
Zend Multibyte Support =&gt; disabled<br />
IPv6 Support =&gt; enabled<br />
Registered PHP Streams =&gt; compress.zlib, php, file, glob, data, http, ftp, phar &nbsp;<br />
Registered Stream Socket Transports =&gt; tcp, udp, unix, udg<br />
Registered Stream Filters =&gt; zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk<br />
<br />
<br />
This program makes use of the Zend Scripting Language Engine:<br />
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ php -m<br />
<br />
[PHP Modules]<br />
Core<br />
ctype<br />
curl<br />
date<br />
dom<br />
ereg<br />
fileinfo<br />
filter<br />
hash<br />
iconv<br />
json<br />
libxml<br />
mbstring<br />
mysql<br />
pcre<br />
PDO<br />
pdo_sqlite<br />
Phar<br />
posix<br />
Reflection<br />
session<br />
SimpleXML<br />
SPL<br />
SQLite<br />
sqlite3<br />
standard<br />
tokenizer<br />
xml<br />
xmlreader<br />
xmlwriter<br />
zlib<br />
<br />
[Zend Modules]</div></div>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ldd /home/apache/modules/libphp5.so <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; linux-gate.so.1 =&gt; &nbsp;(0x00569000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypt.so.1 =&gt; /lib/tls/i686/cmov/libcrypt.so.1 (0x00110000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; librt.so.1 =&gt; /lib/tls/i686/cmov/librt.so.1 (0x001f6000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libmysqlclient.so.16 =&gt; /home/mysql-5.1.30/lib/mysql/libmysqlclient.so.16 (0x00356000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libz.so.1 =&gt; /lib/libz.so.1 (0x00142000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libm.so.6 =&gt; /lib/tls/i686/cmov/libm.so.6 (0x00157000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libdl.so.2 =&gt; /lib/tls/i686/cmov/libdl.so.2 (0x0017d000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libnsl.so.1 =&gt; /lib/tls/i686/cmov/libnsl.so.1 (0x00181000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcurl.so.4 =&gt; /usr/lib/libcurl.so.4 (0x00198000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libxml2.so.2 =&gt; /usr/lib/libxml2.so.2 (0x001ff000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0x00e02000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libpthread.so.0 =&gt; /lib/tls/i686/cmov/libpthread.so.0 (0x001dd000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; /lib/ld-linux.so.2 (0x00339000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libidn.so.11 =&gt; /usr/lib/libidn.so.11 (0x004ad000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; liblber-2.4.so.2 =&gt; /usr/lib/liblber-2.4.so.2 (0x0032a000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libldap_r-2.4.so.2 =&gt; /usr/lib/libldap_r-2.4.so.2 (0x004df000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgssapi_krb5.so.2 =&gt; /usr/lib/libgssapi_krb5.so.2 (0x00526000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libssl.so.0.9.8 =&gt; /lib/i686/cmov/libssl.so.0.9.8 (0x00f5c000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcrypto.so.0.9.8 =&gt; /lib/i686/cmov/libcrypto.so.0.9.8 (0x00fa4000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libresolv.so.2 =&gt; /lib/tls/i686/cmov/libresolv.so.2 (0x00555000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libsasl2.so.2 =&gt; /usr/lib/libsasl2.so.2 (0x1ca3d000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgnutls.so.26 =&gt; /usr/lib/libgnutls.so.26 (0x1eb4b000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkrb5.so.3 =&gt; /usr/lib/libkrb5.so.3 (0x14a7f000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libk5crypto.so.3 =&gt; /usr/lib/libk5crypto.so.3 (0x19f18000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libcom_err.so.2 =&gt; /lib/libcom_err.so.2 (0x13a74000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkrb5support.so.0 =&gt; /usr/lib/libkrb5support.so.0 (0x0c97e000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libkeyutils.so.1 =&gt; /lib/libkeyutils.so.1 (0x0d073000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libtasn1.so.3 =&gt; /usr/lib/libtasn1.so.3 (0x0b5c2000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgcrypt.so.11 =&gt; /lib/libgcrypt.so.11 (0x09524000)<br />
&nbsp; &nbsp; &nbsp; &nbsp; libgpg-error.so.0 =&gt; /lib/libgpg-error.so.0 (0x07565000)</div></div>
<p><h2><strong>3. Debugging Info</strong></h2>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ sudo gdb ./httpd<br />
<br />
GNU gdb (GDB) 7.1-ubuntu<br />
Copyright (C) 2010 Free Software Foundation, Inc.<br />
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;<br />
This is free software: you are free to change and redistribute it.<br />
There is NO WARRANTY, to the extent permitted by law. &nbsp;Type &quot;show copying&quot;<br />
and &quot;show warranty&quot; for details.<br />
This GDB was configured as &quot;i486-linux-gnu&quot;.<br />
For bug reporting instructions, please see:<br />
&lt;http://www.gnu.org/software/gdb/bugs/&gt;...<br />
Reading symbols from /home/apache-2.2.2/bin/httpd...done.<br />
<br />
(gdb) b ap_process_request<br />
Breakpoint 1 at 0x80b2409: file http_request.c, line 252.<br />
(gdb) run -X -d /home/apache<br />
Starting program: /home/apache-2.2.2/bin/httpd -X -d /home/apache<br />
[Thread debugging using libthread_db enabled]<br />
<br />
Breakpoint 1, ap_process_request (r=0x831e390) at http_request.c:252<br />
252 &nbsp; &nbsp; &nbsp; &nbsp; if (ap_extended_status)<br />
(gdb) n<br />
235 &nbsp; &nbsp; {<br />
(gdb) n<br />
252 &nbsp; &nbsp; &nbsp; &nbsp; if (ap_extended_status)<br />
(gdb) n<br />
254 &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_run_quick_handler(r, 0); &nbsp;/* Not a look-up request */<br />
(gdb) n<br />
255 &nbsp; &nbsp; &nbsp; &nbsp; if (access_status == DECLINED) {<br />
(gdb) n<br />
256 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_process_request_internal(r);<br />
(gdb) n<br />
257 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (access_status == OK) {<br />
(gdb) n<br />
258 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_status = ap_invoke_handler(r);<br />
(gdb) n<br />
<br />
Program received signal SIGSEGV, Segmentation fault.<br />
0x0079b611 in php_handler (r=0x831e390)<br />
&nbsp; &nbsp; at /home/kawasaki/src/php/php-5.3.3/sapi/apache2handler/sapi_apache2.c:550<br />
550 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conf = ap_get_module_config(r-&gt;per_dir_config, &amp;php5_module);<br />
(gdb) n<br />
<br />
(gdb) bt<br />
#0 &nbsp;0x0079b611 in php_handler (r=0x831e390)<br />
&nbsp; &nbsp; at /home/kawasaki/src/php/php-5.3.3/sapi/apache2handler/sapi_apache2.c:550<br />
#1 &nbsp;0x0807aa47 in ap_run_handler (r=0x831e390) at config.c:157<br />
#2 &nbsp;0x0807db31 in ap_invoke_handler (r=0x831e390) at config.c:371<br />
#3 &nbsp;0x080b2578 in ap_process_request (r=0x831e390) at http_request.c:258<br />
#4 &nbsp;0x080af81e in ap_process_http_connection (c=0x8314348) at http_core.c:172<br />
#5 &nbsp;0x080817c7 in ap_run_process_connection (c=0x8314348) at connection.c:43<br />
#6 &nbsp;0x080cf1d4 in child_main (child_num_arg=&lt;value optimised out&gt;) at prefork.c:640<br />
#7 &nbsp;0x080cf434 in make_child (s=0x8109f78, slot=0) at prefork.c:680<br />
#8 &nbsp;0x080d01fa in ap_mpm_run (_pconf=0x81010a8, plog=0x814b1d0, s=0x8109f78)<br />
&nbsp; &nbsp; at prefork.c:956<br />
#9 &nbsp;0x0806872f in main (argc=135262496, argv=0x0) at main.c:717</div></div>
<p>参考: <a href="http://httpd.apache.org/dev/debugging.html#gdb">Apache Debugging Guide: Using gdb</a></p>
<p>落ちている箇所、php_handler (php-5.3.3/sapi/apache2handler/sapi_apache2.c:550)のソースコード</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000dd;">538</span> <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> php_handler<span style="color: #009900;">&#40;</span>request_rec <span style="color: #339933;">*</span>r<span style="color: #009900;">&#41;</span><br />
<span style="color: #0000dd;">539</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">540</span> &nbsp; &nbsp; php_struct <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> ctx<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">541</span> &nbsp; &nbsp; <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>conf<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">542</span> &nbsp; &nbsp; apr_bucket_brigade <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> brigade<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">543</span> &nbsp; &nbsp; apr_bucket <span style="color: #339933;">*</span>bucket<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">544</span> &nbsp; &nbsp; apr_status_t rv<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">545</span> &nbsp; &nbsp; request_rec <span style="color: #339933;">*</span> <span style="color: #993333;">volatile</span> parent_req <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">546</span> &nbsp; &nbsp; TSRMLS_FETCH<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">547</span><br />
<span style="color: #0000dd;">548</span> <span style="color: #339933;">#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);</span><br />
<span style="color: #0000dd;">549</span><br />
<span style="color: #0000dd;">550</span> &nbsp; &nbsp; conf <span style="color: #339933;">=</span> ap_get_module_config<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>per_dir_config<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>php5_module<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">551</span><br />
<span style="color: #0000dd;">552</span> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* apply_config() needs r in some cases, so allocate server_context early */</span><br />
<span style="color: #0000dd;">553</span> &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">554</span> &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ctx <span style="color: #339933;">==</span> NULL <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>ctx <span style="color: #339933;">&amp;&amp;</span> ctx<span style="color: #339933;">-&gt;</span>request_processed <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>strcmp<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>protocol<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;INCLUDED&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">555</span> normal<span style="color: #339933;">:</span><br />
<span style="color: #0000dd;">556</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> apr_pcalloc<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">557</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* register a cleanup so we clear out the SG(server_context)<br />
558 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* after each request. Note: We pass in the pointer to the<br />
559 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* server_context in case this is handled by a different thread.<br />
560 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
<span style="color: #0000dd;">561</span> &nbsp; &nbsp; &nbsp; &nbsp; apr_pool_cleanup_register<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>SG<span style="color: #009900;">&#40;</span>server_context<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> php_server_context_cleanup<span style="color: #339933;">,</span> apr_pool_cleanup_null<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">562</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx<span style="color: #339933;">-&gt;</span>r <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">563</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* May look weird to null it here, but it is to catch the right case in the first_try later on */</span><br />
<span style="color: #0000dd;">564</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #0000dd;">565</span> &nbsp; &nbsp; &nbsp; &nbsp; parent_req <span style="color: #339933;">=</span> ctx<span style="color: #339933;">-&gt;</span>r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">566</span> &nbsp; &nbsp; &nbsp; &nbsp; ctx<span style="color: #339933;">-&gt;</span>r <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span><br />
<span style="color: #0000dd;">567</span> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #0000dd;">568</span> &nbsp; &nbsp; apply_config<span style="color: #009900;">&#40;</span>conf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>php5 モジュールの設定情報読み込み時にSegmentation fault(11)でApacheがCrashしている。 理由がわからない。とりあえず調査はここで止め、Apacheの設定ファイルからはphp5 モジュールのロード設定をはずしている。 早まった考えかもしれないがPHPを使うのやめてしまおうかと思っている今日この頃。PHPなんて。。</p>
<p>おわり</p>
<p><h2><strong>追記 2010.12.05</strong></h2>
<p>Apache-2.2.2、PHP-5.3.3共にアンインストールして再インストールしたところ問題なく動いてしまった。evidenceを集め、問題を特定する、それしかないと思い込み（だらだらと）調査していたのでとりあえず再インストールしてみる選択肢は頭になかった。結論として、（素人ぽくてアレなんだけど）困ったときは再インストールしろ &#8211; ということだ。 </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/11/30/php5apache2_segmentation_fault_under_ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgraded to Ubuntu 10.04 LTS</title>
		<link>http://yk55.com/blog/2010/06/03/upgraded_to_ubuntu1004lts/</link>
		<comments>http://yk55.com/blog/2010/06/03/upgraded_to_ubuntu1004lts/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 11:24:20 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Random Topics]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=349</guid>
		<description><![CDATA[3月にXPS M1210にUbuntu 9.10を入れたばかりではあるが4月末にUbuntu 10.04 LTSがリリースされて各所でその完成度の高さが謳われていたのでタイミングを見計らってアップグレードしてみた。9.10からは10.04LTSに直接アップグレードが可能。 今回はアップデートマネジャーの指示に従いポチポチボタンを押しただけ。 so easy, so goodだよ。 Ubuntu 10.04 LTSリリースノート Ubuntu 10.04 LTSへアップグレードを行うには]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/yk55/4652598485/" title="Ubuntu 10.04 LTS by yoichi*, on Flickr"><img src="http://farm5.static.flickr.com/4026/4652598485_fe9d7b7689_b.jpg" width="700" height="438" alt="Ubuntu 10.04 LTS" /></a></p>
<p><a href="http://yk55.com/blog/2010/03/27/ubuntu910_on_my_dell_xpsm1210/">3月</a>にXPS M1210にUbuntu 9.10を入れたばかりではあるが4月末にUbuntu 10.04 LTSがリリースされて各所でその完成度の高さが謳われていたのでタイミングを見計らってアップグレードしてみた。9.10からは10.04LTSに直接アップグレードが可能。 今回はアップデートマネジャーの指示に従いポチポチボタンを押しただけ。 so easy, so goodだよ。</p>
<p><a href="https://wiki.ubuntu.com/LucidLynx/ReleaseNotes/ja">Ubuntu 10.04 LTSリリースノート</a><br />
<a href="https://wiki.ubuntulinux.jp/UbuntuTips/Install/UpgradeLucid">Ubuntu 10.04 LTSへアップグレードを行うには</a></p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/06/03/upgraded_to_ubuntu1004lts/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/06/03/upgraded_to_ubuntu1004lts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.10 on my Dell XPS M1210</title>
		<link>http://yk55.com/blog/2010/03/27/ubuntu910_on_my_dell_xpsm1210/</link>
		<comments>http://yk55.com/blog/2010/03/27/ubuntu910_on_my_dell_xpsm1210/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 14:22:48 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Random Topics]]></category>
		<category><![CDATA[colinux]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=286</guid>
		<description><![CDATA[Vista on Dell XPS M1210（CeleronM,1GMEM）というサイテーに遅いOSの上でvmwareやcolinuxを通じてLinuxを動かしているとそのあまりの遅さに端末を捨ててしまいたくなる衝動にかられていた。なのでたまにTV見ながら膝上に乗せて遊んであげていたけどその遅さ故に使うことが憚られその存在は忘れがちに。 そこで試しに入れてみたUbuntu 9.10。 デュアルブートではなく男らしくフルUbuntu。 Hibernateも問題なく動作しているしサクサク動いて快適。 よみがえったよXPS M1210。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/yk55/4467092436/" title="Ubuntu 9.10 on my Dell XPS M1210 by yoichi*, on Flickr"><img src="http://farm5.static.flickr.com/4001/4467092436_3788a795e7_o.png" width="700" height="438" alt="Ubuntu 9.10 on my Dell XPS M1210" /></a></p>
<p>
Vista on Dell XPS M1210（CeleronM,1GMEM）というサイテーに遅いOSの上で<a href="http://www.vmware.com/">vmware</a>や<a href="http://www.colinux.org/">colinux</a>を通じてLinuxを動かしているとそのあまりの遅さに端末を捨ててしまいたくなる衝動にかられていた。なのでたまにTV見ながら膝上に乗せて遊んであげていたけどその遅さ故に使うことが憚られその存在は忘れがちに。 そこで試しに入れてみた<a href="http://www.ubuntu.com/">Ubuntu</a> 9.10。 デュアルブートではなく男らしくフルUbuntu。 Hibernateも問題なく動作しているしサクサク動いて快適。 よみがえったよXPS M1210。</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/03/27/ubuntu910_on_my_dell_xpsm1210/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/03/27/ubuntu910_on_my_dell_xpsm1210/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scatter/Gather I/O(readv/writev)の実装</title>
		<link>http://yk55.com/blog/2010/01/31/readv_writev_implementation/</link>
		<comments>http://yk55.com/blog/2010/01/31/readv_writev_implementation/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 02:03:15 +0000</pubDate>
		<dc:creator>yoichi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://yk55.com/blog/?p=86</guid>
		<description><![CDATA[readv、writevは複数バッファをまとめて読み書きするシステムコールです。 writevはiovec 構造体の配列に書き込みたいものを突っ込んでまとめてその複数バッファーを書き込み、readvは指定した個数分の複数バッファーをiovec 構造体の配列に格納します。例えばwritevによる複数バッファの書き込みはこんな感じです。 #include &#60;stdio.h&#62; #include &#60;unistd.h&#62; #include &#60;fcntl.h&#62; #include &#60;string.h&#62; #include &#60;sys/uio.h&#62; int &#160;main&#40; int argc, char** argv &#41; &#123; &#160; &#160; int fd = 0; &#160; &#160; ssize_t written; &#160; &#160; struct iovec iov&#91;3&#93;; &#160; &#160; char *buffer0, *buffer1, *buffer2; &#160; &#160; char *file = argv&#91;1&#93;; &#160; &#160; fd = open&#40; file, [...]]]></description>
			<content:encoded><![CDATA[<p>readv、writevは複数バッファをまとめて読み書きするシステムコールです。 writevはiovec 構造体の配列に書き込みたいものを突っ込んでまとめてその複数バッファーを書き込み、readvは指定した個数分の複数バッファーをiovec 構造体の配列に格納します。例えばwritevによる複数バッファの書き込みはこんな感じです。</p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#include &lt;unistd.h&gt;</span><br />
<span style="color: #339933;">#include &lt;fcntl.h&gt; </span><br />
<span style="color: #339933;">#include &lt;string.h&gt;</span><br />
<span style="color: #339933;">#include &lt;sys/uio.h&gt;</span><br />
<span style="color: #993333;">int</span> <br />
&nbsp;main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">**</span> argv <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> fd <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; ssize_t written<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> iovec iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer0<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>buffer1<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>buffer2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>file <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fd <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span> file<span style="color: #339933;">,</span> &nbsp;O_RDWR<span style="color: #339933;">|</span>O_CREAT<span style="color: #339933;">|</span>O_EXCL<span style="color: #339933;">,</span> <span style="color: #208080;">0666</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> fd <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;cannot open file:%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; buffer0 <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;buffer0 string&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; buffer1 <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;buffer1 string&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; buffer2 <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;buffer2 string&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_base</span> <span style="color: #339933;">=</span> buffer0<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_len</span> <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>buffer0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_base</span> <span style="color: #339933;">=</span> buffer1<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_len</span> <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>buffer1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_base</span> <span style="color: #339933;">=</span> buffer2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; iov<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">iov_len</span> <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>buffer2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; written <span style="color: #339933;">=</span> writev<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> iov<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; close<span style="color: #009900;">&#40;</span>fd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><span style="text-decoration: underline;">※iovec 構造体の定義 </span></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* Structure for scatter/gather I/O. &nbsp;*/</span><br />
<span style="color: #993333;">struct</span> iovec<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>iov_base<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Pointer to data. &nbsp;*/</span><br />
&nbsp; &nbsp;size_t iov_len<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Length of data. &nbsp;*/</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p><a href="http://www.linux.or.jp/JM/html/LDP_man-pages/man2/readv.2.html">man</a>によると基本的にはこのシステムコールの特徴は次の2つです。</p>
<ol>
<li>1.  readv、writevともに複数のバッファにデータを読み込む点を除いてそれぞれread(2)、write(2)と全く同様の動作を行う。</li>
<li>2.  readvと writevともにatomic。writevによるデータ書き込み中に他のスレッド、プロセスのwrite による割り込みが入らない。readvも同様にファイルから連続するデータブロックが読み出すことを保証。 </li>
</ol>
<p>本当にこのシステムコールが上記のような実装になっているのか確かめるために実際にソースコードを覗いてみます。readv、writevでは内部で次のdo_readv_writev関数がコールされます。</p>
<p><span style="text-decoration: underline;">do_readv_writev @ linux-2.6.12.1/fs/read_write.c</span></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">static</span> ssize_t do_readv_writev<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> type<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>file<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> iovec __user <span style="color: #339933;">*</span> uvector<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> nr_segs<span style="color: #339933;">,</span> loff_t <span style="color: #339933;">*</span>pos<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #202020;">ret</span> <span style="color: #339933;">=</span> rw_verify_area<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> file<span style="color: #339933;">,</span> pos<span style="color: #339933;">,</span> tot_len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ret<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fnv <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>type <span style="color: #339933;">==</span> READ<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fn <span style="color: #339933;">=</span> file<span style="color: #339933;">-&gt;</span>f_op<span style="color: #339933;">-&gt;</span>read<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fnv <span style="color: #339933;">=</span> file<span style="color: #339933;">-&gt;</span>f_op<span style="color: #339933;">-&gt;</span>readv<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>io_fn_t<span style="color: #009900;">&#41;</span>file<span style="color: #339933;">-&gt;</span>f_op<span style="color: #339933;">-&gt;</span>write<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fnv <span style="color: #339933;">=</span> file<span style="color: #339933;">-&gt;</span>f_op<span style="color: #339933;">-&gt;</span>writev<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fnv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">=</span> fnv<span style="color: #009900;">&#40;</span>file<span style="color: #339933;">,</span> iov<span style="color: #339933;">,</span> nr_segs<span style="color: #339933;">,</span> pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Do it by hand, with file-ops */</span><br />
&nbsp; &nbsp; ret <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; vector <span style="color: #339933;">=</span> iov<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>nr_segs <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">void</span> __user <span style="color: #339933;">*</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size_t len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ssize_t nr<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; base <span style="color: #339933;">=</span> vector<span style="color: #339933;">-&gt;</span>iov_base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; len <span style="color: #339933;">=</span> vector<span style="color: #339933;">-&gt;</span>iov_len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vector<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; nr_segs<span style="color: #339933;">--;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; nr <span style="color: #339933;">=</span> fn<span style="color: #009900;">&#40;</span>file<span style="color: #339933;">,</span> base<span style="color: #339933;">,</span> len<span style="color: #339933;">,</span> pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>nr <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ret<span style="color: #009900;">&#41;</span> ret <span style="color: #339933;">=</span> nr<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ret <span style="color: #339933;">+=</span> nr<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>nr <span style="color: #339933;">!=</span> len<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>後半のwhileブロックを見るとたしかにreadv、writevのときそれぞれ内部でread、writeがループで繰り返されています。 想像を超えたシンプルさでした。次にatomicを保障している箇所ですがREADかWRITEのtypeチェックを行う前のrw_verify_areaがそれっぽい。ということでrw_verify_areaを覗いてみます。</p>
<p><span style="text-decoration: underline;">rw_verify_area @ linux-2.6.12.1/fs/read_write.c</span></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> rw_verify_area<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> read_write<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>file<span style="color: #339933;">,</span> loff_t <span style="color: #339933;">*</span>ppos<span style="color: #339933;">,</span> size_t count<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> inode <span style="color: #339933;">*</span>inode<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; loff_t pos<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>unlikely<span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&gt;</span> file<span style="color: #339933;">-&gt;</span>f_maxcount<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">goto</span> Einval<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; pos <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>ppos<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>unlikely<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>loff_t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">+</span> count<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">goto</span> Einval<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; inode <span style="color: #339933;">=</span> file<span style="color: #339933;">-&gt;</span>f_dentry<span style="color: #339933;">-&gt;</span>d_inode<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>inode<span style="color: #339933;">-&gt;</span>i_flock <span style="color: #339933;">&amp;&amp;</span> MANDATORY_LOCK<span style="color: #009900;">&#40;</span>inode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> locks_mandatory_area<span style="color: #009900;">&#40;</span>read_write <span style="color: #339933;">==</span> READ <span style="color: #339933;">?</span> FLOCK_VERIFY_READ <span style="color: #339933;">:</span> FLOCK_VERIFY_WRITE<span style="color: #339933;">,</span> inode<span style="color: #339933;">,</span> file<span style="color: #339933;">,</span> pos<span style="color: #339933;">,</span> count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
Einval<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>ここではファイルの読み込み・書き込みエリアのバリデーションチェックとlocks_mandatory_areaで排他チェックを行っています。念のためlocks_mandatory_areaを覗いてみます。</p>
<p><span style="text-decoration: underline;">locks_mandatory_area @ linux-2.6.12.1/fs/locks.c</span></p>
<div class="codecolorer-container c mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/**<br />
&nbsp;* locks_mandatory_area - Check for a conflicting lock<br />
&nbsp;* @read_write: %FLOCK_VERIFY_WRITE for exclusive access, %FLOCK_VERIFY_READ<br />
&nbsp;* &nbsp; &nbsp; &nbsp;for shared<br />
&nbsp;* @inode: &nbsp; &nbsp; &nbsp;the file to check<br />
&nbsp;* @filp: &nbsp; &nbsp; &nbsp; how the file was opened (if it was)<br />
&nbsp;* @offset: &nbsp; &nbsp; start of area to check<br />
&nbsp;* @count: &nbsp; &nbsp; &nbsp;length of area to check<br />
&nbsp;*<br />
&nbsp;* Searches the inode's list of locks to find any POSIX locks which conflict.<br />
&nbsp;* This function is called from rw_verify_area() and<br />
&nbsp;* locks_verify_truncate().<br />
&nbsp;*/</span><br />
<span style="color: #993333;">int</span> locks_mandatory_area<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> read_write<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> inode <span style="color: #339933;">*</span>inode<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>filp<span style="color: #339933;">,</span> loff_t offset<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;size_t count<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> file_lock fl<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> error<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; locks_init_lock<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>fl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_owner</span> <span style="color: #339933;">=</span> current<span style="color: #339933;">-&gt;</span>files<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_pid</span> <span style="color: #339933;">=</span> current<span style="color: #339933;">-&gt;</span>tgid<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_file</span> <span style="color: #339933;">=</span> filp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_flags</span> <span style="color: #339933;">=</span> FL_POSIX <span style="color: #339933;">|</span> FL_ACCESS<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>filp <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>filp<span style="color: #339933;">-&gt;</span>f_flags <span style="color: #339933;">&amp;</span> O_NONBLOCK<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fl.<span style="color: #202020;">fl_flags</span> <span style="color: #339933;">|=</span> FL_SLEEP<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_type</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>read_write <span style="color: #339933;">==</span> FLOCK_VERIFY_WRITE<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> F_WRLCK <span style="color: #339933;">:</span> F_RDLCK<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_start</span> <span style="color: #339933;">=</span> offset<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fl.<span style="color: #202020;">fl_end</span> <span style="color: #339933;">=</span> offset <span style="color: #339933;">+</span> count <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #339933;">=</span> __posix_lock_file<span style="color: #009900;">&#40;</span>inode<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>fl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>error <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span>EAGAIN<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>fl.<span style="color: #202020;">fl_flags</span> <span style="color: #339933;">&amp;</span> FL_SLEEP<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #339933;">=</span> wait_event_interruptible<span style="color: #009900;">&#40;</span>fl.<span style="color: #202020;">fl_wait</span><span style="color: #339933;">,</span> <span style="color: #339933;">!</span>fl.<span style="color: #202020;">fl_next</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* If we've been sleeping someone might have<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* changed the permissions behind our back.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>inode<span style="color: #339933;">-&gt;</span>i_mode <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span>S_ISGID <span style="color: #339933;">|</span> S_IXGRP<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> S_ISGID<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; locks_delete_block<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>fl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> error<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><span style="text-decoration: underline;">※ kernelソースコード<a href="http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.12.1.tar.gz">linux-2.6.12.1</a></span> </p>
<p>以上、簡単ではありますがreadv、writevの実装でした。 このシステムコールはこれまで何度か業務で利用していておなじみな物のではありましたが特に内部の実装を気にすることなく使ってました。実際に見てみると単純な複数バッファ分のread, writeの繰り返しではありますがその処理間に排他制御がしっかりされているのでパフォーマンスはさておき安心して使えると思います。その辺の自分で実装するのは面倒ですから。</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http://yk55.com/blog/2010/01/31/readv_writev_implementation/&amp;layout=button_count&amp;show_faces=1&amp;width=450&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>]]></content:encoded>
			<wfw:commentRss>http://yk55.com/blog/2010/01/31/readv_writev_implementation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	<!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) --></channel>
</rss>

