1 /* 2 * %CopyrightBegin% 3 * 4 * Copyright Ericsson AB 2015-2017. All Rights Reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * %CopyrightEnd% 19 * 20 * This file defines the interface between erts and child_setup. 21 */ 22 23 #ifndef _ERL_UNIX_FORKER_H 24 #define _ERL_UNIX_FORKER_H 25 26 #include "sys.h" 27 28 #ifdef __FreeBSD__ 29 /* The freebsd sendmsg man page explicitly states that 30 you should not close fds before they are known 31 to have reached the other side, so this Ack protects 32 against that. */ 33 #define FORKER_PROTO_START_ACK 1 34 #endif 35 36 #define FORKER_ARGV_NO_OF_ARGS 3 37 #define FORKER_ARGV_PROGNAME_IX 0 /* Program name */ 38 #define FORKER_ARGV_MAX_FILES 1 /* max_files */ 39 40 #define FORKER_FLAG_USE_STDIO (1 << 0) /* dup the pipe to stdin/stderr */ 41 #define FORKER_FLAG_EXIT_STATUS (1 << 1) /* send the exit status to parent */ 42 #define FORKER_FLAG_DO_READ (1 << 2) /* dup write fd */ 43 #define FORKER_FLAG_DO_WRITE (1 << 3) /* dup read fd */ 44 45 #if SIZEOF_VOID_P == SIZEOF_LONG 46 typedef unsigned long ErtsSysPortId; 47 #elif SIZEOF_VOID_P == SIZEOF_INT 48 typedef unsigned int ErtsSysPortId; 49 #elif SIZEOF_VOID_P == SIZEOF_LONG_LONG 50 typedef unsigned long long ErtsSysPortId; 51 #endif 52 53 typedef struct ErtsSysForkerProto_ { 54 enum { 55 ErtsSysForkerProtoAction_Start, 56 ErtsSysForkerProtoAction_StartAck, 57 ErtsSysForkerProtoAction_Go, 58 ErtsSysForkerProtoAction_SigChld, 59 ErtsSysForkerProtoAction_Ack 60 } action; 61 union { 62 struct { 63 ErtsSysPortId port_id; 64 int fds[3]; 65 } start; 66 struct { 67 pid_t os_pid; 68 int error_number; 69 } go; 70 struct { 71 ErtsSysPortId port_id; 72 int error_number; 73 } sigchld; 74 } u; 75 } ErtsSysForkerProto; 76 77 #endif /* #ifndef _ERL_UNIX_FORKER_H */ 78