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);
};
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)));
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,
static Nmra buf;
+void die_hook(void) { }
+
static void badusage(const char *why) {
fprintf(stderr,"bad usage: %s\n",why); exit(8);
}
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);
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;
}
}
+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);
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;
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);
#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));