<html style="direction: ltr;">
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <style type="text/css">body p { margin-bottom: 0.2cm; margin-top: 0pt; } </style>
  </head>
  <body style="direction: ltr;"
    bidimailui-detected-decoding-type="UTF-8" bgcolor="#FFFFFF"
    text="#000000">
    <div class="moz-cite-prefix">On 18/06/13 17:43, Elazar Leibovich
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAHNTFmJKzDhhV8Emw0LM_cCa=d5WhOXyZNtgmDoTgSsiLcn9Zg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div style="">Try to open /dev/null, and then to poll the file
          descriptor. Neither in the man page nor in the standard I see
          anything preventing you to poll on /dev/null, yet, it does not
          work on Mac OS X. You get a POLLNVAL.</div>
        <div style=""><br>
        </div>
      </div>
    </blockquote>
    Under Linux, whether you can poll (epoll, select) a character device
    depends on the device's implementation. If the device implements it,
    then you can. If not, you can't.<br>
    <br>
    Under Linux, the device driver's implementer implements one
    callback, and the kernel uses that to allow select, poll and epoll
    (plus the "p" variants of the above) all at once. On Mac OS X,
    however, the BUGS line Oleg pointed to does not appear in the select
    syscall interface, which means that it might be possible to select a
    device file descriptor.<br>
    <br>
    Our of curiosity, however, why would you want to poll /dev/null?<br>
    <br>
    Shachar<br>
    <blockquote
cite="mid:CAHNTFmJKzDhhV8Emw0LM_cCa=d5WhOXyZNtgmDoTgSsiLcn9Zg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Run the following:
        <div><br>
        </div>
        <div><a moz-do-not-send="true"
            href="https://gist.github.com/elazarl/5805848">https://gist.github.com/elazarl/5805848</a><br>
          <div><br>
          </div>
          <div>
            <pre class="" style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:16px;width:744px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0)"><div class="" id="file-poll_dev-c-LC1"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include &lt;stdio.h&gt;</span></div><div class="" id="file-poll_dev-c-LC2"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include &lt;poll.h&gt;</span></div>
<div class="" id="file-poll_dev-c-LC3"> </div><div class="" id="file-poll_dev-c-LC4"><span class="" style="color:rgb(153,153,153);font-weight:bold">#include &lt;fcntl.h&gt;</span></div><div class="" id="file-poll_dev-c-LC5">
 </div><div class="" id="file-poll_dev-c-LC6"><span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">main</span><span class="">()</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC7">    <span class="" style="color:rgb(68,85,136);font-weight:bold">int</span> <span class="" style="color:rgb(51,51,51)">fd</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(51,51,51)">open</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"/dev/null"</span><span class="">,</span> <span class="" style="color:rgb(51,51,51)">O_WRONLY</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC8">    <span class="" style="font-weight:bold">struct</span> <span class="" style="color:rgb(51,51,51)">pollfd</span> <span class="" style="color:rgb(51,51,51)">pollfds</span> <span class="" style="font-weight:bold">=</span> <span class="">{</span> <span class="" style="color:rgb(51,51,51)">fd</span><span class="">,</span> <span class="" style="color:rgb(51,51,51)">POLLOUT</span><span class="">,</span> <span class="" style="color:rgb(0,153,153)">0</span> <span class="">};</span></div>
<div class="" id="file-poll_dev-c-LC9">    <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">fd</span> <span class="" style="font-weight:bold">&lt;</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC10">        <span class="" style="color:rgb(51,51,51)">perror</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"open"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC11">        <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="">;</span></div><div class="" id="file-poll_dev-c-LC12">
    <span class="">}</span></div><div class="" id="file-poll_dev-c-LC13">    <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">poll</span><span class="">(</span><span class="" style="font-weight:bold">&amp;</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">,</span> <span class="" style="color:rgb(0,153,153)">1</span><span class="">,</span> <span class="" style="font-weight:bold">-</span><span class="" style="color:rgb(0,153,153)">1</span><span class="">)</span> <span class="" style="font-weight:bold">&lt;</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC14">        <span class="" style="color:rgb(51,51,51)">perror</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"poll"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC15">        <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">2</span><span class="">;</span></div><div class="" id="file-poll_dev-c-LC16">
    <span class="">}</span></div><div class="" id="file-poll_dev-c-LC17">    <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">.</span><span class="" style="color:rgb(51,51,51)">revents</span> <span class="" style="font-weight:bold">==</span> <span class="" style="color:rgb(51,51,51)">POLLNVAL</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC18">        <span class="" style="color:rgb(51,51,51)">puts</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"huh? why poll({/dev/null, POLLOUT, 0}, 1) returns POLLNVAL?"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC19">    <span class="">}</span></div><div class="" id="file-poll_dev-c-LC20">    <span class="" style="font-weight:bold">if</span> <span class="">(</span><span class="" style="color:rgb(51,51,51)">pollfds</span><span class="">.</span><span class="" style="color:rgb(51,51,51)">revents</span> <span class="" style="font-weight:bold">==</span> <span class="" style="color:rgb(51,51,51)">POLLOUT</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="file-poll_dev-c-LC21">        <span class="" style="color:rgb(51,51,51)">puts</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"working as expected"</span><span class="">);</span></div>
<div class="" id="file-poll_dev-c-LC22">    <span class="">}</span></div><div class="" id="file-poll_dev-c-LC23">    <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="">;</span></div>
<div class="" id="file-poll_dev-c-LC24"><span class="">}</span></div><div class="" id="file-poll_dev-c-LC24"><span class="">
</span></div><div class="" id="file-poll_dev-c-LC24" style=""><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">Is there anything I'm missing? Or is it a real vaguely implemented corner of the standard.</span>

</div><div class="" id="file-poll_dev-c-LC24" style=""><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">If it is, I'll be glad to see a list of supported/unsupported platforms,</span></div>
<div class="" id="file-poll_dev-c-LC24" style=""><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">as well as list of other corner cases (for instance, POLLHUP may or may be received on EOF).</span></div>
<div class="" id="file-poll_dev-c-LC24" style=""><span style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal;white-space:normal">
</span></div></pre>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Linux-il mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a>
<a class="moz-txt-link-freetext" href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>