* Began (but did not finish) applying GPL3+ declarations to each source file. This...
[citadel.git] / citadel / ctdlmigrate.c
index 5f4e8ec7c1e327eaff7c3bc493ea3bee5af853e7..65f06c64409198b388946c1618bd11684f7f5494 100644 (file)
@@ -9,9 +9,21 @@
  *
  * Copyright (c) 2009 citadel.org
  *
- * This program is licensed to you under the terms of the GNU General Public License v3
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
  *
- * FIXME handle -h on both sides
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * (Note: a useful future enhancement might be to support "-h" on both sides)
  *
  */
 
@@ -85,7 +97,6 @@ int main(int argc, char *argv[])
        int linecount = 0;
        char spinning[4] = "-\\|/" ;
        int exitcode = 0;
-       pid_t sshpid;
        
        calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
        CtdlMakeTempFileName(socket_path, sizeof socket_path);
@@ -139,40 +150,14 @@ int main(int argc, char *argv[])
                remote_host);
        getz(remote_user);
 
-       sshpid = fork();
-       if (sshpid < 0)
-       {
-               printf("\n%s\n", strerror(errno));
-               exitcode = errno;
-               goto THEEND;
-       }
-       else if (sshpid == 0)
-       {
-               printf("\nEstablishing an SSH connection to the source system...\n\n");
-               unlink(socket_path);
-               snprintf(cmd, sizeof cmd, "%s@%s", remote_user, remote_host);
-               execlp("ssh", "ssh", "-MNf", "-S", socket_path, cmd, NULL);
-               cmdexit = errno;
-               printf("\n%s\n", strerror(cmdexit));
-               exit(cmdexit);          /* child process exits */
-       }
-
-       /* If we get here we are the parent process */
-       if (waitpid(sshpid, &cmdexit, 0) <= 0) {
-               exitcode = errno;
-               printf("\n%s\n", strerror(errno));
-               goto THEEND;
-       }
-
-       if (WIFSIGNALED(cmdexit)) {
-               exitcode = errno;
-               printf("\n%s\n", strerror(errno));
-               goto THEEND;
-       }
-
-       if ((WIFEXITED(cmdexit)) && (WEXITSTATUS(cmdexit) != 0)) {
-               exitcode = WEXITSTATUS(cmdexit);
-               printf("\n%s\n", strerror(errno));
+       printf("\nEstablishing an SSH connection to the source system...\n\n");
+       unlink(socket_path);
+       snprintf(cmd, sizeof cmd, "ssh -MNf -S %s %s@%s", socket_path, remote_user, remote_host);
+       cmdexit = system(cmd);
+       printf("\n");
+       if (cmdexit != 0) {
+               printf("This program was unable to establish an SSH session to the source system.\n\n");
+               exitcode = cmdexit;
                goto THEEND;
        }
 
@@ -324,7 +309,6 @@ THEEND:     if (exitcode == 0) {
                exitcode = cmdexit;
        }
 
-       /* kill(sshpid, SIGKILL); */
        unlink(socket_path);
        exit(exitcode);
 }