[Sheepdog] [PATCH] Enable sheepdog generate core dump file

Yunkai Zhang yunkai.me at gmail.com
Tue Mar 6 13:50:04 CET 2012


On Tue, Mar 6, 2012 at 9:41 AM, huxinwei <huxinwei at huawei.com> wrote:

> > -----Original Message-----
> > From: sheepdog-bounces at lists.wpkg.org
> > [mailto:sheepdog-bounces at lists.wpkg.org] On Behalf Of Yunkai Zhang
> > Sent: Friday, March 02, 2012 11:42 PM
> > To: morita.kazutaka at lab.ntt.co.jp
> > Cc: Yunkai Zhang; sheepdog at lists.wpkg.org
> > Subject: [Sheepdog] [PATCH] Enable sheepdog generate core dump file
> >
> > If sheepdog received SIGSEGV signal and we have enabled
> > OS to generate it, core dump file would be created in
> > LOCALSTATEDIR/lib/sheepdog directory.
> >
> > We can find the vaule of LOCALSTATEDIR in include/config.h.
> >
> > Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
> > ---
> >  lib/logger.c |   20 +++++++++++++++-----
> >  1 files changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/logger.c b/lib/logger.c
> > index 5be035a..c78329e 100644
> > --- a/lib/logger.c
> > +++ b/lib/logger.c
> > @@ -29,6 +29,7 @@
> >  #include <sys/wait.h>
> >  #include <sys/prctl.h>
> >
> > +#include "../include/config.h"
> >  #include "logger.h"
> >  #include "util.h"
> >
> > @@ -355,11 +356,12 @@ static void log_flush(void)
> >
> >  static void log_sigsegv(void)
> >  {
> > +     (void)signal(SIGSEGV, SIG_DFL);
> >       vprintf(SDOG_ERR, "logger pid %d exiting abnormally\n", getpid());
> >       log_flush();
> >       closelog();
> >       free_logarea();
> > -     exit(1);
> > +     raise(SIGSEGV);
>
> Er, I'm not sure if this makes sense here to raise the signal again.
>
> Here in logger, SIGSEGV usually generated by the exiting of parent process
> (caused by prctl).
> So it has nothing to do with the core dump of sheep itself.


You are right, I haven't noticed that the core dump file would be placed in
/ directory.

Generally, we should put the core dump file in a particular directory so
that users can find it easily, maybe  LOCALSTATEDIR+"/lib/sheepdog" will be
a good path for it.

Thanks.


> Actually, I'd like to propose a patch to rename log_sigsegv to
> log_sigparentexit ;)
> Will send out a patch about logger soon.
>
> >  }
> >
> >  int log_init(char *program_name, int size, int is_daemon, int level,
> char
> > *outfile)
> > @@ -372,6 +374,7 @@ int log_init(char *program_name, int size, int
> > is_daemon, int level, char *outfi
> >       semkey = random();
> >
> >       if (is_daemon) {
> > +             const char *run_dir;
> >               struct sigaction sa_old;
> >               struct sigaction sa_new;
> >               int fd;
> > @@ -395,6 +398,17 @@ int log_init(char *program_name, int size, int
> > is_daemon, int level, char *outfi
> >
> >               la->active = 1;
> >               la->fd = fd;
> > +
> > +             run_dir = LOCALSTATEDIR "/lib/sheepdog";
> > +             if ((mkdir(run_dir, 0700)) == -1 && errno != EEXIST) {
> > +                     syslog(LOG_ERR, "failed to mkdir -p to %s: %m\n",
> run_dir);
> > +             }
> > +
> > +             if (chdir(run_dir) < 0) {
> > +                     syslog(LOG_ERR, "failed to chdir to %s: %m\n",
> run_dir);
> > +                     exit(1);
> > +             }
> > +
> >               pid = fork();
> >               if (pid < 0) {
> >                       syslog(LOG_ERR, "failed to fork the logger
> process: %m\n");
> > @@ -414,10 +428,6 @@ int log_init(char *program_name, int size, int
> > is_daemon, int level, char *outfi
> >               dup2(fd, 1);
> >               dup2(fd, 2);
> >               setsid();
> > -             if (chdir("/") < 0) {
> > -                     syslog(LOG_ERR, "failed to chdir to /: %m\n");
> > -                     exit(1);
> > -             }
> >
> >               /* flush on daemon's crash */
> >               sa_new.sa_handler = (void*)log_sigsegv;
> > --
> > 1.7.7.6
> >
> > --
> > sheepdog mailing list
> > sheepdog at lists.wpkg.org
> > http://lists.wpkg.org/mailman/listinfo/sheepdog
>



-- 
Yunkai Zhang
Work at Taobao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20120306/d0b58875/attachment-0003.html>


More information about the sheepdog mailing list