From fda78a33648bf94623b479e0ea971046a45d54a0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 15 Apr 2014 15:07:41 +0200 Subject: [CLIENT] Debug argument handling in daemon mode --- src/client/client.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/client') diff --git a/src/client/client.c b/src/client/client.c index bb5683b..2b6d213 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -33,7 +33,6 @@ #include #include #include - #include "../types.h" #include "../version.h" @@ -379,7 +378,7 @@ static void dnbd3_client_daemon() ret = recv( client, &len, sizeof(len), MSG_WAITALL ); if ( ret != sizeof(len) || len <= 0 || len + 4 > SOCK_BUFFER ) { // Leave a little room (at least one byte for the appended nullchar) - printf( "Error reading length field\n" ); + printf( "Error reading length field (ret: %d, len: %d)\n", ret, len ); close( client ); continue; } @@ -391,13 +390,17 @@ static void dnbd3_client_daemon() buffer[len] = '\0'; char *pos = buffer, *end = buffer + len; int argc = 1; - char *argv[20] = { 0 }; - while ( pos < end ) { + char *argv[20] = { "dnbd3-client" }; + while ( pos < end && argc < 20 ) { + while ( *pos == '\0' ) { + if ( ++pos >= end ) break; + } + if ( pos >= end ) break; argv[argc++] = pos; - while ( *++pos != '\0' ) { // This will always be in bounds because of -4 above - if ( pos >= end ) break; + printf("Arg %d: '%s'\n", argc, pos); + while ( *pos != '\0' ) { // This will always be in bounds because of -4 above + if ( ++pos >= end ) break; } - ++pos; } dnbd3_daemon_action( client, argc, argv ); } @@ -598,8 +601,9 @@ static int dnbd3_daemon_send(int argc, char **argv) return FALSE; } // (Re)build argument string into a single one, arguments separated by null chars - char *pos = buffer, *end = buffer + SOCK_BUFFER; - pos += snprintf( pos, end - pos, "--user%c%d", '\0', uid ) + 1; + char *pos = buffer; + char *end = buffer + SOCK_BUFFER; + pos += snprintf( pos, end - pos, "--user%c%d", (int)'\0', uid ) + 1; for (i = 1; i < argc && pos < end; ++i) { pos += snprintf( pos, end - pos, "%s", argv[i] ) + 1; } -- cgit v1.2.3-55-g7522