debugged\nadded return key action

This commit is contained in:
2023-01-18 23:12:21 +01:00
parent 13c5c3788f
commit a23ffb6bbe
11 changed files with 846 additions and 160 deletions
+50 -36
View File
@@ -1,5 +1,6 @@
#include "mainwindow.h"
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <pstreams/pstream.h>
@@ -47,55 +48,68 @@ FILE * popen2(array<string, 7> argv, string type, int & pid)
{
pid_t child_pid;
int fd[2];
pipe(fd);
QString message;
if((child_pid = fork()) == -1)
if (pipe(fd) == -1)
{
message = "Open pipe failed" + QString::fromStdString(strerror(errno));
QMessageBox::warning(
NULL,
"RsyncUI",
message);
}else
{
perror("fork");
exit(1);
}
/* child process */
if (child_pid == 0)
{
if (type == "r")
if((child_pid = fork()) == -1)
{
close(fd[READ]); //Close the READ end of the pipe since the child's fd is write-only
dup2(fd[WRITE], 1); //Redirect stdout to pipe
perror("fork");
exit(1);
}
/* child process */
if (child_pid == 0)
{
if (type == "r")
{
close(fd[READ]); //Close the READ end of the pipe since the child's fd is write-only
dup2(fd[WRITE], 1); //Redirect stdout to pipe
}
else
{
close(fd[WRITE]); //Close the WRITE end of the pipe since the child's fd is read-only
dup2(fd[READ], 0); //Redirect stdin to pipe
}
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
if (execl(argv[0].c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str(), argv[3].c_str(), argv[4].c_str(), argv[5].c_str(), NULL ) == -1)
{
perror("execl error => ");
}
exit (0);
}
else
{
close(fd[WRITE]); //Close the WRITE end of the pipe since the child's fd is read-only
dup2(fd[READ], 0); //Redirect stdin to pipe
if (type == "r")
{
close(fd[WRITE]); //Close the WRITE end of the pipe since parent's fd is read-only
}
else
{
close(fd[READ]); //Close the READ end of the pipe since parent's fd is write-only
}
}
setpgid(child_pid, child_pid); //Needed so negative PIDs can kill children of /bin/sh
if (execl(argv[0].c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str(), argv[3].c_str(), argv[4].c_str(), argv[5].c_str(), NULL ) == -1)
{
perror("execl error => ");
}
exit (0);
}
else
{
pid = child_pid;
if (type == "r")
{
close(fd[WRITE]); //Close the WRITE end of the pipe since parent's fd is read-only
}
else
{
close(fd[READ]); //Close the READ end of the pipe since parent's fd is write-only
return fdopen(fd[READ], "r");
}
return fdopen(fd[WRITE], "w");
}
pid = child_pid;
if (type == "r")
{
return fdopen(fd[READ], "r");
}
return fdopen(fd[WRITE], "w");
return 0;
}
int pclose2(FILE * fp, pid_t pid)