[fireserve] play nicer with reboots
authorJoshua Oreman <oremanj@xenon.get-linux.org>
Sun, 3 May 2009 00:41:28 +0000 (17:41 -0700)
committerJoshua Oreman <oremanj@xenon.get-linux.org>
Sun, 3 May 2009 00:41:28 +0000 (17:41 -0700)
src/util/fireserve.c

index d6dd022..87605f3 100644 (file)
@@ -81,20 +81,6 @@ static void fw_write_link()
            fw_link.idx_put);
 }
 
-/* Read fwload_link.elem remotely into fw_link.elem locally. */
-#define FW_READ_LINKELEM(elem) raw1394_read(fw_handle, fw_target, \
-    fw_addrbase + offsetof(struct fwtrans_connection, elem), 4, \
-    (quadlet_t *)((u8 *)&fw_link + offsetof(struct fwtrans_connection, elem)))
-
-/* Reads into fw_link the parts the remote host might change. */
-static void fw_read_link()
-{
-       FW_READ_LINKELEM(request);
-       FW_READ_LINKELEM(idx_get);
-       dbg(3, "-- read  request=%08x idx_get=%d\n", fw_link.request,
-           fw_link.idx_get);
-}
-
 /* Reads everything from the remote host's structure into our
    fw_link. */
 static void fw_read_link_initial()
@@ -109,6 +95,23 @@ static void fw_read_link_initial()
        }
 }
 
+/* Read fwload_link.elem remotely into fw_link.elem locally. */
+#define FW_READ_LINKELEM(elem) raw1394_read(fw_handle, fw_target, \
+    fw_addrbase + offsetof(struct fwtrans_connection, elem), 4, \
+    (quadlet_t *)((u8 *)&fw_link + offsetof(struct fwtrans_connection, elem)))
+
+/* Reads into fw_link the parts the remote host might change. */
+static void fw_read_link()
+{
+       FW_READ_LINKELEM(request);
+       FW_READ_LINKELEM(idx_get);
+       FW_READ_LINKELEM(magic);
+       dbg(3, "-- read  request=%08x idx_get=%d\n", fw_link.request,
+           fw_link.idx_get);
+       if (fw_link.magic != FWTRANS_MAGIC)
+               fw_read_link_initial();
+}
+
 static int fw_write_avail()
 {
        return (fw_link.buffer_size - 1) -
@@ -329,6 +332,8 @@ int main(int argc, char **argv)
                }
 
                fw_read_link();
+               if (fw_link.magic != FWTRANS_MAGIC)
+                       continue;
 
                if (filedes < 0 && (fw_link.request & FWTRANS_SYN) &&
                    !(fw_link.response & FWTRANS_NAK)) {