1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 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 #ifndef HDC_SHELL_H 16 #define HDC_SHELL_H 17 #include "daemon_common.h" 18 #include <mutex> 19 20 namespace Hdc { 21 class HdcShell : public HdcTaskBase { 22 public: 23 HdcShell(HTaskInfo hTaskInfo); 24 virtual ~HdcShell(); 25 bool CommandDispatch(const uint16_t command, uint8_t *payload, const int payloadSize); 26 void StopTask(); 27 bool ReadyForRelease(); 28 29 private: 30 static bool FinishShellProc(const void *context, const bool result, const string exitMsg); 31 static bool ChildReadCallback(const void *context, uint8_t *buf, const int size); 32 int StartShell(); 33 int CreateSubProcessPTY(const char *cmd, const char *arg0, const char *arg1, pid_t *pid); 34 int ChildForkDo(int pts, const char *cmd, const char *arg0, const char *arg1); 35 bool SpecialSignal(uint8_t ch); 36 int ShellFork(const char *cmd, const char *arg0, const char *arg1); 37 38 HdcFileDescriptor *childShell; 39 pid_t pidShell = 0; 40 int fdPTY; 41 int ptm = 0; 42 const string devPTMX = "/dev/ptmx"; 43 static std::mutex mutexPty; 44 char devname[BUF_SIZE_SMALL] = ""; 45 }; 46 } // namespace Hdc 47 #endif