~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/utilbin/qping.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
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
 
16
 * 
 
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.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <stdlib.h>
 
34
#include <stdio.h>
 
35
#include <signal.h>
 
36
#include <string.h>
 
37
#include <ctype.h>
 
38
 
 
39
#include "basis_types.h"
 
40
#include "sge_time.h"
 
41
#include "cl_commlib.h"
 
42
#include "cl_util.h"
 
43
#include "sge_arch.h"
 
44
#include "version.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"
 
52
#include "sge_prog.h"
 
53
#include "sge_security.h"
 
54
#include "sge_all_listsL.h"
 
55
#include "msg_utilbin.h"
 
56
 
 
57
#include "sgeobj/sge_ack.h"
 
58
 
 
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"
 
63
 
 
64
#include "uti/sge_string.h"
 
65
 
 
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"
 
88
};
 
89
 
 
90
static char* cl_names[] = {
 
91
                       "time",
 
92
                       "local",
 
93
                       "d.",
 
94
                       "remote",
 
95
                       "format",
 
96
                       "ack type",
 
97
                       "msg tag",
 
98
                       "msg id",
 
99
                       "msg rid",
 
100
                       "msg len",
 
101
                       "msg time",
 
102
                       "msg dump",
 
103
                       "info",
 
104
                       "msg ltime",
 
105
                       "con count"
 
106
};
 
107
 
 
108
 
 
109
 
 
110
static void sighandler_ping(int sig);
 
111
#if 0
 
112
static int pipe_signal = 0;
 
113
static int hup_signal = 0;
 
114
#endif
 
115
static int do_shutdown = 0;
 
116
 
 
117
static void sighandler_ping(int sig) {
 
118
   if (sig == SIGPIPE) {
 
119
#if 0
 
120
      pipe_signal = 1;
 
121
#endif
 
122
      return;
 
123
   }
 
124
   if (sig == SIGHUP) {
 
125
#if 0
 
126
      hup_signal = 1;
 
127
#endif
 
128
      return;
 
129
   }
 
130
   cl_com_ignore_timeouts(CL_TRUE);
 
131
   do_shutdown = 1;
 
132
}
 
133
 
 
134
static void qping_set_output_option(char* option_string) {
 
135
   char* option = NULL;
 
136
   char* value1 = NULL;
 
137
   char* value2 = NULL;
 
138
   int opt = 0;
 
139
   option = strstr(option_string, ":");
 
140
   if (option) {
 
141
      option[0]=0;
 
142
      if (strcmp(option_string,"h") == 0) {
 
143
         opt = 1;
 
144
         option++;
 
145
         value1=option;
 
146
      }
 
147
      if (strcmp(option_string,"hn") == 0) {
 
148
         opt = 2;
 
149
         option++;
 
150
         value1=option;
 
151
      }
 
152
      if (strcmp(option_string,"w") == 0) {
 
153
         opt = 3;
 
154
         option++;
 
155
         value2=strstr(option,":");
 
156
         value2[0] = 0;
 
157
         value1=option;
 
158
         value2++;
 
159
      }
 
160
      if (strcmp(option_string,"s") == 0) {
 
161
         opt = 4;
 
162
         option++;
 
163
         value1=option;
 
164
      }
 
165
 
 
166
      switch(opt) {
 
167
         case 1: {
 
168
            /* h */
 
169
            int column = -1;
 
170
            if (value1) {
 
171
               column = atoi(value1);
 
172
            }
 
173
            column--;
 
174
            if (column>=0 && column <ARGUMENT_COUNT) {
 
175
               cl_show[column] = 0;
 
176
            }
 
177
            break;
 
178
         }
 
179
         case 4: {
 
180
            /* s */
 
181
            int column = -1;
 
182
            if (value1) {
 
183
               column = atoi(value1);
 
184
            }
 
185
            column--;
 
186
            if (column>=0 && column <ARGUMENT_COUNT) {
 
187
               cl_show[column] = 1;
 
188
            }
 
189
            break;
 
190
         }
 
191
         case 2: {
 
192
            /* hn */
 
193
            if(value1) {
 
194
               if (strcmp(value1,"short") == 0) {
 
195
                  cl_short_host_name_option = 1;
 
196
               }
 
197
               if (strcmp(value1,"long") == 0) {
 
198
                  cl_short_host_name_option = 0;
 
199
               }
 
200
            }
 
201
            break;
 
202
         }
 
203
         case 3: {
 
204
            /* w */
 
205
            int column = -1;
 
206
            int width = -1;
 
207
            if(value1) {
 
208
               column = atoi(value1);
 
209
            }
 
210
            if(value2) {
 
211
               width = atoi(value2);
 
212
            }
 
213
            column--;
 
214
            if (column>=0 && column <ARGUMENT_COUNT) {
 
215
               if (width > 0) {
 
216
                  cl_column_width[column] = width;
 
217
               }
 
218
            }
 
219
            break;
 
220
         }
 
221
      }
 
222
 
 
223
   }
 
224
 
 
225
   
 
226
}
 
