Fixing format issue

This commit is contained in:
CcydtN 2022-06-17 03:19:36 +08:00
parent 5fa61e5a54
commit b69375a918
2 changed files with 24 additions and 24 deletions

View file

@ -169,24 +169,24 @@ void CConfigManager::handleRawExec(const std::string& command, const std::string
toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " " + toExec; toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " " + toExec;
Debug::log(LOG, "Config executing %s", toExec.c_str()); Debug::log(LOG, "Config executing %s", toExec.c_str());
int socket[2];
if (pipe(socket) != 0) {
Debug::log(LOG, "Unable to create pipe for fork");
}
pid_t child ,grandchild; int socket[2];
if (pipe(socket) != 0) {
Debug::log(LOG, "Unable to create pipe for fork");
}
pid_t child, grandchild;
child = fork(); child = fork();
if (child<0){ if (child < 0) {
close(socket[0]); close(socket[0]);
close(socket[1]); close(socket[1]);
Debug::log(LOG, "Fail to create the first fork"); Debug::log(LOG, "Fail to create the first fork");
return; return;
} }
if (child == 0){ if (child == 0) {
// run in child // run in child
grandchild = fork(); grandchild = fork();
if (grandchild==0){ if (grandchild == 0) {
// run in grandchild // run in grandchild
close(socket[0]); close(socket[0]);
close(socket[1]); close(socket[1]);
@ -195,22 +195,22 @@ void CConfigManager::handleRawExec(const std::string& command, const std::string
_exit(0); _exit(0);
} }
close(socket[0]); close(socket[0]);
(void) write(socket[1], &grandchild, sizeof(grandchild)); write(socket[1], &grandchild, sizeof(grandchild));
close(socket[1]); close(socket[1]);
// exit child // exit child
_exit(0); _exit(0);
} }
// run in parent // run in parent
close(socket[1]); close(socket[1]);
(void) read(socket[0], &grandchild,sizeof(grandchild)); read(socket[0], &grandchild, sizeof(grandchild));
close(socket[0]); close(socket[0]);
// clear child and leave child to init // clear child and leave child to init
waitpid(child, NULL, 0); waitpid(child, NULL, 0);
if (child<0){ if (child < 0) {
Debug::log(LOG, "Fail to create the second fork"); Debug::log(LOG, "Fail to create the second fork");
return; return;
} }
Debug::log(LOG, "Process created with pid %d",grandchild); Debug::log(LOG, "Process created with pid %d", grandchild);
} }
void CConfigManager::handleMonitor(const std::string& command, const std::string& args) { void CConfigManager::handleMonitor(const std::string& command, const std::string& args) {

View file

@ -143,22 +143,22 @@ void CKeybindManager::spawn(std::string args) {
Debug::log(LOG, "Executing %s", args.c_str()); Debug::log(LOG, "Executing %s", args.c_str());
int socket[2]; int socket[2];
if (pipe(socket) != 0) { if (pipe(socket) != 0) {
Debug::log(LOG, "Unable to create pipe for fork"); Debug::log(LOG, "Unable to create pipe for fork");
} }
pid_t child ,grandchild; pid_t child, grandchild;
child = fork(); child = fork();
if (child<0){ if (child < 0) {
close(socket[0]); close(socket[0]);
close(socket[1]); close(socket[1]);
Debug::log(LOG, "Fail to create the first fork"); Debug::log(LOG, "Fail to create the first fork");
return; return;
} }
if (child == 0){ if (child == 0) {
// run in child // run in child
grandchild = fork(); grandchild = fork();
if (grandchild==0){ if (grandchild == 0) {
// run in grandchild // run in grandchild
close(socket[0]); close(socket[0]);
close(socket[1]); close(socket[1]);
@ -167,22 +167,22 @@ void CKeybindManager::spawn(std::string args) {
_exit(0); _exit(0);
} }
close(socket[0]); close(socket[0]);
(void) write(socket[1], &grandchild, sizeof(grandchild)); write(socket[1], &grandchild, sizeof(grandchild));
close(socket[1]); close(socket[1]);
// exit child // exit child
_exit(0); _exit(0);
} }
// run in parent // run in parent
close(socket[1]); close(socket[1]);
(void) read(socket[0], &grandchild,sizeof(grandchild)); read(socket[0], &grandchild, sizeof(grandchild));
close(socket[0]); close(socket[0]);
// clear child and leave child to init // clear child and leave child to init
waitpid(child, NULL, 0); waitpid(child, NULL, 0);
if (child<0){ if (child < 0) {
Debug::log(LOG, "Fail to create the second fork"); Debug::log(LOG, "Fail to create the second fork");
return; return;
} }
Debug::log(LOG, "Process Created with pid %d",grandchild); Debug::log(LOG, "Process Created with pid %d", grandchild);
} }
void CKeybindManager::killActive(std::string args) { void CKeybindManager::killActive(std::string args) {