chiark / gitweb /
*** empty log message ***
[sympathy.git] / apps / sympathy.c
index 3ade5cd005f9f3d06ef26d60c3059b3909a573e0..b5bf326f1395e46d4e17502153690afa49a4393b 100644 (file)
@@ -11,6 +11,18 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.23  2008/02/28 16:57:51  james
+ * *** empty log message ***
+ *
+ * Revision 1.22  2008/02/28 01:47:44  james
+ * *** empty log message ***
+ *
+ * Revision 1.21  2008/02/27 16:01:24  james
+ * *** empty log message ***
+ *
+ * Revision 1.20  2008/02/27 10:00:34  james
+ * *** empty log message ***
+ *
  * Revision 1.19  2008/02/27 09:47:05  james
  * *** empty log message ***
  *
@@ -80,6 +92,7 @@ static char rcsid[] =
 #include <string.h>
 #include <strings.h>
 #include <malloc.h>
+#include <fcntl.h>
 
 #include "mainloop.h"
 
@@ -254,7 +267,7 @@ main (int argc, char *argv[])
   int c;
   extern char *optarg;
   extern int optind, opterr, optopt;
-  CRT_Pos size = { VT102_COLS_80, VT102_ROWS };
+  CRT_Pos size = { VT102_COLS_80, VT102_ROWS_24 };
 
   int oflags[128];
   char *oargs[128];
@@ -312,12 +325,14 @@ main (int argc, char *argv[])
     sum += oflags['l'];
     sum += oflags['v'];
 
-    if (!sum) {
-      /*If no mode is specified behave like screen */
-      oflags['s']++;
-      oflags['c']++;
-    }
-       
+    if (!sum)
+      {
+        /*If no mode is specified behave like screen */
+        oflags['s']++;
+        oflags['c']++;
+        sum++;
+      }
+
     if (sum != 1)
       fatal_moan
         ("specifiy exactly one of ( -c and or -s ), -t, -r, -l and -v");
@@ -351,12 +366,19 @@ main (int argc, char *argv[])
   /*Fold -r into -c */
   if (oflags['r'])
     {
-      int id = safe_atoi (oargs['r']);
+      char *id = oargs['r'];
       if (id < 0)
         fatal_moan ("cannot parse -r %s as an integer", oargs['r']);
 
       oflags['k']++;
-      oargs['k'] = mome ("/.sympathy/%s%d", hostname, id);
+      if (safe_atoi (id) > 0)
+        {
+          oargs['k'] = mome ("/.sympathy/%s%d", hostname, safe_atoi (id));
+        }
+      else
+        {
+          oargs['k'] = mome ("/.sympathy/%s", id);
+        }
       oflags['r'] = 0;
       oflags['c']++;
     }
@@ -448,7 +470,7 @@ main (int argc, char *argv[])
       if ((size.x > VT102_MAX_COLS) || (size.x < 1))
         fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS);
 
-      if ((size.y > VT102_ROWS) || (size.y < 1))
+      if ((size.y > VT102_MAX_ROWS) || (size.y < 1))
         fatal_moan ("-w requires a height between 1 and %d\n",
                     VT102_MAX_COLS);
 
@@ -478,6 +500,32 @@ main (int argc, char *argv[])
         }
       else
         {
+          /*HACK-- check that console=device does not occur in */
+          /*/proc/cmdline */
+          if (!oargs['d'])
+            fatal_moan ("no argument to -d");
+
+          {
+            char kernel_cmdline[4096] = { 0 };
+            char search_string[1024] = "console=";
+            char *ptr = oargs['d'];
+            int fd;
+
+            if (!strncmp ("/dev/", ptr, 5))
+              ptr += 5;
+
+            strcat (search_string, ptr);
+
+            fd = open ("/proc/cmdline", O_RDONLY);
+            read (fd, kernel_cmdline, sizeof (kernel_cmdline));
+            close (fd);
+
+            kernel_cmdline[sizeof (kernel_cmdline) - 1] = 0;
+
+            if (strstr (kernel_cmdline, search_string))
+              fatal_moan ("/proc/cmdline contains %s", search_string);
+          }
+
           tty =
             serial_open (oargs['d'],
                          oflags['K'] ? SERIAL_LOCK_ACTIVE :