diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-07-29 17:43:36 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-07-29 18:45:33 -0400 |
commit | e9d9d345fbcfe606df671a174480b7e68c687920 (patch) | |
tree | c7ae4c84a0c4b726cc158dc6c8feb034a337a82f /src | |
parent | 99704743494e0465dc3ba5103ebe0c8b85f7d85f (diff) |
Add SAK registration to the local socket debugging interface.
Required revising the local protocol to support a larger message.
Also conditionally compile the view_debug_dump() interface.
Diffstat (limited to 'src')
-rw-r--r-- | src/debug.c | 22 | ||||
-rw-r--r-- | src/local.c | 33 | ||||
-rw-r--r-- | src/local.h | 12 | ||||
-rw-r--r-- | src/view.c | 2 |
4 files changed, 58 insertions, 11 deletions
diff --git a/src/debug.c b/src/debug.c index a4c209a..86889d5 100644 --- a/src/debug.c +++ b/src/debug.c @@ -34,16 +34,28 @@ bail(const char *msg) exit(1); } +static void +usage(void) +{ + bail("Usage: linpicker-cli <code> [param...]\n\t" + "0 - Dump views\n\t" + "1 <domid> <sak> - Register SAK"); +} + int main(int argc, char **argv) { - char msg; + struct local_message msg = { 0 }; struct sockaddr_un addr; int sd; - if (argc != 2) - bail("Usage: linpicker-cli <code>\n\t0 - Dump views\n"); - msg = atoi(argv[1]); + if (argc < 2) + usage(); + msg.type = atoi(argv[1]); + if (argc > 2) + msg.param1 = atoi(argv[2]); + if (argc > 3) + msg.param2 = atoi(argv[3]); sd = socket(AF_UNIX, SOCK_DGRAM, 0); if (sd < 0) @@ -52,7 +64,7 @@ main(int argc, char **argv) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; memcpy(addr.sun_path, LINPICKER_SOCKNAME, sizeof(LINPICKER_SOCKNAME)); - sendto(sd, &msg, 1, 0, (struct sockaddr *)&addr, sizeof(addr)); + sendto(sd, &msg, sizeof(msg), 0, (struct sockaddr *)&addr, sizeof(addr)); close(sd); return 0; diff --git a/src/local.c b/src/local.c index df2e425..36f1bbe 100644 --- a/src/local.c +++ b/src/local.c @@ -35,33 +35,56 @@ #include "local.h" #include "fd.h" #include "view.h" +#include "sak.h" #ifdef LOCALSOCK static int sd; static void +local_dump_views(void) +{ + view_debug_dump(); +} + +static void +local_set_sak(struct local_message *msg) +{ + struct buffer *b; + + b = buffer_lookup(msg->param1, 0); + if (b) + sak_register(msg->param2, b->bg_view->display); +} + +static void local_process(void *closure) { - char msg; + struct local_message msg; int rc; - rc = recv(sd, &msg, 1, MSG_DONTWAIT); + rc = recv(sd, &msg, sizeof(msg), MSG_DONTWAIT); if (rc < 0) { if (errno == EAGAIN || errno == EINTR) return; FD_LOG(0, "recv() failed: %m\n"); return; - } else if (rc == 1) { - switch (msg) { + } + else if (rc == sizeof(msg)) { + switch (msg.type) { case LINPICKER_LOCAL_DUMP_VIEWS: - view_debug_dump(); + local_dump_views(); + break; + case LINPICKER_LOCAL_SET_SAK: + local_set_sak(&msg); break; default: break; } } + else + FD_LOG(1, "Warning: partial local_message dropped\n"); } int diff --git a/src/local.h b/src/local.h index 1197676..1e6c5eb 100644 --- a/src/local.h +++ b/src/local.h @@ -13,11 +13,21 @@ #ifndef _LINPICKER_LOCAL_H_ #define _LINPICKER_LOCAL_H_ +#include <stdint.h> + /* The local socket address */ #define LINPICKER_SOCKNAME "\0linpicker-server" -/* 1-byte messages accepted over the socket */ +/* Messages accepted over the socket */ #define LINPICKER_LOCAL_DUMP_VIEWS 0 +#define LINPICKER_LOCAL_SET_SAK 1 + +struct local_message { + uint32_t type; + uint32_t param1; + uint32_t param2; + uint32_t param3; +}; int local_init(int argc, char **argv); @@ -433,6 +433,7 @@ view_toggle_labeling(void) } /*** DEBUG INTERFACES ***/ +#ifdef LOCALSOCK void view_debug_dump(void) { @@ -477,3 +478,4 @@ view_debug_dump(void) fprintf(stderr, "------ END VIEW DUMP\n"); } +#endif |