[PATCH 1/1] hwclock: Verify RTC file descriptor; use reentrant functions

Bryan Evenson bevenson at melinkcorp.com
Tue May 6 11:58:35 UTC 2014


Issac,

> -----Original Message-----
> From: Isaac Dunham [mailto:ibid.ag at gmail.com]
> Sent: Monday, May 05, 2014 4:41 PM
> To: Bryan Evenson
> Cc: Denys Vlasenko; busybox; griebl at gmx.de
> Subject: Re: [PATCH 1/1] hwclock: Verify RTC file descriptor; use reentrant
> functions
> 
> On Mon, May 05, 2014 at 03:45:28PM +0000, Bryan Evenson wrote:
> > I did get strace loaded on my system and I used that to get a better
> understanding of where the error occurs.  I modified my test script as
> follows:
> > ----------
> > #!/bin/sh
> > i=0
> > while [ 1 ]; do
> >   strace -f -o /home/root/hwclock_output_"$$_$i".txt /sbin/hwclock -w -u
> >   : $((i++))
> >   sleep 1;
> > done
> > ----------
> >
> > Again, on my system I was able to get an instance of hwclock to enter an
> uninterruptable sleep and hang within seconds when I ran two instances of
> the test script.  By checking the PID of the hung process and the PIDs in the
> output files, I found the strace of the hung process, which is shown below.
> >
> <snip>
> > 1808  ioctl(3, RTC_SET_TIME, {tm_sec=7, tm_min=5, tm_hour=14,
> > tm_mday=5, tm_mon=4, tm_year=114, ...}
> > ----------
> >
> > And here is the output from the hwclock instance that occurred from the
> other test script just before this one:
> >
> > ----------
> <snip>
> > 1799  ioctl(3, RTC_SET_TIME, {tm_sec=7, tm_min=5, tm_hour=14,
> tm_mday=5, tm_mon=4, tm_year=114, ...}) = 0
> > 1799  exit_group(0)                     = ?
> > 1799  +++ exited with 0 +++
> > ----------
> >
> > So on my system, hwclock is hanging on the ioctl to set the time.
> > Both the instance that set the time and the one that could not set the
> > time are trying to set the RTC to the same time.  So I'm assuming from
> > this output that there is something going wrong with the ioctl on my
> > RTC driver when two separate processes attempt to set the time at the
> > same time.  If I'm interpreting this correctly, I need to track down
> > what the RTC driver is doing wrong with the RTC_SET_TIME ioctl.
> >
> 
> Well, having two processes trying to set time is rather nonsensical.
> I suppose that the _right_ thing for the kernel to do would be have one block
> until the other finished, but...it makes sense to lock the fd.
> 
> So does the patch I'm attaching work for you?

I applied the patch just to see what would happen.  I'm still having the same problem.  At the end of the strace of the process that set the RTC I see:

----------
1256  flock(3, LOCK_EX)                 = 0
1256  ioctl(3, RTC_SET_TIME, {tm_sec=21, tm_min=48, tm_hour=11, tm_mday=6, tm_mon=4, tm_year=114, ...}) = 0
1256  flock(3, LOCK_UN)                 = 0
1256  exit_group(0)                     = ?
1256  +++ exited with 0 +++
----------

And at the end of the strace process that fails I see:

----------
1261  flock(3, LOCK_EX)                 = 0
1261  ioctl(3, RTC_SET_TIME, {tm_sec=21, tm_min=48, tm_hour=11, tm_mday=6, tm_mon=4, tm_year=114, ...}
----------

If nobody else can reproduce the problem on different hardware, then this is isolated to a problem either with my hardware or the RTC driver for my hardware.  Sorry for the distraction, but thanks for the help in diagnosing the problem.

Regards,
Bryan
> 
> HTH,
> Isaac Dunham


More information about the busybox mailing list