| Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2009 JetBrains s.r.o. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "stdafx.h" |
| 18 | |
| 19 | |
| 20 | int _tmain(int argc, _TCHAR* argv[]) |
| 21 | { |
| 22 | if (argc < 3) return 0; |
| 23 | int ppid = _ttoi(argv [1]); |
| 24 | HANDLE parent_process = OpenProcess(SYNCHRONIZE, FALSE, ppid); |
| 25 | if (parent_process) |
| 26 | { |
| 27 | WaitForSingleObject(parent_process, INFINITE); |
| 28 | CloseHandle(parent_process); |
| 29 | } |
| 30 | |
| 31 | int child_argc = argc-2; |
| 32 | _TCHAR** child_argv = new _TCHAR* [child_argc+1]; |
| 33 | for(int i = 0; i < child_argc; i++) |
| 34 | { |
| 35 | if (_tcschr(argv[i+2], ' ')) |
| 36 | { |
| 37 | int len = _tcslen(argv[i+2]) + 3; |
| 38 | TCHAR *arg = new TCHAR[len]; |
| 39 | arg[0] = '\"'; |
| 40 | _tcscpy_s(arg+1, len, argv[i+2]); |
| 41 | _tcscat_s(arg, len, _T("\"")); |
| 42 | child_argv[i] = arg; |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | child_argv[i] = argv[i+2]; |
| 47 | } |
| 48 | } |
| 49 | child_argv[child_argc] = '\0'; |
| 50 | |
| 51 | int rc = _texecv(argv [2], child_argv); |
| 52 | if (rc == -1) |
| 53 | { |
| 54 | _tprintf(_T("Error restarting process: errno is %d"), errno); |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |