Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Smith <psmith@gnu.org>
To: Paul Pluzhnikov <ppluzhnikov@google.com>
Cc: gdb@sourceware.org
Subject: Re: Partial cores using Linux "pipe" core_pattern
Date: Mon, 18 May 2009 13:22:00 -0000	[thread overview]
Message-ID: <1242652911.2800.160.camel@homebase.localnet> (raw)
In-Reply-To: <8ac60eac0905172304t4deae98bxbd4f0b1d2186a8a0@mail.gmail.com>

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


  reply	other threads:[~2009-05-18 13:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18  1:23 Paul Smith
2009-05-18  6:05 ` Paul Pluzhnikov
2009-05-18 13:22   ` Paul Smith [this message]
2009-05-18  7:25 ` Andi Kleen
2009-05-18 13:29   ` Paul Smith
2009-05-18 13:49     ` Andreas Schwab
2009-05-18 14:32       ` Paul Smith
2009-05-21 16:32       ` Paul Smith
2009-05-26 19:26         ` Paul Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242652911.2800.160.camel@homebase.localnet \
    --to=psmith@gnu.org \
    --cc=gdb@sourceware.org \
    --cc=ppluzhnikov@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox