Changeset 0b4c12390c2c7ba0a59642aeb55427580763d940
- Timestamp:
- 04/30/11 20:31:38 (2 years ago)
- git-parent:
- Files:
-
- src/stratcon_jlog_streamer.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/stratcon_jlog_streamer.c
ra15dc32 r0b4c123 914 914 } 915 915 916 char * 917 stratcon_console_noit_opts(noit_console_closure_t ncct, 918 noit_console_state_stack_t *stack, 919 noit_console_state_t *dstate, 920 int argc, char **argv, int idx) { 921 if(argc == 1) { 922 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 923 const char *key_id; 924 int klen, i = 0; 925 void *vconn, *vcn; 926 noit_connection_ctx_t *ctx; 927 noit_hash_table dedup = NOIT_HASH_EMPTY; 928 929 pthread_mutex_lock(&noits_lock); 930 while(noit_hash_next(&noits, &iter, &key_id, &klen, &vconn)) { 931 ctx = (noit_connection_ctx_t *)vconn; 932 vcn = NULL; 933 if(ctx->config && noit_hash_retrieve(ctx->config, "cn", 2, &vcn) && 934 !noit_hash_store(&dedup, vcn, strlen(vcn), NULL)) { 935 if(!strncmp(vcn, argv[0], strlen(argv[0]))) { 936 if(idx == i) { 937 pthread_mutex_unlock(&noits_lock); 938 noit_hash_destroy(&dedup, NULL, NULL); 939 return strdup(vcn); 940 } 941 i++; 942 } 943 } 944 if(ctx->remote_str && 945 !noit_hash_store(&dedup, ctx->remote_str, strlen(ctx->remote_str), NULL)) { 946 if(!strncmp(ctx->remote_str, argv[0], strlen(argv[0]))) { 947 if(idx == i) { 948 pthread_mutex_unlock(&noits_lock); 949 noit_hash_destroy(&dedup, NULL, NULL); 950 return strdup(ctx->remote_str); 951 } 952 i++; 953 } 954 } 955 } 956 pthread_mutex_unlock(&noits_lock); 957 noit_hash_destroy(&dedup, NULL, NULL); 958 } 959 if(argc == 2) 960 return noit_console_opt_delegate(ncct, stack, dstate, argc-1, argv+1, idx); 961 return NULL; 962 } 916 963 static int 917 964 stratcon_console_show_noits(noit_console_closure_t ncct, … … 920 967 void *closure) { 921 968 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 922 const char *key_id ;969 const char *key_id, *ecn; 923 970 int klen, n = 0, i; 924 971 void *vconn; 925 972 noit_connection_ctx_t **ctx; 926 973 974 if(closure != (void *)0 && argc == 0) { 975 nc_printf(ncct, "takes an argument\n"); 976 return 0; 977 } 978 if(closure == (void *)0 && argc > 0) { 979 nc_printf(ncct, "takes no arguments\n"); 980 return 0; 981 } 927 982 pthread_mutex_lock(&noits_lock); 928 983 ctx = malloc(sizeof(*ctx) * noits.size); … … 930 985 &vconn)) { 931 986 ctx[n] = (noit_connection_ctx_t *)vconn; 932 noit_atomic_inc32(&ctx[n]->refcnt); 933 n++; 987 if(argc == 0 || 988 !strcmp(ctx[n]->remote_str, argv[0]) || 989 (ctx[n]->config && noit_hash_retr_str(ctx[n]->config, "cn", 2, &ecn) && 990 !strcmp(ecn, argv[0]))) { 991 noit_atomic_inc32(&ctx[n]->refcnt); 992 n++; 993 } 934 994 } 935 995 pthread_mutex_unlock(&noits_lock); … … 1450 1510 1451 1511 noit_console_state_add_cmd(showcmd->dstate, 1512 NCSCMD("noit", stratcon_console_show_noits, 1513 stratcon_console_noit_opts, NULL, (void *)1)); 1514 noit_console_state_add_cmd(showcmd->dstate, 1452 1515 NCSCMD("noits", stratcon_console_show_noits, NULL, NULL, NULL)); 1453 1516 }