227
 
 
228
static void qping_convert_time(char* buffer, char* dest, cl_bool_t show_hour) {
 
229
   time_t i;
 
230
   char* help;
 
231
   char* help2;
 
232
#ifdef HAS_LOCALTIME_R
 
233
   struct tm tm_buffer;
 
234
#endif
 
235
   struct tm *tm;
 
236
   struct saved_vars_s *context = NULL;
 
237
 
 
238
   help=sge_strtok_r(buffer, ".", &context);
 
239
   if (help == NULL) {
 
240
      help = "-";
 
241
   }
 
242
   help2=sge_strtok_r(NULL,".", &context);
 
243
   if (help2 == NULL) {
 
244
      help2 = "NULL";
 
245
   }
 
246
 
 
247
   if (strcmp(help,"-") == 0) {
 
248
      sprintf(dest, "N.A.");
 
249
   } else {
 
250
 
 
251
      i = atoi(help);
 
252
#ifndef HAS_LOCALTIME_R
 
253
      tm = localtime(&i);
 
254
#else
 
255
      tm = (struct tm *)localtime_r(&i, &tm_buffer);
 
256
#endif
 
257
      if (show_hour == CL_TRUE) {
 
258
         sprintf(dest, "%02d:%02d:%02d.%s", tm->tm_hour, tm->tm_min, tm->tm_sec, help2);
 
259
      } else {
 
260
         sprintf(dest, "%02d:%02d.%s", tm->tm_min, tm->tm_sec, help2);
 
261
      }
 
262
   }
 
263
   sge_free_saved_vars(context);
 
264
}
 
265
 
 
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);
 
271
         } else {
 
272
            fprintf(stderr,"error: %s\n", cl_get_error_text(commlib_error->cl_error));
 
273
         }
 
274
         if (commlib_error->cl_error == CL_RETVAL_ACCESS_DENIED) {
 
275
            do_shutdown = 1;
 
276
         } 
 
277
      }
 
278
   }
 
279
}
 
280
 
 
281
static void qping_parse_environment(void) {
 
282
   char* env_opt = NULL;
 
283
   char opt_buffer[1024];
 
284
   char* opt_str = NULL;
 
285
 
 
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, " ");
 
290
      if (opt_str) {
 
291
         qping_set_output_option(opt_str);
 
292
      }
 
293
      while( (opt_str=strtok(NULL, " "))) {
 
294
         qping_set_output_option(opt_str);
 
295
      }
 
296
   }
 
297
}
 
298
 
 
299
static void qping_printf_fill_up(FILE* fd, char* name, int length, char c, int before) {
 
300
   int n = strlen(name);
 
301
   int i;
 
302
 
 
303
   if (before == 0) {
 
304
      fprintf(fd,"%s",name);
 
305
   }
 
306
   for (i=0;i<(length-n);i++) {
 
307
      fprintf(fd,"%c",c);
 
308
   }
 
309
   if (before != 0) {
 
310
      fprintf(fd,"%s",name);
 
311
   }
 
312
 
 
313
}
 
314
 
 
315
static void qping_print_line(const char* buffer, int nonewline, int dump_tag) {
 
316
   int i=0;
 
317
   int max_name_length = 0;
 
318
   int full_width = 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;
 
322
   char  time[512];
 
323
   char  msg_time[512];
 
324
   char  com_time[512];
 
325
   struct saved_vars_s *context = NULL;
 
326
 
 
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]);
 
330
      }
 
331
   }
 
332
   
 
333
   i=0;
 
334
   cl_values[i++] = sge_strtok_r(buffer, "\t", &context);
 
335
   while ((cl_values[i++] = sge_strtok_r(NULL, "\t\n", &context)));
 
336
 
 
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];
 
343
      }
 
344
   }
 
345
 
 
346
   if (debug_tag == CL_DMT_MESSAGE && (dump_tag == 1 || dump_tag == 3)) {
 
347
 
 
348
      qping_convert_time(cl_values[0], time, CL_TRUE);
 
349
      cl_values[0] = time;
 
350
   
 
351
      qping_convert_time(cl_values[10], msg_time, CL_TRUE);
 
352
      cl_values[10] = msg_time;
 
353
 
 
354
      qping_convert_time(cl_values[13], com_time, CL_FALSE);
 
355
      cl_values[13] = com_time;
 
356
   
 
357
      if (cl_short_host_name_option != 0) {
 
358
         char* help = NULL;
 
359
         char* help2 = NULL;
 
360
         char help_buffer[1024];
 
361
   
 
362
         help = strstr(cl_values[1],".");
 
363
         if (help) {
 
364
            help2 = strstr(cl_values[1],"/");
 
365
   
 
366
            help[0]=0;
 
367
            if (help2) {
 
368
               snprintf(help_buffer,1024,"%s%s", cl_values[1], help2);
 
369
               snprintf(cl_values[1],1024, help_buffer);
 
370
            }
 
371
         }
 
372
   
 
373
         help = strstr(cl_values[3],".");
 
374
         if (help) {
 
375
            help2 = strstr(cl_values[3],"/");
 
376
   
 
377
            help[0]=0;
 
378
            if (help2) {
 
379
               snprintf(help_buffer,1024,"%s%s", cl_values[3], help2);
 
380
               snprintf(cl_values[3],1024, help_buffer);
 
381
            }
 
382
         }
 
383
   
 
384
      }
 
385
   
 
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";
 
390
         } else {
 
391
            cl_values[11] = "xml message data";
 
392
         }
 
393
      }
 
394
   
 
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]);
 
398
         }
 
399
         if (cl_column_width[i] < strlen(cl_names[i])) {
 
400
            cl_column_width[i] = strlen(cl_names[i]);
 
401
         }
 
402
         if (cl_show[i]) {
 
403
            full_width += cl_column_width[i];
 
404
            full_width++;
 
405
         }
 
406
      }
 
