OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include <errno.h> |
| 16 #include <limits.h> |
| 17 #include <stdio.h> |
| 18 #include <stdlib.h> |
| 19 #include <sys/types.h> |
| 20 #include <unistd.h> |
| 21 |
| 22 #include <algorithm> |
| 23 |
| 24 int main(int argc, char* argv[]) { |
| 25 // Make sure that there’s nothing open at any FD higher than 3. All FDs other |
| 26 // than stdin, stdout, and stderr should have been closed prior to or at |
| 27 // exec(). |
| 28 int max_fd = std::max(static_cast<int>(sysconf(_SC_OPEN_MAX)), OPEN_MAX); |
| 29 max_fd = std::max(max_fd, getdtablesize()); |
| 30 for (int fd = STDERR_FILENO + 1; fd < max_fd; ++fd) { |
| 31 if (close(fd) == 0 || errno != EBADF) { |
| 32 abort(); |
| 33 } |
| 34 } |
| 35 |
| 36 // Read a byte from stdin, expecting it to be a specific value. |
| 37 char c; |
| 38 ssize_t rv = read(STDIN_FILENO, &c, 1); |
| 39 if (rv != 1 || c != 'z') { |
| 40 abort(); |
| 41 } |
| 42 |
| 43 // Write a byte to stdout. |
| 44 c = 'Z'; |
| 45 rv = write(STDOUT_FILENO, &c, 1); |
| 46 if (rv != 1) { |
| 47 abort(); |
| 48 } |
| 49 |
| 50 return 0; |
| 51 } |
OLD | NEW |