| 770 | | phase1(sp) |
| 771 | | struct slot *sp; |
| 772 | | { |
| 773 | | struct hst *hp; |
| 774 | | char *hn; |
| 775 | | char *av[32]; |
| 776 | | int ac; |
| 777 | | char buf[512]; |
| 778 | | int pid = -1; |
| 779 | | char *p; |
| 780 | | |
| 781 | | #ifndef NOREXEC |
| 782 | | struct servent *se; |
| 783 | | static u_short execport = 0; |
| 784 | | |
| 785 | | if (!execport) { |
| 786 | | if (!(se = getservbyname("exec", "tcp"))) { |
| 787 | | pvmlogprintf("phase1() can't getservbyname(): %s\n", "exec"); |
| 788 | | pvmbailout(0); |
| 789 | | } |
| 790 | | execport = se->s_port; |
| 791 | | endservent(); |
| 792 | | } |
| 793 | | #endif |
| 794 | | |
| 795 | | hp = sp->s_hst; |
| 796 | | hn = hp->h_name; |
| 797 | | sp->s_rfd = sp->s_wfd = sp->s_efd = -1; |
| 798 | | |
| 799 | | |
| 800 | | |
| 801 | | |
| 802 | | |
| 803 | | if (hp->h_flag & HST_MANUAL) {
|
| 804 | | fprintf(stderr, "*** Manual startup ***\n"); |
| 805 | | fprintf(stderr, "Login to \"%s\" and type:\n", hn); |
| 806 | | |
| 807 | | if (hp->h_wincmd) { |
| 808 | | fprintf(stderr, "%s\n\n", hp->h_cmd); |
| 809 | | fprintf(stderr, "or, if that command fails, " ); |
| 810 | | fprintf(stderr, "for WIN32 hosts try:\n"); |
| 811 | | fprintf(stderr, "%s\n\n", hp->h_wincmd); |
| 812 | | } |
| 813 | | else |
| 814 | | fprintf(stderr, "%s\n", hp->h_cmd); |
| 815 | | |
| 816 | | |
| 817 | | |
| 818 | | fprintf(stderr, "Type response: "); |
| 819 | | fflush(stderr); |
| 820 | | if (!(fgets(buf, sizeof(buf), stdin))) { |
| 821 | | pvmlogprintf("host %s read error\n", hn); |
| 822 | | goto oops; |
| 823 | | } |
| 824 | | p = buf + strlen(buf) - 1; |
| 825 | | if (*p == '\n') |
| 826 | | *p = 0; |
| 827 | | hp->h_result = STRALLOC(buf);
|
| 828 | | |
| 829 | | |
| 830 | | |
| 831 | | if (hp->h_vmid) { |
| 832 | | fprintf(stderr, "Now Type the Virtual Machine ID on %s:\n", |
| 833 | | hn); |
| 834 | | fprintf(stderr, "%s\n", hp->h_vmid); |
| 835 | | } |
| 836 | | |
| 837 | | |
| 838 | | |
| 839 | | fprintf(stderr, "Thanks\n"); |
| 840 | | fflush(stderr); |
| 841 | | return 0; |
| 842 | | } |
| 843 | | |
| 844 | | |
| 845 | | |
| 846 | | |
| 847 | | |
| 848 | | if (!(hp->h_flag & HST_PASSWORD)) {
|
| 849 | | int wpfd[2], rpfd[2], epfd[2]; |
| 850 | | int i; |
| 851 | | |
| 852 | | if (pvmdebmask & PDMSTARTUP) {
|
| 853 | | pvmlogprintf("phase1() trying rsh to %s\n", hn); |
| 854 | | } |
| 855 | | |
| 856 | | |
| 857 | | |
| 858 | | #ifdef IMA_TITN |
| 859 | | if (socketpair(AF_UNIX, SOCK_STREAM, 0, wpfd) == -1 |
| 860 | | || socketpair(AF_UNIX, SOCK_STREAM, 0, rpfd) == -1 |
| 861 | | || socketpair(AF_UNIX, SOCK_STREAM, 0, epfd) == -1) { |
| 862 | | pvmlogperror("phase1() socketpair"); |
| 863 | | goto oops; |
| 864 | | } |
| 865 | | #else |
| 866 | | if (pipe(wpfd) == -1 || pipe(rpfd) == -1 || pipe(epfd) == -1) { |
| 867 | | pvmlogperror("phase1() pipe"); |
| 868 | | goto oops; |
| 869 | | } |
| 870 | | #endif |
| 871 | | |
| 872 | | if (pvmdebmask & PDMSTARTUP) {
|
| 873 | | pvmlogprintf("phase1() pipes: %d %d %d %d %d %d\n", |
| 874 | | wpfd[0], wpfd[1], rpfd[0], rpfd[1], epfd[0], epfd[1]); |
| 875 | | } |
| 876 | | |
| 877 | | if ((pid = fork()) == -1) { |
| 878 | | pvmlogperror("phase1() fork"); |
| 879 | | pvmbailout(0); |
| 880 | | } |
| 881 | | if (!pid) { |
| 882 | | (void)dup2(wpfd[0], 0); |
| 883 | | (void)dup2(rpfd[1], 1); |
| 884 | | (void)dup2(epfd[1], 2); |
| 885 | | for (i = getdtablesize(); --i > 2; ) |
| 886 | | (void)close(i); |
| 887 | | ac = 0; |
| 888 | | av[ac++] = pvmgetrsh(); |
| 889 | | av[ac++] = hn; |
| 890 | | if (hp->h_login) { |
| 891 | | av[ac++] = "-l"; |
| 892 | | av[ac++] = hp->h_login; |
| 893 | | } |
| 894 | | #ifdef IMA_BEOSCYLD |
| 895 | | |
| 896 | | |
| 897 | | |
| 898 | | |
| 899 | | |
| 900 | | |
| 901 | | |
| 902 | | |
| 903 | | |
| 904 | | |
| 905 | | p = hp->h_cmd; |
| 906 | | do { |
| 907 | | av[ac++] = p; |
| 908 | | p = strstr(p," "); |
| 909 | | if (p != NULL) |
| 910 | | *p++ = '\0'; |
| 911 | | } while (p != NULL); |
| 912 | | #else |
| 913 | | av[ac++] = hp->h_cmd; |
| 914 | | #endif |
| 915 | | av[ac++] = 0; |
| 916 | | if (pvmdebmask & PDMSTARTUP) {
|
| 917 | | for (ac = 0; av[ac]; ac++) |
| 918 | | fprintf(stderr, "av[%d]=\"%s\" ", ac, av[ac]); |
| 919 | | fputc('\n', stderr); |
| 920 | | } |
| 921 | | execvp(av[0], av); |
| 922 | | fputs("phase1() execvp failed\n", stderr); |
| 923 | | fflush(stderr); |
| 924 | | _exit(1); |
| 925 | | } |
| 926 | | (void)close(wpfd[0]); |
| 927 | | (void)close(rpfd[1]); |
| 928 | | (void)close(epfd[1]); |
| 929 | | sp->s_wfd = wpfd[1]; |
| 930 | | sp->s_rfd = rpfd[0]; |
| 931 | | sp->s_efd = epfd[0]; |
| 932 | | |
| 933 | | } else { |
| 934 | | |
| 935 | | #ifdef NOREXEC |
| 936 | | pvmlogprintf("slconfg() PVM was built without rexec support, can't take passwords\n"); |
| 937 | | goto oops; |
| 938 | | #else |
| 939 | | if (pvmdebmask & PDMSTARTUP) {
|
| 940 | | pvmlogprintf("phase1() rexec \"%s\"\n", hp->h_cmd); |
| 941 | | } |
| 942 | | if ((sp->s_wfd = sp->s_rfd = rexec(&hn, execport, |
| 943 | | (hp->h_login ? hp->h_login : username), |
| 944 | | (char*)0, hp->h_cmd, &sp->s_efd)) |
| 945 | | == -1) { |
| 946 | | pvmlogprintf("phase1() rexec failed for host %s\n", hn); |
| 947 | | goto oops; |
| 948 | | } |
| 949 | | #endif |
| 950 | | } |
| 951 | | |
| 952 | | |
| 953 | | if (sp->s_hst->h_vmid && sp->s_wfd >= 0) { |
| 954 | | #ifdef WIN32 |
| 955 | | win32_write_socket(sp->s_wfd, "PVM_VMID=", 9); |
| 956 | | win32_write_socket(sp->s_wfd, |
| 957 | | sp->s_hst->h_vmid, strlen(sp->s_hst->h_vmid)); |
| 958 | | win32_write_socket(sp->s_wfd, "\n", 1); |
| 959 | | #else |
| 960 | | write(sp->s_wfd, "PVM_VMID=", 9); |
| 961 | | write(sp->s_wfd, sp->s_hst->h_vmid, strlen(sp->s_hst->h_vmid)); |
| 962 | | write(sp->s_wfd, "\n", 1); |
| 963 | | #endif |
| 964 | | } |
| 965 | | |
| 966 | | return 0; |
| 967 | | |
| 968 | | oops: |
| 969 | | hp->h_result = STRALLOC("PvmCantStart");
|
| 970 | | if (sp->s_wfd != -1) |
| 971 | | close(sp->s_wfd); |
| 972 | | if (sp->s_rfd != -1) |
| 973 | | close(sp->s_rfd); |
| 974 | | if (sp->s_efd != -1) |
| 975 | | close(sp->s_efd); |
| 976 | | sp->s_wfd = sp->s_rfd = sp->s_efd = -1; |
| 977 | | return 1; |
| 978 | | } |