407
   
 
408
      if (show_header == 1) {
 
409
         for (i=0;i<ARGUMENT_COUNT;i++) {
 
410
            if (cl_show[i]) {
 
411
               qping_printf_fill_up(stdout, cl_names[i],cl_column_width[i],' ',cl_alignment[i]);
 
412
               printf("|");
 
413
            }
 
414
         }
 
415
         printf("\n");
 
416
         for (i=0;i<ARGUMENT_COUNT;i++) {
 
417
            if (cl_show[i]) {
 
418
               qping_printf_fill_up(stdout, "",cl_column_width[i],'-',cl_alignment[i]);
 
419
               printf("|");
 
420
            }
 
421
         }
 
422
         printf("\n");
 
423
   
 
424
         show_header = 0;
 
425
      }
 
426
      for (i=0;i<ARGUMENT_COUNT;i++) {
 
427
         if (cl_show[i]) {
 
428
            qping_printf_fill_up(stdout, cl_values[i],cl_column_width[i],' ',cl_alignment[i]);
 
429
            printf("|");
 
430
         }
 
431
      }
 
432
      printf("\n");
 
433
   
 
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 ";
 
439
            int counter = 0;
 
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++) {
 
443
               printf("-");
 
444
            }
 
445
            printf("\n");
 
446
            for (i=0;i<message_debug_data_length;i++) {
 
447
               if (counter == 0) {
 
448
                  printf("   ");
 
449
               }
 
450
               printf("%c", message_debug_data[i]);
 
451
               counter++;
 
452
               if (counter % 16 == 0) {
 
453
                  printf(" ");
 
454
               }
 
455
               if(counter == 64) {
 
456
                  int x = i - 63;
 
457
                  int hi,lo;
 
458
                  int value = 0;
 
459
                  int printed = 0;
 
460
                  printf("   ");
 
461
                  while(x<=i) {
 
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)) {
 
466
                        printf("%c",value);
 
467
                     } else {
 
468
                        printf(".");
 
469
                     }
 
470
                     printed++;
 
471
   
 
472
                     if ( printed % 8 == 0) {
 
473
                        printf(" ");
 
474
                     }
 
475
                  }
 
476
                  counter = 0;
 
477
                  printf("\n");
 
478
               }
 
479
               
 
480
               if((i+1) == message_debug_data_length && counter != 0 ) {
 
481
                  int x = i - counter + 1;
 
482
                  int hi,lo;
 
483
                  int value = 0;
 
484
                  int printed = 0; 
 
485
                  int a;
 
486
                  printf("   ");
 
487
                  for(a=0;a<(64 - counter);a++) {
 
488
                     printf(" ");
 
489
                     if (a % 16 == 0) {
 
490
                        printf(" ");
 
491
                     }
 
492
   
 
493
                  }
 
494
                  while(x<=i) {
 
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)) {
 
499
                        printf("%c",value);
 
500
                     } else {
 
501
                        printf(".");
 
502
                     }
 
503
                     printed++;
 
504
   
 
505
                     if ( printed % 8 == 0) {
 
506
                        printf(" ");
 
507
                     }
 
508
                  }
 
509
                  printf("\n");
 
510
               }
 
511
            }
 
512
   
 
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) {
 
517
                  sge_pack_buffer buf;
 
518
   
 
519
                  if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
 
520
                     sge_gdi_packet_class_t *packet = NULL;
 
521
               
 
522
                     if (sge_gdi_packet_unpack(&packet, NULL, &buf)) {
 
523
                        sge_gdi_task_class_t *task = NULL;
 
524
 
 
525
                        printf("      unpacked gdi request (binary buffer length %lu):\n", buffer_length );
 
526
 
 
527
                        printf("         packet:\n");
 
528
 
 
529
                        if (packet->id) {
 
530
                           printf("id   : "sge_U32CFormat"\n", sge_u32c(packet->id));
 
531
                        } else {
 
532
                           printf("id   : %s\n", "NULL");
 
533
                        } 
 
534
                        if (packet->host) {
 
535
                           printf("host   : %s\n", packet->host);
 
536
                        } else {
 
537
                           printf("host   : %s\n", "NULL");
 
538
                        }
 
539
                        if (packet->commproc) {
 
540
                           printf("commproc   : %s\n", packet->commproc);
 
541
                        } else {
 
542
                           printf("commproc   : %s\n", "NULL");
 
543
                        }
 
544
                        if (packet->version) {
 
545
                           printf("version   : "sge_U32CFormat"\n", sge_u32c(packet->version));
 
546
                        } else {
 
547
                           printf("version   : %s\n", "NULL");
 
548
                        }
 
549
                        if (packet->auth_info) {
 
550
                           printf("auth_info   : %s\n", packet->auth_info);
 
551
                        } else {
 
552
                           printf("auth_info   : %s\n", "NULL");
 
553
                        }
 
554
                        task = packet->first_task;
 
555
                        while (task != NULL) {
 
556
                           printf("         task:\n");
 
557
 
 
558
                           if (task->command) {
 
559
                              printf("op     : "sge_U32CFormat"\n", sge_u32c(task->command));
 
560
                           } else {
 
561
                              printf("op     : %s\n", "NULL");
 
562
                           }
 
563
                           if (task->target) {
 
564
                              printf("target : "sge_U32CFormat"\n", sge_u32c(task->target));
 
565
                           } else {
 
566
                              printf("target : %s\n", "NULL");
 
567
                           }
 
568
   
 
569
                           if (task->data_list) {
 
570
                              lWriteListTo(task->data_list,stdout); 
 
571
                           } else {
 
572
                              printf("lp   : %s\n", "NULL");
 
573
   
 
574
                           }
 
575
                           if (task->answer_list) {
 
576
                              lWriteListTo(task->answer_list,stdout); 
 
577
                           } else {
 
578
                              printf("alp   : %s\n", "NULL");
 
579
                           }
 
580
   
 
581
                           if (task->condition) {
 
582
                              lWriteWhereTo(task->condition,stdout); 
 
583
                           } else {
 
584
                              printf("cp   : %s\n", "NULL");
 
585
                           }
 
586
                           if (task->enumeration) {
 
587
                              lWriteWhatTo(task->enumeration,stdout); 
 
588
                           } else {
 
589
                              printf("enp   : %s\n", "NULL");
 
590
                           }
 
591
                           if (task->id) {
 
592
                              printf("id     : "sge_U32CFormat"\n", sge_u32c(task->id));
 
593
                           } else {
 
594
                              printf("id    : %s\n", "NULL");
 
595
                           }
 
596
   
 
597
                           task = task->next;
 
598
                        }
 
599
                     }
 
600
 
 
601
                     sge_gdi_packet_free(&packet);
 
602
                     clear_packbuffer(&buf);
 
603
                  }
 
