[Nut-upsuser] upsd crashes with a "broken pipe" error
Arjen de Korte
nut+users at de-korte.org
Tue Feb 15 20:27:55 UTC 2011
Citeren Zach La Celle <lacelle op roboticresearch.com>:
> You can see where the problem happens in parseconf.c, on line 125
> with the code:
> /* resize the lists */
> ctx->arglist = realloc(ctx->arglist,
> sizeof(char *) * ctx->numargs);
With the given arguments, this boils down to
ctx->arglist = realloc(NULL, sizeof(char *));
This is all normal. Upon the first invocation of add_arg_word,
ctx->arglist will be a NULL pointer (since there is nothing in the
list yet). This should then allocate a one element array of a pointer
to char (to store the
"If ptr is a null pointer, realloc() shall be equivalent to malloc()
for the specified size."
After that, all hell breaks loose, but that's out of our control.
There is a slight problem in lines 131-132
ctx->argsize = realloc(ctx->argsize, sizeof(int *) * ctx->numargs);
which should really read
ctx->argsize = realloc(ctx->argsize, sizeof(size_t) * ctx->numargs);
but I doubt that sizeof(size_t) will be smaller that sizeof(int *), so
this just wastes a few bytes of memory.
> This also might help:
> (gdb) p *ctx
> $4 = {f = 0x0, state = 5, ch = 9, arglist = 0x0, argsize = 0x0,
> numargs = 1, maxargs = 1, wordbuf = 0x61f2e0 "Z", wordptr = 0x61f2fd
> "", wordbufsize = 16, linenum = 0, error = 0, errmsg = '\000'
> <repeats 255 times>, errhandler = 0, magic = 7497264, arg_limit =
> 32, wordlen_limit = 512}
None of these values is suspect.
> If I go "up" in GDB to the pconf_char function, here is the
> character which is killing it:
> (gdb) p ch
> $6 = 9 '\t'
This is expected. Any whitespace character ends the collection of
characters for the current argument and will start a new one. Nothing
out of the ordinary. If it was, 100% of the NUT installations would
suffer the same problems as you're seeing 100% of the time they start
the upsd server. This is not the case and even in your case, the
problem seems to occur intermittently, which is more an indication
you're either running out of memory or the system is suffering from
bad memory. Did you run a memory check lately?
Best regards, Arjen
--
Please keep list traffic on the list (off-list replies will be rejected)
More information about the Nut-upsuser
mailing list