Added a statusallnb stroke command to show status non-blocking
authorMartin Willi <martin@revosec.ch>
Wed, 4 May 2011 09:21:33 +0000 (11:21 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:24:14 +0000 (15:24 +0200)
src/libcharon/plugins/stroke/stroke_list.c
src/libcharon/plugins/stroke/stroke_list.h
src/libcharon/plugins/stroke/stroke_socket.c
src/stroke/stroke.c
src/stroke/stroke_keywords.h
src/stroke/stroke_keywords.txt
src/stroke/stroke_msg.h

index 9dd1ca4..35571a0 100644 (file)
@@ -389,7 +389,8 @@ static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
 }
 
 METHOD(stroke_list_t, status, void,
-       private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bool all)
+       private_stroke_list_t *this, stroke_msg_t *msg, FILE *out,
+       bool all, bool wait)
 {
        enumerator_t *enumerator, *children;
        ike_cfg_t *ike_cfg;
@@ -531,7 +532,7 @@ METHOD(stroke_list_t, status, void,
 
        fprintf(out, "Security Associations:\n");
        enumerator = charon->controller->create_ike_sa_enumerator(
-                                                                                                       charon->controller, TRUE);
+                                                                                                       charon->controller, wait);
        while (enumerator->enumerate(enumerator, &ike_sa))
        {
                bool ike_printed = FALSE;
index b5bedc6..a0d2d18 100644 (file)
@@ -47,8 +47,10 @@ struct stroke_list_t {
         * @param msg           stroke message
         * @param out           stroke console stream
         * @param all           TRUE for "statusall"
+        * @param wait          TRUE to wait for IKE_SA entries, FALSE to skip if locked
         */
-       void (*status)(stroke_list_t *this, stroke_msg_t *msg, FILE *out, bool all);
+       void (*status)(stroke_list_t *this, stroke_msg_t *msg, FILE *out,
+                                  bool all, bool wait);
 
        /**
         * Log pool leases to stroke console.
index 592c776..d684680 100644 (file)
@@ -322,11 +322,11 @@ static void stroke_del_ca(private_stroke_socket_t *this,
  * show status of daemon
  */
 static void stroke_status(private_stroke_socket_t *this,
-                                                 stroke_msg_t *msg, FILE *out, bool all)
+                                                 stroke_msg_t *msg, FILE *out, bool all, bool wait)
 {
        pop_string(msg, &(msg->status.name));
 
-       this->list->status(this->list, msg, out, all);
+       this->list->status(this->list, msg, out, all, wait);
 }
 
 /**
@@ -546,10 +546,13 @@ static job_requeue_t process(stroke_job_context_t *ctx)
                        stroke_rekey(this, msg, out);
                        break;
                case STR_STATUS:
-                       stroke_status(this, msg, out, FALSE);
+                       stroke_status(this, msg, out, FALSE, TRUE);
                        break;
                case STR_STATUS_ALL:
-                       stroke_status(this, msg, out, TRUE);
+                       stroke_status(this, msg, out, TRUE, TRUE);
+                       break;
+               case STR_STATUS_ALL_NOBLK:
+                       stroke_status(this, msg, out, TRUE, FALSE);
                        break;
                case STR_ADD_CONN:
                        stroke_add_conn(this, msg);
index 6dbaf64..7410f5c 100644 (file)
@@ -231,7 +231,18 @@ static int show_status(stroke_keyword_t kw, char *connection)
 {
        stroke_msg_t msg;
 
-       msg.type = (kw == STROKE_STATUS)? STR_STATUS:STR_STATUS_ALL;
+       switch (kw)
+       {
+               case STROKE_STATUSALL:
+                       msg.type = STR_STATUS_ALL;
+                       break;
+               case STROKE_STATUSALL_NOBLK:
+                       msg.type = STR_STATUS_ALL_NOBLK;
+                       break;
+               default:
+                       msg.type = STR_STATUS;
+                       break;
+       }
        msg.length = offsetof(stroke_msg_t, buffer);
        msg.status.name = push_string(&msg, connection);
        return send_stroke_msg(&msg);
@@ -498,6 +509,7 @@ int main(int argc, char *argv[])
                        break;
                case STROKE_STATUS:
                case STROKE_STATUSALL:
+               case STROKE_STATUSALL_NOBLK:
                        res = show_status(token->kw, argc > 2 ? argv[2] : NULL);
                        break;
                case STROKE_LIST_PUBKEYS:
index dd00dc2..3e55ef8 100644 (file)
@@ -29,6 +29,7 @@ typedef enum {
        STROKE_LOGLEVEL,
        STROKE_STATUS,
        STROKE_STATUSALL,
+       STROKE_STATUSALL_NOBLK,
        STROKE_LIST_PUBKEYS,
        STROKE_LIST_CERTS,
        STROKE_LIST_CACERTS,
index f87b157..78212c2 100644 (file)
@@ -36,6 +36,7 @@ rekey,           STROKE_REKEY
 loglevel,        STROKE_LOGLEVEL
 status,          STROKE_STATUS
 statusall,       STROKE_STATUSALL
+statusallnb,     STROKE_STATUSALL_NOBLK
 listpubkeys,     STROKE_LIST_PUBKEYS
 listcerts,       STROKE_LIST_CERTS
 listcacerts,     STROKE_LIST_CACERTS
index 2fbacec..3c1221a 100644 (file)
@@ -194,6 +194,8 @@ struct stroke_msg_t {
                STR_STATUS,
                /* show verbose connection status */
                STR_STATUS_ALL,
+               /* show verbose connection status, non-blocking variant */
+               STR_STATUS_ALL_NOBLK,
                /* add a ca information record */
                STR_ADD_CA,
                /* delete ca information record */