OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/mac/service_management.h" | 15 #include "util/mac/service_management.h" |
16 | 16 |
17 #include <errno.h> | 17 #include <errno.h> |
18 #include <launch.h> | 18 #include <launch.h> |
19 #include <time.h> | |
20 | 19 |
21 #include "base/mac/scoped_launch_data.h" | 20 #include "base/mac/scoped_launch_data.h" |
22 #include "util/mac/launchd.h" | 21 #include "util/mac/launchd.h" |
| 22 #include "util/misc/clock.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 launch_data_t LaunchDataDictionaryForJob(const std::string& label) { | 26 launch_data_t LaunchDataDictionaryForJob(const std::string& label) { |
27 base::mac::ScopedLaunchData request( | 27 base::mac::ScopedLaunchData request( |
28 launch_data_alloc(LAUNCH_DATA_DICTIONARY)); | 28 launch_data_alloc(LAUNCH_DATA_DICTIONARY)); |
29 launch_data_dict_insert( | 29 launch_data_dict_insert( |
30 request, launch_data_new_string(label.c_str()), LAUNCH_KEY_GETJOB); | 30 request, launch_data_new_string(label.c_str()), LAUNCH_KEY_GETJOB); |
31 | 31 |
32 base::mac::ScopedLaunchData response(launch_msg(request)); | 32 base::mac::ScopedLaunchData response(launch_msg(request)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 | 90 |
91 int err = launch_data_get_errno(response); | 91 int err = launch_data_get_errno(response); |
92 if (err == EINPROGRESS) { | 92 if (err == EINPROGRESS) { |
93 if (wait) { | 93 if (wait) { |
94 // TODO(mark): Use a kqueue to wait for the process to exit. To avoid a | 94 // TODO(mark): Use a kqueue to wait for the process to exit. To avoid a |
95 // race, the kqueue would need to be set up prior to asking launchd to | 95 // race, the kqueue would need to be set up prior to asking launchd to |
96 // remove the job. Even so, the job’s PID may change between the time it’s | 96 // remove the job. Even so, the job’s PID may change between the time it’s |
97 // obtained and the time the kqueue is set up, so this is nontrivial. | 97 // obtained and the time the kqueue is set up, so this is nontrivial. |
98 do { | 98 do { |
99 timespec sleep_time; | 99 SleepNanoseconds(1E5); // 100 microseconds |
100 sleep_time.tv_sec = 0; | |
101 sleep_time.tv_nsec = 1E5; // 100 microseconds | |
102 nanosleep(&sleep_time, NULL); | |
103 } while (ServiceManagementIsJobLoaded(label)); | 100 } while (ServiceManagementIsJobLoaded(label)); |
104 } | 101 } |
105 | 102 |
106 return true; | 103 return true; |
107 } | 104 } |
108 | 105 |
109 if (err != 0) { | 106 if (err != 0) { |
110 return false; | 107 return false; |
111 } | 108 } |
112 | 109 |
(...skipping 17 matching lines...) Expand all Loading... |
130 | 127 |
131 launch_data_t pid = launch_data_dict_lookup(dictionary, LAUNCH_JOBKEY_PID); | 128 launch_data_t pid = launch_data_dict_lookup(dictionary, LAUNCH_JOBKEY_PID); |
132 if (launch_data_get_type(pid) != LAUNCH_DATA_INTEGER) { | 129 if (launch_data_get_type(pid) != LAUNCH_DATA_INTEGER) { |
133 return 0; | 130 return 0; |
134 } | 131 } |
135 | 132 |
136 return launch_data_get_integer(pid); | 133 return launch_data_get_integer(pid); |
137 } | 134 } |
138 | 135 |
139 } // namespace crashpad | 136 } // namespace crashpad |
OLD | NEW |