[Openais] [RFC] simple blackbox
Steven Dake
sdake at redhat.com
Thu Oct 9 10:00:49 PDT 2008
On Thu, 2008-10-09 at 11:33 -0500, David Teigland wrote:
> > Wow that is a complicated solution. I though that simple and blackbox
> > went well together.
>
> Completely agree, too complex. The logging code I copy into all the
> daemons I write is at the opposite end of the spectrum; I doubt it's
> possible to be much simpler. (I copy it everywhere because it's too short
> and simple to bother with a lib.)
>
> #define DUMP_SIZE (1024 * 1024)
>
> extern char dump_buf[DUMP_SIZE];
> extern int dump_point;
> extern int dump_wrap;
>
> extern char daemon_debug_buf[256];
>
> void daemon_dump_save(void)
> {
> int len, i;
>
> len = strlen(daemon_debug_buf);
>
> for (i = 0; i < len; i++) {
> dump_buf[dump_point++] = daemon_debug_buf[i];
>
> if (dump_point == DUMP_SIZE) {
> dump_point = 0;
> dump_wrap = 1;
> }
> }
> }
>
> #define log_debug(fmt, args...) \
> do { \
> snprintf(daemon_debug_buf, 255, "%ld " fmt "\n", time(NULL), ##args); \
> daemon_dump_save(); \
> } while (0)
>
>
> That's it, just over 20 lines. I also have a function that will write
> dump_buf over a unix socket so a command line program can see it while the
> daemon is running (that's the only way I ever use it, actually). This is
> non-threaded, of course, and corosync will need something more complex,
> but the point is you can keep it simple.
>
> Dave
... I guess you don't count snprintf as complicated? Go read the
implementation in glibc and tell me if that function + dependent
functions (sprintf) are less complicated then the patch in this thread.
If log_rec were part of glibc and operated on a buffer of predetermined
size, this conversation would be moot since its complexity would be
hidden.
Regards
-steve
>
> _______________________________________________
> Openais mailing list
> Openais at lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/openais
More information about the Openais
mailing list