1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
39
#include "basis_types.h"
41
#include "cl_commlib.h"
45
#include "sge_mt_init.h"
46
#include "sge_profiling.h"
47
#include "sge_uidgid.h"
48
#include "sge_signal.h"
49
#include "setup_path.h"
50
#include "sge_bootstrap.h"
51
#include "sge_feature.h"
53
#include "sge_security.h"
54
#include "sge_all_listsL.h"
55
#include "msg_utilbin.h"
57
#include "sgeobj/sge_ack.h"
59
#include "gdi/sge_gdi.h"
60
#include "gdi/sge_gdi_ctx.h"
61
#include "gdi/sge_gdi_packet.h"
62
#include "gdi/sge_gdi_packet_pb_cull.h"
64
#include "uti/sge_string.h"
66
#define ARGUMENT_COUNT 15
67
static char* cl_values[ARGUMENT_COUNT+2];
68
static int cl_short_host_name_option = 0;
69
static int cl_show[] = {1,1 ,1,1 ,1,1,1 ,1,1,1,1,0 ,0,1,1};
70
static int cl_alignment[] = {1,0 ,1,0 ,1,1,1 ,1,1,1,1,0 ,0,1,1};
71
static int cl_column_width[] = {0,0 ,0,30,0,0,22,0,0,0,0,20,5,0,0};
72
static char* cl_description[] = {
73
/* 00 */ "time of debug output creation",
74
/* 01 */ "endpoint service name where debug client is connected",
75
/* 02 */ "message direction",
76
/* 03 */ "name of participating communication endpoint",
77
/* 04 */ "message data format",
78
/* 05 */ "message acknowledge type",
79
/* 06 */ "message tag information",
80
/* 07 */ "message id",
81
/* 08 */ "message response id",
82
/* 09 */ "message length",
83
/* 10 */ "time when message was sent/received",
84
/* 11 */ "message content dump (xml/bin/cull)",
85
/* 12 */ "additional information",
86
/* 13 */ "commlib linger time",
87
/* 14 */ "nr. of connections"
90
static char* cl_names[] = {
110
static void sighandler_ping(int sig);
112
static int pipe_signal = 0;
113
static int hup_signal = 0;
115
static int do_shutdown = 0;
117
static void sighandler_ping(int sig) {
118
if (sig == SIGPIPE) {
130
cl_com_ignore_timeouts(CL_TRUE);
134
static void qping_set_output_option(char* option_string) {
139
option = strstr(option_string, ":");
142
if (strcmp(option_string,"h") == 0) {
147
if (strcmp(option_string,"hn") == 0) {
152
if (strcmp(option_string,"w") == 0) {
155
value2=strstr(option,":");
160
if (strcmp(option_string,"s") == 0) {
171
column = atoi(value1);
174
if (column>=0 && column <ARGUMENT_COUNT) {
183
column = atoi(value1);
186
if (column>=0 && column <ARGUMENT_COUNT) {
194
if (strcmp(value1,"short") == 0) {
195
cl_short_host_name_option = 1;
197
if (strcmp(value1,"long") == 0) {
198
cl_short_host_name_option = 0;
208
column = atoi(value1);
211
width = atoi(value2);
214
if (column>=0 && column <ARGUMENT_COUNT) {
216
cl_column_width[column] = width;
228
static void qping_convert_time(char* buffer, char* dest, cl_bool_t show_hour) {
232
#ifdef HAS_LOCALTIME_R
236
struct saved_vars_s *context = NULL;
238
help=sge_strtok_r(buffer, ".", &context);
242
help2=sge_strtok_r(NULL,".", &context);
247
if (strcmp(help,"-") == 0) {
248
sprintf(dest, "N.A.");
252
#ifndef HAS_LOCALTIME_R
255
tm = (struct tm *)localtime_r(&i, &tm_buffer);
257
if (show_hour == CL_TRUE) {
258
sprintf(dest, "%02d:%02d:%02d.%s", tm->tm_hour, tm->tm_min, tm->tm_sec, help2);
260
sprintf(dest, "%02d:%02d.%s", tm->tm_min, tm->tm_sec, help2);
263
sge_free_saved_vars(context);
266
static void qping_general_communication_error(const cl_application_error_list_elem_t* commlib_error) {
267
if (commlib_error != NULL) {
268
if (commlib_error->cl_already_logged == CL_FALSE) {
269
if (commlib_error->cl_info != NULL) {
270
fprintf(stderr,"%s: %s\n", cl_get_error_text(commlib_error->cl_error), commlib_error->cl_info);
272
fprintf(stderr,"error: %s\n", cl_get_error_text(commlib_error->cl_error));
274
if (commlib_error->cl_error == CL_RETVAL_ACCESS_DENIED) {
281
static void qping_parse_environment(void) {
282
char* env_opt = NULL;
283
char opt_buffer[1024];
284
char* opt_str = NULL;
286
env_opt = getenv("SGE_QPING_OUTPUT_FORMAT");
287
if (env_opt != NULL) {
288
snprintf(opt_buffer, 1024, "%s", env_opt);
289
opt_str=strtok(opt_buffer, " ");
291
qping_set_output_option(opt_str);
293
while( (opt_str=strtok(NULL, " "))) {
294
qping_set_output_option(opt_str);
299
static void qping_printf_fill_up(FILE* fd, char* name, int length, char c, int before) {
300
int n = strlen(name);
304
fprintf(fd,"%s",name);
306
for (i=0;i<(length-n);i++) {
310
fprintf(fd,"%s",name);
315
static void qping_print_line(const char* buffer, int nonewline, int dump_tag) {
317
int max_name_length = 0;
319
cl_com_debug_message_tag_t debug_tag = CL_DMT_MESSAGE;
320
static int show_header = 1;
321
char* message_debug_data = NULL;
325
struct saved_vars_s *context = NULL;
327
for (i=0;i<ARGUMENT_COUNT;i++) {
328
if (max_name_length < strlen(cl_names[i])) {
329
max_name_length = strlen(cl_names[i]);
334
cl_values[i++] = sge_strtok_r(buffer, "\t", &context);
335
while ((cl_values[i++] = sge_strtok_r(NULL, "\t\n", &context)));
337
i = atoi(cl_values[0]);
338
/* check if this message version has tag info (qping after 60u3 release) */
339
if (i >= CL_DMT_MESSAGE &&i < CL_DMT_MAX_TYPE) {
340
debug_tag = (cl_com_debug_message_tag_t)i;
341
for (i=0;i<ARGUMENT_COUNT;i++) {
342
cl_values[i] = cl_values[i+1];
346
if (debug_tag == CL_DMT_MESSAGE && (dump_tag == 1 || dump_tag == 3)) {
348
qping_convert_time(cl_values[0], time, CL_TRUE);
351
qping_convert_time(cl_values[10], msg_time, CL_TRUE);
352
cl_values[10] = msg_time;
354
qping_convert_time(cl_values[13], com_time, CL_FALSE);
355
cl_values[13] = com_time;
357
if (cl_short_host_name_option != 0) {
360
char help_buffer[1024];
362
help = strstr(cl_values[1],".");
364
help2 = strstr(cl_values[1],"/");
368
snprintf(help_buffer,1024,"%s%s", cl_values[1], help2);
369
snprintf(cl_values[1],1024, help_buffer);
373
help = strstr(cl_values[3],".");
375
help2 = strstr(cl_values[3],"/");
379
snprintf(help_buffer,1024,"%s%s", cl_values[3], help2);
380
snprintf(cl_values[3],1024, help_buffer);
386
if (nonewline != 0) {
387
message_debug_data = cl_values[11];
388
if ( strstr( cl_values[4] , "bin") != NULL ) {
389
cl_values[11] = "binary message data";
391
cl_values[11] = "xml message data";
395
for(i=0;i<ARGUMENT_COUNT;i++) {
396
if (cl_column_width[i] < strlen(cl_values[i])) {
397
cl_column_width[i] = strlen(cl_values[i]);
399
if (cl_column_width[i] < strlen(cl_names[i])) {
400
cl_column_width[i] = strlen(cl_names[i]);
403
full_width += cl_column_width[i];
408
if (show_header == 1) {
409
for (i=0;i<ARGUMENT_COUNT;i++) {
411
qping_printf_fill_up(stdout, cl_names[i],cl_column_width[i],' ',cl_alignment[i]);
416
for (i=0;i<ARGUMENT_COUNT;i++) {
418
qping_printf_fill_up(stdout, "",cl_column_width[i],'-',cl_alignment[i]);
426
for (i=0;i<ARGUMENT_COUNT;i++) {
428
qping_printf_fill_up(stdout, cl_values[i],cl_column_width[i],' ',cl_alignment[i]);
434
if (nonewline != 0 && cl_show[11]) {
435
if ( strstr( cl_values[4] , "bin") != NULL ) {
436
unsigned char* binary_buffer = NULL;
437
char* bin_start = "--- BINARY block start ";
438
char* bin_end = "--- BINARY block end ";
440
unsigned long message_debug_data_length = strlen(message_debug_data);
441
printf("%s", bin_start);
442
for(i=strlen(bin_start);i<full_width;i++) {
446
for (i=0;i<message_debug_data_length;i++) {
450
printf("%c", message_debug_data[i]);
452
if (counter % 16 == 0) {
462
hi = message_debug_data[x++];
463
lo = message_debug_data[x++];
464
value = (cl_util_get_hex_value(hi) << 4) + cl_util_get_hex_value(lo);
465
if (isalnum(value)) {
472
if ( printed % 8 == 0) {
480
if((i+1) == message_debug_data_length && counter != 0 ) {
481
int x = i - counter + 1;
487
for(a=0;a<(64 - counter);a++) {
495
hi = message_debug_data[x++];
496
lo = message_debug_data[x++];
497
value = (cl_util_get_hex_value(hi) << 4) + cl_util_get_hex_value(lo);
498
if (isalnum(value)) {
505
if ( printed % 8 == 0) {
513
/* try to unpack gdi data */
514
if ( strstr( cl_values[6] , "TAG_GDI_REQUEST") != NULL ) {
515
unsigned long buffer_length = 0;
516
if ( cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
519
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
520
sge_gdi_packet_class_t *packet = NULL;
522
if (sge_gdi_packet_unpack(&packet, NULL, &buf)) {
523
sge_gdi_task_class_t *task = NULL;
525
printf(" unpacked gdi request (binary buffer length %lu):\n", buffer_length );
527
printf(" packet:\n");
530
printf("id : "sge_U32CFormat"\n", sge_u32c(packet->id));
532
printf("id : %s\n", "NULL");
535
printf("host : %s\n", packet->host);
537
printf("host : %s\n", "NULL");
539
if (packet->commproc) {
540
printf("commproc : %s\n", packet->commproc);
542
printf("commproc : %s\n", "NULL");
544
if (packet->version) {
545
printf("version : "sge_U32CFormat"\n", sge_u32c(packet->version));
547
printf("version : %s\n", "NULL");
549
if (packet->auth_info) {
550
printf("auth_info : %s\n", packet->auth_info);
552
printf("auth_info : %s\n", "NULL");
554
task = packet->first_task;
555
while (task != NULL) {
559
printf("op : "sge_U32CFormat"\n", sge_u32c(task->command));
561
printf("op : %s\n", "NULL");
564
printf("target : "sge_U32CFormat"\n", sge_u32c(task->target));
566
printf("target : %s\n", "NULL");
569
if (task->data_list) {
570
lWriteListTo(task->data_list,stdout);
572
printf("lp : %s\n", "NULL");
575
if (task->answer_list) {
576
lWriteListTo(task->answer_list,stdout);
578
printf("alp : %s\n", "NULL");
581
if (task->condition) {
582
lWriteWhereTo(task->condition,stdout);
584
printf("cp : %s\n", "NULL");
586
if (task->enumeration) {
587
lWriteWhatTo(task->enumeration,stdout);
589
printf("enp : %s\n", "NULL");
592
printf("id : "sge_U32CFormat"\n", sge_u32c(task->id));
594
printf("id : %s\n", "NULL");
601
sge_gdi_packet_free(&packet);
602
clear_packbuffer(&buf);
607
if (strstr(cl_values[6], "TAG_REPORT_REQUEST") != NULL) {
608
unsigned long buffer_length = 0;
609
if ( cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
612
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
615
if (cull_unpack_list(&buf, &rep) == 0) {
616
printf(" unpacked report request (binary buffer length %lu):\n", buffer_length );
618
lWriteListTo(rep,stdout);
620
printf("rep: NULL\n");
625
clear_packbuffer(&buf);
630
if ( strstr( cl_values[6] , "TAG_EVENT_CLIENT_EXIT") != NULL ) {
631
unsigned long buffer_length = 0;
632
if ( cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
635
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
636
u_long32 client_id = 0;
637
if (unpackint(&buf, &client_id) == PACK_SUCCESS) {
638
printf(" unpacked event client exit (binary buffer length %lu):\n", buffer_length );
639
printf("event client "sge_U32CFormat" exit\n", sge_u32c(client_id));
641
clear_packbuffer(&buf);
646
if (strstr( cl_values[6] , "TAG_ACK_REQUEST") != NULL ) {
647
unsigned long buffer_length = 0;
648
if (cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
651
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
654
while (pb_unused(&buf) > 0) {
655
if (cull_unpack_elem(&buf, &ack, NULL)) {
656
printf("TAG_ACK_REQUEST: unpack error\n");
658
lWriteElemTo(ack ,stdout); /* ack */
662
clear_packbuffer(&buf);
667
if (strstr(cl_values[6] , "TAG_JOB_EXECUTION") != NULL ||
668
strstr(cl_values[6] , "TAG_SLAVE_ALLOW") != NULL) {
669
unsigned long buffer_length = 0;
670
if (cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
673
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
674
u_long32 feature_set;
675
lListElem *job = NULL;
676
if (unpackint(&buf, &feature_set) == PACK_SUCCESS) {
677
printf(" unpacked tag job execution (binary buffer length %lu):\n", buffer_length );
678
printf("feature_set: "sge_U32CFormat"\n", sge_u32c(feature_set));
680
if (cull_unpack_elem(&buf, &job, NULL) == PACK_SUCCESS) {
681
lWriteElemTo(job,stdout); /* job */
683
printf("could not unpack job\n");
686
clear_packbuffer(&buf);
691
if (strstr(cl_values[6] , "TAG_SIGJOB") != NULL) {
692
unsigned long buffer_length = 0;
693
if (cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
696
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
698
u_long32 job_signal = 0;
699
u_long32 jataskid = 0;
702
if (unpackint(&buf, &jobid) == PACK_SUCCESS) {
703
printf("jobid (JB_job_number): "sge_U32CFormat"\n", sge_u32c(jobid));
705
if (unpackint(&buf, &jataskid) == PACK_SUCCESS) {
706
printf("jataskid (JAT_task_number): "sge_U32CFormat"\n", sge_u32c(jataskid));
708
if (unpackstr(&buf, &qname) == PACK_SUCCESS) {
710
printf("qname(QU_full_name): \"%s\"\n", qname);
712
printf("qping: qname(QU_full_name) is NULL !!!!\n");
716
if (unpackint(&buf, &job_signal) == PACK_SUCCESS) {
717
printf("signal: "sge_U32CFormat" (%s)\n", sge_u32c(job_signal), sge_sig2str(job_signal));
723
clear_packbuffer(&buf);
729
if (strstr(cl_values[6], "TAG_SIGQUEUE") != NULL) {
730
unsigned long buffer_length = 0;
731
if ( cl_util_get_binary_buffer(message_debug_data, &binary_buffer , &buffer_length) == CL_RETVAL_OK) {
734
printf("binary buffer length is %lu\n",buffer_length);
736
if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
738
u_long32 queue_signal = 0;
739
u_long32 jataskid = 0;
742
if (unpackint(&buf, &jobid) == PACK_SUCCESS) {
743
printf("jobid (0 - unused): "sge_U32CFormat"\n", sge_u32c(jobid));
745
if (unpackint(&buf, &jataskid) == PACK_SUCCESS) {
746
printf("jataskid (0 - unused): "sge_U32CFormat"\n", sge_u32c(jataskid));
748
if (unpackstr(&buf, &qname) == PACK_SUCCESS) {
750
printf("qname(QU_full_name): \"%s\"\n", qname);
752
printf("qping: qname(QU_full_name) is NULL !!!!\n");
755
if (unpackint(&buf, &queue_signal) == PACK_SUCCESS) {
756
printf("signal: "sge_U32CFormat" (%s)\n", sge_u32c(queue_signal), sge_sig2str(queue_signal));
762
clear_packbuffer(&buf);
774
a) Add a option do ignore hosts/components
776
b) Following Tags are not unpacked
778
case TAG_CHANGE_TICKET
782
case TAG_NEW_FEATURES
783
case TAG_GET_NEW_CONF
784
case TAG_FULL_LOAD_REPORT
789
printf("%s", bin_end);
790
for(i=strlen(bin_end);i<full_width;i++) {
800
char* xml_start = "--- XML block start ";
801
char* xml_end = "--- XML block end ";
802
unsigned long message_debug_data_length = strlen(message_debug_data);
803
printf("%s", xml_start);
804
for(i=strlen(xml_start);i<full_width;i++) {
809
for (i=0;i<message_debug_data_length;i++) {
810
if (message_debug_data[i] == '<' && message_debug_data[i+1] != '/') {
811
if (new_line != -1) {
817
if (message_debug_data[i] == '<' && message_debug_data[i+1] == '/' && spaces == 1) {
823
for(x=0;x<spaces;x++) {
828
printf("%c", message_debug_data[i]);
829
if (message_debug_data[i] == '<' && message_debug_data[i+1] == '/') {
835
printf("\n%s", xml_end);
836
for(i=strlen(xml_end);i<full_width;i++) {
842
sge_free_saved_vars(context);
844
} /* end of CL_DMT_MESSAGE tag */
846
if (debug_tag == CL_DMT_APP_MESSAGE && (dump_tag == 1 || dump_tag == 2)) {
847
qping_convert_time(cl_values[0], time, CL_TRUE);
849
if (nonewline != 0) {
851
char* app_start = "--- APPLICATION debug block start ";
852
char* app_end = "--- APPLICATION debug block end ";
855
printf("--- APP: %s: %s\n", time, cl_values[1]);
857
sge_free_saved_vars(context);
860
sge_free_saved_vars(context);
865
static void usage(void)
867
int max_name_length = 0;
869
fprintf(stderr, "%s %s\n", GE_SHORTNAME, GDI_VERSION);
870
fprintf(stderr, "%s qping [-help] [-noalias] [-ssl|-tcp] [ [ [-i <interval>] [-info] [-f] ] | [ [-dump_tag tag [param] ] [-dump] [-nonewline] ] ] <host> <port> <name> <id>\n",MSG_UTILBIN_USAGE);
871
fprintf(stderr, " -i : set ping interval time\n");
872
fprintf(stderr, " -info : show full status information and exit\n");
873
fprintf(stderr, " -f : show full status information on each ping interval\n");
874
fprintf(stderr, " -noalias : ignore $SGE_ROOT/SGE_CELL/common/host_aliases file\n");
875
fprintf(stderr, " -ssl : use SSL framework\n");
876
fprintf(stderr, " -tcp : use TCP framework\n");
877
fprintf(stderr, " -dump : dump communication traffic (see \"communication traffic output options\" for additional information)\n");
878
fprintf(stderr, " (provides the same output like -dump_tag MSG)\n");
879
fprintf(stderr, " -dump_tag : dump communication traffic (see \"communication traffic output options\" for additional information)\n");
880
fprintf(stderr, " tag=ALL <debug level> - show all\n");
881
fprintf(stderr, " tag=APP <debug level> - show application messages\n");
882
fprintf(stderr, " tag=MSG - show commlib protocol messages\n");
883
fprintf(stderr, " <debug level> - ERROR, WARNING, INFO, DEBUG or DPRINTF\n");
884
fprintf(stderr, " -nonewline : dump output will not have a linebreak within a message\n");
885
fprintf(stderr, " -help : show this info\n");
886
fprintf(stderr, " host : host name of running component\n");
887
fprintf(stderr, " port : port number of running component\n");
888
fprintf(stderr, " name : name of running component (e.g.: \"qmaster\" or \"execd\")\n");
889
fprintf(stderr, " id : id of running component (e.g.: 1 for daemons)\n\n");
890
fprintf(stderr, "example:\n");
891
fprintf(stderr, " qping -info clustermaster 5000 qmaster 1\n\n");
892
fprintf(stderr, "communication traffic output options:\n");
893
fprintf(stderr, " The environment variable SGE_QPING_OUTPUT_FORMAT can be used to hide columns and\n");
894
fprintf(stderr, " to set default column width. For hostname output the parameter hn is used.\n");
895
fprintf(stderr, " SGE_QPING_OUTPUT_FORMAT=\"h:1 h:4 w:1:20\"\n");
896
fprintf(stderr, " will hide the columns 1 and 4 and set the width of column 1 to 20 characters.\n");
897
fprintf(stderr, " h:X -> hide column X\n");
898
fprintf(stderr, " s:X -> show column X\n");
899
fprintf(stderr, " w:X:Y -> set width of column X to Y\n");
900
fprintf(stderr, " hn:X -> set hostname output parameter X. X values are \"long\" or \"short\"\n\n");
901
fprintf(stderr, " available columns are:\n\n");
904
qping_parse_environment();
906
for (i=0;i<ARGUMENT_COUNT;i++) {
907
if (max_name_length < strlen(cl_names[i])) {
908
max_name_length = strlen(cl_names[i]);
912
for(i=0;i<ARGUMENT_COUNT;i++) {
914
if (cl_show[i] == 0) {
918
fprintf(stderr, " nr active ");
919
qping_printf_fill_up(stderr, "name", max_name_length, ' ', 0);
920
fprintf(stderr, " description\n");
921
fprintf(stderr, " == ====== ");
922
qping_printf_fill_up(stderr, "====", max_name_length, ' ', 0);
923
fprintf(stderr, " ===========\n");
925
fprintf(stderr, " %02d %3s ", i + 1, visible);
926
qping_printf_fill_up(stderr, cl_names[i], max_name_length, ' ', 0);
927
fprintf(stderr, " %s\n",cl_description[i] );
933
int main(int argc, char *argv[]) {
934
char* comp_host = NULL;
935
char* resolved_comp_host = NULL;
936
char* comp_name = NULL;
937
cl_com_handle_t* handle = NULL;
938
cl_framework_t communication_framework = CL_CT_TCP;
939
cl_tcp_connect_t connect_type = CL_TCP_DEFAULT;
940
cl_xml_connection_type_t connection_type = CL_CM_CT_MESSAGE;
941
char* client_name = "qping";
943
int got_no_framework = 0;
946
int parameter_start = 1;
953
int retval = CL_RETVAL_OK;
957
int option_noalias = 0;
961
int option_nonewline = 1;
962
int option_debuglevel = 0;
963
int parameter_count = 4;
964
int commlib_error = CL_RETVAL_OK;
967
/* setup signalhandling */
968
memset(&sa, 0, sizeof(sa));
969
sa.sa_handler = sighandler_ping; /* one handler for all signals */
970
sigemptyset(&sa.sa_mask);
971
sigaction(SIGINT, &sa, NULL);
972
sigaction(SIGTERM, &sa, NULL);
973
sigaction(SIGHUP, &sa, NULL);
974
sigaction(SIGPIPE, &sa, NULL);
976
for (i=1;i<argc;i++) {
977
if (argv[i][0] == '-') {
978
if (strcmp( argv[i] , "-i") == 0) {
979
parameter_count = parameter_count + 2;
980
parameter_start = parameter_start + 2;
982
if ( argv[i] != NULL) {
983
interval = atoi(argv[i]);
985
fprintf(stderr, "interval parameter must be larger than 0\n");
989
fprintf(stderr, "no interval parameter value\n");
993
if (strcmp( argv[i] , "-info") == 0) {
998
if (strcmp( argv[i] , "-f") == 0) {
1003
if (strcmp( argv[i] , "-noalias") == 0) {
1008
if (strcmp( argv[i] , "-tcp") == 0) {
1013
if (strcmp( argv[i] , "-ssl") == 0) {
1018
if (strcmp( argv[i] , "-dump") == 0) {
1024
if (strcmp( argv[i] , "-dump_tag") == 0) {
1026
parameter_count += 2;
1027
parameter_start += 2;
1029
if ( argv[i] != NULL) {
1030
if (strcmp(argv[i],"ALL") == 0) {
1035
if (argv[i] != NULL) {
1036
if (strcmp(argv[i],"ERROR") == 0) {
1037
option_debuglevel = 1;
1039
if (strcmp(argv[i],"WARNING") == 0) {
1040
option_debuglevel = 2;
1042
if (strcmp(argv[i],"INFO") == 0) {
1043
option_debuglevel = 3;
1045
if (strcmp(argv[i],"DEBUG") == 0) {
1046
option_debuglevel = 4;
1048
if (strcmp(argv[i],"DPRINTF") == 0) {
1049
option_debuglevel = 5;
1051
if (option_debuglevel == 0) {
1052
fprintf(stderr, "unexpected debug level\n");
1057
if (strcmp(argv[i],"APP") == 0) {
1062
if (argv[i] != NULL) {
1063
if (strcmp(argv[i],"ERROR") == 0) {
1064
option_debuglevel = 1;
1066
if (strcmp(argv[i],"WARNING") == 0) {
1067
option_debuglevel = 2;
1069
if (strcmp(argv[i],"INFO") == 0) {
1070
option_debuglevel = 3;
1072
if (strcmp(argv[i],"DEBUG") == 0) {
1073
option_debuglevel = 4;
1075
if (strcmp(argv[i],"DPRINTF") == 0) {
1076
option_debuglevel = 5;
1078
if (option_debuglevel == 0) {
1079
fprintf(stderr, "unexpected debug level\n");
1084
if (strcmp(argv[i],"MSG") == 0) {
1087
if (dump_tag == 0) {
1088
fprintf(stderr, "unexpected dump tag\n");
1092
fprintf(stderr, "no -dump_tag parameter value\n");
1098
if (strcmp( argv[i] , "-nonewline") == 0) {
1099
option_nonewline = 0;
1104
if (strcmp( argv[i] , "-help") == 0) {
1112
if (argc != parameter_count + 1 ) {
1116
comp_host = argv[parameter_start];
1117
if (argv[parameter_start + 1] != NULL) {
1118
comp_port = atoi(argv[parameter_start + 1]);
1120
comp_name = argv[parameter_start + 2];
1121
if (argv[parameter_start + 3] != NULL) {
1122
comp_id = atoi(argv[parameter_start + 3]);
1125
if ( comp_host == NULL ) {
1126
fprintf(stderr,"please enter a host name\n");
1130
if ( comp_name == NULL ) {
1131
fprintf(stderr,"please enter a component name\n");
1134
if ( comp_port < 0 ) {
1135
fprintf(stderr,"please enter a correct port number\n");
1138
if ( comp_id <= 0 ) {
1139
fprintf(stderr,"please enter a component id larger than 0\n");
1148
bootstrap_mt_init();
1157
retval = cl_com_setup_commlib(CL_RW_THREAD ,CL_LOG_OFF, NULL);
1158
if (retval != CL_RETVAL_OK) {
1159
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1163
retval = cl_com_set_error_func(qping_general_communication_error);
1164
if (retval != CL_RETVAL_OK) {
1165
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1169
/* set alias file */
1170
if ( !option_noalias ) {
1171
const char *alias_path = sge_get_alias_path();
1172
if (alias_path != NULL) {
1173
retval = cl_com_set_alias_file(alias_path);
1174
if (retval != CL_RETVAL_OK) {
1175
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1181
if ( option_ssl != 0 && option_tcp != 0) {
1182
fprintf(stderr,"using of option -ssl and option -tcp not supported\n");
1187
/* find out the framework type to use */
1188
if ( option_ssl == 0 && option_tcp == 0 ) {
1189
char buffer[2*1024];
1191
sge_dstring_init(&bw, buffer, sizeof(buffer));
1193
sge_setup_paths(QPING, sge_get_default_cell(), &bw);
1194
if (sge_bootstrap(path_state_get_bootstrap_file(), NULL) != true) {
1195
fprintf(stderr,"please use option -ssl or -tcp to bypass bootstrap file read\n");
1199
got_no_framework = 1;
1201
if ( strcmp( "csp", bootstrap_get_security_mode()) == 0) {
1208
if (option_ssl != 0) {
1209
communication_framework = CL_CT_SSL;
1211
if (got_no_framework == 1) {
1212
/* we got no framework and we have a bootstrap file */
1214
sge_ssl_setup_security_path("qping", uti_state_get_user_name());
1216
if (getenv("SSL_CA_CERT_FILE") == NULL) {
1217
fprintf(stderr,"You have not set the SGE default environment or you specified the -ssl option.\n");
1218
fprintf(stderr,"Please set the following environment variables to specifiy your certificates:\n");
1219
fprintf(stderr,"- SSL_CA_CERT_FILE - CA certificate file\n");
1220
fprintf(stderr,"- SSL_CERT_FILE - certificates file\n");
1221
fprintf(stderr,"- SSL_KEY_FILE - key file\n");
1222
fprintf(stderr,"- SSL_RAND_FILE - rand file\n");
1225
cl_ssl_setup_t ssl_config;
1226
ssl_config.ssl_method = CL_SSL_v23; /* v23 method */
1227
ssl_config.ssl_CA_cert_pem_file = getenv("SSL_CA_CERT_FILE"); /* CA certificate file */
1228
ssl_config.ssl_CA_key_pem_file = NULL; /* private certificate file of CA (not used) */
1229
ssl_config.ssl_cert_pem_file = getenv("SSL_CERT_FILE"); /* certificates file */
1230
ssl_config.ssl_key_pem_file = getenv("SSL_KEY_FILE"); /* key file */
1231
ssl_config.ssl_rand_file = getenv("SSL_RAND_FILE"); /* rand file (if RAND_status() not ok) */
1232
ssl_config.ssl_reconnect_file = NULL; /* file for reconnect data (not used) */
1233
ssl_config.ssl_crl_file = NULL; /* file for revocation list */
1234
ssl_config.ssl_refresh_time = 0; /* key alive time for connections (not used) */
1235
ssl_config.ssl_password = NULL; /* password for encrypted keyfiles (not used) */
1236
ssl_config.ssl_verify_func = NULL; /* function callback for peer user/name check */
1237
cl_com_specify_ssl_configuration(&ssl_config);
1242
if (option_tcp != 0) {
1243
communication_framework = CL_CT_TCP;
1246
if (option_dump != 0) {
1247
connect_type = CL_TCP_RESERVED_PORT;
1248
connection_type = CL_CM_CT_STREAM;
1249
client_name = "debug_client";
1252
retval = cl_com_set_error_func(qping_general_communication_error);
1253
if (retval != CL_RETVAL_OK) {
1254
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1258
handle=cl_com_create_handle(&commlib_error, communication_framework, connection_type, CL_FALSE, comp_port, connect_type, client_name, 0, 1,0 );
1260
if (handle == NULL) {
1261
fprintf(stderr, "could not create communication handle: %s\n", cl_get_error_text(commlib_error));
1262
cl_com_cleanup_commlib();
1266
if (option_dump == 0) {
1267
/* enable auto close of application */
1268
cl_com_set_auto_close_mode(handle, CL_CM_AC_ENABLED );
1272
retval = cl_com_cached_gethostbyname(comp_host, &resolved_comp_host,NULL, NULL, NULL);
1273
if (retval != CL_RETVAL_OK) {
1274
fprintf(stderr, "could not resolve hostname %s\n", comp_host);
1275
cl_com_cleanup_commlib();
1279
if (option_dump == 0) {
1280
while (do_shutdown == 0 ) {
1281
cl_com_SIRM_t* status = NULL;
1282
retval = cl_commlib_get_endpoint_status(handle, resolved_comp_host , comp_name, comp_id, &status);
1283
if (retval != CL_RETVAL_OK) {
1284
printf("endpoint %s/%s/"sge_U32CFormat" at port %d: %s\n",
1285
resolved_comp_host, comp_name, sge_u32c(comp_id), comp_port,
1286
cl_get_error_text(retval) );
1289
if (status != NULL) {
1292
sge_dstring_init(&ds, buffer, sizeof(buffer));
1294
printf("%s", sge_ctime(0, &ds));
1296
if (option_info == 0 && option_f == 0) {
1297
printf(" endpoint %s/%s/%d at port %d is up since %ld seconds\n",
1298
resolved_comp_host, comp_name, comp_id, comp_port,
1302
starttime = (time_t)status->starttime;
1304
printf(":\nSIRM version: %s\n", status->version );
1305
printf("SIRM message id: "sge_U32CFormat"\n", sge_u32c(status->mid) );
1306
printf("start time: %s ("sge_U32CFormat")\n", sge_ctime(starttime, &ds),sge_u32c(status->starttime));
1307
printf("run time [s]: "sge_U32CFormat"\n", sge_u32c(status->runtime) );
1308
printf("messages in read buffer: "sge_U32CFormat"\n", sge_u32c(status->application_messages_brm) );
1309
printf("messages in write buffer: "sge_U32CFormat"\n", sge_u32c(status->application_messages_bwm) );
1310
printf("nr. of connected clients: "sge_U32CFormat"\n", sge_u32c(status->application_connections_noc) );
1311
printf("status: "sge_U32CFormat"\n", sge_u32c(status->application_status) );
1312
printf("info: %s\n", status->info );
1316
printf("unexpected error\n");
1320
cl_com_free_sirm_message(&status);
1322
if (option_info != 0) {
1328
dstring line_buffer = DSTRING_INIT;
1330
qping_parse_environment();
1332
while (do_shutdown == 0 ) {
1335
static int stop_running = 15;
1337
cl_com_message_t* message = NULL;
1338
cl_com_endpoint_t* sender = NULL;
1341
if (stop_running-- == 0) {
1346
cl_commlib_trigger(handle, 1);
1347
retval = cl_commlib_receive_message(handle, NULL, NULL, 0, /* handle, comp_host, comp_name , comp_id, */
1348
CL_FALSE, 0, /* syncron, response_mid */
1349
&message, &sender );
1351
if ( retval != CL_RETVAL_OK) {
1352
if ( retval == CL_RETVAL_CONNECTION_NOT_FOUND ) {
1353
char command_buffer[256];
1354
cl_byte_t *reference = (cl_byte_t *)command_buffer;
1355
printf("open connection to \"%s/%s/"sge_U32CFormat"\" ... " ,resolved_comp_host , comp_name, sge_u32c(comp_id) );
1356
retval = cl_commlib_open_connection(handle, resolved_comp_host , comp_name, comp_id);
1357
printf("%s\n", cl_get_error_text(retval));
1358
if (retval == CL_RETVAL_CREATE_RESERVED_PORT_SOCKET) {
1359
printf("please start qping as root\n");
1365
* set message tag we want to receive from endpoint
1369
snprintf(command_buffer,256,"set tag ALL");
1373
snprintf(command_buffer,256,"set tag APP");
1377
snprintf(command_buffer,256,"set tag MSG");
1381
cl_commlib_send_message(handle,
1382
resolved_comp_host, comp_name, comp_id,
1384
&reference, strlen(command_buffer)+1,
1385
NULL, 0, 0, CL_TRUE, CL_FALSE);
1388
* set if we want the message dump
1391
if (cl_show[11] != 0) {
1392
snprintf(command_buffer,256,"set dump ON");
1394
snprintf(command_buffer,256,"set dump OFF");
1396
cl_commlib_send_message(handle,
1397
resolved_comp_host, comp_name, comp_id,
1399
&reference, strlen(command_buffer)+1,
1400
NULL, 0, 0, CL_TRUE, CL_FALSE);
1406
switch(option_debuglevel) {
1408
snprintf(command_buffer,256,"set debug ERROR");
1412
snprintf(command_buffer,256,"set debug WARNING");
1416
snprintf(command_buffer,256,"set debug INFO");
1420
snprintf(command_buffer,256,"set debug DEBUG");
1424
snprintf(command_buffer,256,"set debug DPRINTF");
1428
snprintf(command_buffer,256,"set debug OFF");
1433
cl_commlib_send_message(handle,
1434
resolved_comp_host, comp_name, comp_id,
1436
&reference, strlen(command_buffer)+1,
1437
NULL, 0, 0, CL_TRUE, CL_FALSE);
1441
for (i=0; i < message->message_length; i++) {
1442
sge_dstring_append_char(&line_buffer, message->message[i]);
1443
if (message->message[i] == '\n') {
1444
qping_print_line((char*)sge_dstring_get_string(&line_buffer), option_nonewline, dump_tag );
1445
sge_dstring_free(&line_buffer);
1449
cl_com_free_message(&message);
1450
cl_com_free_endpoint(&sender);
1453
sge_dstring_free(&line_buffer);
1455
retval = cl_commlib_shutdown_handle(handle,CL_FALSE);
1456
if (retval != CL_RETVAL_OK) {
1457
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1458
free(resolved_comp_host);
1459
resolved_comp_host = NULL;
1460
cl_com_cleanup_commlib();
1464
retval = cl_com_cleanup_commlib();
1465
if (retval != CL_RETVAL_OK) {
1466
fprintf(stderr,"%s\n",cl_get_error_text(retval));
1467
free(resolved_comp_host);
1468
resolved_comp_host = NULL;
1471
free(resolved_comp_host);
1472
resolved_comp_host = NULL;