604
               }
 
605
   
 
606
            }
 
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) {
 
610
                  sge_pack_buffer buf;
 
611
   
 
612
                  if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
 
613
                     lList *rep = NULL;
 
614
   
 
615
                     if (cull_unpack_list(&buf, &rep) == 0) {
 
616
                        printf("      unpacked report request (binary buffer length %lu):\n", buffer_length );
 
617
                        if (rep) {
 
618
                           lWriteListTo(rep,stdout); 
 
619
                        } else {
 
620
                           printf("rep: NULL\n");
 
621
                        }
 
622
                     }
 
623
                     lFreeList(&rep);
 
624
                     rep = NULL;
 
625
                     clear_packbuffer(&buf);
 
626
                  }
 
627
               }
 
628
            }
 
629
   
 
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) {
 
633
                  sge_pack_buffer buf;
 
634
   
 
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));
 
640
                     }
 
641
                     clear_packbuffer(&buf);
 
642
                  }
 
643
               }
 
644
            }
 
645
   
 
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) {
 
649
                  sge_pack_buffer buf;
 
650
   
 
651
                  if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
 
652
                     lListElem *ack;
 
653
 
 
654
                     while (pb_unused(&buf) > 0) {
 
655
                        if (cull_unpack_elem(&buf, &ack, NULL)) {
 
656
                           printf("TAG_ACK_REQUEST: unpack error\n");
 
657
                        } else {
 
658
                           lWriteElemTo(ack ,stdout); /* ack */
 
659
                        }
 
660
                     }
 
661
 
 
662
                     clear_packbuffer(&buf);
 
663
                  }
 
664
               }
 
665
            }
 
666
   
 
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) {
 
671
                  sge_pack_buffer buf;
 
672
   
 
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));
 
679
                     }
 
680
                     if (cull_unpack_elem(&buf, &job, NULL) == PACK_SUCCESS) {
 
681
                        lWriteElemTo(job,stdout); /* job */
 
682
                     } else {
 
683
                        printf("could not unpack job\n");
 
684
                     }
 
685
                     lFreeElem(&job);
 
686
                     clear_packbuffer(&buf);
 
687
                  }
 
688
               }
 
689
            }
 
690
   
 
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) {
 
694
                  sge_pack_buffer buf;
 
695
   
 
696
                  if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
 
697
                     u_long32 jobid    = 0;
 
698
                     u_long32 job_signal   = 0;
 
699
                     u_long32 jataskid = 0;
 
700
                     char *qname       = NULL;
 
701
   
 
702
                     if (unpackint(&buf, &jobid) == PACK_SUCCESS) {
 
703
                        printf("jobid (JB_job_number):    "sge_U32CFormat"\n", sge_u32c(jobid));
 
704
                     }
 
705
                     if (unpackint(&buf, &jataskid) == PACK_SUCCESS) {
 
706
                        printf("jataskid (JAT_task_number): "sge_U32CFormat"\n", sge_u32c(jataskid));
 
707
                     }
 
708
                     if (unpackstr(&buf, &qname) == PACK_SUCCESS) {
 
709
                        if (qname != NULL) {
 
710
                           printf("qname(QU_full_name):    \"%s\"\n", qname);
 
711
                        } else {
 
712
                           printf("qping: qname(QU_full_name) is NULL !!!!\n");
 
713
                        }
 
714
                     }
 
715
   
 
716
                     if (unpackint(&buf, &job_signal) == PACK_SUCCESS) {
 
717
                        printf("signal:   "sge_U32CFormat" (%s)\n", sge_u32c(job_signal), sge_sig2str(job_signal));
 
718
                     }
 
719
   
 
720
                     if (qname) {
 
721
                        free(qname);
 
722
                     }
 
723
                     clear_packbuffer(&buf);
 
724
                  }
 
725
               }
 
726
            }
 
