chiark / gitweb /
persistence seems to work
authorian <ian>
Sat, 26 Apr 2008 23:50:20 +0000 (23:50 +0000)
committerian <ian>
Sat, 26 Apr 2008 23:50:20 +0000 (23:50 +0000)
hostside/.cvsignore
hostside/TODO
hostside/persist.c
hostside/record.c
hostside/resolve.c

index 024a957c6eafb41f5830643884ce10afcbcdd556..b86480b1fc8dccf1623dccad9eea19d1375ae32b 100644 (file)
@@ -25,3 +25,4 @@ persist.data.new
 persist.conv.old
 persist.conv
 persist.conv.new
+persist.record
index 6f19047a9cf43ada900d9f8a263b03aca5ffa30e..edc3f070b1b9ed43e495e3e76f7e542d138f21e2 100644 (file)
@@ -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
index e28553d69a0e2ff141857ac4fa4c7c0be268f83a..21a2af8df7dc894edb16185387c678378ea8f7f3 100644 (file)
@@ -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 &&
index 18d4cbb2916a37f85b8544053cf1b1b9777a230c..df7a6689652dec1f9a620d0228f99a3da8cef60b 100644 (file)
@@ -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;
index 6d9c7992b5cc22998c913e5a333e569c4b82efc5..7845fc89b21d39f2b41b191582b54568929dbc81 100644 (file)
@@ -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++;
              }