Revert "netutils: Make telnetd_daemon() in public"

This reverts commit 000d1455b4.
This commit is contained in:
Xiang Xiao 2022-10-17 04:06:07 +08:00 committed by Masayuki Ishikawa
parent d6070cdfc8
commit 58c3dbac95
3 changed files with 23 additions and 131 deletions

View File

@ -65,20 +65,6 @@ struct telnetd_config_s
* connection is accepted. */
};
/* This structure represents the overall state of one telnet daemon instance
* (Yes, multiple telnet daemons are supported).
*/
struct telnetd_s
{
uint16_t port; /* The port to listen on (in network byte order) */
sa_family_t family; /* Address family */
uint8_t priority; /* The execution priority of the spawned task, */
size_t stacksize; /* The stack size needed by the spawned task */
main_t entry; /* The entrypoint of the task to spawn when a new
* connection is accepted. */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -91,23 +77,6 @@ extern "C"
#define EXTERN extern
#endif
/****************************************************************************
* Name: telnetd_daemon
*
* Description:
* This function is the Telnet daemon. It does not return (unless an
* error occurs).
*
* Parameters:
* Standard task start up arguments.
*
* Return:
* Does not return unless an error occurs.
*
****************************************************************************/
int telnetd_daemon(int argc, FAR char *argv[]);
/****************************************************************************
* Name: telnetd_start
*

View File

@ -11,24 +11,5 @@ config NETUTILS_TELNETD
---help---
Enable support for the Telnet daemon.
config NETUTILS_TELNETD_USE_POSIX_SPAWNP
bool "Telnet daemon uses posix_spawnp"
default y if BUILD_KERNEL
default n if !BUILD_KERNEL
depends on NETUTILS_TELNETD
---help---
Enable to use posix_spawnp instead of tak_create
config NETUTILS_TELNETD_PATH
string "Telnetd path"
default "/bin/telnetd"
depends on NETUTILS_TELNETD_USE_POSIX_SPAWNP
---help---
The path to the telnetd.
config NETUTILS_TELNETD_SHELL_PATH
string "Telnetd shell path"
default "/bin/sh"
depends on NETUTILS_TELNETD_USE_POSIX_SPAWNP
---help---
The path to the shell executable.
if NETUTILS_TELNETD
endif

View File

@ -41,7 +41,6 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <spawn.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@ -55,12 +54,22 @@
* Private Types
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/* This structure represents the overall state of one telnet daemon instance
* (Yes, multiple telnet daemons are supported).
*/
struct telnetd_s
{
uint16_t port; /* The port to listen on (in network byte order) */
sa_family_t family; /* Address family */
uint8_t priority; /* The execution priority of the spawned task, */
size_t stacksize; /* The stack size needed by the spawned task */
main_t entry; /* The entrypoint of the task to spawn when a new
* connection is accepted. */
};
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
@ -78,7 +87,7 @@
*
****************************************************************************/
int telnetd_daemon(int argc, FAR char *argv[])
static int telnetd_daemon(int argc, FAR char *argv[])
{
UNUSED(argc);
@ -94,11 +103,6 @@ int telnetd_daemon(int argc, FAR char *argv[])
#endif
} addr;
#ifdef CONFIG_NETUTILS_TELNETD_USE_POSIX_SPAWNP
posix_spawn_file_actions_t file_actions;
posix_spawnattr_t attr;
FAR char *argv1[2];
#endif
struct telnet_session_s session;
#ifdef CONFIG_NET_SOLINGER
struct linger ling;
@ -314,29 +318,6 @@ int telnetd_daemon(int argc, FAR char *argv[])
close(drvrfd);
}
#ifdef CONFIG_NETUTILS_TELNETD_USE_POSIX_SPAWNP
posix_spawn_file_actions_init(&file_actions);
ret = posix_spawnattr_init(&attr);
if (ret < 0)
{
nerr("ERROR in posix_spawnattr_init(): %d\n", errno);
goto errout_with_socket;
}
argv1[0] = CONFIG_NETUTILS_TELNETD_SHELL_PATH;
argv1[1] = NULL;
ret = posix_spawnp(&pid,
CONFIG_NETUTILS_TELNETD_SHELL_PATH,
&file_actions, &attr, argv1, NULL);
if (ret < 0)
{
nerr("ERROR in posix_spawnp(): %d\n", errno);
goto errout_with_attrs;
}
#else
/* Create a task to handle the connection. The created task
* will inherit the new stdin, stdout, and stderr.
*/
@ -349,7 +330,6 @@ int telnetd_daemon(int argc, FAR char *argv[])
nerr("ERROR: Failed start the telnet session: %d\n", errno);
goto errout_with_socket;
}
#endif
/* Forget about the connection. */
@ -361,11 +341,6 @@ int telnetd_daemon(int argc, FAR char *argv[])
errout_with_acceptsd:
close(acceptsd);
#ifdef CONFIG_NETUTILS_TELNETD_USE_POSIX_SPAWNP
errout_with_attrs:
posix_spawnattr_destroy(&attr);
#endif
errout_with_socket:
close(listensd);
errout_with_daemon:
@ -373,6 +348,10 @@ errout_with_daemon:
return 1;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: telnetd_start
*
@ -394,46 +373,10 @@ errout_with_daemon:
int telnetd_start(FAR struct telnetd_config_s *config)
{
FAR char *argv[2];
pid_t pid;
#ifdef CONFIG_NETUTILS_TELNETD_USE_POSIX_SPAWNP
posix_spawn_file_actions_t file_actions;
posix_spawnattr_t attr;
int ret = 0;
posix_spawn_file_actions_init(&file_actions);
ret = posix_spawnattr_init(&attr);
if (ret < 0)
{
nerr("ERROR in posix_spawnattr_init(): %d\n", errno);
pid = -1;
goto errout;
}
argv[0] = CONFIG_NETUTILS_TELNETD_PATH;
argv[1] = NULL;
ret = posix_spawnp(&pid,
CONFIG_NETUTILS_TELNETD_PATH,
&file_actions, &attr, argv, NULL);
if (ret < 0)
{
nerr("ERROR in posix_spawnp(): %d\n", errno);
pid = -1;
goto errout_with_attrs;
}
errout_with_attrs:
posix_spawnattr_destroy(&attr);
errout:
return pid;
#else
FAR struct telnetd_s *daemon;
FAR char *argv[2];
char arg0[sizeof("0x1234567812345678")];
pid_t pid;
/* Allocate a state structure for the new daemon */
@ -470,5 +413,4 @@ errout:
/* Return success */
return pid;
#endif
}