Re: [PATCH v2] trace-cmd: Remove all die()s from trace-cmd library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 24, 2021 at 11:53 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Wed, 24 Mar 2021 15:51:43 +0200
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:
>
> > @@ -366,36 +366,32 @@ void __noreturn __vdie(const char *fmt, va_list ap)
> >       vfprintf(stderr, fmt, ap);
> >
> >       fprintf(stderr, "\n");
> > -     exit(ret);
> > +     return ret;
> >  }
> >
> > -void __noreturn __die(const char *fmt, ...)
> > +#ifdef LIB_DIE
>
> I wonder if it would be more useful not to have it as a compile time
> define, but instead a global variable:
>
> static bool lib_die;
>
> void tracecmd_die_on_error(void)
> {
>         lib_die = true;
> }
>

There is tracecmd_set_debug() API already, It can be used to trigger
that die() logic. It makes sense for the library to do a real die()
when running in debug mode, if a fatal error is encountered.

> Make the "die()" functions into static variables here.
>
> void __hidden _lib_fatal(const char *fmt, ...)
> {
>         va_list ap;
>
>         va_start(ap, fmt);
>         if (lib_die)
>                 __vdie(fmt, ap);
>         else
>                 __vwarning(fmt, ap);
>         va_end(ap);
> }
>
> That way if we run trace-cmd with the --debug option, it could then call
> the tracecmd_die_on_error() function, and it will crash on any "fatal"
> places.
>
> -- Steve
>
>
> > +
> > +void __noreturn _lib_fatal(const char *fmt, ...)
> >  {
> >       va_list ap;
> > +     int ret;
> >
> >       va_start(ap, fmt);
> > -     __vdie(fmt, ap);
> > +     ret = __vlib_fatal(fmt, ap);
> >       va_end(ap);
> > +     exit(ret);
> >  }
> >
> > -void __weak __noreturn die(const char *fmt, ...)
> > +#else
> > +void _lib_fatal(const char *fmt, ...)
> >  {
> >       va_list ap;
> >
> >       va_start(ap, fmt);
> > -     __vdie(fmt, ap);
> > +     __vlib_fatal(fmt, ap);
> >       va_end(ap);
> >  }
> > -
> > -void __weak *malloc_or_die(unsigned int size)
> > -{
> > -     void *data;
> > -
> > -     data = malloc(size);
> > -     if (!data)
> > -             die("malloc");
> > -     return data;
> > -}
> > +#endif
> >



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux