On Tuesday, 2011-02-15 at 13:16:58 -0000, Arnaud Quette wrote:

> this is not the problem. This code is in the smartmode() function of
> apcsmart.c:
> http://svn.debian.org/wsvn/nut/trunk/drivers/apcsmart.c

> we see the 5 attempts to go to smart mode ('Y' command), but my aim is to
> understand why it is failing, and how to cleanly solve this without
> impacting support for other units.

I found no code that does five attempts. But this code in main.c,
starting on Line 618:

        while (!exit_flag) {

                struct timeval  timeout;

                gettimeofday(&timeout, NULL);
                timeout.tv_sec += poll_interval;

                upsdrv_updateinfo();

                while (!dstate_poll_fds(timeout, extrafd) && !exit_flag) {
                        /* repeat until time is up or extrafd has data */


upsdrv_updateinfo() calls smartmode().

dstate_poll_fds() checks if there is any file descriptor that is
"available". In our case:

select(7, [4 5 6], NULL, NULL, {1, 999837}) = 1 (in [4], left {1,
999835})

FD 4 is the serial line, which is passed to dstate_poll_fds() as
extrafd.

When there is data that can be read from the UPS no code in
dstate_poll_fds() reads from extrafd, there is only code that reads
from the other input FDs. The outer loop above also ignores extrafd.
exit_flag is never set, so it continues. And because there is an active
file descriptor, the select returns immediately (actually it takes two
microseconds).

The solution is to add code that reads all data from extrafd and discards
it because nobody asked for it. I would also close and reopen the serial
line in smartmode(). I would prepare a patch if I knew more about the
I/O abstractions used in the nut driver code. Sorry.

HTH,
Lupe Christoph
-- 
| It is a well-known fact in any organisation that, if you want a job    |
| done, you should give it to someone who is already very busy.          |
| Terry Pratchett, "Unseen Academicals"                                  |

-- 
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to nut in ubuntu.
https://bugs.launchpad.net/bugs/535583

Title:
  Excessive logging by apcsmart program

-- 
Ubuntu-server-bugs mailing list
Ubuntu-server-bugs@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-server-bugs

Reply via email to