727
            
 
728
   
 
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) {
 
732
                  sge_pack_buffer buf;
 
733
   
 
734
                  printf("binary buffer length is %lu\n",buffer_length);  
 
735
   
 
736
                  if (init_packbuffer_from_buffer(&buf, (char*)binary_buffer, buffer_length) == PACK_SUCCESS) {
 
737
                     u_long32 jobid    = 0;
 
738
                     u_long32 queue_signal   = 0;
 
739
                     u_long32 jataskid = 0;
 
740
                     char *qname       = NULL;
 
741
   
 
742
                     if (unpackint(&buf, &jobid) == PACK_SUCCESS) {
 
743
                        printf("jobid (0 - unused):    "sge_U32CFormat"\n", sge_u32c(jobid));
 
744
                     }
 
745
                     if (unpackint(&buf, &jataskid) == PACK_SUCCESS) {
 
746
                        printf("jataskid (0 - unused): "sge_U32CFormat"\n", sge_u32c(jataskid));
 
747
                     }
 
748
                     if (unpackstr(&buf, &qname) == PACK_SUCCESS) {
 
749
                        if (qname != NULL) {
 
750
                           printf("qname(QU_full_name):    \"%s\"\n", qname);
 
751
                        } else {
 
752
                           printf("qping: qname(QU_full_name) is NULL !!!!\n");
 
753
                        }
 
754
                     }
 
755
                     if (unpackint(&buf, &queue_signal) == PACK_SUCCESS) {
 
756
                        printf("signal:   "sge_U32CFormat" (%s)\n", sge_u32c(queue_signal), sge_sig2str(queue_signal));
 
757
                     }
 
758
   
 
759
                     if (qname) {
 
760
                        free(qname);
 
761
                     }
 
762
                     clear_packbuffer(&buf);
 
763
                  }
 
764
               }
 
765
            }
 
766
   
 
767
            
 
768
            
 
769
   #if 0
 
770
         CR: 
 
771
   
 
772
         qping TODO:
 
773
    
 
774
         a) Add a option do ignore hosts/components
 
775
   
 
776
         b) Following Tags are not unpacked
 
777
         case TAG_SLAVE_ALLOW
 
778
         case TAG_CHANGE_TICKET
 
779
         case TAG_SIGJOB
 
780
         case TAG_SIGQUEUE
 
781
         case TAG_KILL_EXECD
 
782
         case TAG_NEW_FEATURES
 
783
         case TAG_GET_NEW_CONF
 
784
         case TAG_FULL_LOAD_REPORT
 
785
         ...
 
786
         are missing !!!
 
787
   #endif
 
788
   
 
789
            printf("%s", bin_end);
 
790
            for(i=strlen(bin_end);i<full_width;i++) {
 
791
               printf("-");
 
792
            }
 
793
            printf("\n");
 
794
   
 
795
   
 
796
         } else {
 
797
            int spaces = 1;
 
798
            int new_line = -1;
 
799
            int x;
 
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++) {
 
805
               printf("-");
 
806
            }
 
807
            printf("\n");
 
808
   
 
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) {
 
812
                     printf("\n");
 
813
                     spaces++;
 
814
                  }
 
815
                  new_line = 1;
 
816
               }
 
817
               if (message_debug_data[i] == '<' && message_debug_data[i+1] == '/' && spaces == 1) {
 
818
                  new_line = 1;
 
819
                  printf("\n");
 
820
               }
 
821
   
 
822
               if (new_line == 1) {
 
823
                  for(x=0;x<spaces;x++) {
 
824
                     printf("   ");
 
825
                  }
 
826
                  new_line = 0;
 
827
               }
 
828
               printf("%c", message_debug_data[i]);
 
829
               if (message_debug_data[i] == '<' && message_debug_data[i+1] == '/') {
 
830
                  spaces--;
 
831
               }
 
832
   
 
833
            }
 
834
            
 
835
            printf("\n%s", xml_end);
 
836
            for(i=strlen(xml_end);i<full_width;i++) {
 
837
               printf("-");
 
838
            }
 
839
            printf("\n");
 
840
         }
 
841
      }
 
842
      sge_free_saved_vars(context);
 
843
      return;
 
844
   }  /* end of CL_DMT_MESSAGE tag */
 
845
 
 
846
   if (debug_tag == CL_DMT_APP_MESSAGE && (dump_tag == 1 || dump_tag == 2)) {
 
847
      qping_convert_time(cl_values[0], time, CL_TRUE);
 
848
      
 
849
      if (nonewline != 0) {
 
850
#if 0
 
851
         char* app_start = "--- APPLICATION debug block start ";
 
852
         char* app_end   = "--- APPLICATION debug block end ";
 
853
#endif
 
854
         
 
855
         printf("--- APP: %s: %s\n", time, cl_values[1]);
 
856
      }
 
857
      sge_free_saved_vars(context);
 
858
      return;
 
859
   }
 
860
   sge_free_saved_vars(context);
 
861
   return;
 
862
}
 
863
 
 
864
 
 
865
static void usage(void)
 
866
{
 
867
  int max_name_length = 0;
 
868
  int i=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");
 
902
 
 
903
  
 
904
  qping_parse_environment();
 
905
 
 
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]);
 
909
      }
 
910
  }
 
911
 
 
912
  for(i=0;i<ARGUMENT_COUNT;i++) {
 
913
     char* visible="yes";
 
914
     if (cl_show[i] == 0) {
 
915
        visible="no";
 
916
     }
 
917
     if (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");
 
924
     }
 
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] );
 
928
  }
 
929
  exit(1);
 
930
}
 
931
 
 
932
 
 
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";
 
942
#ifdef SECURE
 
943
   int   got_no_framework  = 0;
 
944
#endif
 
945
 
 
946
   int   parameter_start   = 1;
 
947
   int   comp_id           = -1;
 
948
   int   comp_port         = -1;
 
949
   int   interval          = 1;
 
