chiark / gitweb /
Debianization.
[tripe] / client.c
index 8890f6c0682b3081b63c2146464f626793e73fac..1910ef742a3933555f33169ecd2b8a051f2f99dd 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: client.c,v 1.8 2001/06/19 22:09:37 mdw Exp $
+ * $Id: client.c,v 1.13 2003/11/29 23:49:32 mdw Exp $
  *
  * Client for TrIPE
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: client.c,v $
+ * Revision 1.13  2003/11/29 23:49:32  mdw
+ * Debianization.
+ *
+ * Revision 1.12  2003/10/15 09:29:38  mdw
+ * Cosmetic fix to changelog comment.
+ *
+ * Revision 1.11  2003/07/13 11:19:49  mdw
+ * Incompatible protocol fix!  Include message type code under MAC tag to
+ * prevent cut-and-paste from key-exchange messages to general packet
+ * transport.
+ *
+ * Revision 1.10  2003/05/17 10:59:19  mdw
+ * Put a newline in the pidfile.
+ *
+ * Revision 1.9  2002/01/13 14:57:18  mdw
+ * Track @lbuf@ changes in mLib.
+ *
  * Revision 1.8  2001/06/19 22:09:37  mdw
  * Move the program name to the right place when constructing the arguments
  * to pass to a new server.
@@ -140,7 +157,7 @@ static void writelog(const char *cat, const char *msg)
   fprintf(logfp, "%s %s: %s\n", buf, cat, msg);
 }
 
-static void cline(char *p, void *b)
+static void cline(char *p, size_t len, void *b)
 {
   char *q;
   if (!p) {
@@ -182,7 +199,7 @@ static void cline(char *p, void *b)
     die(EXIT_FAILURE, "unexpected output `%s %s'", q, p); 
 }
 
-static void sline(char *p, void *b)
+static void sline(char *p, size_t len, void *b)
 {
   if (!p) {
     if (!(f & f_uclose))
@@ -192,17 +209,15 @@ static void sline(char *p, void *b)
   puts(p);
 }
 
-static void uline(char *p, void *b)
+static void uline(char *p, size_t len, void *b)
 {
-  size_t sz;
   if (!p) {
     selbuf_destroy(b);
     shutdown(fd, 1);
     f |= f_uclose;
   } else {
-    sz = strlen(p);
-    p[sz] = '\n';
-    write(fd, p, sz + 1);
+    p[len] = '\n';
+    write(fd, p, len + 1);
   }
 }
 
@@ -277,8 +292,9 @@ Options in full:\n\
 -u, --usage            Show brief usage message.\n\
 \n\
 -D, --daemon           Become a background task after connecting.\n\
--d, --directory=DIR    Select current directory [default /var/lib/tripe]\n\
--a, --admin-socket=FILE        Select socket to connect to.\n\
+-d, --directory=DIR    Select current directory [default " CONFIGDIR "].\n\
+-a, --admin-socket=FILE        Select socket to connect to
+                          [default " SOCKETDIR "/tripesock].\n\
 -P, --pidfile=FILE     Write process-id to FILE.\n\
 \n\
 -s, --spawn            Start server rather than connecting.\n\
@@ -293,8 +309,8 @@ Options in full:\n\
 
 int main(int argc, char *argv[])
 {
-  const char *dir = "/var/lib/tripe";
-  const char *sock = "tripesock";
+  const char *dir = CONFIGDIR;
+  const char *sock = SOCKETDIR "/tripesock";
   const char *spawnpath = "tripe";
   string_v spawnopts = DA_INIT;
   char *p;
@@ -436,6 +452,8 @@ int main(int argc, char *argv[])
       close(pfd[0]);
       if (logfp)
        fclose(logfp);
+      if (pidfp)
+       fclose(pidfp);
       closelog();
       if (f & f_daemon)
        u_detach();
@@ -467,7 +485,7 @@ int main(int argc, char *argv[])
       die(EXIT_FAILURE, "error becoming daemon: %s", strerror(errno));
   }
   if (pidfp) {
-    fprintf(pidfp, "%li", (long)getpid());
+    fprintf(pidfp, "%li\n", (long)getpid());
     fclose(pidfp);
   }