rexecd: avoid socket/pipe/socketpair dup to new task
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
57011d2313
commit
cc66e34fbf
@ -256,7 +256,7 @@ int main(int argc, FAR char **argv)
|
||||
|
||||
while (1)
|
||||
{
|
||||
sock = accept(serv, NULL, 0);
|
||||
sock = accept4(serv, NULL, 0, SOCK_CLOEXEC);
|
||||
if (sock < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <spawn.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
@ -139,7 +140,8 @@ FILE *popen(FAR const char *command, FAR const char *mode)
|
||||
* Is the pipe the input to the shell? Or the output?
|
||||
*/
|
||||
|
||||
if (strcmp(mode, "r") == 0 && (result = pipe(fd)) >= 0)
|
||||
if (strcmp(mode, "r") == 0 &&
|
||||
(result = pipe2(fd, O_CLOEXEC)) >= 0)
|
||||
{
|
||||
/* Pipe is the output from the shell */
|
||||
|
||||
@ -147,7 +149,8 @@ FILE *popen(FAR const char *command, FAR const char *mode)
|
||||
newfd[0] = fd[1];
|
||||
retfd = fd[0]; /* Use read side of the pipe to create the return stream */
|
||||
}
|
||||
else if (strcmp(mode, "w") == 0 && (result = pipe(fd)) >= 0)
|
||||
else if (strcmp(mode, "w") == 0 &&
|
||||
(result = pipe2(fd, O_CLOEXEC)) >= 0)
|
||||
{
|
||||
/* Pipe is the input to the shell */
|
||||
|
||||
@ -160,7 +163,8 @@ FILE *popen(FAR const char *command, FAR const char *mode)
|
||||
|
||||
#if defined(CONFIG_NET_LOCAL) && defined(CONFIG_NET_LOCAL_STREAM)
|
||||
else if ((strcmp(mode, "r+") == 0 || strcmp(mode, "w+") == 0) &&
|
||||
(result = socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) >= 0)
|
||||
(result = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
|
||||
0, fd)) >= 0)
|
||||
{
|
||||
/* Socketpair is the input/output to the shell */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user