2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_LIGHT_PROCESS_H_
18 #define incl_HPHP_LIGHT_PROCESS_H_
29 #include "hphp/util/process.h"
30 #include "hphp/util/lock.h"
33 ///////////////////////////////////////////////////////////////////////////////
34 // light-weight process
42 static bool Available();
43 static void Initialize(const std::string
&prefix
, int count
,
44 const std::vector
<int> &inherited_fds
);
45 static void ChangeUser(const std::string
&username
);
47 typedef std::function
<void(pid_t
)> LostChildHandler
;
48 static void SetLostChildHandler(const LostChildHandler
& handler
);
50 static FILE *popen(const char *cmd
, const char *type
,
51 const char *cwd
= nullptr);
52 static int pclose(FILE *f
);
55 * Opens a process with given cwd and environment variables.
57 * The parameters "created" and "desired" describe the pipes that need to
58 * be setup for the child process: "created" contains created fd for child,
59 * and "desired" contains desired fd in child.
61 * The parameter env contains strings of the form <name>=<content>.
63 static pid_t
proc_open(const char *cmd
, const std::vector
<int> &created
,
64 const std::vector
<int> &desired
,
65 const char *cwd
, const std::vector
<std::string
> &env
);
68 * The main process is not the (direct) parent of the worker process,
69 * and therefore it has to delegate to the shadow process to do waitpid.
70 * There can be a timeout (in seconds), after which SIGKILL is sent to
73 static pid_t
waitpid(pid_t pid
, int *stat_loc
, int options
, int timeout
= 0);
75 static pid_t
pcntl_waitpid(pid_t pid
, int *stat_loc
, int options
);
79 static void SigChldHandler(int sig
, siginfo_t
* info
, void* ctx
);
81 bool initShadow(const std::string
&prefix
, int id
,
82 const std::vector
<int> &inherited_fds
);
83 void runShadow(int fdin
, int fdout
);
87 * For later light processes to close their pipes to previous ones.
91 static FILE *LightPopenImpl(const char *cmd
, const char *type
,
93 static FILE *HeavyPopenImpl(const char *cmd
, const char *type
,
97 pid_t m_shadowProcess
;
98 FILE *m_fin
; // the pipe to read from the child
99 FILE *m_fout
; // the pipe to write to the child
101 std::string m_afdtFilename
;
104 std::map
<int64_t, int64_t> m_popenMap
;
107 ///////////////////////////////////////////////////////////////////////////////
110 #endif // incl_HPHP_LIGHT_PROCESS_H_