Fix ctrlproxy-admin.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 16 Sep 2007 23:33:21 +0000 (01:33 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 16 Sep 2007 23:33:21 +0000 (01:33 +0200)
NEWS
src/admin-cmd.c
src/admin.c

diff --git a/NEWS b/NEWS
index 0a86d422d67e1a096bdb0f62953bbb9f27cd6fca..e9c2cd1b9dd34a0bdd5fa9f7a7ddd0fe6cb46dc1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,10 @@
 
 Ctrlproxy 3.0.4 UNRELEASED
 
+  IMPROVEMENTS
+
+    * Add ctrlproxy-admin command for command-line access to the admin network.
+
   BUG FIXES
 
     * Check for empty argument to /CTRLPROXY BACKLOG (#132)
index 600f91eb525e38be1e8cb014ad0473e0a246462d..0487600e92f27d4d142c50e80a8e032fc931f12c 100644 (file)
@@ -38,12 +38,14 @@ gboolean admin_socket_prompt(const char *config_dir)
        strncpy(un.sun_path, admin_dir, sizeof(un.sun_path));
 
        if (connect(sock, (struct sockaddr *)&un, sizeof(un)) < 0) {
-               fprintf(stderr, "unable to connect to %s: %s", un.sun_path, strerror(errno));
+               fprintf(stderr, "unable to connect to %s: %s\n", un.sun_path, strerror(errno));
                g_free(admin_dir);
                return FALSE;
        }
 
        ch = g_io_channel_unix_new(sock);
+
+       g_io_channel_set_flags(ch, G_IO_FLAG_NONBLOCK, NULL);
        
 #ifdef HAVE_READLINE
        while (1) {
@@ -69,6 +71,8 @@ gboolean admin_socket_prompt(const char *config_dir)
 
                g_free(data);
 
+               g_usleep(G_USEC_PER_SEC / 10);
+
                while (g_io_channel_read_line(ch, &raw, NULL, NULL, &error) == G_IO_STATUS_NORMAL) 
                {
                        printf("%s", raw);
index b28635f2c921b89f65ed69e2b8b6f9fdaa8f29b6..2fa74368c2014b88a37a4781b569cd08e6f2e0fa 100644 (file)
@@ -235,20 +235,24 @@ static void com_disconnect_network (admin_handle h, char **args, void *userdata)
 {
        struct network *n;
 
-       n = admin_get_network(h);
-
        if (args[1] != NULL) {
                n = find_network(admin_get_global(h), args[1]);
                if (!n) {
                        admin_out(h, "Can't find active network with that name");
                        return;
                }
+       } else {
+               n = admin_get_network(h);
+               if (n == NULL) {
+                       admin_out(h, "Usage: DISCONNECT <network>");
+                       return;
+               }
        }
 
        if (n->connection.state == NETWORK_CONNECTION_STATE_NOT_CONNECTED) {
-               admin_out(h, "Already disconnected from `%s'", args[1]);
+               admin_out(h, "Already disconnected from `%s'", n->info.name);
        } else {
-               admin_out(h, "Disconnecting from `%s'", args[1]);
+               admin_out(h, "Disconnecting from `%s'", n->info.name);
                disconnect_network(n);
        }
 }
@@ -316,6 +320,11 @@ static void detach_client(admin_handle h, char **args, void *userdata)
 {
        struct client *c = admin_get_client(h);
 
+       if (c == NULL) {
+               admin_out(h, "No client set");
+               return;
+       }
+
        disconnect_client(c, "Client exiting");
 }
 
@@ -888,6 +897,7 @@ static gboolean handle_client_data(GIOChannel *channel,
        gsize eol;
 
        ah.global = _global;
+       ah.client = NULL;
        ah.user_data = channel;
        ah.send_fn = iochannel_admin_out;