]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Properly handle the case where read() may return the text for more than one
authorRussell Bryant <russell@russellbryant.com>
Sat, 13 Oct 2007 05:24:33 +0000 (05:24 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 13 Oct 2007 05:24:33 +0000 (05:24 +0000)
CLI command at once for a remote console.

(closes issue #10888)
Reported by: jamesgolovich
Patches:
      asterisk-climultiple.diff.txt uploaded by jamesgolovich (license 176)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@85532 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/cli.h
main/asterisk.c
main/cli.c

index e2a6f818b03a0e5740d596835cef56a7f0832c51..9a7b53a3659b42fdaa20403d5d5c70c3cfe6179b 100644 (file)
@@ -108,6 +108,14 @@ char *ast_cli_complete(const char *word, char *const choices[], int pos);
  */
 int ast_cli_command(int fd, const char *s);
 
+/*! 
+ * \brief Executes multiple CLI commands
+ * Interpret strings separated by '\0' and execute each one, sending output to fd
+ * \param size is the total size of the string
+ * \retval number of commands executed
+ */
+int ast_cli_command_multiple(int fd, size_t size, const char *s);
+
 /*! \brief Registers a command or an array of commands
  * \param e which cli entry to register
  * Register your own command
index 53e4d042ba312e0a5c848665d576536f0b995aa2..9f0f049dee9227a15624874bb9437ee6f19e00c2 100644 (file)
@@ -936,7 +936,7 @@ static void *netconsole(void *vconsole)
                                break;
                        }
                        tmp[res] = 0;
-                       ast_cli_command(con->fd, tmp);
+                       ast_cli_command_multiple(con->fd, res, tmp);
                }
                if (fds[1].revents) {
                        res = read(con->p[0], tmp, sizeof(tmp));
index 1d3a7b94bf59bd39e264fd40541698c4d34fafde..826ed6f2a75479b3a178b1926ca7da053b178115 100644 (file)
@@ -2005,3 +2005,20 @@ int ast_cli_command(int fd, const char *s)
        
        return 0;
 }
+
+int ast_cli_command_multiple(int fd, size_t size, const char *s)
+{
+       char cmd[512];
+       int x, y = 0, count = 0;
+
+       for (x = 0; x < size; x++) {
+               cmd[y] = s[x];
+               y++;
+               if (s[x] == '\0') {
+                       ast_cli_command(fd, cmd);
+                       y = 0;
+                       count++;
+               }
+       }
+       return count;
+}