ccs_tool.c | ccs_tool.c | |||
---|---|---|---|---|
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <getopt.h> | #include <getopt.h> | |||
#include <string.h> | #include <string.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include "copyright.cf" | #include "copyright.cf" | |||
#include "editconf.h" | #include "editconf.h" | |||
#include "ccs.h" | #include "ccs.h" | |||
/* | ||||
* Old libccs retruned -error (mostly!) but didn't set errno (sigh) | ||||
* New libccs sets errno correctly | ||||
*/ | ||||
static char *errstring(int retcode) | ||||
{ | ||||
return strerror(errno); | ||||
} | ||||
static void tool_print_usage(FILE *stream); | static void tool_print_usage(FILE *stream); | |||
int globalverbose=0; | int globalverbose=0; | |||
static void test_print_usage(FILE *stream); | static void test_print_usage(FILE *stream); | |||
static int test_main(int argc, char *argv[], int old_format){ | static int test_main(int argc, char *argv[], int old_format){ | |||
int desc=0; | int desc=0; | |||
int i=0; | int i=0; | |||
int error = 0; | ||||
int force = 0, blocking = 0; | int force = 0, blocking = 0; | |||
char *str=NULL; | char *str=NULL; | |||
char *cluster_name = NULL; | char *cluster_name = NULL; | |||
if(argc <= 1){ | if(argc <= 1){ | |||
test_print_usage(stderr); | test_print_usage(stderr); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
for(i=1; i < argc; i++){ | for(i=1; i < argc; i++){ | |||
skipping to change at line 78 | skipping to change at line 68 | |||
if(force){ | if(force){ | |||
desc = ccs_force_connect(cluster_name, blocking); | desc = ccs_force_connect(cluster_name, blocking); | |||
} else { | } else { | |||
if(cluster_name){ | if(cluster_name){ | |||
fprintf(stderr, "A cluster name can only be specified when using 'fo rce'.\n"); | fprintf(stderr, "A cluster name can only be specified when using 'fo rce'.\n"); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
desc = ccs_connect(); | desc = ccs_connect(); | |||
} | } | |||
if(desc < 0){ | if(desc < 0){ | |||
fprintf(stderr, "ccs_connect failed: %s\n", errstring(-desc)); | fprintf(stderr, "ccs_connect failed: %s\n", strerror(errno)); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} else { | } else { | |||
printf("Connect successful.\n"); | printf("Connect successful.\n"); | |||
printf(" Connection descriptor = %d\n", desc); | printf(" Connection descriptor = %d\n", desc); | |||
ccs_disconnect(desc); | ccs_disconnect(desc); | |||
} | } | |||
} | } | |||
else if(!strcmp(argv[1], "disconnect")){ | else if(!strcmp(argv[1], "disconnect")){ | |||
if(argc < 3){ | if(argc < 3){ | |||
fprintf(stderr, "Wrong number of arguments.\n"); | fprintf(stderr, "Wrong number of arguments.\n"); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
desc = ccs_connect(); | desc = ccs_connect(); | |||
if((error = ccs_disconnect(desc))){ | if (desc < 0) { | |||
fprintf(stderr, "ccs_disconnect failed: %s\n", errstring(-error)); | fprintf(stderr, "ccs_disconnect failed: unable to communicate with cc | |||
s\n"); | ||||
exit(EXIT_FAILURE); | ||||
} | ||||
if(ccs_disconnect(desc)){ | ||||
fprintf(stderr, "ccs_disconnect failed: %s\n", strerror(errno)); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} else { | } else { | |||
printf("Disconnect successful.\n"); | printf("Disconnect successful.\n"); | |||
} | } | |||
} | } | |||
else if(!strcmp(argv[1], "get")){ | else if(!strcmp(argv[1], "get")){ | |||
if(argc < 4){ | if(argc < 4){ | |||
fprintf(stderr, "Wrong number of arguments.\n"); | fprintf(stderr, "Wrong number of arguments.\n"); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
desc = ccs_connect(); | desc = ccs_connect(); | |||
if((desc < 0) || (error = ccs_get(desc, argv[3], &str))){ | if((desc < 0) || ccs_get(desc, argv[3], &str)){ | |||
fprintf(stderr, "ccs_get failed: %s\n", errstring(-error)); | fprintf(stderr, "ccs_get failed: %s\n", strerror(errno)); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} else { | } else { | |||
if (old_format) { | if (old_format) { | |||
printf("Get successful.\n"); | printf("Get successful.\n"); | |||
printf(" Value = <%s>\n", str); | printf(" Value = <%s>\n", str); | |||
} | } | |||
else { | else { | |||
printf("%s\n", str); | printf("%s\n", str); | |||
} | } | |||
if(str)free(str); | if(str)free(str); | |||
skipping to change at line 175 | skipping to change at line 169 | |||
if (strcmp(argv[1], "-n") == 0) { | if (strcmp(argv[1], "-n") == 0) { | |||
argv++; | argv++; | |||
argc--; | argc--; | |||
/* Actually ... no we don't */ | /* Actually ... no we don't */ | |||
fullxpath = 0; | fullxpath = 0; | |||
} | } | |||
handle = ccs_connect(); | handle = ccs_connect(); | |||
if (handle < 0) { | ||||
fprintf(stderr, "Unable to connect to ccs\n"); | ||||
exit(EXIT_FAILURE); | ||||
} | ||||
/* Process all the queries on the command-line */ | /* Process all the queries on the command-line */ | |||
for (i=1; i<argc; i++) { | for (i=1; i<argc; i++) { | |||
if (!ccs_get(handle, argv[1], &ret)) { | if (!ccs_get(handle, argv[1], &ret)) { | |||
printf("%s\n", ret); | printf("%s\n", ret); | |||
free(ret); | free(ret); | |||
} | } | |||
else { | else { | |||
fprintf(stderr, "Query failed: %s\n", strerror(errno )); | fprintf(stderr, "Query failed: %s\n", strerror(errno )); | |||
ccs_disconnect(handle); | ccs_disconnect(handle); | |||
End of changes. 6 change blocks. | ||||
15 lines changed or deleted | 14 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |