/******************************************* * to submit FTP * * * *******************************************/ #include #include #include #include #include "comx.h" #define BIT32 0x80000000 extern int os9forkc(); extern char **environ; char *argblk[5]; int ftp_ok; sighand(signal) register int signal; { if ( signal == FTP_TIMEOUT ){ ftp_ok = 0; } else if ( signal >= 2 && signal <= 3){ /* ^C or ^E ? */ exit(0); } } main(argc, argv) int argc; char *argv[]; { unsigned ftp_status; int ftp_id; int ftp_in, ftp_out, ftp_err; int pathin1, pathout1, patherr1; int pathin2, pathout2, patherr2; int alarm_id; int secs = 20; intercept(sighand); if (argc < 3) exit(_errmsg( -2 ," please give HOST and pipe\n")); if (argc >= 4 && (atoi(argv[3]) > FTP_T_MIN && atoi(argv[3]) < FTP_T_MAX)) secs = atoi(argv[3]); /* 1/8/93 : per motivi misteriosi il programma non funziona se si tolgono i printf seguenti, fa casino con le successive riallocazioni dei path. Nel 1992 non c'erano mai stati problemi. L'unico grosso cambiamento da allora e' stato l'utilizzo delle nuove eprom di Timellini con SSM. ???? */ /* printf(" ** ftpx called node : %s\n", argv[1]); printf(" ** pipe : %s\n", argv[2]); printf(" ** timeout : %d\n", secs); */ /* fork FTP */ argblk[0] = "ftp"; argblk[1] = argv[1]; argblk[2] = 0; /* change the paths */ pathin1 = dup(0); pathout1 = dup(1); patherr1 = dup(2); close(0); close(1); close(2); if( ( ftp_in = open(argv[2], S_IREAD) ) == -1 ) exit(_errmsg(errno ," cannot open %s \n", argv[2])); /* if( (ftp_out = open("/nil", S_IWRITE) ) == -1) */ if( (ftp_out = open("ftpx.log", S_IWRITE) ) == -1) exit(_errmsg(errno ," cannot open /nil \n")); ftp_err = dup(ftp_out); /* stderr */ printf(" ftpx: ports redefined \n"); printf(" ftpx tries to connect to node %s\n", argv[1]); printf(" commands read from %s\n", argv[2]); printf(" ( ftp_in = %d, ftp_out = %d, ftp_err = %d )\n", ftp_in, ftp_out, ftp_err ); if ((ftp_id = os9exec(os9forkc,argblk[0],argblk,environ,0,0,3)) == -1) exit(_errmsg(-1 ," error returned from os9exec(%s) \n", argblk[0])); printf(" ftp ID : %d\n", ftp_id); close (ftp_in); close (ftp_out); close (ftp_err); pathin2 = dup(pathin1); pathout2 = dup(pathout1); patherr2 = dup(patherr1); close (pathin1); close (pathout1); close (patherr1); if ((alarm_id = alm_set(FTP_TIMEOUT, ( secs << 8 ) | BIT32 )) == -1) exit(_errmsg(errno, "can't set alarm - ")); printf(" ** ftp submitted \n"); ftp_ok = 1; wait(&ftp_status); /* wait FTP to finish */ printf(" ** ftp_status %d \n", ftp_status); if (ftp_ok){ if ( alm_delete(alarm_id) == -1) exit(_errmsg(errno, "can't delete alarm - \n")); if (ftp_status) exit(_errmsg(ftp_status,"FTP return code %d\n", ftp_status)); exit(0); } else{ if ( kill(ftp_id, SIGKILL) == -1) exit(_errmsg(errno," error killing FTP \n")); exit(FTP_TIMEOUT); } }