From: ian Date: Sat, 26 Apr 2008 23:50:20 +0000 (+0000) Subject: persistence seems to work X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=ffc331cf91fa8943255d053219b22384c30d87fc;p=trains.git persistence seems to work --- diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 024a957..b86480b 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -25,3 +25,4 @@ persist.data.new persist.conv.old persist.conv persist.conv.new +persist.record diff --git a/hostside/TODO b/hostside/TODO index 6f19047..edc3f07 100644 --- a/hostside/TODO +++ b/hostside/TODO @@ -14,6 +14,8 @@ want to document commands [!]movfeat and speed stop all trains command ? stop and turn off calmly when ^D + mlock + rtprio optional but maybe before can test: wiring to gui display diff --git a/hostside/persist.c b/hostside/persist.c index e28553d..21a2af8 100644 --- a/hostside/persist.c +++ b/hostside/persist.c @@ -57,7 +57,7 @@ static int datalen; #define FN(dcl,suffix) persist_fn_ephemeral("." #dcl "." #suffix) #define FN1(dcl) persist_fn_ephemeral("." #dcl) -#define PFES 20 +#define PFES 50 static const char *persist_fn_ephemeral(const char *suffix) { static char *rr[PFES]; static int i; @@ -119,7 +119,7 @@ static int persist_convert(const char *data, const char *conv) { if (!child) { if (dup2(data_fd,0)) diee("persist child: failed to dup2 0"); - if (dup2(newrecord_fd,1)) diee("persist child: failed to dup2 1"); + if (dup2(newrecord_fd,1)!=1) diee("persist child: failed to dup2 1"); execl(conv, conv, PERSIST_CONVERT_OPTION, (char*)0); diee("persist child: failed to exec `%s'", conv); } @@ -150,11 +150,13 @@ static int try(const char *data, const char *conv) { void persist_entrails_interpret(void) { /* creates persist_record_converted */ + assert(!persist_record_converted); persist_record_converted= mstrdup(FN1(record)); if (try(FN1(data), FN1(conv))) return; if (try(FN(data,old), FN(conv,old))) return; if (try(FN1(data), FN(conv,old))) return; + free(persist_record_converted); persist_record_converted =0; } @@ -215,18 +217,21 @@ static void mapmem(int fd, int datalen, int prot) { /*---------- installing of our data as the current one ----------*/ void persist_install(void) { + const char *devnull= "/dev/null"; FILE *src, *dst; DIR *dir; const char *dirname; char *dirname_buf, *slash; - int c; + int c, dst_fd; if (fd==-1) return; src= fopen("/proc/self/exe","rb"); if (!src) diee("open /proc/self/exe"); unlink_or_enoent(FN(conv,new)); - dst= fopen(FN(conv,new),"wb"); if (!dst) diee("create persist new conv"); + dst_fd= open(FN(conv,new), O_WRONLY|O_CREAT|O_TRUNC, 0777); + if (dst_fd<0) diee("create persist new conv"); + dst= fdopen(dst_fd,"wb"); if (!dst) diee("fdopen persist new conv"); while ((c= getc(src)) != EOF) if (putc(c,dst) == EOF) diee("write persist new conv"); @@ -239,8 +244,11 @@ void persist_install(void) { diee("sync persist new data"); /* Now we have the .new's, but let's just check ... */ + persist_record_converted= (char*)devnull; if (!persist_convert(FN(data,new),FN(conv,new))) die("persist conversion claims .new's do not exist ?!"); + assert(persist_record_converted == devnull); + persist_record_converted= 0; dirname_buf= mstrdup(persist_fn); slash= strrchr(dirname_buf, '/'); @@ -375,7 +383,7 @@ void persist_entrails_run_converter(void) { !seg->owner || !seg->owner->pname) continue; printf("seg %s has %s%s\n", segi->pname, - (seg->tr_backwards & seg->owner->backwards) ? "-" : "", + (seg->tr_backwards ^ seg->owner->backwards) ? "-" : "", seg->owner->pname); if (segi->n_poscombs>1 && diff --git a/hostside/record.c b/hostside/record.c index 18d4cbb..df7a668 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -56,6 +56,8 @@ found: Segment *record_pname2seg(const char *pname) { SEG_IV; + if (!segments) return 0; + FOR_SEG if (!strcmp(segi->pname, pname)) return seg; diff --git a/hostside/resolve.c b/hostside/resolve.c index 6d9c799..7845fc8 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -195,9 +195,10 @@ static int resolve_complete_main(void) { continue; /* 3. we have a violation of D \subset U, namely d */ - oprintf(DUPO("resolving") " violation @%s\n", di->pname); + oprintf(DUPO("resolving") " violation %s\n", di->pname); if (d->owner) { /* 3a perhaps */ + t= d->owner; oprintf(DUPO("resolving") " expected %s\n", t->pname); if (t->addr < 0) { @@ -226,7 +227,7 @@ static int resolve_complete_main(void) { if (d1->owner == t && d1->iselem_u) { FOR_TRAIN(t2, NOOP, NOOP) { if (t2->resolution == RR_H && d1->owner == t2) { - oprintf(DUPO("resolving") " clash @%s %s\n", + oprintf(DUPO("resolving") " clash %s %s\n", d1i->pname, t2->pname); clashes++; }