Home | History | Annotate | Download | only in tombstoned
      1 /*
      2  * Copyright 2016, The Android Open Source Project
      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 #pragma once
     18 
     19 #include <sys/types.h>
     20 
     21 #include <unordered_map>
     22 
     23 #include <event2/event.h>
     24 #include <event2/listener.h>
     25 
     26 #include <android-base/unique_fd.h>
     27 
     28 struct InterceptManager;
     29 
     30 struct Intercept {
     31   ~Intercept() {
     32     event_free(intercept_event);
     33   }
     34 
     35   InterceptManager* intercept_manager = nullptr;
     36   event* intercept_event = nullptr;
     37   android::base::unique_fd sockfd;
     38 
     39   pid_t intercept_pid = -1;
     40   android::base::unique_fd output_fd;
     41   bool registered = false;
     42 };
     43 
     44 struct InterceptManager {
     45   event_base* base;
     46   std::unordered_map<pid_t, std::unique_ptr<Intercept>> intercepts;
     47   evconnlistener* listener = nullptr;
     48 
     49   InterceptManager(event_base* _Nonnull base, int intercept_socket);
     50   InterceptManager(InterceptManager& copy) = delete;
     51   InterceptManager(InterceptManager&& move) = delete;
     52 
     53   bool GetIntercept(pid_t pid, android::base::unique_fd* out_fd);
     54 };
     55