]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'refs/heads/t/com_tasks'
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 14 Dec 2014 20:48:06 +0000 (21:48 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 14 Dec 2014 20:49:45 +0000 (21:49 +0100)
cooking for almost a month.

NEWS
client.c
command.c
server.c
server.cmd
server.h

diff --git a/NEWS b/NEWS
index 87337d1c0b18b969e3d231a79aef2353ae6d68a6..b945484b19fe4c3ae6276ad9088a1a71dc4b9558 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ NEWS
 
 Another cleanup and bugfix release.
 
+       - New server command: tasks.
        - Minor cleanups to daemon.c.
        - New URLs for home page and git services.
        - Improved error diagnostics for the mvblob commands.
index 2159117e7cbff55b04e38d1ab167482419546680..f53147f1c8d6f1ae03cac62496c6fcf1aae65847 100644 (file)
--- a/client.c
+++ b/client.c
@@ -208,6 +208,7 @@ I9E_DUMMY_COMPLETER(version);
 I9E_DUMMY_COMPLETER(stop);
 I9E_DUMMY_COMPLETER(addatt);
 I9E_DUMMY_COMPLETER(init);
+I9E_DUMMY_COMPLETER(tasks);
 
 static struct i9e_completer completers[];
 
index 551fe05a66eb4eab694f62f6ac1578ad0992d742..a9f5aa697be2e3f7ab51819898b14afb7d0535c6 100644 (file)
--- a/command.c
+++ b/command.c
@@ -718,7 +718,7 @@ static int com_ff(struct command_context *cc)
                promille += 1000 * i / mmd->afd.afhi.seconds_total;
        if (promille < 0)
                promille = 0;
-       if (promille >  1000) {
+       if (promille > 1000) {
                mmd->new_vss_status_flags |= VSS_NEXT;
                goto out;
        }
@@ -749,8 +749,8 @@ static int com_jmp(struct command_context *cc)
        if (i > 100)
                i = 100;
        PARA_INFO_LOG("jumping to %lu%%\n", i);
-       mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50)/ 100;
-       PARA_INFO_LOG("sent: %lu,  offset before jmp: %lu\n",
+       mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50) / 100;
+       PARA_INFO_LOG("sent: %lu, offset before jmp: %lu\n",
                mmd->chunks_sent, mmd->offset);
        mmd->new_vss_status_flags |= VSS_REPOS;
        mmd->new_vss_status_flags &= ~VSS_NEXT;
@@ -761,6 +761,16 @@ out:
        return ret;
 }
 
+static int com_tasks(struct command_context *cc)
+{
+       char *tl = server_get_tasks();
+       int ret = 1;
+
+       if (tl)
+               ret = send_sb(&cc->scc, tl, strlen(tl), SBD_OUTPUT, false);
+       return ret;
+}
+
 /*
  * check if perms are sufficient to exec a command having perms cmd_perms.
  * Returns 0 if perms are sufficient, -E_PERM otherwise.
@@ -865,24 +875,22 @@ out:
  * \param fd The file descriptor to send output to.
  * \param peername Identifies the connecting peer.
  *
- * Whenever para_server accepts an incoming tcp connection on
- * the port it listens on, it forks and the resulting child
- * calls this function.
+ * Whenever para_server accepts an incoming tcp connection on the port it
+ * listens on, it forks and the resulting child calls this function.
  *
- * An RSA-based challenge/response is used to authenticate
- * the peer. It that authentication succeeds, a random
- * session key is generated and sent back to the peer,
- * encrypted with its RSA public key.  From this point on,
- * all transfers are crypted with this session key.
+ * An RSA-based challenge/response is used to authenticate the peer. It that
+ * authentication succeeds, a random session key is generated and sent back to
+ * the peer, encrypted with its RSA public key. From this point on, all
+ * transfers are crypted with this session key.
  *
- * Next it is checked if the peer supplied  a valid server command or a command
- * for the audio file selector.  If yes, and if the user has sufficient
+ * Next it is checked if the peer supplied a valid server command or a command
+ * for the audio file selector. If yes, and if the user has sufficient
  * permissions to execute that command, the function calls the corresponding
  * command handler which does argument checking and further processing.
  *
- * In order to cope with a DOS attacks, a timeout is set up
- * which terminates the function if the connection was not
- * authenticated when the timeout expires.
+ * In order to cope with a DOS attacks, a timeout is set up which terminates
+ * the function if the connection was not authenticated when the timeout
+ * expires.
  *
  * \sa alarm(2), crypt.c, crypt.h
  */
@@ -905,7 +913,7 @@ __noreturn void handle_connect(int fd, const char *peername)
                goto net_err;
        /* send Welcome message */
        ret = write_va_buffer(fd, "This is para_server, version "
-               PACKAGE_VERSION  ".\n"
+               PACKAGE_VERSION ".\n"
                "Features: sideband,aes_ctr128\n"
        );
        if (ret < 0)
index b5063e2dfc2a7bd66c9b25836438e6c4677167c7..fc81b9440150f886af47b97ce77878f937959344 100644 (file)
--- a/server.c
+++ b/server.c
@@ -113,6 +113,19 @@ struct server_command_task {
        struct task *task;
 };
 
+/**
+ * Return the list of tasks for the server process.
+ *
+ * This is called from \a com_tasks(). The helper is necessary since command
+ * handlers can not access the scheduler structure directly.
+ *
+ * \return A dynamically allocated string that must be freed by the caller.
+ */
+char *server_get_tasks(void)
+{
+       return get_task_list(&sched);
+}
+
 static int want_colors(void)
 {
        if (conf.color_arg == color_arg_no)
index ebe372b7da67442c11dd2854300aa867fed0408a..5f46ba1eae979b7d1da428d0cd0a069f23640ee5 100644 (file)
@@ -108,6 +108,12 @@ U: stop
 H: Clear the 'P' (playing) bit and set the 'N' (next audio file) bit of the vss
 H: status flags, effectively stopping playback.
 ---
+N: tasks
+P: 0
+D: List server tasks.
+U: tasks
+H: For each task, print ID, status and name.
+---
 N: term
 P: VSS_READ | VSS_WRITE
 D: Ask the server to terminate.
index 16449e6dad787d31010ca856f258c89e7d1147e3..e24dd834faecb4c5c7b8b1fe2567260875a66b15 100644 (file)
--- a/server.h
+++ b/server.h
@@ -98,3 +98,4 @@ extern struct server_args_info conf;
 
 __noreturn void handle_connect(int fd, const char *peername);
 void parse_config_or_die(int override);
+char *server_get_tasks(void);