[Box Backup-dev] COMMIT r782 - box/chris/general/lib/server
Ben Summers
boxbackup-dev at fluffy.co.uk
Sat Aug 19 17:35:22 BST 2006
mutter mutter coding standards mutter local variables mutter mutter
On 19 Aug 2006, at 16:32, subversion at fluffy.co.uk wrote:
> Author: chris
> Date: 2006-08-19 16:32:16 +0100 (Sat, 19 Aug 2006)
> New Revision: 782
>
> Modified:
> box/chris/general/lib/server/LocalProcessStream.cpp
> Log:
> * LocalProcessStream.cpp
> - Added support for SyncAllowScript under Win32
>
>
> Modified: box/chris/general/lib/server/LocalProcessStream.cpp
> ===================================================================
> --- box/chris/general/lib/server/LocalProcessStream.cpp 2006-08-19
> 15:31:48 UTC (rev 781)
> +++ box/chris/general/lib/server/LocalProcessStream.cpp 2006-08-19
> 15:32:16 UTC (rev 782)
> @@ -18,10 +18,15 @@
> #endif
>
> #include "LocalProcessStream.h"
> -#include "SocketStream.h"
> #include "autogen_ServerException.h"
> #include "Utils.h"
>
> +#ifdef WIN32
> + #include "FileStream.h"
> +#else
> + #include "SocketStream.h"
> +#endif
> +
> #include "MemLeakFindOn.h"
>
> #define MAX_ARGUMENTS 64
> @@ -101,9 +106,64 @@
> // Return the stream object and PID
> rPidOut = pid;
> return stream;
> +
> #else // WIN32
> - ::syslog(LOG_ERR, "vfork not implemented - LocalProcessStream.cpp");
> - std::auto_ptr<IOStream> stream;
> +
> + SECURITY_ATTRIBUTES secAttr;
> + secAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
> + secAttr.bInheritHandle = TRUE;
> + secAttr.lpSecurityDescriptor = NULL;
> +
> + HANDLE WriteInChild, ReadFromChild;
> + if (!CreatePipe(&ReadFromChild, &WriteInChild, &secAttr, 0))
> + {
> + ::syslog(LOG_ERR, "Failed to CreatePipe for child process: "
> + "error %d", GetLastError());
> + THROW_EXCEPTION(ServerException, SocketPairFailed)
> + }
> + SetHandleInformation(ReadFromChild, HANDLE_FLAG_INHERIT, 0);
> +
> + PROCESS_INFORMATION ProcInfo;
> + STARTUPINFO StartupInfo;
> +
> + ZeroMemory(&ProcInfo, sizeof(ProcInfo));
> + ZeroMemory(&StartupInfo, sizeof(StartupInfo));
> + StartupInfo.cb = sizeof(StartupInfo);
> + StartupInfo.hStdError = WriteInChild;
> + StartupInfo.hStdOutput = WriteInChild;
> + StartupInfo.hStdInput = INVALID_HANDLE_VALUE;
> + StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
> +
> + CHAR* CommandLineCopy = (CHAR*)malloc(strlen(CommandLine) + 1);
> + strcpy(CommandLineCopy, CommandLine);
> +
> + bool result = CreateProcess(NULL,
> + CommandLineCopy, // command line
> + NULL, // process security attributes
> + NULL, // primary thread security attributes
> + TRUE, // handles are inherited
> + 0, // creation flags
> + NULL, // use parent's environment
> + NULL, // use parent's current directory
> + &StartupInfo, // STARTUPINFO pointer
> + &ProcInfo); // receives PROCESS_INFORMATION
> +
> + free(CommandLineCopy);
> +
> + if (!result)
> + {
> + ::syslog(LOG_ERR, "Failed to CreateProcess: '%s': "
> + "error %d", CommandLine, GetLastError());
> + CloseHandle(WriteInChild);
> + CloseHandle(ReadFromChild);
> + THROW_EXCEPTION(ServerException, ServerForkError)
> + }
> +
> + CloseHandle(ProcInfo.hProcess);
> + CloseHandle(ProcInfo.hThread);
> + CloseHandle(WriteInChild);
> +
> + std::auto_ptr<IOStream> stream(new FileStream(ReadFromChild));
> return stream;
> #endif // ! WIN32
> }
>
> _______________________________________________
> Boxbackup-dev mailing list
> Boxbackup-dev at fluffy.co.uk
> http://lists.warhead.org.uk/mailman/listinfo/boxbackup-dev
More information about the Boxbackup-dev
mailing list