From 521df0ad89d1a296e483780dc98d4f4d8cd94b75 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 4 May 2008 16:00:03 +0000 Subject: [PATCH] log copy feature - not yet tested --- hostside/daemons.h | 1 + hostside/obc.c | 8 ++++++++ hostside/realtime.c | 12 +++++++++--- hostside/simulate.c | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hostside/daemons.h b/hostside/daemons.h index d0878e6..daea235 100644 --- a/hostside/daemons.h +++ b/hostside/daemons.h @@ -26,6 +26,7 @@ struct OutBufferChain { /* set by user: */ char *desc; int fd; + FILE *logcopy; int limit; /* 0 means obc_init will set a default */ OutBufferError *error; /* set/used by obc_..., oprintf, etc., only */ diff --git a/hostside/obc.c b/hostside/obc.c index e572b5a..91d8321 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -59,6 +59,14 @@ static void *writeable(oop_source *evts, int fd, } static void addlink(OutBufferChain *ch, OutBuffer *ob) { + if (ch->logcopy) { + size_t r; + r= fwrite(ob->m,1,ob->l,ch->logcopy); + if (r!=ob->l) { + assert(ferror(ch->logcopy)); + ch->error(ch,"write log",strerror(errno)); + } + } if (!ch->obs.head) events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch); LIST_LINK_TAIL(ch->obs, ob); diff --git a/hostside/realtime.c b/hostside/realtime.c index f9bf1e7..7acd982 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -12,6 +12,7 @@ CommandInput cmdi; int picio_send_noise= 1; static const char *device= "/dev/ttya0"; +static const char *logcopy_fn= "realtime.log"; /*---------- general event handling ----------*/ @@ -343,6 +344,7 @@ int main(int argc, const char **argv) { case 's': device= arg; break; case 'p': persist_fn= arg; break; case 'v': picio_send_noise= atoi(arg); break; + case 'L': logcopy_fn= arg; break; case 'S': simulate= arg; break; default: badusage("unknown option"); } @@ -353,13 +355,15 @@ int main(int argc, const char **argv) { cmdi.out.error= obc_error; cmdi.doline= command_doline; - persist_entrails_interpret(); - records_parse(argv); - if (!simulate) { sys_events= oop_sys_new(); if (!sys_events) diee("oop_sys_new"); events= oop_sys_source(sys_events); massert(events); + if (logcopy_fn[0] && strcmp(logcopy_fn,"-")) { + cmdi.out.logcopy= fopen(logcopy_fn,"w"); + if (!cmdi.out.logcopy) diee("open log copy %s",logcopy_fn); + } + cmdin_new(&cmdi, 0); serial_open(device); @@ -373,6 +377,8 @@ int main(int argc, const char **argv) { sys_events= 0; } + persist_entrails_interpret(); + records_parse(argv); sta_startup(); if (!simulate) oop_sys_run(sys_events); diff --git a/hostside/simulate.c b/hostside/simulate.c index 8123e9e..5a58601 100644 --- a/hostside/simulate.c +++ b/hostside/simulate.c @@ -163,6 +163,7 @@ static void se_eof(void) { /*---------- core ----------*/ void sim_initialise(void) { + cmdi.out.logcopy= 0; obc_init_core(&cmdi.out); serial_fd= open("/dev/null",O_WRONLY); if (serial_fd<0) diee("open /dev/null for dummy serial"); -- 2.30.2