[OpenAFS-devel] butc crash on linux/amd64

Russ Allbery rra@stanford.edu
Sun, 19 Mar 2006 20:37:09 -0800


Sidney Cammeresi <sac@cheesecake.org> writes:

> I'm an AFS newbie, setting up a new cell on an AMD64 machine running
> Debian 3.1 and the OpenAFS 1.4.0 packages from unstable.

> I was experimenting with backups when I hit a crash in butc after hitting
> enter at the `insert a tape' prompt.

> Program received signal SIGSEGV, Segmentation fault.
> ktimeDate_FromInt32 (timeSecs=1141237580, ktimePtr=0x594a60)
>     at ./kreltime.c:122
> 122         ktimePtr->sec = timePtr->tm_sec;
> (gdb) bt
> #0  ktimeDate_FromInt32 (timeSecs=1141237580, ktimePtr=0x594a60)
>     at ./kreltime.c:122
> #1  0x000000000045fcc4 in Add_RelDate_to_Time (relDatePtr=0x2a95ef3788,
>     atime=-383805929) at ./kreltime.c:290
> #2  0x0000000000412004 in calcExpirationDate (expType=-1673440488,
> expDate=-1,
>     createTime=1141237580) at dump.c:162
> #3  0x0000000000412729 in getDumpTape (dparamsPtr=0x2a95ef5288,
>     interactiveFlag=1873051225, append=0) at dump.c:1753
> #4  0x0000000000414bb1 in Dumper (nodePtr=0x5caed0) at dump.c:1229
> #5  0x000000000045af58 in Create_Process_Part2 () at ./lwp.c:778
> #6  0x0000002a957ca1a0 in swapcontext () from /lib/libc.so.6

> Turns out timePtr was null.  On a guess, I changed the localtime call
> to localtime_r (and made the other changes that required), and butc
> stopped crashing.

Hm, yes.  butc is built threaded on platforms that support it, so using a
non-reentrant interface could potentially cause problems.  It would
require some other thread to be calling localtime at the same time, but I
suppose that's possible.

The problem is that you can't just use localtime_r without providing a
replacement if one is needed.  butc already provides its own replacement,
but that doesn't help for this code, since it's in util.

Should we just move the localtime_r replacement to util for anyone who
needs to use it, and then change the references in util that currently use
localtime to use localtime_r instead?  I'm not sure what all in AFS is
threaded and what of the other uses of localtime might be problems:

bozo/bnode.c:    TimeFields = localtime(&Start.tv_sec);
bucoord/commands.c:     ltime = localtime(&t);
bucoord/expire.c:    timePtr = localtime(&timeSecs);
budb/server.c:    lt = localtime(&t);
kauth/rebuild.c:    tm_p = localtime((time_t *) & entry->user_expiration);
kauth/rebuild.c:                 localtime((time_t *) & entryp->user_expiration));
ptserver/display.c:     tm = localtime(&now);
ptserver/display.c:    tm = localtime(&clock);
util/kreltime.c:    timePtr = localtime((time_t *) & timeSecs);
util/ktime.c:   tsp = localtime(&probe);        /* find out what UTC time "probe" is */
util/ktime.c:   tsp = localtime(&time_next);
util/ktime.c:   tsp = localtime(&temp);
util/serverLog.c:       TimeFields = localtime(&t);
vol/vol-info.c:    struct tm *tm = localtime(&date);
vol/vol-salvage.c:    lt = localtime(&clock);
vol/vol-salvage.c:    lt = localtime(&now);

> I don't know enough about all the various systems OpenAFS supports to
> say whether this is correct across the board, but it fixes the crash
> on my machine, at least, so here it is, FWIW.

butc/dump.c says that localtime_r loses on:

#if defined(AFS_NT40_ENV) || (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV)) || defined(AFS_SUN4_ENV)

Other than AFS_NT40_ENV, that's a set of platforms that I must admit I
have some trouble caring a great deal about....

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>