From 61fa9a721dcf7009048638b731411ff1f5a1b49d Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Wed, 1 Sep 2021 19:53:24 +0000 Subject: remove unused methods * both StarterDoWait() and StarterDoCreateProcess() are now unused. * after this, SendFileDescriptor() isn't used either, remove it and some support code for sending file descriptors * also ReceiveEnvironmentVariables() has no usage, remove it. --- fastos/src/vespa/fastos/unix_process.cpp | 283 ------------------------------- fastos/src/vespa/fastos/unix_process.h | 7 - 2 files changed, 290 deletions(-) (limited to 'fastos/src') diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp index 2d3ef4a534e..b7358e5adb4 100644 --- a/fastos/src/vespa/fastos/unix_process.cpp +++ b/fastos/src/vespa/fastos/unix_process.cpp @@ -25,22 +25,6 @@ extern char **environ; } -#ifndef FASTOS_HAVE_ACCRIGHTSLEN - -#ifndef ALIGN -#define ALIGN(x) (((x) + sizeof(int) - 1) & ~(sizeof(int) - 1)) -#endif - -#ifndef CMSG_SPACE -#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l)) -#endif - -#ifndef CMSG_LEN -#define CMSG_LEN(l)(ALIGN(sizeof(struct cmsghdr)) + (l)) -#endif - -#endif - using namespace std::chrono_literals; using namespace std::chrono; @@ -1034,245 +1018,6 @@ RemoveChildProcess (FastOS_UNIX_RealProcess *node) node->_prev = nullptr; } -bool FastOS_UNIX_ProcessStarter::SendFileDescriptor (int fd) -{ - // printf("SENDFILEDESCRIPTOR\n"); - bool rc = false; - - struct msghdr msg; - struct iovec iov; - - memset(&msg, 0, sizeof(msg)); - memset(&iov, 0, sizeof(iov)); - -#ifndef FASTOS_HAVE_ACCRIGHTSLEN - union - { - struct cmsghdr cm; - char control[CMSG_SPACE(sizeof(int))]; - } control_un; - struct cmsghdr *cmptr; - - memset(&control_un, 0, sizeof(control_un)); - msg.msg_control = control_un.control; - msg.msg_controllen = sizeof(control_un.control); - - cmptr = CMSG_FIRSTHDR(&msg); - cmptr->cmsg_len = CMSG_LEN(sizeof(int)); - cmptr->cmsg_level = SOL_SOCKET; - cmptr->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmptr), &fd, sizeof(int)); -#else - msg.msg_accrights = static_cast(&fd); - msg.msg_accrightslen = sizeof(int); -#endif - - msg.msg_name = nullptr; - msg.msg_namelen = 0; - - char dummyData = '\0'; - iov.iov_base = &dummyData; - iov.iov_len = 1; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - int sendmsgrc = sendmsg(_starterSocketDescr, &msg, 0); - // printf("sendmsg = %d\n", sendmsgrc); - if (sendmsgrc < 0) - perror("sendmsg"); - else - rc = true; - - return rc; -} - -void FastOS_UNIX_ProcessStarter::StarterDoWait () -{ - // printf("WAIT FOR PROCESSES\n"); - - pid_t pid; - int status; - - pid_t deadProcesses[MAX_PROCESSES_PER_WAIT]; - int returnCodes[MAX_PROCESSES_PER_WAIT]; - int numDeadProcesses = 0; - - while((pid = waitpid(-1, &status, WNOHANG)) > 0) - { - // printf("Child %d has died\n", pid); - bool foundProcess = false; - - FastOS_UNIX_RealProcess *process, *next; - for(process = FastOS_UNIX_ProcessStarter::_processList; - process != nullptr; process = next) - { - - // Need to do this here since we are deleting entries - next = process->_next; - - if (process->GetProcessId() == pid) { - foundProcess = true; - RemoveChildProcess(process); - delete process; - break; - } - } - - if (!foundProcess && !_hasDetachedProcess) - printf("*** Strange... We don't know about pid %d\n", int(pid)); - - if (!foundProcess) - continue; /* Don't report death of detached processes */ - - deadProcesses[numDeadProcesses] = pid; - - returnCodes[numDeadProcesses] = normalizedWaitStatus(status); - - numDeadProcesses++; - if (numDeadProcesses == MAX_PROCESSES_PER_WAIT) - break; - } - - WriteBytes(_starterSocket, &numDeadProcesses, sizeof(int)); - for(int i=0; i 0) { - char runDir[runDirLength]; - ReadBytes(_starterSocket, runDir, runDirLength); - process->SetRunDir(runDir); - } - - int stdoutRedirNameLen = ReadInt(_starterSocket); - if (stdoutRedirNameLen > 0) { - char stdoutRedirName[stdoutRedirNameLen]; - ReadBytes(_starterSocket, stdoutRedirName, stdoutRedirNameLen); - process->SetStdoutRedirName(stdoutRedirName); - } - - int stderrRedirNameLen = ReadInt(_starterSocket); - if (stderrRedirNameLen > 0) { - char stderrRedirName[stderrRedirNameLen]; - ReadBytes(_starterSocket, stderrRedirName, stderrRedirNameLen); - process->SetStderrRedirName(stderrRedirName); - } - - if (process->Setup()) { - WriteInt(_starterSocket, CODE_SUCCESS); - - // Send IPC descriptor if the shell is not used - if (process->IsUsingShell()) - rc = true; - else { - if (SendFileDescriptor(process->GetIPCDescriptor())) { - process->CloseIPCDescriptor(); - WriteInt(_starterSocket, CODE_SUCCESS); - if (ReadInt(_starterSocket) == CODE_SUCCESS) - rc = true; - } else { - WriteInt(_starterSocket, CODE_FAILURE); - } - } - - if (rc) { - rc = false; - - if (!process->IsStdinPiped()) { - rc = true; - } else { - if (SendFileDescriptor(process->GetStdinDescriptor())) { - process->CloseStdinDescriptor(); - WriteInt(_starterSocket, CODE_SUCCESS); - if (ReadInt(_starterSocket) == CODE_SUCCESS) - rc = true; - } else { - WriteInt(_starterSocket, CODE_FAILURE); - } - } - } - - if (rc) { - rc = false; - - if (!process->IsStdoutPiped()) { - rc = true; - } else { - if (SendFileDescriptor(process->GetStdoutDescriptor())) { - process->CloseStdoutDescriptor(); - WriteInt(_starterSocket, CODE_SUCCESS); - if (ReadInt(_starterSocket) == CODE_SUCCESS) { - rc = true; - } - } else { - WriteInt(_starterSocket, CODE_FAILURE); - } - } - } - - if (rc) { - rc = false; - - if (!process->IsStderrPiped()) { - rc = true; - } else { - if (SendFileDescriptor(process->GetStderrDescriptor())) { - process->CloseStderrDescriptor(); - WriteInt(_starterSocket, CODE_SUCCESS); - if (ReadInt(_starterSocket) == CODE_SUCCESS) - rc = true; - } else { - WriteInt(_starterSocket, CODE_FAILURE); - } - } - } - - if (rc) { - rc = false; - - pid_t processId = -1; - if (process->ForkAndExec(cmdLine, - environmentVariables, - nullptr, - this)) - { - processId = process->GetProcessID(); - AddChildProcess(process); - rc = true; - } - WriteBytes(_starterSocket, &processId, sizeof(pid_t)); - } - } else { - WriteInt(_starterSocket, CODE_FAILURE); - } - - - if (!rc) delete process; - - char **pe = environmentVariables; - while(*pe != nullptr) { - delete [] *pe++; - } - delete [] environmentVariables; -} bool FastOS_UNIX_ProcessStarter::CreateSocketPairs () { @@ -1323,34 +1068,6 @@ FastOS_UNIX_ProcessStarter::~FastOS_UNIX_ProcessStarter () close(_mainSocket); } -char ** FastOS_UNIX_ProcessStarter::ReceiveEnvironmentVariables () -{ - int numEnvVars = ReadInt(_starterSocket); - - // printf("Receiving %d environment variables\n", numEnvVars); - char **myEnvironment = new char *[numEnvVars + 2]; - - // Reserve the first entry for the IPC parent variable - myEnvironment[0] = new char [1024]; - - int fillIndex=1; - for(int i=0; i