950
   int   dump_tag          = 0;
 
951
   int   i                 = 0;
 
952
   int   exit_value        = 0;
 
953
   int   retval            = CL_RETVAL_OK;
 
954
   struct sigaction sa;
 
955
   int   option_f          = 0;
 
956
   int   option_info       = 0;
 
957
   int   option_noalias    = 0;
 
958
   int   option_ssl        = 0;
 
959
   int   option_tcp        = 0;
 
960
   int   option_dump       = 0;
 
961
   int   option_nonewline  = 1;
 
962
   int   option_debuglevel = 0;
 
963
   int   parameter_count   = 4;
 
964
   int   commlib_error = CL_RETVAL_OK;
 
965
 
 
966
   
 
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);
 
975
 
 
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;
 
981
             i++;
 
982
             if ( argv[i] != NULL) {
 
983
                interval = atoi(argv[i]);
 
984
                if (interval < 1) {
 
985
                   fprintf(stderr, "interval parameter must be larger than 0\n");
 
986
                   exit(1);
 
987
                }
 
988
             } else {
 
989
                fprintf(stderr, "no interval parameter value\n");
 
990
                exit(1);
 
991
             }
 
992
         }
 
993
         if (strcmp( argv[i] , "-info") == 0) {
 
994
             option_info = 1;
 
995
             parameter_count++;
 
996
             parameter_start++;
 
997
         }
 
998
         if (strcmp( argv[i] , "-f") == 0) {
 
999
             option_f = 1;
 
1000
             parameter_count++;
 
1001
             parameter_start++;
 
1002
         }
 
1003
         if (strcmp( argv[i] , "-noalias") == 0) {
 
1004
             option_noalias = 1;
 
1005
             parameter_count++;
 
1006
             parameter_start++;
 
1007
         }
 
1008
         if (strcmp( argv[i] , "-tcp") == 0) {
 
1009
             option_tcp = 1;
 
1010
             parameter_count++;
 
1011
             parameter_start++;
 
1012
         }
 
1013
         if (strcmp( argv[i] , "-ssl") == 0) {
 
1014
             option_ssl = 1;
 
1015
             parameter_count++;
 
1016
             parameter_start++;
 
1017
         }
 
1018
         if (strcmp( argv[i] , "-dump") == 0) {
 
1019
             option_dump = 1;
 
1020
             dump_tag = 3;
 
1021
             parameter_count++;
 
1022
             parameter_start++;
 
1023
         }
 
1024
         if (strcmp( argv[i] , "-dump_tag") == 0) {
 
1025
             option_dump = 1;
 
1026
             parameter_count += 2;
 
1027
             parameter_start += 2;
 
1028
             i++;
 
1029
             if ( argv[i] != NULL) {
 
1030
                if (strcmp(argv[i],"ALL") == 0) {
 
1031
                   dump_tag = 1;
 
1032
                   parameter_count++;
 
1033
                   parameter_start++;
 
1034
                   i++;
 
1035
                   if (argv[i] != NULL) {
 
1036
                      if (strcmp(argv[i],"ERROR") == 0) {
 
1037
                         option_debuglevel = 1;
 
1038
                      }
 
1039
                      if (strcmp(argv[i],"WARNING") == 0) {
 
1040
                         option_debuglevel = 2;
 
1041
                      }
 
1042
                      if (strcmp(argv[i],"INFO") == 0) {
 
1043
                         option_debuglevel = 3;
 
1044
                      }
 
1045
                      if (strcmp(argv[i],"DEBUG") == 0) {
 
1046
                         option_debuglevel = 4;
 
1047
                      }
 
1048
                      if (strcmp(argv[i],"DPRINTF") == 0) {
 
1049
                         option_debuglevel = 5;
 
1050
                      }
 
1051
                      if (option_debuglevel == 0) {
 
1052
                         fprintf(stderr, "unexpected debug level\n");
 
1053
                         exit(1);
 
1054
                      }
 
1055
                   }
 
1056
                }
 
1057
                if (strcmp(argv[i],"APP") == 0) {
 
1058
                   dump_tag = 2;
 
1059
                   parameter_count++;
 
1060
                   parameter_start++;
 
1061
                   i++;
 
1062
                   if (argv[i] != NULL) {
 
1063
                      if (strcmp(argv[i],"ERROR") == 0) {
 
1064
                         option_debuglevel = 1;
 
1065
                      }
 
1066
                      if (strcmp(argv[i],"WARNING") == 0) {
 
1067
                         option_debuglevel = 2;
 
1068
                      }
 
1069
                      if (strcmp(argv[i],"INFO") == 0) {
 
1070
                         option_debuglevel = 3;
 
1071
                      }
 
1072
                      if (strcmp(argv[i],"DEBUG") == 0) {
 
1073
                         option_debuglevel = 4;
 
1074
                      }
 
1075
                      if (strcmp(argv[i],"DPRINTF") == 0) {
 
1076
                         option_debuglevel = 5;
 
1077
                      }
 
1078
                      if (option_debuglevel == 0) {
 
1079
                         fprintf(stderr, "unexpected debug level\n");
 
1080
                         exit(1);
 
1081
                      }
 
1082
                   }
 
1083
                }
 
1084
                if (strcmp(argv[i],"MSG") == 0) {
 
1085
                   dump_tag = 3;
 
1086
                }
 
1087
                if (dump_tag == 0) {
 
1088
                   fprintf(stderr, "unexpected dump tag\n");
 
1089
                   exit(1);
 
1090
                }
 
1091
             } else {
 
1092
                fprintf(stderr, "no -dump_tag parameter value\n");
 
1093
                exit(1);
 
1094
             }
 
1095
         }
 
