1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
|
/*
* Copyright 1999-2010 University of Chicago
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file globus_gram_streamer.c
* @brief GRAM File Streamer Application
*
* @details
* The globus-gram-streamer program provides support for live file
* streaming of stdout and stderr. It is intended to be run by the fork
* job management module for cases where output streaming is required during
* the execution of the job. It is started as an additional process by
* the fork module and its pid is included along with the other pids that
* must be monitored for the job to be complete.
*/
#include "globus_common.h"
#include "globus_gass_transfer.h"
#include "globus_gram_job_manager.h"
#include "globus_symboltable.h"
#include <sys/wait.h>
enum { STREAMER_MAX = 256 };
const off_t STREAMER_BLOCKSIZE = 4096;
typedef enum
{
GLOBUS_GRAM_STREAM_NONE,
GLOBUS_GRAM_STREAM_NEW,
GLOBUS_GRAM_STREAM_ACTIVE,
GLOBUS_GRAM_STREAM_RESTART,
GLOBUS_GRAM_STREAM_RESTART_NEW,
GLOBUS_GRAM_STREAM_FAIL,
GLOBUS_GRAM_STREAM_DONE
}
globus_gram_stream_state_t;
typedef struct
{
int fd;
off_t sent;
char * source;
char * destination;
globus_gass_transfer_request_t handle;
globus_gram_stream_state_t state;
int blocks;
int last_sent;
}
globus_gram_stream_t;
typedef struct
{
globus_mutex_t mutex;
globus_cond_t cond;
globus_gram_jobmanager_request_t request;
globus_callback_handle_t local_poll_periodic;
time_t remote_io_url_file_time;
globus_gram_stream_t output_stream;
globus_gram_stream_t error_stream;
globus_callback_handle_t waitpids_poll_periodic;
pid_t pids[STREAMER_MAX];
int pid_count;
}
globus_gram_streamer_monitor_t;
static
void
globus_l_gram_streamer_request_ready(
void * arg,
globus_gass_transfer_request_t request);
static
void
globus_l_gram_streamer_local_poll(
void * arg);
static
int
globus_l_gram_streamer_get_destinations(
globus_gram_streamer_monitor_t * monitor);
static
int
globus_l_gram_streamer_open_destination(
globus_gram_streamer_monitor_t * monitor,
globus_gram_stream_t * stream);
static
void
globus_l_gram_streamer_waitpids(
void * arg);
int
main(
int argc,
char ** argv)
{
int opt;
globus_gram_streamer_monitor_t monitor;
int rc;
char local_path[16];
globus_result_t result;
globus_reltime_t period;
globus_module_descriptor_t * modules[] =
{
GLOBUS_COMMON_MODULE,
GLOBUS_GASS_TRANSFER_MODULE,
NULL
};
globus_module_descriptor_t * failed_module;
memset(&monitor, 0, sizeof(globus_gram_streamer_monitor_t));
globus_mutex_init(&monitor.request.mutex, NULL);
globus_cond_init(&monitor.request.cond, NULL);
while ((opt = getopt(argc, argv, "s:p:d:h")) != -1)
{
switch (opt)
{
case 's':
monitor.request.job_state_file = optarg;
/*
* Assume that the remote I/O file will not be newer than the
* current time
*/
monitor.remote_io_url_file_time = time(NULL);
rc = globus_gram_job_manager_state_file_read(&monitor.request);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Error reading state file %s\n",
rc, optarg);
}
break;
case 'p':
if ((monitor.pid_count+1) == STREAMER_MAX)
{
fprintf(stderr, "%d:Too many pids for streamer\n",
GLOBUS_GRAM_PROTOCOL_ERROR_NO_RESOURCES);
exit(EXIT_FAILURE);
}
monitor.pids[monitor.pid_count++] =
(pid_t) strtol(optarg, NULL, 10);
break;
case 'd':
rc = chdir(optarg);
if (rc != 0)
{
int save_errno = errno;
fprintf(stderr,
"%d:Error accessing job state directory: %s (%d)\n",
GLOBUS_GRAM_PROTOCOL_ERROR_BAD_DIRECTORY,
strerror(save_errno),
save_errno);
exit(EXIT_FAILURE);
}
break;
case 'h':
printf("Usage: %s -s STATE-FILE -p pid [-p pid]...\n", argv[0]);
exit(EXIT_SUCCESS);
break;
case '?':
default:
fprintf(stderr, "%d:Unknown option: %c\n",
GLOBUS_GRAM_PROTOCOL_ERROR_GATEKEEPER_MISCONFIGURED,
(char) opt);
exit(EXIT_FAILURE);
}
}
rc = globus_module_activate_array(modules, &failed_module);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Activation failed: %s %d\n",
GLOBUS_GRAM_PROTOCOL_ERROR_GATEKEEPER_MISCONFIGURED,
failed_module->module_name,
rc);
exit(EXIT_FAILURE);
}
strcpy(local_path, "stdout");
monitor.output_stream.fd = open(local_path, O_RDONLY);
strcpy(local_path, "stderr");
monitor.error_stream.fd = open(local_path, O_RDONLY);
rc = globus_mutex_init(&monitor.mutex, NULL);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Mutex init failed\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED);
exit(EXIT_FAILURE);
}
rc = globus_cond_init(&monitor.cond, NULL);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Mutex init failed\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED);
exit(EXIT_FAILURE);
}
globus_mutex_lock(&monitor.mutex);
GlobusTimeReltimeSet(period, 5, 0);
result = globus_callback_register_periodic(
&monitor.local_poll_periodic,
&globus_i_reltime_zero,
&period,
globus_l_gram_streamer_local_poll,
&monitor);
if (result != GLOBUS_SUCCESS)
{
char * errstr = globus_error_print_friendly(globus_error_peek(result));
fprintf(stderr, "%d:Initialization error: %s\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED,
errstr);
free(errstr);
exit(EXIT_FAILURE);
}
result = globus_callback_register_periodic(
&monitor.waitpids_poll_periodic,
&globus_i_reltime_zero,
&period,
globus_l_gram_streamer_waitpids,
&monitor);
if (result != GLOBUS_SUCCESS)
{
char * errstr = globus_error_print_friendly(globus_error_peek(result));
fprintf(stderr, "%d:Initialization error: %s\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED,
errstr);
free(errstr);
exit(EXIT_FAILURE);
}
rc = globus_l_gram_streamer_get_destinations(
&monitor);
if (rc != GLOBUS_SUCCESS)
{
exit(EXIT_FAILURE);
}
if (monitor.output_stream.fd != -1 &&
monitor.output_stream.destination != NULL)
{
rc = globus_l_gram_streamer_open_destination(
&monitor,
&monitor.output_stream);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Error opening stdout destination %s (%d)\n",
GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT,
monitor.output_stream.destination,
rc);
exit(EXIT_FAILURE);
}
monitor.output_stream.state = GLOBUS_GRAM_STREAM_NEW;
}
else
{
monitor.output_stream.state = GLOBUS_GRAM_STREAM_NONE;
}
if (monitor.error_stream.fd != -1 &&
monitor.error_stream.destination != NULL)
{
rc = globus_l_gram_streamer_open_destination(
&monitor,
&monitor.error_stream);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:Error opening stderr destination %s (%d)\n",
GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDERR,
monitor.error_stream.destination,
rc);
exit(EXIT_FAILURE);
}
monitor.error_stream.state = GLOBUS_GRAM_STREAM_NEW;
}
else
{
monitor.error_stream.state = GLOBUS_GRAM_STREAM_NONE;
}
while (monitor.pid_count > 0 ||
(monitor.output_stream.state != GLOBUS_GRAM_STREAM_NONE &&
monitor.output_stream.state != GLOBUS_GRAM_STREAM_DONE &&
monitor.output_stream.state != GLOBUS_GRAM_STREAM_FAIL) ||
(monitor.error_stream.state != GLOBUS_GRAM_STREAM_NONE &&
monitor.error_stream.state != GLOBUS_GRAM_STREAM_DONE &&
monitor.error_stream.state != GLOBUS_GRAM_STREAM_FAIL))
{
globus_cond_wait(&monitor.cond, &monitor.mutex);
}
if (monitor.output_stream.state == GLOBUS_GRAM_STREAM_DONE)
{
printf("%s %s\n",
monitor.output_stream.source,
monitor.output_stream.destination);
}
if (monitor.error_stream.state == GLOBUS_GRAM_STREAM_DONE)
{
printf("%s %s\n",
monitor.error_stream.source,
monitor.error_stream.destination);
}
globus_mutex_unlock(&monitor.mutex);
globus_module_deactivate(GLOBUS_GASS_TRANSFER_MODULE);
globus_module_activate(GLOBUS_COMMON_MODULE);
exit(EXIT_SUCCESS);
}
/* main() */
static
void
globus_l_gram_streamer_request_ready(
void * arg,
globus_gass_transfer_request_t request)
{
globus_gram_streamer_monitor_t * monitor = arg;
globus_gram_stream_t * stream;
globus_gass_transfer_request_status_t
status;
globus_mutex_lock(&monitor->mutex);
stream = globus_gass_transfer_request_get_user_pointer(request);
status = globus_gass_transfer_request_get_status(request);
switch (status)
{
case GLOBUS_GASS_TRANSFER_REQUEST_INVALID:
case GLOBUS_GASS_TRANSFER_REQUEST_STARTING:
globus_gass_transfer_request_destroy(request);
stream->state = GLOBUS_GRAM_STREAM_FAIL;
globus_cond_signal(&monitor->cond);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_FAILED:
case GLOBUS_GASS_TRANSFER_REQUEST_DENIED:
globus_gass_transfer_request_destroy(request);
stream->state = GLOBUS_GRAM_STREAM_FAIL;
globus_cond_signal(&monitor->cond);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_REFERRED:
globus_gass_transfer_request_destroy(request);
stream->state = GLOBUS_GRAM_STREAM_DONE;
globus_cond_signal(&monitor->cond);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_DONE:
globus_gass_transfer_request_destroy(request);
stream->state = GLOBUS_GRAM_STREAM_DONE;
globus_cond_signal(&monitor->cond);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_PENDING:
stream->state = GLOBUS_GRAM_STREAM_ACTIVE;
break;
default:
fprintf(stderr, "%d:GASS Transfer returned invalid status: %d\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED,
(int) status);
exit(EXIT_FAILURE);
}
globus_mutex_unlock(&monitor->mutex);
}
static
void
globus_l_gram_streamer_fail(
void * arg,
globus_gass_transfer_request_t request)
{
globus_gram_streamer_monitor_t * monitor = arg;
globus_gram_stream_t * stream;
globus_mutex_lock(&monitor->mutex);
stream = globus_gass_transfer_request_get_user_pointer(request);
stream->state = GLOBUS_GRAM_STREAM_RESTART_NEW;
stream->sent = 0;
stream->last_sent = GLOBUS_FALSE;
lseek(stream->fd, 0, SEEK_SET);
stream->handle = GLOBUS_NULL_HANDLE;
globus_mutex_unlock(&monitor->mutex);
}
/* globus_l_gram_streamer_fail() */
static
void
globus_l_gram_streamer_data_callback(
void * arg,
globus_gass_transfer_request_t request,
globus_byte_t * bytes,
globus_size_t length,
globus_bool_t last_data)
{
globus_gram_streamer_monitor_t * monitor = arg;
globus_gram_stream_t * stream;
globus_gass_transfer_request_status_t
status;
globus_mutex_lock(&monitor->mutex);
stream = globus_gass_transfer_request_get_user_pointer(request);
free(bytes);
stream->blocks--;
status = globus_gass_transfer_request_get_status(request);
if (last_data && stream->blocks == 0)
{
switch (status)
{
case GLOBUS_GASS_TRANSFER_REQUEST_INVALID:
case GLOBUS_GASS_TRANSFER_REQUEST_STARTING:
case GLOBUS_GASS_TRANSFER_REQUEST_FAILED:
case GLOBUS_GASS_TRANSFER_REQUEST_DENIED:
case GLOBUS_GASS_TRANSFER_REQUEST_REFERRED:
globus_gass_transfer_request_destroy(request);
if (stream->state != GLOBUS_GRAM_STREAM_RESTART)
{
stream->state = GLOBUS_GRAM_STREAM_FAIL;
globus_cond_signal(&monitor->cond);
}
break;
case GLOBUS_GASS_TRANSFER_REQUEST_DONE:
globus_gass_transfer_request_destroy(request);
if (stream->state == GLOBUS_GRAM_STREAM_ACTIVE)
{
stream->state = GLOBUS_GRAM_STREAM_DONE;
}
globus_cond_signal(&monitor->cond);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_PENDING:
break;
default:
fprintf(stderr, "%d:GASS Transfer returned invalid status: %d\n",
GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED,
(int) status);
exit(EXIT_FAILURE);
}
}
globus_mutex_unlock(&monitor->mutex);
}
/* globus_l_gram_streamer_data_callback() */
static
void
globus_l_gram_streamer_local_poll(
void * arg)
{
globus_gram_streamer_monitor_t * monitor = arg;
int rc;
struct stat st;
unsigned char * data;
off_t data_size;
globus_size_t amt;
globus_bool_t last_data;
int i;
char * save_state_file;
globus_gram_stream_t * streams[] =
{
&monitor->output_stream,
&monitor->error_stream,
NULL
};
globus_gram_stream_t * stream;
globus_mutex_lock(&monitor->mutex);
/* Check if remote_io_file has changed */
rc = stat("remote_io_file", &st);
if (rc == 0)
{
if (st.st_mtime > monitor->remote_io_url_file_time)
{
/* Start the termination of the current output streams */
for (i = 0; streams[i] != NULL; i++)
{
stream = streams[i];
switch (stream->state)
{
case GLOBUS_GRAM_STREAM_NEW:
case GLOBUS_GRAM_STREAM_ACTIVE:
globus_gass_transfer_fail(
stream->handle,
globus_l_gram_streamer_fail,
monitor);
stream->state = GLOBUS_GRAM_STREAM_RESTART;
break;
case GLOBUS_GRAM_STREAM_FAIL:
case GLOBUS_GRAM_STREAM_DONE:
stream->state = GLOBUS_GRAM_STREAM_RESTART_NEW;
stream->sent = 0;
stream->last_sent = GLOBUS_FALSE;
lseek(stream->fd, 0, SEEK_SET);
stream->handle = GLOBUS_NULL_HANDLE;
break;
case GLOBUS_GRAM_STREAM_RESTART:
case GLOBUS_GRAM_STREAM_RESTART_NEW:
case GLOBUS_GRAM_STREAM_NONE:
break;
}
}
monitor->remote_io_url_file_time = st.st_mtime;
/* Load new state file */
save_state_file = monitor->request.job_state_file;
monitor->request.job_state_file = NULL;
globus_gram_job_manager_request_free(&monitor->request);
monitor->request.rsl = NULL;
monitor->request.job_state_file = save_state_file;
rc = globus_gram_job_manager_state_file_read(&monitor->request);
if (rc != GLOBUS_SUCCESS)
{
fprintf(stderr, "%d:",
rc);
exit(EXIT_FAILURE);
}
if (monitor->output_stream.source != NULL)
{
free(monitor->output_stream.source);
monitor->output_stream.source = NULL;
}
if (monitor->output_stream.destination != NULL)
{
free(monitor->output_stream.destination);
monitor->output_stream.destination = NULL;
}
if (monitor->error_stream.source != NULL)
{
free(monitor->error_stream.source);
monitor->error_stream.source = NULL;
}
if (monitor->error_stream.destination != NULL)
{
free(monitor->error_stream.destination);
monitor->error_stream.destination = NULL;
}
/* Re-evaluate RSL */
rc = globus_l_gram_streamer_get_destinations(
monitor);
}
}
/* On the first poll after everything is ready to restart, we'll reload
* state information and reopen the stream
*/
for (i = 0; streams[i] != NULL; i++)
{
stream = streams[i];
if (stream->state == GLOBUS_GRAM_STREAM_RESTART_NEW)
{
/* Re-open output stream */
if (stream->fd != -1 &&
stream->destination != NULL)
{
rc = globus_l_gram_streamer_open_destination(
monitor,
stream);
if (rc == GLOBUS_SUCCESS)
{
stream->state = GLOBUS_GRAM_STREAM_NEW;
}
else
{
stream->state = GLOBUS_GRAM_STREAM_FAIL;
}
}
else
{
stream->state = GLOBUS_GRAM_STREAM_DONE;
}
}
}
/* Only queue data if the transfer is alive */
for (i = 0; streams[i] != NULL; i++)
{
stream = streams[i];
if (stream->state == GLOBUS_GRAM_STREAM_ACTIVE &&
(fstat(stream->fd, &st) == 0))
{
data_size = st.st_size - stream->sent;
if (data_size > STREAMER_BLOCKSIZE)
{
data_size = STREAMER_BLOCKSIZE;
}
amt = 0;
data = NULL;
if (data_size > 0)
{
data = malloc((size_t) data_size);
do
{
rc = read(stream->fd, data + amt, data_size - amt);
if (rc < 0)
{
if (errno != EINTR)
{
break;
}
}
else if (rc == 0)
{
break;
}
else
{
amt += rc;
}
}
while (amt < data_size);
}
if (amt > 0 || ((monitor->pid_count == 0) && (!stream->last_sent)))
{
stream->sent += amt;
stream->blocks++;
last_data = (monitor->pid_count == 0) &&
(stream->sent == st.st_size);
rc = globus_gass_transfer_send_bytes(
stream->handle,
(data == NULL) ? malloc(1) : data,
amt,
last_data,
globus_l_gram_streamer_data_callback,
monitor);
switch (rc)
{
case GLOBUS_SUCCESS:
stream->last_sent = last_data;
break;
case GLOBUS_GASS_TRANSFER_ERROR_NULL_POINTER:
fprintf(stderr, "NULL pointer");
exit(EXIT_FAILURE);
break;
case GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE:
stream->last_sent = GLOBUS_TRUE;
globus_gass_transfer_request_destroy(stream->handle);
stream->state = GLOBUS_GRAM_STREAM_FAIL;
break;
case GLOBUS_GASS_TRANSFER_ERROR_NOT_INITIALIZED:
fprintf(stderr, "Not initialized");
exit(EXIT_FAILURE);
break;
case GLOBUS_GASS_TRANSFER_REQUEST_FAILED:
fprintf(stderr, "Failed ");
exit(EXIT_FAILURE);
}
}
}
}
globus_mutex_unlock(&monitor->mutex);
}
static
int
globus_l_gram_streamer_get_destinations(
globus_gram_streamer_monitor_t * monitor)
{
globus_list_t * tmp;
globus_gram_job_manager_staging_info_t *
info;
char * s;
tmp = monitor->request.stage_stream_todo;
while (tmp != NULL)
{
info = globus_list_first(tmp);
tmp = globus_list_rest(tmp);
if (monitor->output_stream.destination == NULL)
{
s = strstr(info->evaled_from, "/stdout");
if (s != NULL && strcmp(s, "/stdout") == 0)
{
monitor->output_stream.source = strdup(info->evaled_from);
monitor->output_stream.destination = strdup(info->evaled_to);
continue;
}
}
if (monitor->error_stream.destination == NULL)
{
s = strstr(info->evaled_from, "/stderr");
if (s != NULL && strcmp(s, "/stderr") == 0)
{
monitor->error_stream.source = strdup(info->evaled_from);
monitor->error_stream.destination = strdup(info->evaled_to);
continue;
}
}
}
return 0;
}
static
int
globus_l_gram_streamer_open_destination(
globus_gram_streamer_monitor_t * monitor,
globus_gram_stream_t * stream)
{
globus_gass_transfer_requestattr_t attr;
char scheme[16];
int i;
int rc;
for (i = 0; i < sizeof(scheme); i++)
{
if (stream->destination[i] == ':')
{
scheme[i] = 0;
break;
}
else
{
scheme[i] = stream->destination[i];
}
}
scheme[15] = 0;
rc = globus_gass_transfer_requestattr_init(
&attr,
scheme);
if (rc != GLOBUS_SUCCESS)
{
return rc;
}
rc = globus_gass_transfer_register_append(
&stream->handle,
&attr,
(char *) stream->destination,
GLOBUS_GASS_TRANSFER_LENGTH_UNKNOWN,
globus_l_gram_streamer_request_ready,
monitor);
if (rc == GLOBUS_SUCCESS)
{
(void) globus_gass_transfer_request_set_user_pointer(
stream->handle,
stream);
}
(void) globus_gass_transfer_requestattr_destroy(&attr);
return rc;
}
/* globus_l_gram_streamer_open_destination() */
/**
* @brief Determine if the job's processes are still running
*
* The globus_l_gram_streamer_waitpids() function is called periodically to
* check whether the pids associated with this streamer are still running.
* If they are all complete, globus_l_gram_streamer_waitpids() will signal
* the main thread and disable this callback from being called again.
*/
static
void
globus_l_gram_streamer_waitpids(
void * arg)
{
int i;
globus_gram_streamer_monitor_t * monitor = arg;
globus_mutex_lock(&monitor->mutex);
for (i = 0; i < STREAMER_MAX; i++)
{
if (monitor->pids[i] == 0)
{
continue;
}
if (kill(monitor->pids[i], 0) == -1)
{
monitor->pids[i] = 0;
monitor->pid_count--;
}
}
if (monitor->pid_count == 0)
{
globus_cond_signal(&monitor->cond);
globus_callback_unregister(
monitor->waitpids_poll_periodic,
NULL,
NULL,
NULL);
}
globus_mutex_unlock(&monitor->mutex);
}
/* globus_l_gram_streamer_waitpids */
|