fish: Add --listen --csh to for csh, tcsh compatibility.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 5 Nov 2010 15:17:45 +0000 (15:17 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 5 Nov 2010 15:39:27 +0000 (15:39 +0000)
(Thanks Eric Blake).

fish/fish.c
fish/fish.h
fish/guestfish.pod
fish/rc.c

index d9a92dd..9f20bba 100644 (file)
@@ -67,6 +67,7 @@ int read_only = 0;
 int quit = 0;
 int verbose = 0;
 int remote_control_listen = 0;
 int quit = 0;
 int verbose = 0;
 int remote_control_listen = 0;
+int remote_control_csh = 0;
 int remote_control = 0;
 int exit_on_error = 1;
 int command_num = 0;
 int remote_control = 0;
 int exit_on_error = 1;
 int command_num = 0;
@@ -105,6 +106,7 @@ usage (int status)
              "  -h|--cmd-help cmd    Display detailed help on 'cmd'\n"
              "  -a|--add image       Add image\n"
              "  -c|--connect uri     Specify libvirt URI for -d option\n"
              "  -h|--cmd-help cmd    Display detailed help on 'cmd'\n"
              "  -a|--add image       Add image\n"
              "  -c|--connect uri     Specify libvirt URI for -d option\n"
+             "  --csh                Make --listen csh-compatible\n"
              "  -d|--domain guest    Add disks from libvirt guest\n"
              "  -D|--no-dest-paths   Don't tab-complete paths from guest fs\n"
              "  --echo-keys          Don't turn off echo for passphrases\n"
              "  -d|--domain guest    Add disks from libvirt guest\n"
              "  -D|--no-dest-paths   Don't tab-complete paths from guest fs\n"
              "  --echo-keys          Don't turn off echo for passphrases\n"
@@ -153,6 +155,7 @@ main (int argc, char *argv[])
     { "add", 1, 0, 'a' },
     { "cmd-help", 2, 0, 'h' },
     { "connect", 1, 0, 'c' },
     { "add", 1, 0, 'a' },
     { "cmd-help", 2, 0, 'h' },
     { "connect", 1, 0, 'c' },
+    { "csh", 0, 0, 0 },
     { "domain", 1, 0, 'd' },
     { "echo-keys", 0, 0, 0 },
     { "file", 1, 0, 'f' },
     { "domain", 1, 0, 'd' },
     { "echo-keys", 0, 0, 0 },
     { "file", 1, 0, 'f' },
@@ -262,6 +265,8 @@ main (int argc, char *argv[])
           format = NULL;
         else
           format = optarg;
           format = NULL;
         else
           format = optarg;
+      } else if (STREQ (long_options[option_index].name, "csh")) {
+        remote_control_csh = 1;
       } else {
         fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
                  program_name, long_options[option_index].name, option_index);
       } else {
         fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
                  program_name, long_options[option_index].name, option_index);
index 8fedf5d..3597805 100644 (file)
@@ -61,6 +61,7 @@ extern int command_num;
 extern int utf8_mode;
 extern int have_terminfo;
 extern int progress_bars;
 extern int utf8_mode;
 extern int have_terminfo;
 extern int progress_bars;
+extern int remote_control_csh;
 extern const char *libvirt_uri;
 extern int issue_command (const char *cmd, char *argv[], const char *pipe);
 extern void pod2text (const char *name, const char *shortdesc, const char *body);
 extern const char *libvirt_uri;
 extern int issue_command (const char *cmd, char *argv[], const char *pipe);
 extern void pod2text (const char *name, const char *shortdesc, const char *body);
index 2806102..d265a3d 100644 (file)
@@ -174,6 +174,11 @@ When used in conjunction with the I<-d> option, this specifies
 the libvirt URI to use.  The default is to use the default libvirt
 connection.
 
 the libvirt URI to use.  The default is to use the default libvirt
 connection.
 
+=item B<--csh>
+
+If using the I<--listen> option and a csh-like shell, use this option.
+See section L</REMOTE CONTROL AND CSH> below.
+
 =item B<-d libvirt-domain> | B<--domain libvirt-domain>
 
 Add disks from the named libvirt domain.  If the I<--ro> option is
 =item B<-d libvirt-domain> | B<--domain libvirt-domain>
 
 Add disks from the named libvirt domain.  If the I<--ro> option is
@@ -758,6 +763,13 @@ You can have several guestfish listener processes running using:
  guestfish --remote=$pid1 cmd
  guestfish --remote=$pid2 cmd
 
  guestfish --remote=$pid1 cmd
  guestfish --remote=$pid2 cmd
 
+=head2 REMOTE CONTROL AND CSH
+
+When using csh-like shells (csh, tcsh etc) you have to add the
+I<--csh> option:
+
+ eval "`guestfish --listen --csh`"
+
 =head2 REMOTE CONTROL DETAILS
 
 Remote control happens over a Unix domain socket called
 =head2 REMOTE CONTROL DETAILS
 
 Remote control happens over a Unix domain socket called
index 2d2f227..a2bde4a 100644 (file)
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -198,7 +198,12 @@ rc_listen (void)
 
   if (pid > 0) {
     /* Parent process. */
 
   if (pid > 0) {
     /* Parent process. */
-    printf ("GUESTFISH_PID=%d; export GUESTFISH_PID\n", pid);
+
+    if (!remote_control_csh)
+      printf ("GUESTFISH_PID=%d; export GUESTFISH_PID\n", pid);
+    else
+      printf ("setenv GUESTFISH_PID %d\n", pid);
+
     fflush (stdout);
     _exit (0);
   }
     fflush (stdout);
     _exit (0);
   }