1096
         
 
1097
 
 
1098
         if (strcmp( argv[i] , "-nonewline") == 0) {
 
1099
             option_nonewline = 0;
 
1100
             parameter_count++;
 
1101
             parameter_start++;
 
1102
         }
 
1103
 
 
1104
         if (strcmp( argv[i] , "-help") == 0) {
 
1105
             usage();
 
1106
         }
 
1107
      } else {
 
1108
         break;
 
1109
      }
 
1110
   }
 
1111
 
 
1112
   if (argc != parameter_count + 1 ) {
 
1113
      usage();
 
1114
   }
 
1115
 
 
1116
   comp_host = argv[parameter_start];
 
1117
   if (argv[parameter_start + 1] != NULL) {
 
1118
      comp_port = atoi(argv[parameter_start + 1]);
 
1119
   }
 
1120
   comp_name = argv[parameter_start + 2];
 
1121
   if (argv[parameter_start + 3] != NULL) {
 
1122
      comp_id   = atoi(argv[parameter_start + 3]);
 
1123
   }
 
1124
 
 
1125
   if ( comp_host == NULL  ) {
 
1126
      fprintf(stderr,"please enter a host name\n");
 
1127
      exit(1);
 
1128
   }
 
1129
 
 
1130
   if ( comp_name == NULL  ) {
 
1131
      fprintf(stderr,"please enter a component name\n");
 
1132
      exit(1);
 
1133
   }
 
1134
   if ( comp_port < 0  ) {
 
1135
      fprintf(stderr,"please enter a correct port number\n");
 
1136
      exit(1);
 
1137
   }
 
1138
   if ( comp_id <= 0 ) {
 
1139
      fprintf(stderr,"please enter a component id larger than 0\n");
 
1140
      exit(1);
 
1141
   }
 
1142
 
 
1143
   prof_mt_init();
 
1144
   
 
1145
   uidgid_mt_init();
 
1146
   path_mt_init();
 
1147
 
 
1148
   bootstrap_mt_init(); 
 
1149
   feature_mt_init();
 
1150
 
 
1151
   gdi_mt_init();
 
1152
 
 
1153
   sge_getme(QPING);
 
1154
 
 
1155
   lInit(nmv);
 
1156
 
 
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));
 
1160
      exit(1);
 
1161
   }
 
1162
 
 
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));
 
1166
   }
 
1167
 
 
1168
 
 
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));
 
1176
         }
 
1177
         FREE(alias_path);
 
1178
      }
 
1179
   }
 
1180
 
 
1181
   if ( option_ssl != 0 && option_tcp != 0) {
 
1182
      fprintf(stderr,"using of option -ssl and option -tcp not supported\n");
 
1183
      exit(1);
 
1184
   }
 
1185
   
 
1186
 
 
1187
   /* find out the framework type to use */
 
1188
   if ( option_ssl == 0 && option_tcp == 0 ) {
 
1189
      char buffer[2*1024];
 
1190
      dstring bw;
 
1191
      sge_dstring_init(&bw, buffer, sizeof(buffer)); 
 
1192
 
 
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");
 
1196
         exit(1);
 
1197
      }
 
1198
#ifdef SECURE
 
1199
      got_no_framework = 1;
 
1200
#endif
 
1201
      if ( strcmp( "csp", bootstrap_get_security_mode()) == 0) {
 
1202
         option_ssl = 1;
 
1203
      } else {
 
1204
         option_tcp = 1;
 
1205
      }
 
1206
   }
 
1207
 
 
1208
   if (option_ssl != 0) {
 
1209
      communication_framework = CL_CT_SSL;
 
1210
#ifdef SECURE
 
1211
      if (got_no_framework == 1) {
 
1212
         /* we got no framework and we have a bootstrap file */
 
1213
         sge_getme(QPING);
 
1214
         sge_ssl_setup_security_path("qping", uti_state_get_user_name());
 
1215
      } else {
 
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");
 
1223
            exit(1);
 
1224
         } else {
 
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);
 
1238
         }
 
1239
      }
 
1240
#endif
 
1241
   }
 
1242
   if (option_tcp != 0) {
 
1243
      communication_framework = CL_CT_TCP;
 
1244
   }
 
1245
 
 
1246
   if (option_dump != 0) {
 
1247
      connect_type = CL_TCP_RESERVED_PORT;
 
1248
      connection_type = CL_CM_CT_STREAM;
 
1249
      client_name  = "debug_client";
 
1250
   }
 
1251
 
 
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));
 
1255
   }
 
1256
 
 
1257
 
 
1258
   handle=cl_com_create_handle(&commlib_error, communication_framework, connection_type, CL_FALSE, comp_port, connect_type, client_name, 0, 1,0 );
 
1259
 
 
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();
 
1263
      exit(1);
 
1264
   }
 
1265
 
 
1266
   if (option_dump == 0) {
 
1267
      /* enable auto close of application */
 
1268
      cl_com_set_auto_close_mode(handle, CL_CM_AC_ENABLED );
 
1269
   }
 
1270
 
 
1271
 
 
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();
 
1276
      exit(1);
 
1277
   }
 
1278
 
 
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) );  
 
1287
            exit_value = 1;
 
