<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Being Cellfish : *nix</title><link>http://blogs.msdn.com/cellfish/archive/tags/_2A00_nix/default.aspx</link><description>Tags: *nix</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>pthread_cond_timedwait behaving differently on different platforms</title><link>http://blogs.msdn.com/cellfish/archive/2009/09/01/pthread-cond-timedwait-behaving-differently-on-different-platforms.aspx</link><pubDate>Tue, 01 Sep 2009 19:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889696</guid><dc:creator>cellfish</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/9889696.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=9889696</wfw:commentRss><description>&lt;P&gt;pthread_cond_timedwait is a nice little function that can be used to "atomically" release a mutex, wait for a condition with a timeout&amp;nbsp;and then acquire the mutex. The first pitfall of this method is that the "timeout" is an absolute time, not a relative time as with most timeouts. Other than that it works fine for most platforms I've encountered. Until I used it on a BSD based system. Suddenly the code did not work in some cases. I managed to track it down to the situation where the time had already passed in which case I got odd behavior.&lt;/P&gt;
&lt;P&gt;Turns out most platforms implement this method in a way so that if the time have passed, the mutex is released and reacquired immediately (an assumption used in the code I was working on), but on BSD this is not the case. For most platforms the MAN-page clearly states that this is the case (i.e. release and reacquire the mutex) but for BSD it says nothing about it. I can only assume there is an optimization in the code skipping the release-reacquire action if the time have already passed. I think that is an odd behavior since it blocks any other threads waiting for that mutex (unless you work around it with an extra release-acquire scheme).&lt;/P&gt;
&lt;P&gt;So know your APIs and be careful if you're writing code for several platforms. And I can ensure that a number of unit tests exploring the behavior of an API can save time trouble shooting differences like this.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889696" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/_2A00_nix/default.aspx">*nix</category></item><item><title>Mounting a file system to an FTP server</title><link>http://blogs.msdn.com/cellfish/archive/2009/05/16/mounting-a-file-system-to-an-ftp-server.aspx</link><pubDate>Sun, 17 May 2009 06:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9623922</guid><dc:creator>cellfish</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/9623922.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=9623922</wfw:commentRss><description>&lt;P&gt;I recently needed to move all my private domains to a new hosting solution and the new solution did not allow any other access than FTP. I considered setting up a mirror on my ubuntu host at home but that didn't feel like the best solution. So I thought there must be a way to mount a file system using FTP. And there is several I think. The one I tested and that looks good so far is &lt;A href="http://curlftpfs.sourceforge.net/" target=_blank mce_href="http://curlftpfs.sourceforge.net/"&gt;curlftpfs&lt;/A&gt;. The only tweak not mentioned on the curlftpfs site (in an obvious place) is that you need to put the following in your /etc/fstab to make sure all users (and not just root) have access to the mounted file system:&lt;/P&gt;
&lt;P&gt;curlftpfs#ftp-user:ftp-password@ftp-host /mount/point fuse rw,uid=500,user,allow_other,noauto 0 0&lt;/P&gt;
&lt;P&gt;"allow_other" is the magic enabling all users access. Since it uses FTP under the hood you will notice the file system is quite slow at times. Especially when editing large files. But compared with having a local mirror and updating all changed files when needed I think this a pretty convenient way to access the files on the FTP server.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9623922" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/_2A00_nix/default.aspx">*nix</category></item><item><title>A reminder if you want to read/write your file in non blocking mode (in C(++))</title><link>http://blogs.msdn.com/cellfish/archive/2009/04/16/a-reminder-if-you-want-to-read-write-your-file-in-non-blocking-mode-in-c.aspx</link><pubDate>Thu, 16 Apr 2009 14:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9552063</guid><dc:creator>cellfish</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/9552063.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=9552063</wfw:commentRss><description>&lt;P&gt;Sometimes you might want to read a file &lt;A href="http://en.wikipedia.org/wiki/Non-blocking_I/O" target=_blank mce_href="http://en.wikipedia.org/wiki/Non-blocking_I/O"&gt;non-blocking&lt;/A&gt;. It could be &lt;A href="http://en.wikipedia.org/wiki//dev/random" target=_blank mce_href="http://en.wikipedia.org/wiki//dev/random"&gt;/dev/random&lt;/A&gt; because waiting for entropy might take very long. Also when you have to read device files on unix you sometimes have to read them non-blocking. A common pattern is to open the file non-blocking using the &lt;A href="http://linux.die.net/man/2/open" target=_blank mce_href="http://linux.die.net/man/2/open"&gt;open&lt;/A&gt; method: open(..., O_NONBLOCK, ...)&lt;/P&gt;
&lt;P&gt;This however may be a problem. This type of open will typically succeed (because the system is opening the file non-blocking) and when you then start reading (or writing) you get a failure. The failure can be anything from permission problems to unavailable devices. This is how non-blocking I/O works and something you're well aware of if you're using sockets for communication but since "this is files" you might forget to take non-blocking into account.&lt;/P&gt;
&lt;P&gt;So there is a really easy way to work around this. Files, unlike network sockets completes the open operation very fast. So making the open call non-blocking generally does not make so much sense. Instead I suggest you open the file in blocking mode and then change it to non-blocking one opened. And this is how you do that:&lt;/P&gt;
&lt;P&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;PRE&gt;&lt;DIV class=csharpcode&gt;
&lt;SPAN class=lnum&gt;   1:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; fd = open(..., 0, ...); &lt;SPAN class=rem&gt;// Filed open in blocking&lt;/SPAN&gt;
&lt;SPAN class=lnum&gt;   2:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; fd_flags = fcntl(fd, F_GETFL);
&lt;SPAN class=lnum&gt;   3:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (fd_flags &amp;lt; 0) { &lt;SPAN class=rem&gt;// Get any flags set on the fd.&lt;/SPAN&gt;
&lt;SPAN class=lnum&gt;   4:  &lt;/SPAN&gt;    close(fd);
&lt;SPAN class=lnum&gt;   5:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; error;
&lt;SPAN class=lnum&gt;   6:  &lt;/SPAN&gt;}
&lt;SPAN class=lnum&gt;   7:  &lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (-1 == fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK)) { &lt;SPAN class=rem&gt;// Add non blocking to the fd flags&lt;/SPAN&gt;
&lt;SPAN class=lnum&gt;   8:  &lt;/SPAN&gt;    close(fd);
&lt;SPAN class=lnum&gt;   9:  &lt;/SPAN&gt;    &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; error;
&lt;SPAN class=lnum&gt;  10:  &lt;/SPAN&gt;}
&lt;/DIV&gt;&lt;/PRE&gt;
&lt;P&gt;But there is (at least) one situation where a non-blocking open might make some sense. That is when you open a file on a remote server and you cannot afford the waiting of an open call. And in this case you must treat the file descriptor like any other file descriptor used for network communication and use&amp;nbsp;&lt;A href="http://en.wikipedia.org/wiki/Select_(Unix)" target=_blank mce_href="http://en.wikipedia.org/wiki/Select_(Unix)"&gt;select&lt;/A&gt; to make sure the file descriptor is ready before you start using it.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9552063" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/_2A00_nix/default.aspx">*nix</category></item><item><title>Fixing disk configuration/statistics mismatch on HPUX</title><link>http://blogs.msdn.com/cellfish/archive/2009/04/10/fixing-disk-configuration-statistics-mismatch-on-hpux.aspx</link><pubDate>Fri, 10 Apr 2009 14:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9542375</guid><dc:creator>cellfish</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/9542375.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=9542375</wfw:commentRss><description>&lt;P&gt;I recently was involved in troubleshooting a problem on a HPUX system.It turned out that the system command &lt;EM&gt;iostat&lt;/EM&gt; showed one disk and the configuration (/etc/lvmtab) showed another disk. Yet another symptom was that &lt;EM&gt;lvdisplay&lt;/EM&gt; didn't work at all. Since there had been a bunch of activity on that system it took some detective work to find out that the reason for the problem was that the raid controller had been replaced.&lt;/P&gt;
&lt;P&gt;So this still amazes me. The configuration said one thing and the monitoring tools another but still the host worked just fine. Actually it was a little slow but apparently the mix-up of disk devices didn't matter. So when other systems have their hardware changed you need to rescan it so how do you do that on HPUX? Well this is how you fix your disk configuration if you have one volume group named "vg00":&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;In multiuser mode:&lt;BR&gt;&lt;/EM&gt;&lt;STRONG&gt;#/sbin/vgexport -m /vg00.map -s -p -v vg00&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;EM&gt;Reboot the system and go to maintenance mode:&lt;BR&gt;&lt;/EM&gt;&lt;STRONG&gt;#shutdown -ry 0 &lt;/STRONG&gt;&lt;EM&gt;[Esc]&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Main Menu: boot pri isl&lt;BR&gt;Interact with the IPL?&amp;gt; y&lt;BR&gt;ISL&amp;gt; hpux –lm&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;STRONG&gt;#/sbin/vgexport -v vg00&lt;BR&gt;#/sbin/mkdir /dev/vg00&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;EM&gt;Create the special device file (SDF), use the next available minor number:&lt;/EM&gt;&lt;BR&gt;&lt;STRONG&gt;#/sbin/mknod /dev/vg00/group c 64 0x##0000&lt;BR&gt;#/sbin/vgimport -m /vg00.map -N -v -s vg00 vgchange -a y vg00&lt;/STRONG&gt; &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&lt;EM&gt;Reboot the system to multiuser mode again.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Preemptive comment response&lt;/STRONG&gt;&lt;/EM&gt;: No I don't know why the system was not reconfigured immediately after replacing the RAID controller. Probably because everything seamed to work after booting.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9542375" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/_2A00_nix/default.aspx">*nix</category></item></channel></rss>