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 25 matching lines...) Expand all Loading... |
36 // 1 bytes, expecting to only receive args_size_estimate. If it gets the extra | 36 // 1 bytes, expecting to only receive args_size_estimate. If it gets the extra |
37 // byte, it indicates that the string area has grown, and the sysctl() pair | 37 // byte, it indicates that the string area has grown, and the sysctl() pair |
38 // will be retried a limited number of times. | 38 // will be retried a limited number of times. |
39 | 39 |
40 size_t args_size_estimate; | 40 size_t args_size_estimate; |
41 size_t args_size; | 41 size_t args_size; |
42 std::string args; | 42 std::string args; |
43 int tries = 3; | 43 int tries = 3; |
44 do { | 44 do { |
45 int mib[] = {CTL_KERN, KERN_PROCARGS2, pid}; | 45 int mib[] = {CTL_KERN, KERN_PROCARGS2, pid}; |
46 int rv = sysctl(mib, arraysize(mib), NULL, &args_size_estimate, NULL, 0); | 46 int rv = |
| 47 sysctl(mib, arraysize(mib), nullptr, &args_size_estimate, nullptr, 0); |
47 if (rv != 0) { | 48 if (rv != 0) { |
48 return false; | 49 return false; |
49 } | 50 } |
50 | 51 |
51 args_size = args_size_estimate + 1; | 52 args_size = args_size_estimate + 1; |
52 args.resize(args_size); | 53 args.resize(args_size); |
53 rv = sysctl(mib, arraysize(mib), &args[0], &args_size, NULL, 0); | 54 rv = sysctl(mib, arraysize(mib), &args[0], &args_size, nullptr, 0); |
54 if (rv != 0) { | 55 if (rv != 0) { |
55 return false; | 56 return false; |
56 } | 57 } |
57 } while (args_size == args_size_estimate + 1 && tries--); | 58 } while (args_size == args_size_estimate + 1 && tries--); |
58 | 59 |
59 if (args_size == args_size_estimate + 1) { | 60 if (args_size == args_size_estimate + 1) { |
60 return false; | 61 return false; |
61 } | 62 } |
62 | 63 |
63 // KERN_PROCARGS2 needs to at least contain argc. | 64 // KERN_PROCARGS2 needs to at least contain argc. |
(...skipping 29 matching lines...) Expand all Loading... |
93 if (argc >= 0) { | 94 if (argc >= 0) { |
94 // Not every argument was recovered. | 95 // Not every argument was recovered. |
95 return false; | 96 return false; |
96 } | 97 } |
97 | 98 |
98 argv->swap(local_argv); | 99 argv->swap(local_argv); |
99 return true; | 100 return true; |
100 } | 101 } |
101 | 102 |
102 } // namespace crashpad | 103 } // namespace crashpad |
OLD | NEW |