- 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));
- goto THEEND;
- }
-
- printf("\nTesting a command over the connection...\n\n");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s 'echo Remote commands are executing successfully.'",
- socket_path, remote_user, remote_host);
- cmdexit = system(cmd);
- printf("\n");
- if (cmdexit != 0) {
- printf("Remote commands are not succeeding.\n\n");
- exitcode = cmdexit;
- goto THEEND;
- }
-
- printf("\nLocating the remote 'sendcommand' and Citadel installation...\n");
- snprintf(remote_sendcommand, sizeof remote_sendcommand, "/usr/local/citadel/sendcommand");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s %s NOOP",
- socket_path, remote_user, remote_host, remote_sendcommand);
- cmdexit = system(cmd);
- if (cmdexit != 0) {
- snprintf(remote_sendcommand, sizeof remote_sendcommand, "/usr/sbin/sendcommand");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s %s NOOP",
- socket_path, remote_user, remote_host, remote_sendcommand);
- cmdexit = system(cmd);
+
+ snprintf(cmd, sizeof cmd, "ssh -MNf -S %s -l %s %s", socket_path, remote_user, remote_host);
+ sshpid = fork();
+ if (sshpid < 0) {
+ printf("%s\n", strerror(errno));
+ cmdexit = errno;
+ }
+ else if (sshpid == 0) {
+ execl("/bin/bash", "bash", "-c", cmd, (char *) NULL);
+ exit(1);
+ }
+ else { // Wait for SSH to go into the background
+ waitpid(sshpid, &cmdexit, 0);
+ }