Hi Lupe,<br><br>since we now have an apcsmart maintainer, I&#39;m forwarding this issue to him.<br><br>@Michal: could you please have a look at this issue [1], and give us your feeling?<br><br>cheers,<br>Arnaud<br>--<br>[1] <a href="https://bugs.launchpad.net/bugs/535583" target="_blank">https://bugs.launchpad.net/bugs/535583</a><br>
<br><div class="gmail_quote">2011/2/15 Lupe Christoph <span dir="ltr">&lt;<a href="mailto:lupe@lupe-christoph.de">lupe@lupe-christoph.de</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Tuesday, 2011-02-15 at 13:16:58 -0000, Arnaud Quette wrote:<br>
<br>
&gt; this is not the problem. This code is in the smartmode() function of<br>
&gt; apcsmart.c:<br>
&gt; <a href="http://svn.debian.org/wsvn/nut/trunk/drivers/apcsmart.c" target="_blank">http://svn.debian.org/wsvn/nut/trunk/drivers/apcsmart.c</a><br>
<br>
&gt; we see the 5 attempts to go to smart mode (&#39;Y&#39; command), but my aim is to<br>
&gt; understand why it is failing, and how to cleanly solve this without<br>
&gt; impacting support for other units.<br>
<br>
</div>I found no code that does five attempts. But this code in main.c,<br>
starting on Line 618:<br>
<br>
        while (!exit_flag) {<br>
<br>
                struct timeval  timeout;<br>
<br>
                gettimeofday(&amp;timeout, NULL);<br>
                timeout.tv_sec += poll_interval;<br>
<br>
                upsdrv_updateinfo();<br>
<br>
                while (!dstate_poll_fds(timeout, extrafd) &amp;&amp; !exit_flag) {<br>
                        /* repeat until time is up or extrafd has data */<br>
<br>
<br>
<br>
upsdrv_updateinfo() calls smartmode().<br>
<br>
dstate_poll_fds() checks if there is any file descriptor that is<br>
&quot;available&quot;. In our case:<br>
<div class="im"><br>
select(7, [4 5 6], NULL, NULL, {1, 999837}) = 1 (in [4], left {1, 999835})<br>
<br>
</div>FD 4 is the serial line, which is passed to dstate_poll_fds() as<br>
extrafd.<br>
<br>
When there is data that can be read from the UPS no code in<br>
dstate_poll_fds() reads from extrafd, there is only code that reads<br>
from the other input FDs. The outer loop above also ignores extrafd.<br>
exit_flag is never set, so it continues. And because there is an active<br>
file descriptor, the select returns immediately (actually it takes two<br>
microseconds).<br>
<br>
The solution is to add code that reads all data from extrafd and discards<br>
it because nobody asked for it. I would also close and reopen the serial<br>
line in smartmode(). I would prepare a patch if I knew more about the<br>
I/O abstractions used in the nut driver code. Sorry.<br>
<br>
HTH,<br>
<div><div></div><div class="h5">Lupe Christoph<br>
--<br>
| It is a well-known fact in any organisation that, if you want a job    |<br>
| done, you should give it to someone who is already very busy.          |<br>
| Terry Pratchett, &quot;Unseen Academicals&quot;                                  |<br>
</div></div></blockquote></div><br><br>