Commit Diff


commit - 5c69b561db9f5713670e2f1e1519cc7f61b06645
commit + 4fa9a3072fca4cf36e741f089076684d00f8ed82
blob - 4ce8ea6188ebfe8c70940f3afbb81dc010e09231
blob + 09b1c3ee364a6a90b2311761332208464b2268f9
--- kamictl/ctl_parser.c
+++ kamictl/ctl_parser.c
@@ -43,6 +43,7 @@ static const struct token t_log[];
 static const struct token t_main[] = {
 	{KEYWORD,	"reload",	RELOAD,		NULL},
 	{KEYWORD,	"log",		NONE,		t_log},
+	{KEYWORD,	"debug",	DEBUG,		NULL},
 	{ENDTOKEN,	"",		NONE,		NULL},
 };
 
blob - 1c41496f316a505b67099be11f5f5d3deec51a7b
blob + 3f2afd6aad5136841ba50176b997ee01ae06a437
--- kamictl/ctl_parser.h
+++ kamictl/ctl_parser.h
@@ -23,6 +23,7 @@ enum actions {
 	LOG_VERBOSE,
 	LOG_BRIEF,
 	RELOAD,
+	DEBUG,
 };
 
 struct parse_result {
blob - 34607ae1e6d70d9065d0da1719a00985a289f58a
blob + 075b6d02caa58d41f3892c6f3985dd179cfd4ab6
--- kamictl/kamictl.c
+++ kamictl/kamictl.c
@@ -21,6 +21,8 @@
 #include <sys/uio.h>
 #include <sys/un.h>
 
+#include <errno.h>
+#include <inttypes.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -116,26 +118,55 @@ main(int argc, char **argv)
 		puts("reload request sent.");
 		done = 1;
 		break;
+	case DEBUG:
+		imsg_compose(ibuf, IMSG_CTL_DEBUG, 0, getpid(), -1, NULL, 0);
+		break;
 	default:
 		usage();
 	}
 
-	imsg_flush(ibuf);
+	if (imsg_flush(ibuf) == -1)
+		err(1, "imsg_flush");
 
-	/*
-	 * Later we may add commands which requires a response.
-	 */
 	while (!done) {
-		if ((n = imsg_get(ibuf, &imsg)) == -1)
-			errx(1, "imsg_get error");
+		if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
+			errx(1, "write error");
 		if (n == 0)
-			break;
+			errx(0, "pipe closed");
 
-		switch (res->action) {
-		default:
-			break;
+		while (!done) {
+			if ((n = imsg_get(ibuf, &imsg)) == -1)
+				errx(1, "imsg_get error");
+			if (n == 0)
+				break;
+
+			switch (res->action) {
+			case DEBUG: {
+				struct kd_debug_info d;
+
+				if (imsg.hdr.type == IMSG_CTL_DEBUG_END) {
+					done = 1;
+					break;
+				}
+
+				if (imsg.hdr.type != IMSG_CTL_DEBUG_BACK ||
+				    IMSG_DATA_SIZE(imsg) != sizeof(d))
+					errx(1, "got invalid reply (%d)",
+					    imsg.hdr.type);
+
+				memcpy(&d, imsg.data, sizeof(d));
+				if (d.path[sizeof(d.path)-1] != '\0')
+					errx(1, "got invalid reply");
+
+				printf("%"PRIu32"\t%"PRIu32"\t%s\n",
+				    d.client_id, d.fid, d.path);
+				break;
+			}
+			default:
+				break;
+			}
+			imsg_free(&imsg);
 		}
-		imsg_free(&imsg);
 	}
 	close(ctl_sock);
 	free(ibuf);