[PATCH] build: Include header.am in cpukit/Makefile.am

2018-10-10 Thread Sebastian Huber
Include all cpukit/*/header.am files in cpukit/Makefile.am.  This gets
rid of all subtree Makefile.am and the sudirs hack.
---
 bootstrap |  57 ++--
 cpukit/Makefile.am|  56 +++-
 cpukit/automake/subdirs.am|  53 
 cpukit/configure.ac   |  24 +---
 cpukit/header-dirs.am |  80 +++
 cpukit/headers.am |  65 -
 cpukit/libnetworking/Makefile.am  |   3 -
 cpukit/libnetworking/headers.am   | 245 +++---
 cpukit/score/Makefile.am  |   9 --
 cpukit/score/cpu/Makefile.am  |  23 
 cpukit/score/cpu/arm/Makefile.am  |   1 -
 cpukit/score/cpu/arm/headers.am   |  34 ++---
 cpukit/score/cpu/bfin/Makefile.am |   1 -
 cpukit/score/cpu/bfin/headers.am  |  32 ++---
 cpukit/score/cpu/epiphany/Makefile.am |   1 -
 cpukit/score/cpu/epiphany/headers.am  |  20 +--
 cpukit/score/cpu/h8300/headers.am |   5 +-
 cpukit/score/cpu/i386/Makefile.am |   1 -
 cpukit/score/cpu/i386/headers.am  |  29 ++--
 cpukit/score/cpu/lm32/Makefile.am |   1 -
 cpukit/score/cpu/lm32/headers.am  |  23 +---
 cpukit/score/cpu/m32c/Makefile.am |   1 -
 cpukit/score/cpu/m32c/headers.am  |  22 +--
 cpukit/score/cpu/m68k/Makefile.am |   1 -
 cpukit/score/cpu/m68k/headers.am  |  32 ++---
 cpukit/score/cpu/mips/Makefile.am |   1 -
 cpukit/score/cpu/mips/headers.am  |  28 ++--
 cpukit/score/cpu/moxie/Makefile.am|   1 -
 cpukit/score/cpu/moxie/headers.am |  21 +--
 cpukit/score/cpu/nios2/Makefile.am|   1 -
 cpukit/score/cpu/nios2/headers.am |  27 ++--
 cpukit/score/cpu/no_cpu/Makefile.am   |   1 -
 cpukit/score/cpu/no_cpu/headers.am|  16 +--
 cpukit/score/cpu/or1k/Makefile.am |   1 -
 cpukit/score/cpu/or1k/headers.am  |  20 +--
 cpukit/score/cpu/powerpc/Makefile.am  |   1 -
 cpukit/score/cpu/powerpc/headers.am   |  28 ++--
 cpukit/score/cpu/riscv/Makefile.am|   1 -
 cpukit/score/cpu/riscv/headers.am |  20 +--
 cpukit/score/cpu/sh/Makefile.am   |   1 -
 cpukit/score/cpu/sh/headers.am|  18 +--
 cpukit/score/cpu/sparc/Makefile.am|   1 -
 cpukit/score/cpu/sparc/headers.am |  30 ++---
 cpukit/score/cpu/sparc64/Makefile.am  |   1 -
 cpukit/score/cpu/sparc64/headers.am   |  16 +--
 cpukit/score/cpu/v850/Makefile.am |   1 -
 cpukit/score/cpu/v850/headers.am  |  23 +---
 cpukit/score/cpu/x86_64/Makefile.am   |   1 -
 cpukit/score/cpu/x86_64/headers.am|  25 ++--
 49 files changed, 435 insertions(+), 668 deletions(-)
 delete mode 100644 cpukit/automake/subdirs.am
 create mode 100644 cpukit/header-dirs.am
 delete mode 100644 cpukit/libnetworking/Makefile.am
 delete mode 100644 cpukit/score/Makefile.am
 delete mode 100644 cpukit/score/cpu/Makefile.am
 delete mode 100644 cpukit/score/cpu/arm/Makefile.am
 delete mode 100644 cpukit/score/cpu/bfin/Makefile.am
 delete mode 100644 cpukit/score/cpu/epiphany/Makefile.am
 delete mode 100644 cpukit/score/cpu/i386/Makefile.am
 delete mode 100644 cpukit/score/cpu/lm32/Makefile.am
 delete mode 100644 cpukit/score/cpu/m32c/Makefile.am
 delete mode 100644 cpukit/score/cpu/m68k/Makefile.am
 delete mode 100644 cpukit/score/cpu/mips/Makefile.am
 delete mode 100644 cpukit/score/cpu/moxie/Makefile.am
 delete mode 100644 cpukit/score/cpu/nios2/Makefile.am
 delete mode 100644 cpukit/score/cpu/no_cpu/Makefile.am
 delete mode 100644 cpukit/score/cpu/or1k/Makefile.am
 delete mode 100644 cpukit/score/cpu/powerpc/Makefile.am
 delete mode 100644 cpukit/score/cpu/riscv/Makefile.am
 delete mode 100644 cpukit/score/cpu/sh/Makefile.am
 delete mode 100644 cpukit/score/cpu/sparc/Makefile.am
 delete mode 100644 cpukit/score/cpu/sparc64/Makefile.am
 delete mode 100644 cpukit/score/cpu/v850/Makefile.am
 delete mode 100644 cpukit/score/cpu/x86_64/Makefile.am

diff --git a/bootstrap b/bootstrap
index 8e284a552e..7ed592d435 100755
--- a/bootstrap
+++ b/bootstrap
@@ -81,21 +81,58 @@ headers)
 exit 1
   fi
   base="$PWD"
+
+  # Generate cpukit/header-dirs.am
+  tmp="$base/cpukit/header-dirs.am.new"
+  hdr_dirs=`for i in cpukit/include cpukit/libnetworking 
cpukit/score/cpu/*/include ; do
+cd "$i"
+find -mindepth 1 -type d
+cd "$base"
+  done | sort -u | sed 's%^\./%%'`
+  echo '## This file was generated by "./boostrap -H".' > "$tmp"
+  echo 'include_HEADERS =' >> "$tmp"
+  for dir in $hdr_dirs ; do
+am_dir=`echo $dir | sed 's%[/-]%_%g'`
+echo "include_${am_dir}dir = \$(includedir)/$dir" >> "$tmp"
+echo "include_${am_dir}_HEADERS =" >> "$tmp"
+  done
+  diff -q "$tmp" "cpukit/header-dirs.am" || mv "$tmp" "cpukit/header-dirs.am"
+  rm -f "$tmp"
+
+  # Generate cpukit/*/headers.am
   tmp="$base/headers.am.new"
-  for i in cpukit/include cpukit/score/cpu/*/include bsps/include 
bsps/*/include bsps/*/*/include ; do
+  cpukit="$base/cpukit"
+  cd "$cpukit"
+  for inc in include score/cpu/*/include ; do
+echo '## This f

Merged cpukit Makefile breaks covoar

2018-10-10 Thread Joel Sherrill
Hi

Just a reminder that coverage testing is now completely dead until the
method for getting symbols from the build tree is reworked.

As Chris suggested, the reference to the temporary libraries has to change
to wildcarded .o sets (possibly multiple patterns per old library). This
logic is likely contained in only one file in covoar but it has to be
updated.

--joel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 6/6] telnetd: Add server port to configuration

2018-10-10 Thread Sebastian Huber
Close #3543.
---
 cpukit/include/rtems/telnetd.h  |  9 -
 cpukit/telnetd/telnetd.c| 13 ++---
 testsuites/libtests/telnetd01/telnetd01.scn |  2 +-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/cpukit/include/rtems/telnetd.h b/cpukit/include/rtems/telnetd.h
index e662874a81..1f8e1c55c3 100644
--- a/cpukit/include/rtems/telnetd.h
+++ b/cpukit/include/rtems/telnetd.h
@@ -92,6 +92,13 @@ typedef struct {
* Use 0 for the default value.
*/
   uint16_t client_maximum;
+
+  /**
+   * @brief Server port number in host byte order.
+   *
+   * Use 0 for the default value.
+   */
+  uint16_t port;
 } rtems_telnetd_config_table;
 
 /**
@@ -100,7 +107,7 @@ typedef struct {
  * @retval RTEMS_SUCCESSFUL Successful operation.
  * @retval RTEMS_INVALID_ADDRESS The command function in the configuration is
  *   @c NULL.
- * @retval RTEMS_RESOURCE_IN_USE The Telnet server was already started.
+ * @retval RTEMS_RESOURCE_IN_USE The server port is already in use.
  * @retval RTEMS_NOT_IMPLEMENTED The keep stdio configuration option is true.
  * @retval RTEMS_UNSATISFIED Not enough resources to start the Telnet server or
  *   task priority in configuration is invalid.
diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 9f2dc25c93..4f4edff71b 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -44,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,7 +52,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -295,7 +295,7 @@ static rtems_status_code 
telnetd_create_server_socket(telnetd_context *ctx)
 
   memset(&srv, 0, sizeof(srv));
   srv.sin.sin_family = AF_INET;
-  srv.sin.sin_port = htons(23);
+  srv.sin.sin_port = htons(ctx->config.port);
   address_len = sizeof(srv.sin);
 
   if (bind(ctx->server_socket, &srv.sa, address_len) != 0) {
@@ -415,6 +415,10 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 ctx->config.stack_size = (size_t)32 * 1024;
   }
 
+  if (ctx->config.port == 0) {
+ctx->config.port = 23;
+  }
+
   sc = telnetd_create_server_socket(ctx);
   if (sc != RTEMS_SUCCESSFUL) {
 telnetd_destroy_context(ctx);
@@ -447,6 +451,9 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 (rtems_task_argument) ctx
   );
 
-  syslog(LOG_DAEMON | LOG_INFO, "telnetd: started successfully");
+  syslog(
+LOG_DAEMON | LOG_INFO,
+"telnetd: started successfully on port %" PRIu16, ctx->config.port
+  );
   return RTEMS_SUCCESSFUL;
 }
diff --git a/testsuites/libtests/telnetd01/telnetd01.scn 
b/testsuites/libtests/telnetd01/telnetd01.scn
index 31439da5a0..3202f3e094 100644
--- a/testsuites/libtests/telnetd01/telnetd01.scn
+++ b/testsuites/libtests/telnetd01/telnetd01.scn
@@ -5,7 +5,7 @@
 *** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 
9670d7541e0621915e521fe76e7bb33de8cee661, Newlib 
d13c84eb07e35984bf7a974cd786a6cdac29e6b9)
 syslog: telnetd: configuration with invalid command
 syslog: telnetd: cannot create session task
-syslog: telnetd: started successfully
+syslog: telnetd: started successfully on port 23
 syslog: telnetd: cannot bind server socket
 
 *** END OF TEST TELNETD 1 ***
-- 
2.16.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 0/6] Allocate resources at Telnet server start

2018-10-10 Thread Sebastian Huber
This patch set changes the Telnet server implementation to allocate all
resources (except the socket returned by accept()) at the service start
via rtems_telnetd_start().

You can now also start the Telnet server on non-standard ports.

I tested it using libbsd.

Sebastian Huber (6):
  telnetd: Simplify task spawn function
  telnetd: Rename shell_args to telnetd_session
  telnetd: Create server socket at start
  telnetd: Allocate the server context
  telnetd: Create sessions at start
  telnetd: Add server port to configuration

 cpukit/include/rtems/pty.h  |  11 +-
 cpukit/include/rtems/telnetd.h  |   9 +-
 cpukit/telnetd/pty.c|  33 +-
 cpukit/telnetd/telnetd.c| 634 ++--
 testsuites/libtests/telnetd01/init.c|   6 +-
 testsuites/libtests/telnetd01/telnetd01.scn |   7 +-
 6 files changed, 360 insertions(+), 340 deletions(-)

-- 
2.16.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 4/6] telnetd: Allocate the server context

2018-10-10 Thread Sebastian Huber
Update #3543.
---
 cpukit/telnetd/telnetd.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 0fd3b317a9..aadf33deb7 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -81,9 +81,6 @@ typedef union uni_sa {
   struct sockaddr sa;
 } uni_sa;
 
-/***/
-static telnetd_context telnetd_instance;
-
 static telnetd_session *grab_a_Connection(telnetd_context *ctx)
 {
   telnetd_session *session;
@@ -245,6 +242,8 @@ static void telnetd_destroy_context(telnetd_context *ctx)
   if (ctx->server_socket >= 0) {
 close(ctx->server_socket);
   }
+
+  free(ctx);
 }
 
 static rtems_status_code telnetd_create_server_socket(telnetd_context *ctx)
@@ -288,7 +287,7 @@ static rtems_status_code 
telnetd_create_server_socket(telnetd_context *ctx)
 
 rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
 {
-  telnetd_context *ctx = &telnetd_instance;
+  telnetd_context *ctx;
   rtems_id task_id;
   rtems_status_code sc;
 
@@ -297,12 +296,14 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 return RTEMS_INVALID_ADDRESS;
   }
 
-  if (ctx->config.command != NULL) {
-syslog(LOG_DAEMON | LOG_ERR, "telnetd: already started");
-return RTEMS_RESOURCE_IN_USE;
+  ctx = calloc(1, sizeof(*ctx));
+  if (ctx == NULL) {
+syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot allocate server context");
+return RTEMS_UNSATISFIED;
   }
 
   ctx->config = *config;
+  ctx->server_socket = -1;
 
   /* Check priority */
 #ifdef RTEMS_NETWORKING
-- 
2.16.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/6] telnetd: Rename shell_args to telnetd_session

2018-10-10 Thread Sebastian Huber
Update #3543.
---
 cpukit/telnetd/telnetd.c | 66 
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index fcc89ff5e3..1fcd4c54d9 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -64,11 +64,11 @@
 
 typedef struct telnetd_context telnetd_context;
 
-struct shell_args {
+typedef struct telnetd_session {
   rtems_pty_context  pty;
   char   peername[16];
   telnetd_context   *ctx;
-};
+} telnetd_session;
 
 struct telnetd_context {
   rtems_telnetd_config_table config;
@@ -85,7 +85,7 @@ static int sockpeername(int sock, char *buf, int bufsz);
 /***/
 static telnetd_context telnetd_instance;
 
-static struct shell_args *grab_a_Connection(
+static telnetd_session *grab_a_Connection(
   telnetd_context *ctx,
   int des_socket,
   uni_sa *srv,
@@ -93,7 +93,7 @@ static struct shell_args *grab_a_Connection(
   int sz
 )
 {
-  struct shell_args *args;
+  telnetd_session *session;
   socklen_t size_adr = sizeof(srv->sin);
   int acp_sock;
 
@@ -101,8 +101,8 @@ static struct shell_args *grab_a_Connection(
 return NULL;
   }
 
-  args = malloc(sizeof(*args));
-  if (args == NULL) {
+  session = malloc(sizeof(*session));
+  if (session == NULL) {
 perror("telnetd:malloc");
 return NULL;
   }
@@ -110,14 +110,14 @@ static struct shell_args *grab_a_Connection(
   acp_sock = accept(des_socket,&srv->sa,&size_adr);
   if (acp_sock<0) {
 perror("telnetd:accept");
-free(args);
+free(session);
 return NULL;
   };
 
-  if (telnet_get_pty(&args->pty, acp_sock) == NULL) {
+  if (telnet_get_pty(&session->pty, acp_sock) == NULL) {
 syslog( LOG_DAEMON | LOG_ERR, "telnetd: unable to obtain PTY");
 /* NOTE: failing 'do_get_pty()' closed the socket */
-free(args);
+free(session);
 return NULL;
   }
 
@@ -128,12 +128,12 @@ static struct shell_args *grab_a_Connection(
   syslog(LOG_DAEMON | LOG_INFO,
   "telnetd: accepted connection from %s on %s",
   peername,
-  args->pty.name);
+  session->pty.name);
 #endif
 
   ++ctx->active_clients;
-  args->ctx = ctx;
-  return args;
+  session->ctx = ctx;
+  return session;
 }
 
 
@@ -199,20 +199,20 @@ static rtems_id telnetd_spawn_task(
 }
 
 static void
-spawned_shell(rtems_task_argument arg);
+telnetd_session_task(rtems_task_argument arg);
 
 /***/
 static void
-telnetd_server_task(rtems_task_argument targ)
+telnetd_server_task(rtems_task_argument arg)
 {
   intdes_socket;
   uni_sa srv;
   char   peername[16];
   inti=1;
   intsize_adr;
-  struct shell_args *arg = NULL;
+  telnetd_session   *session = NULL;
   rtems_id   task_id;
-  telnetd_context   *ctx = (telnetd_context *) targ;
+  telnetd_context   *ctx = (telnetd_context *) arg;
 
   if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
 perror("telnetd:socket");
@@ -239,23 +239,23 @@ telnetd_server_task(rtems_task_argument targ)
* was started from the console anyway ..
*/
   do {
-arg = grab_a_Connection(ctx, des_socket, &srv, peername,
+session = grab_a_Connection(ctx, des_socket, &srv, peername,
   sizeof(peername));
 
-if (arg == NULL) {
+if (session == NULL) {
   /* if something went wrong, sleep for some time */
   sleep(10);
   continue;
 }
 
-strncpy(arg->peername, peername, sizeof(arg->peername));
+strncpy(session->peername, peername, sizeof(session->peername));
 
 task_id = telnetd_spawn_task(
   rtems_build_name('T', 'N', 'T', 'a'),
   ctx->config.priority,
   ctx->config.stack_size,
-  spawned_shell,
-  arg
+  telnetd_session_task,
+  session
 );
 if (task_id == RTEMS_ID_NONE) {
   FILE *dummy;
@@ -267,10 +267,10 @@ telnetd_server_task(rtems_task_argument targ)
* a stream...
*/
 
-  if ( !(dummy=fopen(arg->pty.name,"r+")) )
+  if ( !(dummy=fopen(session->pty.name,"r+")) )
 perror("Unable to dummy open the pty, losing a slot :-(");
-  release_a_Connection(ctx, arg->pty.name, peername, &dummy, 1);
-  free(arg);
+  release_a_Connection(ctx, session->pty.name, peername, &dummy, 1);
+  free(session);
   sleep(2); /* don't accept connections too fast */
 }
   } while(1);
@@ -339,14 +339,14 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 
 /* utility wrapper */
 static void
-spawned_shell(rtems_task_argument targ)
+telnetd_session_task(rtems_task_argument arg)
 {
   rtems_status_codesc;
   FILE*nstd[3]={0};
   FILE*ostd[3]={ stdin, stdout, stderr };
   int  i=0;
-  struct shell_args  *arg = (struct shell_args *) targ;
-  telnetd_context*ctx = arg->ctx;
+  telnetd_session*session = (telnetd

[PATCH 1/6] telnetd: Simplify task spawn function

2018-10-10 Thread Sebastian Huber
Use the minimum task size for the telnet server task since it has to
deal only with simple socket operations.

Update #3543.
---
 cpukit/telnetd/telnetd.c | 128 +--
 1 file changed, 36 insertions(+), 92 deletions(-)

diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 56e48b9d78..fcc89ff5e3 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -82,31 +82,9 @@ typedef union uni_sa {
 
 static int sockpeername(int sock, char *buf, int bufsz);
 
-rtems_id telnetd_dflt_spawn(
-  const char *name,
-  unsigned priority,
-  unsigned stackSize,
-  void (*fn)(void*),
-  void *fnarg
-);
-
 /***/
 static telnetd_context telnetd_instance;
 
-/*
- * chrisj: this variable was global and with no declared interface in a header
- * file and with no means to set it so I have stopped it being global;
- * if this breaks any user they will have be to provide a formal
- * interface to get this change reverted.
- */
-static const rtems_id (*telnetd_spawn_task)(
-  const char *,
-  unsigned,
-  unsigned,
-  void (*)(void*),
-  void *
-) = telnetd_dflt_spawn;
-
 static struct shell_args *grab_a_Connection(
   telnetd_context *ctx,
   int des_socket,
@@ -193,12 +171,39 @@ static int sockpeername(int sock, char *buf, int bufsz)
   return rval;
 }
 
+static rtems_id telnetd_spawn_task(
+  rtems_name name,
+  rtems_task_priority priority,
+  size_t stack_size,
+  rtems_task_entry entry,
+  void *arg
+)
+{
+  rtems_status_code sc;
+  rtems_id task_id;
+
+  sc = rtems_task_create(
+name,
+priority,
+stack_size,
+RTEMS_DEFAULT_MODES,
+RTEMS_FLOATING_POINT,
+&task_id
+  );
+  if (sc != RTEMS_SUCCESSFUL) {
+return RTEMS_ID_NONE;
+  }
+
+  (void)rtems_task_start(task_id, entry, (rtems_task_argument) arg);
+  return task_id;
+}
+
 static void
-spawned_shell(void *arg);
+spawned_shell(rtems_task_argument arg);
 
 /***/
 static void
-rtems_task_telnetd(void *task_argument)
+telnetd_server_task(rtems_task_argument targ)
 {
   intdes_socket;
   uni_sa srv;
@@ -207,7 +212,7 @@ rtems_task_telnetd(void *task_argument)
   intsize_adr;
   struct shell_args *arg = NULL;
   rtems_id   task_id;
-  telnetd_context   *ctx = task_argument;
+  telnetd_context   *ctx = (telnetd_context *) targ;
 
   if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
 perror("telnetd:socket");
@@ -246,7 +251,7 @@ rtems_task_telnetd(void *task_argument)
 strncpy(arg->peername, peername, sizeof(arg->peername));
 
 task_id = telnetd_spawn_task(
-  arg->pty.name,
+  rtems_build_name('T', 'N', 'T', 'a'),
   ctx->config.priority,
   ctx->config.stack_size,
   spawned_shell,
@@ -255,10 +260,6 @@ rtems_task_telnetd(void *task_argument)
 if (task_id == RTEMS_ID_NONE) {
   FILE *dummy;
 
-  if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
-fprintf(stderr,"Telnetd: Unable to spawn child task\n");
-  }
-
   /* hmm - the pty driver slot can only be
* released by opening and subsequently
* closing the PTY - this also closes
@@ -319,12 +320,11 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 ctx->config.client_maximum = 5;
   }
 
-  /* Spawn task */
   task_id = telnetd_spawn_task(
-"TNTD",
+rtems_build_name('T', 'N', 'T', 'D'),
 ctx->config.priority,
-ctx->config.stack_size,
-rtems_task_telnetd,
+RTEMS_MINIMUM_STACK_SIZE,
+telnetd_server_task,
 ctx
   );
   if (task_id == RTEMS_ID_NONE) {
@@ -339,13 +339,13 @@ rtems_status_code rtems_telnetd_start(const 
rtems_telnetd_config_table* config)
 
 /* utility wrapper */
 static void
-spawned_shell(void *targ)
+spawned_shell(rtems_task_argument targ)
 {
   rtems_status_codesc;
   FILE*nstd[3]={0};
   FILE*ostd[3]={ stdin, stdout, stderr };
   int  i=0;
-  struct shell_args  *arg = targ;
+  struct shell_args  *arg = (struct shell_args *) targ;
   telnetd_context*ctx = arg->ctx;
   bool login_failed = false;
   bool start = true;
@@ -407,59 +407,3 @@ cleanup:
   release_a_Connection(ctx, arg->pty.name, arg->peername, nstd, i);
   free(arg);
 }
-
-struct wrap_delete_args {
-  void (*t)(void *);
-  void   *a;
-};
-
-static rtems_task
-wrap_delete(rtems_task_argument arg)
-{
-  struct wrap_delete_args *pwa = (struct wrap_delete_args *)arg;
-  register void  (*t)(void *) = pwa->t;
-  register void   *a   = pwa->a;
-
-  /* free argument before calling function (which may never return if
-   * they choose to delete themselves)
-   */
-  free(pwa);
-  t(a);
-  rtems_task_exit();
-}
-
-rtems_id
-telnetd_dflt_spawn(const char *name, unsigned int priority, unsigned int 
stackSize, void (*fn)(void *), void* fnarg)
-{
-  rtems_stat

[PATCH 3/6] telnetd: Create server socket at start

2018-10-10 Thread Sebastian Huber
Update #3543.
---
 cpukit/telnetd/telnetd.c | 162 +--
 1 file changed, 86 insertions(+), 76 deletions(-)

diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index 1fcd4c54d9..0fd3b317a9 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -72,6 +72,7 @@ typedef struct telnetd_session {
 
 struct telnetd_context {
   rtems_telnetd_config_table config;
+  intserver_socket;
   uint16_t   active_clients;
 };
 
@@ -80,21 +81,14 @@ typedef union uni_sa {
   struct sockaddr sa;
 } uni_sa;
 
-static int sockpeername(int sock, char *buf, int bufsz);
-
 /***/
 static telnetd_context telnetd_instance;
 
-static telnetd_session *grab_a_Connection(
-  telnetd_context *ctx,
-  int des_socket,
-  uni_sa *srv,
-  char *peername,
-  int sz
-)
+static telnetd_session *grab_a_Connection(telnetd_context *ctx)
 {
   telnetd_session *session;
-  socklen_t size_adr = sizeof(srv->sin);
+  uni_sa peer;
+  socklen_t address_len;
   int acp_sock;
 
   if (ctx->active_clients >= ctx->config.client_maximum) {
@@ -107,7 +101,8 @@ static telnetd_session *grab_a_Connection(
 return NULL;
   }
 
-  acp_sock = accept(des_socket,&srv->sa,&size_adr);
+  address_len = sizeof(peer.sin);
+  acp_sock = accept(ctx->server_socket, &peer.sa, &address_len);
   if (acp_sock<0) {
 perror("telnetd:accept");
 free(session);
@@ -121,13 +116,21 @@ static telnetd_session *grab_a_Connection(
 return NULL;
   }
 
-  if (sockpeername(acp_sock, peername, sz))
-strncpy(peername, "", sz);
+  if (
+inet_ntop(
+  AF_INET,
+  &peer.sin.sin_addr,
+  session->peername,
+  sizeof(session->peername)
+) == NULL
+  ) {
+strlcpy(session->peername, "", sizeof(session->peername));
+  }
 
 #ifdef PARANOIA
   syslog(LOG_DAEMON | LOG_INFO,
   "telnetd: accepted connection from %s on %s",
-  peername,
+  session->peername,
   session->pty.name);
 #endif
 
@@ -137,15 +140,20 @@ static telnetd_session *grab_a_Connection(
 }
 
 
-static void release_a_Connection(telnetd_context *ctx, const char *devname,
-  const char *peername, FILE **pstd, int n)
+static void release_a_Connection(
+  telnetd_context *ctx,
+  telnetd_session *session,
+  FILE **pstd,
+  int n
+)
 {
-
 #ifdef PARANOIA
-  syslog( LOG_DAEMON | LOG_INFO,
-  "telnetd: releasing connection from %s on %s",
-  peername,
-  devname );
+  syslog(
+LOG_DAEMON | LOG_INFO,
+"telnetd: releasing connection from %s on %s",
+session->peername,
+session->pty.name
+  );
 #endif
 
   --ctx->active_clients;
@@ -153,22 +161,7 @@ static void release_a_Connection(telnetd_context *ctx, 
const char *devname,
   while (--n>=0)
 if (pstd[n]) fclose(pstd[n]);
 
-  unlink(devname);
-}
-
-static int sockpeername(int sock, char *buf, int bufsz)
-{
-  uni_sa peer;
-  intrval = sock < 0;
-  socklen_t len  = sizeof(peer.sin);
-
-  if ( !rval )
-rval = getpeername(sock, &peer.sa, &len);
-
-  if ( !rval )
-rval = !inet_ntop( AF_INET, &peer.sin.sin_addr, buf, bufsz );
-
-  return rval;
+  unlink(session->pty.name);
 }
 
 static rtems_id telnetd_spawn_task(
@@ -205,42 +198,15 @@ telnetd_session_task(rtems_task_argument arg);
 static void
 telnetd_server_task(rtems_task_argument arg)
 {
-  intdes_socket;
-  uni_sa srv;
-  char   peername[16];
-  inti=1;
-  intsize_adr;
   telnetd_session   *session = NULL;
   rtems_id   task_id;
   telnetd_context   *ctx = (telnetd_context *) arg;
 
-  if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
-perror("telnetd:socket");
-rtems_task_exit();
-  };
-  (void)setsockopt(des_socket,SOL_SOCKET,SO_KEEPALIVE,&i,sizeof(i));
-
-  memset(&srv,0,sizeof(srv));
-  srv.sin.sin_family=AF_INET;
-  srv.sin.sin_port=htons(23);
-  size_adr=sizeof(srv.sin);
-  if ((bind(des_socket,&srv.sa,size_adr))<0) {
-perror("telnetd:bind");
-close(des_socket);
-rtems_task_exit();
-  };
-  if ((listen(des_socket,5))<0) {
-perror("telnetd:listen");
-  close(des_socket);
-rtems_task_exit();
-  };
-
   /* we don't redirect stdio as this probably
* was started from the console anyway ..
*/
   do {
-session = grab_a_Connection(ctx, des_socket, &srv, peername,
-  sizeof(peername));
+session = grab_a_Connection(ctx);
 
 if (session == NULL) {
   /* if something went wrong, sleep for some time */
@@ -248,8 +214,6 @@ telnetd_server_task(rtems_task_argument arg)
   continue;
 }
 
-strncpy(session->peername, peername, sizeof(session->peername));
-
 task_id = telnetd_spawn_task(
   rtems_build_name('T', 'N', 'T', 'a'),
   ctx->config.priority,
@@ -269,25 +233,64 @@ telnetd_server_task(rtems_task_argument arg)
 
   if ( !(dummy=fopen(session->pty.name,"r+")) )
 perror("Unable to dummy open the pty, l

[PATCH 5/6] telnetd: Create sessions at start

2018-10-10 Thread Sebastian Huber
Update #3543.
---
 cpukit/include/rtems/pty.h  |  11 +-
 cpukit/telnetd/pty.c|  33 +-
 cpukit/telnetd/telnetd.c| 476 +++-
 testsuites/libtests/telnetd01/init.c|   6 +-
 testsuites/libtests/telnetd01/telnetd01.scn |   5 +-
 5 files changed, 291 insertions(+), 240 deletions(-)

diff --git a/cpukit/include/rtems/pty.h b/cpukit/include/rtems/pty.h
index d8f886d76a..94b66d63c4 100644
--- a/cpukit/include/rtems/pty.h
+++ b/cpukit/include/rtems/pty.h
@@ -34,7 +34,16 @@ typedef struct {
   char  name[sizeof("/dev/pty18446744073709551615")];
 } rtems_pty_context;
 
-char *telnet_get_pty(rtems_pty_context *ctx, int socket);
+const char *rtems_pty_initialize(rtems_pty_context *pty, uintptr_t unique);
+
+RTEMS_INLINE_ROUTINE const char *rtems_pty_get_path(const rtems_pty_context 
*pty)
+{
+  return pty->name;
+}
+
+void rtems_pty_close_socket(rtems_pty_context *pty);
+
+void rtems_pty_set_socket(rtems_pty_context *pty, int socket);
 
 #ifdef __cplusplus
 }
diff --git a/cpukit/telnetd/pty.c b/cpukit/telnetd/pty.c
index 7a47fddbc9..8bf550d313 100644
--- a/cpukit/telnetd/pty.c
+++ b/cpukit/telnetd/pty.c
@@ -94,26 +94,37 @@ int send_iac(rtems_pty_context *pty, unsigned char mode, 
unsigned char option)
   return write(pty->socket, buf, sizeof(buf));
 }
 
-/* This procedure returns the devname for a pty slot free.
- * If not slot availiable (field socket>=0)
- *  then the socket argument is closed
- */
-
-char *telnet_get_pty(rtems_pty_context *pty, int socket)
+const char *rtems_pty_initialize(rtems_pty_context *pty, uintptr_t unique)
 {
   rtems_status_code sc;
-  struct timeval t;
 
   memset(pty, 0, sizeof(*pty));
-  snprintf(pty->name, sizeof(pty->name), "/dev/pty%" PRIuPTR, (uintptr_t)pty);
+  snprintf(pty->name, sizeof(pty->name), "/dev/pty%" PRIuPTR, 
(uintptr_t)unique);
   rtems_termios_device_context_initialize(&pty->base, "pty");
-  pty->socket = socket;
+  pty->socket = -1;
   sc = rtems_termios_device_install(pty->name, &pty_handler, NULL, &pty->base);
   if (sc != RTEMS_SUCCESSFUL) {
-close(socket);
 return NULL;
   }
 
+  return pty->name;
+}
+
+void rtems_pty_close_socket(rtems_pty_context *pty)
+{
+  if (pty->socket >= 0) {
+(void)close(pty->socket);
+pty->socket = -1;
+  }
+}
+
+void rtems_pty_set_socket(rtems_pty_context *pty, int socket)
+{
+  struct timeval t;
+
+  rtems_pty_close_socket(pty);
+  pty->socket = socket;
+
   /* set a long polling interval to save CPU time */
   t.tv_sec=2;
   t.tv_usec=0;
@@ -121,8 +132,6 @@ char *telnet_get_pty(rtems_pty_context *pty, int socket)
 
   /* inform the client that we will echo */
   send_iac(pty, IAC_WILL, 1);
-
-  return pty->name;
 }
 
 /*---*/
diff --git a/cpukit/telnetd/telnetd.c b/cpukit/telnetd/telnetd.c
index aadf33deb7..9f2dc25c93 100644
--- a/cpukit/telnetd/telnetd.c
+++ b/cpukit/telnetd/telnetd.c
@@ -23,13 +23,13 @@
  *possible to have 'telnetd' run an arbitrary 'shell'
  *program.
  *
- * Copyright (c) 2009 embedded brains GmbH and others.
+ * Copyright (c) 2009, 2018 embedded brains GmbH and others.
  *
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * 
+ *   embedded brains GmbH
+ *   Dornierstr. 4
+ *   D-82178 Puchheim
+ *   Germany
+ *   
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -40,6 +40,7 @@
 #include "config.h"
 #endif
 
+#include 
 #include 
 #include 
 #include 
@@ -54,201 +55,226 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef RTEMS_NETWORKING
 #include 
 #endif
 
-#define PARANOIA
+#define TELNETD_EVENT_SUCCESS RTEMS_EVENT_0
+
+#define TELNETD_EVENT_ERROR RTEMS_EVENT_1
 
 typedef struct telnetd_context telnetd_context;
 
 typedef struct telnetd_session {
-  rtems_pty_context  pty;
-  char   peername[16];
-  telnetd_context   *ctx;
+  rtems_pty_contextpty;
+  char peername[16];
+  telnetd_context *ctx;
+  rtems_id task_id;
+  LIST_ENTRY(telnetd_session)  link;
 } telnetd_session;
 
 struct telnetd_context {
-  rtems_telnetd_config_table config;
-  intserver_socket;
-  uint16_t   active_clients;
+  rtems_telnetd_config_table   config;
+  int  server_socket;
+  rtems_id task_id;
+  rtems_mutex  mtx;
+  LIST_HEAD(, telnetd_session) free_sessions;
+  telnetd_session  sessions[RTEMS_ZERO_LENGTH_ARRAY];
 };
 
-typedef union uni_sa {
+typedef union {
   struct sockaddr_in sin;
-  struct sockaddr sa;
-} uni_sa;
+  struct sockaddrsa;
+} telnetd_address;
 
-static telnetd_session *grab_a_Connection(telnetd_context *ctx)
+RTEMS_NO_RETURN static void telnetd_session_fatal_error(
+  const telnetd_context *ctx
+)
 {
-  te

Re: [examples-v2 commit] Add various programs to report default attributes for various POSIX objects

2018-10-10 Thread Chris Johns

> On 9 Oct 2018, at 2:33 pm, Joel Sherrill  wrote:
> 
>> On Tue, Oct 9, 2018, 4:19 PM Chris Johns  wrote:
>> On 8/10/18 8:56 am, Joel Sherrill wrote:
>> > diff --git a/posix_api/Makefile b/posix_api/Makefile
>> > index b070ea9..8af26dc 100644
>> > --- a/posix_api/Makefile
>> > +++ b/posix_api/Makefile
>> > @@ -4,5 +4,14 @@ include $(RTEMS_SHARE)/make/directory.cfg
>> 
>> I had forgotten the Makefile.in build support was present in this repo. I 
>> have
>> not used Makefile.inc when building any RTEMS exe for decades.
>> 
>> Is it a good idea to have both or should we have waf as the method to build 
>> the
>> examples? For example you end up with this in the repo ..
>> 
>> https://git.rtems.org/examples-v2/tree/misc/wscript#n18
> 
> 
> Both still work. I have been working under the impression that 5.1 was the 
> last release with these supported. When we switch to watch for RTEMS, we can 
> kill these.

Ok that fine. What about a README.Makefil to say this and an example showing 
how to us it. It help our users in the forest that is RTEMS after building a 
kernel. 

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH] sb: Add support to search for a suitable vrsion of python.

2018-10-10 Thread chrisj
From: Chris Johns 

The command python has been removed from upstream python and python2
and python3 is now used. This patch wraps the commands in a shell
script that locates a suitable python to run.

Updates #3537
---
 source-builder/pkg-config | 241 +++---
 source-builder/sb-bootstrap   |  24 ++-
 source-builder/sb-builder |  24 ++-
 source-builder/sb-check   |  24 ++-
 source-builder/sb-defaults|  24 ++-
 source-builder/sb-reports |  24 ++-
 source-builder/sb-rtems-config|  24 ++-
 source-builder/sb-set-builder |  25 ++-
 source-builder/sb/cmd-bootstrap.py|  29 
 source-builder/sb/cmd-builder.py  |  29 
 source-builder/sb/cmd-check.py|  29 
 source-builder/sb/cmd-defaults.py |  29 
 source-builder/sb/cmd-pkg-config.py   | 220 +++
 source-builder/sb/cmd-reports.py  |  29 
 source-builder/sb/cmd-rtems-config.py |  29 
 source-builder/sb/cmd-set-builder.py  |  29 
 source-builder/sb/options.py  |   7 +-
 source-builder/sb/python-wrapper.sh   |  39 +
 18 files changed, 559 insertions(+), 320 deletions(-)
 create mode 100755 source-builder/sb/cmd-bootstrap.py
 create mode 100755 source-builder/sb/cmd-builder.py
 create mode 100755 source-builder/sb/cmd-check.py
 create mode 100755 source-builder/sb/cmd-defaults.py
 create mode 100755 source-builder/sb/cmd-pkg-config.py
 create mode 100755 source-builder/sb/cmd-reports.py
 create mode 100755 source-builder/sb/cmd-rtems-config.py
 create mode 100755 source-builder/sb/cmd-set-builder.py
 create mode 100644 source-builder/sb/python-wrapper.sh

diff --git a/source-builder/pkg-config b/source-builder/pkg-config
index fa251e5..65ee307 100755
--- a/source-builder/pkg-config
+++ b/source-builder/pkg-config
@@ -1,226 +1,27 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2014-2016 Chris Johns (chr...@rtems.org)
+# Copyright 2018 Chris Johns (chr...@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
 #
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-
-from __future__ import print_function
-
-import os
-import sys
-
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-
-try:
-import argparse
-except:
-sys.path.insert(0, base + '/sb/imports')
-try:
-import argparse
-except:
-print("Incorrect Source Builder installation", file = sys.stderr)
-sys.exit(1)
-
-try:
-import pkgconfig
-except ImportError:
-print("Incorrect Source Builder installation", file = sys.stderr)
-sys.exit(1)
-
-#
-# Make trace true to get a file of what happens and what is being asked.
-#
-trace = True
-trace_stdout = False
-logfile = 'pkg-config.log'
-out = None
-srcfd = None
-
-#
-# Write all the package source parsed to a single file.
-#
-trace_src = True
-if trace_src:
-srcfd = open('pkg-src.txt', 'w')
-
-def src(text):
-if srcfd:
-srcfd.writelines(text)
-
-def log(s, lf = True):
-global trace, logfile, out
-if trace:
-if out is None:
-if logfile:
-out = open(logfile, 'a')
-else:
-out = sys.stdout
-if lf:
-if out != sys.stdout and trace_stdout:
-print(s)
-print(s, file = out)
-else:
-if out != sys.stdout and trace_stdout:
-print(s, end = '')
-sys.stdout.flush()
-print(s, end = '', file = out)
-
-def run(argv):
-
-class version_action(argparse.Action):
-def __call__(self, parser, namespace, values, option