This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Partial cores using Linux "pipe" core_pattern
On Sun, 2009-05-17 at 23:04 -0700, Paul Pluzhnikov wrote:
> On Sun, May 17, 2009 at 6:22 PM, Paul Smith <psmith@gnu.org> wrote:
>
> > I've instrumented every single function with checking for errors and
> > writing issues to syslog (including informational messages so I know the
> > logging works) and no errors are printed. The size of the core that I
> > get from read(2)'ing stdin is just short, but read(2) never fails or
> > shows any errors!
>
> You can't be read(2)ing stdin, since read(2) doesn't take FILE*.
> Are you doing read(0, ...) or are you doing fread(..., stdin) ?
>
> If the latter, are you handling the feof() vs. ferror() difference
> correctly? A small code sample might help.
Oh sorry; I should have been explicit. I use fileno(stdin) to get an
FD. I'm ONLY using FD-based calls; I don't use FILE*-based calls at all
(on stdin).
Here's my main loop. I've hacked it a bit for ridiculous safety (for
example I used to have the errno log inside the if (l<0) but moved it
out of a surfeit of caution). When I get a short core, the syslog entry
at the end shows the actual short core length, not the "full" core
length--so basically that's all the kernel is giving me.
------------------------------------------------------------
coref = gzopen(core_path, "wb");
if (!coref) {
_vlog(LOG_ERR, "gzopen(%s): %s\n", core_path, _zerr());
exit(1);
}
ssize_t tot = 0;
while (true) {
errno = 0;
ssize_t l = read(infd, buf, bufsize);
if (errno)
_vlog(LOG_ERR, "read(stdin): %s\n", strerror(errno));
// Did we read it all?
if (l == 0)
break;
if (caughtsig) {
_vlog(LOG_ERR, "savecore got signal %d--continuing\n",
caughtsig);
caughtsig = 0;
}
// Did we get an error?
if (l < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
_clean_and_fail();
}
// Write what we got so far
tot += l;
char *p = buf;
while (l > 0) {
int w = gzwrite(coref, p, l);
if (w <= 0) {
_vlog(LOG_ERR, "gzwrite(%s): %s\n", core_path, _zerr());
_clean_and_fail();
}
// Some amount of write succeeded; write the rest
p += w;
l -= w;
}
}
if (gzclose(coref) < 0) {
_vlog(LOG_ERR, "gzclose(%s): %s\n", core_path, _zerr());
_clean_and_fail();
}
// Give some information on the core
_vlog(LOG_ERR, "%s(%s): coredump complete: core.%s (%lu B)\n",
argv[av_CMDNAME], argv[av_PID], core_suffix, tot);
--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@gnu.org> Find some GNU make tips at:
http://www.gnu.org http://make.mad-scientist.us
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist