chiark / gitweb /
flush obc on death
authorian <ian>
Tue, 9 May 2006 22:39:22 +0000 (22:39 +0000)
committerian <ian>
Tue, 9 May 2006 22:39:22 +0000 (22:39 +0000)
hostside/common.h
hostside/daemons.h
hostside/gui-plan.c
hostside/main.c
hostside/obc.c
hostside/realtime.c
hostside/utils.c

index 7354b09be8fa8b9e25943c8e227e9da96972f506..008d21976f0a94a4fe8cf7e0f351cc716db804bf 100644 (file)
@@ -92,6 +92,8 @@ void die(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2)));
 void diee(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2)));
 void diem(void) __attribute__((noreturn));
 
+void die_hook(void);
+
 void *mmalloc(size_t sz);
 char *mstrdupl(const char *s, int l);
 char *mstrdup(const char *s);
index dbe8c1c573b9140445b4712f48121193d43464e4..0db79631e8462cbd2e8cb9a39cb7b561f02790f9 100644 (file)
@@ -33,6 +33,8 @@ struct OutBufferChain {
 };
 
 void obc_init(OutBufferChain *ch);
+int obc_tryflush(OutBufferChain *ch);
+ /* returns 0 for all flushed or errno, including particularly EWOULDBLOCK */
 
 void ovprintf(OutBufferChain *ch, const char *fmt, va_list al)
      __attribute__((format(printf,2,0)));
index 3f40f890b08d5f69f79bcb53837f228dca668347..961ef1944d2b57c21928486838140a5ec5141c15 100644 (file)
@@ -57,6 +57,8 @@ static unsigned long train_pixel, owned_pixel;
 static const char *badcmdreport_data;
 static size_t badcmdreport_recsz;
 
+void die_hook(void) { }
+
 static void diex(const char *fn, const char *w) __attribute__((noreturn));
 static void diex(const char *fn, const char *w) {
   die("Xlib call failed: %s%s%s%s", fn,
index 378c173292159ec4439c210d7dac61a6db92769d..f14a5dfc557867b386ba6330e997bc742e4d0fb7 100644 (file)
@@ -27,6 +27,8 @@ static const char *serial_port;
 
 static Nmra buf;
 
+void die_hook(void) { }
+
 static void badusage(const char *why) {
   fprintf(stderr,"bad usage: %s\n",why); exit(8);
 }
index 7154d8341cb4cf0347a2886b70adc764764fcb7e..040ee6a5c50c0765c792648c32505fc6ff3bf585 100644 (file)
@@ -18,20 +18,15 @@ struct OutBuffer {
   int l;
 };
 
-static void *writeable(oop_source *evts, int fd,
-                      oop_event evt, void *ch_v) {
-  OutBufferChain *ch= ch_v;
+int obc_tryflush(OutBufferChain *ch) {
   OutBuffer *ob;
   int r;
   
-  assert(fd == ch->fd);
-  assert(evt == OOP_WRITE);
-
   for (;;) {
     ob= ch->obs.head;
     if (!ob) {
-      events->cancel_fd(events, fd, OOP_WRITE);
-      return OOP_CONTINUE;
+      events->cancel_fd(events, ch->fd, OOP_WRITE);
+      return 0;
     }
     if (ch->done_of_head == ob->l) {
       LIST_UNLINK(ch->obs, ob);
@@ -43,8 +38,9 @@ static void *writeable(oop_source *evts, int fd,
     r= write(ch->fd, ob->m + ch->done_of_head, ob->l - ch->done_of_head);
     if (r==-1) {
       if (errno==EINTR) continue;
-      if (errno==EWOULDBLOCK) return OOP_CONTINUE;
+      if (errno==EWOULDBLOCK) return errno;
       ch->error(ch,"write",strerror(errno));
+      return errno;
     }
     assert(r>=0);
     ch->done_of_head += r;
@@ -52,6 +48,15 @@ static void *writeable(oop_source *evts, int fd,
   }
 }
 
+static void *writeable(oop_source *evts, int fd,
+                      oop_event evt, void *ch_v) {
+  OutBufferChain *ch= ch_v;
+  assert(fd == ch->fd);
+  assert(evt == OOP_WRITE);
+  obc_tryflush(ch);
+  return OOP_CONTINUE;
+}
+
 static void addlink(OutBufferChain *ch, OutBuffer *ob) {
   if (!ch->obs.head)
     events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch);
index 0c650260e19e919b6be1b64913ff1b00578a9fc2..e636ed12efa68d88e4c1b629f8801dc70f842ce8 100644 (file)
@@ -70,6 +70,12 @@ void ouhex(const char *word, const Byte *command, int length) {
   oprintf(UPO, "\n");
 }
 
+void die_hook() {
+  int e;
+  e= obc_tryflush(UPO);
+  if (e) fprintf(stderr,"(unwritten command output: %s)\n",strerror(e));
+}
+
 /*---------- serial input (via oop) ----------*/
 
 static PicInsn serial_buf;
@@ -130,7 +136,7 @@ int main(int argc, const char **argv) {
   int r;
 
   device= argv[1];
-  if (!device) device= "/dev/ttyS0";
+  if (!device) device= "/dev/ttya0";
 
   sys_events= oop_sys_new();  if (!sys_events) diee("oop_sys_new");
   events= oop_sys_source(sys_events);  massert(events);
index 3a1cb42227bcc48caa36a19055bb12728129169b..8b128cd0f5a9159f237b78146bad315e6143bee1 100644 (file)
@@ -12,6 +12,7 @@
 #include "common.h"
 
 void vdie(const char *fmt, int ev, va_list al) {
+  die_hook();
   fprintf(stderr, "%s: fatal: ", progname);
   vfprintf(stderr,fmt,al);
   if (ev) fprintf(stderr,": %s",strerror(ev));