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, |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace crashpad { | 24 namespace crashpad { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 launch_data_t LaunchDataDictionaryForJob(const std::string& label) { | 28 launch_data_t LaunchDataDictionaryForJob(const std::string& label) { |
29 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); | 29 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); |
30 LaunchDataDictInsert( | 30 LaunchDataDictInsert( |
31 request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_GETJOB); | 31 request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_GETJOB); |
32 | 32 |
33 base::mac::ScopedLaunchData response(launch_msg(request)); | 33 base::mac::ScopedLaunchData response(LaunchMsg(request)); |
34 if (LaunchDataGetType(response) != LAUNCH_DATA_DICTIONARY) { | 34 if (LaunchDataGetType(response) != LAUNCH_DATA_DICTIONARY) { |
35 return nullptr; | 35 return nullptr; |
36 } | 36 } |
37 | 37 |
38 return response.release(); | 38 return response.release(); |
39 } | 39 } |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 bool ServiceManagementSubmitJob(CFDictionaryRef job_cf) { | 43 bool ServiceManagementSubmitJob(CFDictionaryRef job_cf) { |
44 base::mac::ScopedLaunchData job_launch(CFPropertyToLaunchData(job_cf)); | 44 base::mac::ScopedLaunchData job_launch(CFPropertyToLaunchData(job_cf)); |
45 if (!job_launch.get()) { | 45 if (!job_launch.get()) { |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 base::mac::ScopedLaunchData jobs(LaunchDataAlloc(LAUNCH_DATA_ARRAY)); | 49 base::mac::ScopedLaunchData jobs(LaunchDataAlloc(LAUNCH_DATA_ARRAY)); |
50 LaunchDataArraySetIndex(jobs, job_launch.release(), 0); | 50 LaunchDataArraySetIndex(jobs, job_launch.release(), 0); |
51 | 51 |
52 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); | 52 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); |
53 LaunchDataDictInsert(request, jobs.release(), LAUNCH_KEY_SUBMITJOB); | 53 LaunchDataDictInsert(request, jobs.release(), LAUNCH_KEY_SUBMITJOB); |
54 | 54 |
55 base::mac::ScopedLaunchData response(launch_msg(request)); | 55 base::mac::ScopedLaunchData response(LaunchMsg(request)); |
56 | |
57 if (LaunchDataGetType(response) != LAUNCH_DATA_ARRAY) { | 56 if (LaunchDataGetType(response) != LAUNCH_DATA_ARRAY) { |
58 return false; | 57 return false; |
59 } | 58 } |
60 | 59 |
61 if (LaunchDataArrayGetCount(response) != 1) { | 60 if (LaunchDataArrayGetCount(response) != 1) { |
62 return false; | 61 return false; |
63 } | 62 } |
64 | 63 |
65 launch_data_t response_element = LaunchDataArrayGetIndex(response, 0); | 64 launch_data_t response_element = LaunchDataArrayGetIndex(response, 0); |
66 if (LaunchDataGetType(response_element) != LAUNCH_DATA_ERRNO) { | 65 if (LaunchDataGetType(response_element) != LAUNCH_DATA_ERRNO) { |
67 return false; | 66 return false; |
68 } | 67 } |
69 | 68 |
70 int err = LaunchDataGetErrno(response_element); | 69 int err = LaunchDataGetErrno(response_element); |
71 if (err != 0) { | 70 if (err != 0) { |
72 return false; | 71 return false; |
73 } | 72 } |
74 | 73 |
75 return true; | 74 return true; |
76 } | 75 } |
77 | 76 |
78 bool ServiceManagementRemoveJob(const std::string& label, bool wait) { | 77 bool ServiceManagementRemoveJob(const std::string& label, bool wait) { |
79 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); | 78 base::mac::ScopedLaunchData request(LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); |
80 LaunchDataDictInsert( | 79 LaunchDataDictInsert( |
81 request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_REMOVEJOB); | 80 request, LaunchDataNewString(label.c_str()), LAUNCH_KEY_REMOVEJOB); |
82 | 81 |
83 base::mac::ScopedLaunchData response(launch_msg(request)); | 82 base::mac::ScopedLaunchData response(LaunchMsg(request)); |
84 if (LaunchDataGetType(response) != LAUNCH_DATA_ERRNO) { | 83 if (LaunchDataGetType(response) != LAUNCH_DATA_ERRNO) { |
85 return false; | 84 return false; |
86 } | 85 } |
87 | 86 |
88 int err = LaunchDataGetErrno(response); | 87 int err = LaunchDataGetErrno(response); |
89 if (err == EINPROGRESS) { | 88 if (err == EINPROGRESS) { |
90 if (wait) { | 89 if (wait) { |
91 // TODO(mark): Use a kqueue to wait for the process to exit. To avoid a | 90 // TODO(mark): Use a kqueue to wait for the process to exit. To avoid a |
92 // race, the kqueue would need to be set up prior to asking launchd to | 91 // race, the kqueue would need to be set up prior to asking launchd to |
93 // remove the job. Even so, the job’s PID may change between the time it’s | 92 // remove the job. Even so, the job’s PID may change between the time it’s |
(...skipping 30 matching lines...) Expand all Loading... |
124 | 123 |
125 launch_data_t pid = LaunchDataDictLookup(dictionary, LAUNCH_JOBKEY_PID); | 124 launch_data_t pid = LaunchDataDictLookup(dictionary, LAUNCH_JOBKEY_PID); |
126 if (!pid) { | 125 if (!pid) { |
127 return 0; | 126 return 0; |
128 } | 127 } |
129 | 128 |
130 if (LaunchDataGetType(pid) != LAUNCH_DATA_INTEGER) { | 129 if (LaunchDataGetType(pid) != LAUNCH_DATA_INTEGER) { |
131 return 0; | 130 return 0; |
132 } | 131 } |
133 | 132 |
134 return launch_data_get_integer(pid); | 133 return LaunchDataGetInteger(pid); |
135 } | 134 } |
136 | 135 |
137 } // namespace crashpad | 136 } // namespace crashpad |
OLD | NEW |