Files
@ a97b3182afc5
Branch filter:
Location: DistRen/src/server/slavefuncs.c - annotation
a97b3182afc5
25.0 KiB
text/plain
better handle execio failure
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 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 12f4253fa8db d6d0d0d26d0b d851e72d74a8 c3b079b8a2dd c3b079b8a2dd c3b079b8a2dd c3b079b8a2dd c3b079b8a2dd c567abe6076a d6d0d0d26d0b c567abe6076a c567abe6076a e166f7bf8ca0 e166f7bf8ca0 e166f7bf8ca0 32109b7e973a b4fe3a4fca78 8feb0005e773 7225f5e7ec44 38944c233d6a 38944c233d6a 32109b7e973a d0f64b1f3376 1b885b7c9c3e 5964e275c410 5964e275c410 5964e275c410 2dc2e27d24ef 5964e275c410 99a5a69d493c 50619baaac4d 99a5a69d493c 50619baaac4d 2dc2e27d24ef 50619baaac4d 262e6275036b 262e6275036b 50619baaac4d 9211f8b8061b 50619baaac4d 50619baaac4d 262e6275036b 262e6275036b 262e6275036b 262e6275036b 262e6275036b 262e6275036b 262e6275036b 262e6275036b 99a5a69d493c 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 9211f8b8061b 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dc2e27d24ef 2dac5dfaf6bc f1fb3f3ed558 f1fb3f3ed558 f1fb3f3ed558 f1fb3f3ed558 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc c27e5bb830d1 c27e5bb830d1 2dac5dfaf6bc b36d84a3204a 2dac5dfaf6bc 2dac5dfaf6bc 03f549da3f73 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 1b885b7c9c3e 1b885b7c9c3e 2dac5dfaf6bc 2cc251e83bbb b236a45982d4 b236a45982d4 7a147d9d03a8 b236a45982d4 1ae1d5e6b902 1ae1d5e6b902 2cc251e83bbb 2cc251e83bbb 2cc251e83bbb c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a 2e6b26cb909d f597c84c5247 f597c84c5247 4b8e027a0b0c f597c84c5247 f597c84c5247 f597c84c5247 454b0844bf6e c567abe6076a f3a89be554ba 2e6b26cb909d c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f 4e072ce1165f c567abe6076a f597c84c5247 78516a1d1aee 1ae1d5e6b902 c567abe6076a c567abe6076a c567abe6076a eb2893bc7a0a 78516a1d1aee 2cc251e83bbb c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee c567abe6076a c567abe6076a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a 78516a1d1aee eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a 78516a1d1aee eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a 78516a1d1aee c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a 2cc251e83bbb c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a c567abe6076a 7f610e2808f2 7f610e2808f2 7f610e2808f2 c567abe6076a d1b199f51bbd c567abe6076a c567abe6076a 1f744ce71f83 7225f5e7ec44 d851e72d74a8 d851e72d74a8 f993fd280c02 f621356ea2ca 1f744ce71f83 1f744ce71f83 a255abd6e6f8 a255abd6e6f8 5b8e1f111c7f a255abd6e6f8 a255abd6e6f8 e1169a0b7eae e1169a0b7eae 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f a255abd6e6f8 5b8e1f111c7f 5b8e1f111c7f 7511a4140204 f9829af53ca6 f9829af53ca6 7511a4140204 7511a4140204 f9829af53ca6 f9829af53ca6 7511a4140204 7511a4140204 5b8e1f111c7f 5b8e1f111c7f f9829af53ca6 a255abd6e6f8 f9829af53ca6 f9829af53ca6 f9829af53ca6 a255abd6e6f8 f9829af53ca6 f9829af53ca6 f9829af53ca6 5b8e1f111c7f 7511a4140204 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 7511a4140204 7225f5e7ec44 9b1f363559ec 0deae41fe011 1f744ce71f83 83b5a81f8c76 1f744ce71f83 d131e91f8598 384331f8928e 1f744ce71f83 a04225d4bde8 a04225d4bde8 df7e1f917a6d b50933ddbb8f a255abd6e6f8 d0f64b1f3376 b50933ddbb8f 78516a1d1aee df7e1f917a6d 5908e352e267 a04225d4bde8 a04225d4bde8 00132229c637 a255abd6e6f8 1ae1d5e6b902 a97b3182afc5 f9829af53ca6 a97b3182afc5 a97b3182afc5 a97b3182afc5 a97b3182afc5 a97b3182afc5 a97b3182afc5 f9829af53ca6 f9829af53ca6 f9829af53ca6 f9829af53ca6 7f610e2808f2 384331f8928e 1f744ce71f83 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc 2dac5dfaf6bc d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 d98084136220 14cd2541024e 14cd2541024e 14cd2541024e 14cd2541024e 14cd2541024e 14cd2541024e 14cd2541024e 14cd2541024e 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 4e072ce1165f 4e072ce1165f 48325fa3515c 9638840eaba2 48325fa3515c 48325fa3515c 4e072ce1165f 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c d0f64b1f3376 d0f64b1f3376 48325fa3515c 48325fa3515c 48325fa3515c eb2893bc7a0a 78516a1d1aee eb2893bc7a0a 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c eb2893bc7a0a 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 48325fa3515c 33de0c52b059 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e166f7bf8ca0 e166f7bf8ca0 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e166f7bf8ca0 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e1171561f32f e166f7bf8ca0 e166f7bf8ca0 33de0c52b059 2d6b6ba3b549 e166f7bf8ca0 78516a1d1aee e1171561f32f 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 4ec01e2efee7 78516a1d1aee 78516a1d1aee 4ec01e2efee7 78516a1d1aee 6331e72e3889 6331e72e3889 4ec01e2efee7 6331e72e3889 2d6b6ba3b549 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee df7e1f917a6d 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 7d056f57c29a 7d056f57c29a 7d056f57c29a 7d056f57c29a 2d6b6ba3b549 7d056f57c29a 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 2d6b6ba3b549 9638840eaba2 e1171561f32f e1171561f32f 9638840eaba2 9638840eaba2 9638840eaba2 eb2893bc7a0a eb2893bc7a0a 9638840eaba2 9638840eaba2 9638840eaba2 b480ae9d4b12 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 eb2893bc7a0a 9638840eaba2 eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a eb2893bc7a0a 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 e01acca74331 9638840eaba2 e01acca74331 e1171561f32f 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 9638840eaba2 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 78516a1d1aee 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b ac130e840b4b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b ac130e840b4b 9cfd803fe96b df7e1f917a6d 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 9cfd803fe96b 0307f7fcc410 78516a1d1aee 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 9cfd803fe96b d0f64b1f3376 4ec01e2efee7 4ec01e2efee7 4ec01e2efee7 4ec01e2efee7 9cfd803fe96b df7e1f917a6d 4ec01e2efee7 4ec01e2efee7 9cfd803fe96b 9cfd803fe96b ac130e840b4b ac130e840b4b ac130e840b4b ac130e840b4b ac130e840b4b 9cfd803fe96b 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 0307f7fcc410 ac130e840b4b ac130e840b4b ac130e840b4b ac130e840b4b 8ee4266bf89b ac130e840b4b 195048ceb561 438aba733ea8 438aba733ea8 8ee4266bf89b 195048ceb561 195048ceb561 195048ceb561 8ee4266bf89b 8ee4266bf89b 195048ceb561 195048ceb561 8ee4266bf89b 8ee4266bf89b 438aba733ea8 438aba733ea8 438aba733ea8 195048ceb561 195048ceb561 195048ceb561 195048ceb561 195048ceb561 195048ceb561 195048ceb561 ac130e840b4b 9cfd803fe96b 9cfd803fe96b d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 9cfd803fe96b 9cfd803fe96b d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 7c6860c8d8cd d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 83327de59216 83327de59216 83327de59216 83327de59216 83327de59216 83327de59216 7c6860c8d8cd 83327de59216 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 d0f64b1f3376 7f610e2808f2 7f610e2808f2 7f610e2808f2 7f610e2808f2 d0f64b1f3376 9cfd803fe96b | /*
Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
This file is a part of DistRen.
DistRen is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DistRen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with DistRen. If not, see <http://www.gnu.org/licenses/>.
*/
#include "distrenjob.h"
#include "slavefuncs.h"
#include "common/asprintf.h"
#include "common/execio.h"
#include "common/protocol.h"
#include "common/remoteio.h"
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/types.h>
#include <archive.h>
#include <archive_entry.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
/**
Sends the server a single request (see protocol.h)
*/
int sendSignal(struct remoteio *rem, char signal)
{
size_t written;
size_t towrite;
char *ssignal;
_distren_asprintf(&ssignal, "%c", signal);
towrite = strlen(ssignal);
while( towrite
&& !remoteio_write(rem, ssignal, towrite, &written))
{
fprintf(stderr, "Sending request...\n");
towrite -= written;
}
if(written)
return 0;
/**
if remoteio_write returned 1, the connection
is probably dead or there was a real error
*/
return 1;
}
/**
Sends the server an extended signal (request + data)
*/
int sendExtSignal(struct remoteio *rem, char signal, char *data){
size_t written;
size_t towrite;
char *ssignal;
_distren_asprintf(&ssignal, "%c%s", signal, data); // Just append the data FIXME: We should do this differently
towrite = strlen(ssignal);
while( towrite
&& !remoteio_write(rem, ssignal, towrite, &written))
{
fprintf(stderr, "Sending request...\n");
towrite -= written;
}
if(written)
return 0;
/**
if remoteio_write returned 1, the connection
is probably dead or there was a real error
*/
return 1;
}
/**
Grabs the xml DOM node reached by an XPath.
@param path an XPath that lead to DOM node
@return the first node associated with the path or NULL if there is no match
*/
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path)
{
xmlNodePtr toreturn;
xmlXPathObjectPtr xmlxpathobjptr;
xmlxpathobjptr = xmlXPathEval(path, xpathctxt);
if(!xmlxpathobjptr
|| !xmlxpathobjptr->nodesetval->nodeNr)
{
fprintf(stderr, "XPath resolution failed for ``%s'' in ``%s'' (``%s'')\n", path, xpathctxt->doc->name, xpathctxt->doc->URL);
return (xmlNodePtr)NULL;
}
toreturn = *(xmlxpathobjptr->nodesetval->nodeTab);
xmlXPathFreeObject(xmlxpathobjptr);
return toreturn;
}
/** Stub for deleting job data from the disk. @TODO: unstubify me! */
int delete_jobdata(int jobnum, char *datadir)
{
char *jobpath;
_distren_asprintf(&jobpath, "%s/%d", datadir, jobnum);
// rmdir(jobpath);
fprintf(stderr, "Please manually remove %s. Automatic removal is currently not implemented.\n", jobpath);
return 0;
}
/** Function referenced by curlget() to write data to disk. */
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return fwrite(ptr, size, nmemb, stream);
}
/** Helper function for cURL's progress display */
int curl_progress( char *Bar,double t,double d,double ultotal,double ulnow)
{
fprintf(stderr,"Downloading: %f%% complete\r",d/t*100);
return 0;
}
/** Retrieves a URL with cURL and saves it to disk */
int curlget(char *url, char *out){
fprintf(stderr,"Preparing to download %s\n",url);
double *Bar; // Stores cURL progress display info
CURL *curl;
CURLcode res;
FILE *outfile;
curl = curl_easy_init();
if(curl) {
outfile = fopen(out, "w"); // Open where we're writing to
if(outfile == NULL)
return 2; // Output dir doesn't exist
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat.
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
fprintf(stderr,"\n"); // Clears out he progressbar's carriage return
fclose(outfile);
return res; // 0 is OK, 1 is 404 or other error
}
/** Posts a file to a url with cUrl */
int curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey){
fprintf(stderr,"Uploading to %s\n", url);
char *targetname = "uploadedfile"; // Name of the target in the php file on the server (Don't change me unless you have different PHP code)
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
char *sjobnum;
char *sframenum;
char *sslavekey;
_distren_asprintf(&sjobnum,"%d",jobnum);
_distren_asprintf(&sframenum,"%d",framenum);
_distren_asprintf(&sslavekey,"%d",slavekey);
curl_global_init(CURL_GLOBAL_ALL);
/* jobnum field... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "jobnum",
CURLFORM_COPYCONTENTS, sjobnum, CURLFORM_END);
/* framenum field... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "framenum",
CURLFORM_COPYCONTENTS, sframenum, CURLFORM_END);
/* slavekey field... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "slavekey",
CURLFORM_COPYCONTENTS, sslavekey, CURLFORM_END);
/* upload field... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, targetname,
CURLFORM_FILE, filename,
CURLFORM_END);
/* filename field... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, filename,
CURLFORM_END);
/* submit field, not usually needed, just in case... */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if(curl) {
/* Setting the URL to get the post, and the contents of the post */
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
/* cleanup the formpost junk */
curl_formfree(formpost);
curl_slist_free_all (headerlist);
free(sjobnum);
free(sframenum);
free(sslavekey);
}
return res;
}
/** Logs the user into the server after ensuring that keys exist */
int login_user(char *username)
{
// @TODO: Put some telnet-style auth code here unless this is obselete
return 1; // success
}
/** Replaces wordtoreplace with replacewith in conffile (relative to SYSCONFDIR) */
int conf_replace(char *conffile, char *wordtoreplace, char *replacewith){
int maxlinelen = 120;
char *fileOrig;
char *fileRepl;
_distren_asprintf(&fileOrig, "%s/%s", SYSCONFDIR, conffile);
_distren_asprintf(&fileRepl, "%s%s.edited", SYSCONFDIR, conffile);
char buffer[maxlinelen+2];
char *buff_ptr, *find_ptr;
FILE *fp1, *fp2;
size_t find_len = strlen(wordtoreplace);
fp1 = fopen(fileOrig,"r");
fp2 = fopen(fileRepl,"w");
if (fp1 ==NULL){
fprintf(stderr, "%s doesn't exist\n",fileOrig);
return 0;
}
else if(fp2 ==NULL){
fprintf(stderr, "Can't write a file to disk! Check permissions.\n");
return 0;
}
else{
while(fgets(buffer,maxlinelen+2,fp1))
{
buff_ptr = buffer;
while ((find_ptr = strstr(buff_ptr,wordtoreplace)))
{
while(buff_ptr < find_ptr)
fputc((int)*buff_ptr++,fp2);
fputs(replacewith,fp2);
buff_ptr += find_len;
}
fputs(buff_ptr,fp2);
}
rename(fileRepl, fileOrig);
}
fclose(fp2);
fclose(fp1);
fprintf(stderr,"Wrote conf file...\n");
return 1; // Success
}
/* Executors */
/** Executor function for Blender operations */
int exec_blender(char *input, char *output, int frame)
{
int ret;
char *frame_str;
_distren_asprintf(&frame_str, "%i", frame);
char *command = "blender"; // @TODO: We currently expect this to be in PATH
char *cmd[] = { command, "-b", input, "-o", output, "-f", frame_str, "-t", "0", (char *)NULL }; // arguments for blender
fprintf(stderr,"Preparing to execute command: %s -b %s -o %s -f %s\n", command, input, output, frame_str);
char buf[20];
struct execio *testrem;
size_t readlen;
fprintf(stderr,"Executing: %s\n", frame_str);
ret = execio_open(&testrem, command, cmd);
if(ret)
{
fprintf(stderr, "error running blender\n");
return 1;
}
buf[19] = '\0';
while(!execio_read(testrem, buf, 19, &readlen))
{
buf[readlen] = '\0';
fprintf(stderr, "read \"%s\"\n", buf);
}
execio_close(testrem);
free(frame_str);
return ret;
}
void xmlinit()
{
xmlInitParser();
xmlXPathInit();
}
void xmlcleanup()
{
xmlCleanupParser();
}
/** Creates directories recursively */
int distren_mkdir_recurse(char *dirname)
{
size_t counter;
char *nextdir;
nextdir = strdup(dirname);
for(counter = 0; nextdir[counter]; counter ++)
{
/** @TODO OS-portabalize the path-separators */
if(nextdir[counter] == '/')
{
nextdir[counter] = '\0';
mkdir(nextdir, S_IRWXU | S_IRGRP | S_IROTH);
nextdir[counter] = '/';
}
}
return 0;
}
/**
@TODO: Use for constructing path to job data locally and/or on data.distren.org
*/
int job_build_path(char *filename, unsigned int jobnum)
{
return 0;
}
int downloadTar(char *url, char *destinationPath){
// Prepare to download the job tar if it isn't present
struct stat buffer;
int fstatus = stat(destinationPath, &buffer);
if(fstatus == -1)
{
// Download the Tar
int ret = curlget(url, destinationPath);
if(ret == 0){
fprintf(stderr, "Job data retrieved successfully\n");
// free(url); @FIXME: causes doublefree! Curl must free the url?
return 0;
}
else if(ret == 1){
fprintf(stderr, "Downloading job data from %s failed. Check your network connection.\n",url);
free(url);
return 1; // Eventually make a retry loop
}
}
fprintf(stderr, "Tar already exists! Download cancelled.\n");
return 2;
}
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey){
//fprintf(stderr,"Uploading output %s to url %s for job %d and frame %d for slavekey %d", pathtoOutput, urltoOutput, jobnum, framenum, slavekey);
if( !curlpost(pathtoOutput, urltoOutput, jobnum, framenum, slavekey)) // Uploads output
{
fprintf(stderr,"Upload successful, removing old output...\n");
remove(pathtoOutput); // Delete the file after its uploaded
return 0;
}
else
{
fprintf(stderr,"Upload failed. Check your network connection. Retrying upload...\n");
int tries=1;
while(tries<=10 && curlpost(pathtoOutput, urltoOutput, jobnum, framenum, slavekey))
{
fprintf(stderr, "Upload failed. Trying again in 10 seconds... (attempt %d of 10)\n", tries);
tries++;
sleep(10);
}
return 1; // Upload failed after multiple tries
// @FUTURE: Keep track of files that we were unable to upload, and upload them later
}
}
/**
Extracts archive to the specified directory, creating this directory
if necessary (but this directory will not be recursively created).
@param outdir output directory
@param pathtoTar filename of the archive to extract
*/
int unpackJob(char *outdir, char *pathtoTar)
{
int ret;
struct archive *a;
struct archive_entry *ae;
int astatus;
/* ignore return because directory may exist already */
mkdir(outdir, 0700);
ret = chdir(outdir);
if(ret == -1)
{
perror("chdir");
return 1;
}
a = archive_read_new();
ae = archive_entry_new();
archive_read_support_compression_all(a);
archive_read_support_format_raw(a);
astatus = archive_read_open_filename(a, pathtoTar, 8192);
if (astatus != ARCHIVE_OK)
{
fprintf(stderr, "error opening archive\n");
return 1;
}
for(astatus = ARCHIVE_OK;
astatus == ARCHIVE_OK
|| astatus == ARCHIVE_WARN;
)
{
astatus = archive_read_next_header2(a, ae);
if(astatus == ARCHIVE_WARN)
fprintf(stderr, "Encountered nonfatal read error somehow\n");
if(astatus == ARCHIVE_OK
|| astatus == ARCHIVE_WARN)
astatus = archive_read_extract(a, ae,
ARCHIVE_EXTRACT_NO_OVERWRITE
| ARCHIVE_EXTRACT_SECURE_SYMLINKS
| ARCHIVE_EXTRACT_SECURE_NODOTDOT);
}
archive_entry_free(ae);
archive_read_finish(a);
if(astatus != ARCHIVE_EOF)
{
fprintf(stderr, "Error reading archive\n");
return 1;
}
return 0;
}
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile, char **urltoJobfile, char **urltoOutput,char **pathtoOutput, char **pathtoRenderOutput, char **pathtoOutdir)
{
// Variable Preparation
char *jobdatapath;
_distren_asprintf(&jobdatapath, "job%d", jobnum);
_distren_asprintf(urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum, jobnum); // Prepares URL to download from
_distren_asprintf(urltoJobfile, "http://data.distren.org/job%d/job.blend", jobnum); // Prepares URL to download from
_distren_asprintf(pathtoTar, "%s/%s/job%d.tar.gz", datadir, jobdatapath, jobnum); // Prepares destination to save to
_distren_asprintf(pathtoTardir, "%s/%s/", datadir, jobdatapath); // Prepares destination to save to
_distren_asprintf(pathtoJob, "%s/%s/", datadir, jobdatapath);
_distren_asprintf(pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
_distren_asprintf(urltoOutput, "http://dev.distren.org/slaveUpload.php?jobkey=%d&framekey=%d",jobnum,framenum); // Prepares the URL where output is posted
_distren_asprintf(pathtoRenderOutput, "%s/%s/output/job%d-frame#.%s", datadir, jobdatapath, jobnum, outputExt ); // Note: the # is for blender to put in framenum in output file
_distren_asprintf(pathtoOutput, "%s/%s/output/job%d-frame%d.%s", datadir, jobdatapath, jobnum, framenum, outputExt ); // Note: the # is for blender to put in framenum in output file
_distren_asprintf(pathtoOutdir, "%s/%s/output", datadir, jobdatapath);
free(jobdatapath);
}
int checkUsername(char *username)
{
if(username == NULL || strcmp(username, "!username") == 0 )
{
fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf\n");
return 1;
}
else
if( username != NULL || strcmp(username, "!username") != 0 )
{
// Log in the user
if(login_user(username) == 1){
fprintf(stderr, "You should now be logged into distren.\n");
return 0;
}
else
{
fprintf(stderr, "Login failed, please check your username. If you have not registered, please do so on the DistRen website.\n");
return 1;
}
}
else
{
fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n");
return 1;
}
}
void slaveTest(char *datadir)
{
int command;
int test = 1;
int jobnum = 0;
int framenum = 0;
int slavekey = 0;
fprintf(stderr,"Hello!\n");
char tmpString1[100] = "";
char tmpString2[100] = "";
char *uploadURL = "http://distren.org/slaveUpload.php";
while(test == 1)
{
fprintf(stderr, "Welcome to DistRenSlave Alpha Interactive Test Mode\n\n");
fprintf(stderr, "\t1 \tTest posting (uploading) data\n");
fprintf(stderr, "\t2 \tTest getting frame from server\n");
fprintf(stderr, "\t3 \tTest data downloading\n");
fprintf(stderr, "\t4 \tTest archive decompression\n");
fprintf(stderr, "\t5 \tQuit\n");
scanf("%d", &command);
switch(command)
{
case 1:
fprintf(stderr,"Path to output file to upload: ");
scanf("%99s", tmpString1);
fprintf(stderr,"Framenum that is being uploaded: ");
scanf("%d", &framenum);
fprintf(stderr,"Jobnum that frame belongs to: ");
scanf("%d", &jobnum);
fprintf(stderr,"Slavekey that rendered this output: ");
scanf("%d", &slavekey);
uploadOutput(tmpString1, uploadURL, jobnum, framenum, slavekey);
break;
case 2:
fprintf(stderr,"Remotio not implemented yet!\n");
break;
case 3:
fprintf(stderr,"URL to file: ");
scanf("%s", tmpString1);
fprintf(stderr,"Local save path (including filename): ");
scanf("%s", tmpString2);
if(downloadTar(tmpString1, tmpString2))
fprintf(stderr,"Error downloading!\n");
else
fprintf(stderr,"Success!\n");
break;
case 4:
fprintf(stderr,"Jobnum to decompress: ");
scanf("%d", &jobnum);
fprintf(stderr,"Path to compressed data: ");
scanf("%s", tmpString2);
unpackJob(datadir, tmpString1);
break;
case 5:
test = 0;
break;
default:
fprintf(stderr, "Invalid input, please try again.\n");
break;
}
}
}
/*
int runBenchmark(int slavekey, char *datadir){
// Execute blender
if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
{
fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
_web_resetframe(slavekey, password, jobnum, framenum); // Unassign the frame on the server so other slaves can render it
return 1;
}
free(pathtoJobfile);
struct stat buffer;
int fstatus = stat(pathtoOutput, &buffer);
if(fstatus == -1){
fprintf(stderr,"*** Frame was not rendered correctly! Scene may not have camera, or your blender installation is not working.\n");
_web_resetframe(slavekey, password, jobnum, framenum); // Unassign the frame on the server so other slaves can render it
return 1;
}
}
*/
/* simpleSlave functions */
/** Memory struct for curl */
struct _web_memorystruct {
char *memory;
size_t size;
};
static void *_web_myrealloc(void *ptr, size_t size);
static void *_web_myrealloc(void *ptr, size_t size)
{
/* There might be a realloc() out there that doesn't like reallocing
NULL pointers, so we take care of it here */
if(ptr)
return realloc(ptr, size);
else
return malloc(size);
}
static size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
struct _web_memorystruct *mem = (struct _web_memorystruct *)data;
mem->memory = _web_myrealloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}
struct _web_memorystruct _web_getrequest(char *url){
// fprintf(stderr,"Preparing to get request at %s",url);
CURL *curl;
CURLcode res;
struct _web_memorystruct chunk;
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _web_writememorycallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
/* we're done with libcurl, so clean it up */
curl_global_cleanup();
return chunk; // 0 is OK, 1 is 404 or other error
}
void _web_finishframe(int slavekey, char *slavepass, int jobnum, int framenum){
char *url;
_distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=finishframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
struct _web_memorystruct data = _web_getrequest(url);
free(url);
fprintf(stderr,"%s\n", data.memory);
if(data.memory)
free(data.memory);
}
void _web_resetframe(int slavekey, char *slavepass, int jobnum, int framenum){
fprintf(stderr,"Resetting frame %d in job %d on server... ",framenum,jobnum);
char *url;
_distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=resetframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
struct _web_memorystruct data = _web_getrequest(url);
free(url);
fprintf(stderr,"%s\n", data.memory);
if(data.memory)
free(data.memory);
}
void _web_startframe(int slavekey, char *slavepass, int jobnum, int framenum){
fprintf(stderr,"Marking frame %d started on server... ",framenum);
char *url;
_distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=startframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
struct _web_memorystruct data = _web_getrequest(url);
free(url);
fprintf(stderr,"%s\n", data.memory);
if(data.memory)
free(data.memory);
}
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum){
char *url;
_distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=getwork&slavekey=%d&slavepass=%s", slavekey, slavepass);
struct _web_memorystruct data = _web_getrequest(url);
free(url);
if(!data.memory || !strcmp(data.memory,",")){
fprintf(stderr,"No work available on server!\n");
return 0;
}
else if(!strcmp(data.memory, "ERROR_BADKEY")){
fprintf(stderr,"*** Slave %d does not exist!\n",slavekey);
free(data.memory);
return 0;
}
// Compare to PACKAGE_VERSION
else{
char *tmp;
char *serverversion;
tmp = strtok (data.memory,",,");
if(tmp != NULL){ // make sure work is available
*jobnum = atoi(tmp);
tmp = strtok (NULL, ",");
if(tmp == NULL)
return 0; // no work
*framenum = atoi(tmp);
tmp = strtok (NULL, ",");
if(tmp == NULL)
return 0; // no work
serverversion = tmp;
if(strcmp(PACKAGE_VERSION,serverversion)){
fprintf(stderr,"Your distren package is out of date! Please acquire a newer version. (%s local vs %s remote)\n", PACKAGE_VERSION, serverversion);
return 0;
}
free(data.memory);
return 1;
}
else
return 0; // error
}
}
void _web_setrenderpower(int slavekey, char *slavepass, int renderpower){
fprintf(stderr,"Setting render power on server... ");
char *url;
_distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=setrenderpower&slavekey=%d&slavepass=%s&renderpower=%d", slavekey, slavepass, renderpower);
struct _web_memorystruct data = _web_getrequest(url);
free(url);
fprintf(stderr,"%s\n", data.memory);
if(data.memory)
free(data.memory);
}
int slaveBenchmark(char *datadir, int *benchmarkTime, int *renderPower){
int ret;
int frameToRender = 1;
char *frame_str;
_distren_asprintf(&frame_str, "%d", frameToRender); // Render frame 1
char *output;
_distren_asprintf(&output, "%s/benchmark#.jpg", datadir); // Where to save benchmark output
char *realOutput;
_distren_asprintf(&realOutput, "%s/benchmark%d.jpg", datadir, frameToRender); // Where to save benchmark output
char *input;
_distren_asprintf(&input, "%s/benchmark.blend", datadir); // Input file
fprintf(stderr,"Downloading benchmark data...\n");
curlget("http://data.distren.org/benchmark.blend", input); // Download to input file location
char *command = "blender"; // @TODO: We currently expect this to be in PATH
char *cmd[] = { command, "-b", input, "-o", output, "-f", frame_str, "-t", "0", (char *)NULL }; // arguments for blender
// fprintf(stderr,"Preparing to execute command: %s -b %s -o %s -f %s\n", command, input, output, frame_str);
fprintf(stderr,"Running benchmark...\n");
long startTime;
long endTime;
time(&startTime);
char buf[20];
struct execio *testrem;
size_t readlen;
ret = execio_open(&testrem, command, cmd);
if(ret)
{
fprintf(stderr, "Error executing blender\n");
return 1;
}
buf[19] = '\0';
while(!execio_read(testrem, buf, 19, &readlen))
{
buf[readlen] = '\0';
fprintf(stderr, "read \"%s\"\n", buf);
}
execio_close(testrem);
time(&endTime);
struct stat buffer;
int ostatus = stat(realOutput, &buffer);
if(ostatus == -1){
ret = 1; // Return error if output wasn't generated
}
else
remove(output);
*benchmarkTime = abs(difftime(startTime,endTime));
float tmp = *benchmarkTime;
tmp = (1/tmp) * 50000;
*renderPower = (int)tmp;
free(realOutput);
free(frame_str);
free(input);
free(output);
return ret;
}
|