1288
         } else {
 
1289
            if (status != NULL) {
 
1290
               char buffer[512];
 
1291
               dstring ds;
 
1292
               sge_dstring_init(&ds, buffer, sizeof(buffer));
 
1293
   
 
1294
               printf("%s", sge_ctime(0, &ds));
 
1295
   
 
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,
 
1299
                         status->runtime);  
 
1300
               } else {
 
1301
                  time_t starttime;
 
1302
                  starttime = (time_t)status->starttime;
 
1303
                  
 
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 );
 
1313
                  printf("\n");
 
1314
               }
 
1315
            } else {
 
1316
               printf("unexpected error\n");
 
1317
            }
 
1318
         }
 
1319
   
 
1320
         cl_com_free_sirm_message(&status);
 
1321
   
 
1322
         if (option_info != 0) {
 
1323
            break;
 
1324
         }
 
1325
         sleep(interval);
 
1326
      }
 
1327
   } else {
 
1328
      dstring line_buffer = DSTRING_INIT;
 
1329
 
 
1330
      qping_parse_environment();
 
1331
 
 
1332
      while (do_shutdown == 0 ) {
 
1333
         int                retval  = 0;
 
1334
#if 0
 
1335
         static int stop_running = 15;
 
1336
#endif
 
1337
         cl_com_message_t*  message = NULL;
 
1338
         cl_com_endpoint_t* sender  = NULL;
 
1339
 
 
1340
#if 0
 
1341
         if (stop_running-- == 0) {
 
1342
            do_shutdown = 1;
 
1343
         }
 
1344
#endif
 
1345
 
 
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 );
 
1350
         
 
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");
 
1360
                   break;       
 
1361
                }
 
1362
 
 
1363
 
 
1364
                /*
 
1365
                 * set message tag we want to receive from endpoint 
 
1366
                 */
 
1367
                switch(dump_tag) {
 
1368
                   case 1: {
 
1369
                      snprintf(command_buffer,256,"set tag ALL");
 
1370
                      break;
 
1371
                   }
 
1372
                   case 2: {
 
1373
                      snprintf(command_buffer,256,"set tag APP");
 
1374
                      break;
 
1375
                   }
 
1376
                   case 3: {
 
1377
                      snprintf(command_buffer,256,"set tag MSG");
 
1378
                      break;
 
1379
                   }
 
1380
                }
 
1381
                cl_commlib_send_message(handle,
 
1382
                                    resolved_comp_host, comp_name, comp_id,
 
1383
                                    CL_MIH_MAT_NAK, 
 
1384
                                    &reference, strlen(command_buffer)+1, 
 
1385
                                    NULL, 0, 0, CL_TRUE, CL_FALSE);
 
1386
 
 
1387
                /*
 
1388
                 * set if we want the message dump 
 
1389
                 */
 
1390
 
 
1391
                if (cl_show[11] != 0) {
 
1392
                   snprintf(command_buffer,256,"set dump ON");
 
1393
                } else {
 
1394
                   snprintf(command_buffer,256,"set dump OFF");
 
1395
                }
 
1396
                cl_commlib_send_message(handle,
 
1397
                                    resolved_comp_host, comp_name, comp_id,
 
1398
                                    CL_MIH_MAT_NAK, 
 
1399
                                    &reference, strlen(command_buffer)+1, 
 
1400
                                    NULL, 0, 0, CL_TRUE, CL_FALSE);
 
1401
 
 
1402
                            
 
1403
                /*
 
1404
                 * set debug level 
 
1405
                 */
 
1406
                switch(option_debuglevel) {
 
1407
                   case 1: {
 
1408
                      snprintf(command_buffer,256,"set debug ERROR");
 
1409
                      break;
 
1410
                   }
 
1411
                   case 2: {
 
1412
                      snprintf(command_buffer,256,"set debug WARNING");
 
1413
                      break;
 
1414
                   }
 
1415
                   case 3: {
 
1416
                      snprintf(command_buffer,256,"set debug INFO");
 
1417
                      break;
 
1418
                   }
 
1419
                   case 4: {
 
1420
                      snprintf(command_buffer,256,"set debug DEBUG");
 
1421
                      break;
 
1422
                   }
 
1423
                   case 5: {
 
1424
                      snprintf(command_buffer,256,"set debug DPRINTF");
 
1425
                      break;
 
1426
                   }
 
1427
                   default: {
 
1428
                      snprintf(command_buffer,256,"set debug OFF");
 
1429
                      break;
 
1430
                   }
 
1431
                }
 
1432
 
 
1433
                cl_commlib_send_message(handle,
 
1434
                                    resolved_comp_host, comp_name, comp_id,
 
1435
                                    CL_MIH_MAT_NAK, 
 
1436
                                    &reference, strlen(command_buffer)+1, 
 
1437
                                    NULL, 0, 0, CL_TRUE, CL_FALSE);
 
1438
            }
 
1439
         } else {
 
1440
            int i;
 
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);
 
1446
               }
 
1447
            }
 
1448
            fflush(stdout);
 
1449
            cl_com_free_message(&message);
 
1450
            cl_com_free_endpoint(&sender);
 
1451
         }
 
1452
      }
 
1453
      sge_dstring_free(&line_buffer);
 
1454
   }
 
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();
 
1461
      exit(1);
 
1462
   }
 
1463
 
 
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;
 
1469
      exit(1);
 
1470
   }
 
1471
   free(resolved_comp_host);
 
1472
   resolved_comp_host = NULL;
 
1473
   
 
1474
   sge_prof_cleanup();
 
1475
   return exit_value;  
 
1476
}