Making the check_version coep well with old ts servers.
authorviric@mandarina
Wed, 18 Feb 2009 23:18:43 +0100
changeset 265 8c16cd53f772
parent 264 d0ad4eadd619
child 266 e35af91aa426
Making the check_version coep well with old ts servers.
Changelog
client.c
main.h
signals.c
--- a/Changelog	Sun Feb 15 21:59:52 2009 +0100
+++ b/Changelog	Wed Feb 18 23:18:43 2009 +0100
@@ -13,7 +13,7 @@
 v0.6.3:
  - Fixed a bug on -c and -t.
  - Adding first support for -D (run depending on any job)
- - Adding version control on the protocol. It will work only from now on.
+ - Adding version control on the protocol.
  - Making the ts server chdir to the socket directory, so it doesn't annoy on umounting.
 v0.6.2:
  - Fixed a bug on -w
--- a/client.c	Sun Feb 15 21:59:52 2009 +0100
+++ b/client.c	Wed Feb 18 23:18:43 2009 +0100
@@ -194,9 +194,19 @@
     m.type = GET_VERSION;
     send_msg(server_socket, &m);
 
+    /* Set up a 2 second timeout to receive the
+    version msg. */
+    install_sigalrm_donothing();
+    alarm(2);
+
     res = recv_msg(server_socket, &m);
     if(res == -1 || res == 0)
+    {
+        fprintf(stderr,
+            "Error checking version with the server. Did you forget an "
+            "old ts server running?\n");
         error("Error checking version");
+    }
 
     if (m.type != VERSION || m.u.version != PROTOCOL_VERSION)
     {
--- a/main.h	Sun Feb 15 21:59:52 2009 +0100
+++ b/main.h	Wed Feb 18 23:18:43 2009 +0100
@@ -260,6 +260,7 @@
 void restore_sigmask();
 void block_sigint();
 void unblock_sigint_and_install_handler();
+void install_sigalrm_donothing();
 
 /* msg.c */
 void send_bytes(const int fd, const char *data, int bytes);
--- a/signals.c	Sun Feb 15 21:59:52 2009 +0100
+++ b/signals.c	Wed Feb 18 23:18:43 2009 +0100
@@ -71,3 +71,18 @@
      * only that sets the normal_sigmask. */
     sigprocmask(SIG_UNBLOCK, &set, 0);
 }
+
+static void sigalrm_donothing(int s)
+{
+}
+
+void install_sigalrm_donothing()
+{
+    struct sigaction act;
+
+    /* Install the handler */
+    act.sa_handler = sigalrm_donothing;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+    sigaction(SIGALRM, &act, 0);
+}