917{
919 {
920 const char *mode;
923 {
924 if (
l->mode[0] !=
'\0' && (strcmp(
l->mode,
"r") == 0))
927 }
928
930 else if (strcmp(
l->mode,
"w") == 0) mode =
"w";
931 else if (strcmp(
l->mode,
"fork") == 0) mode =
"fork";
932 else if (strcmp(
l->mode,
"tcp") == 0) mode =
"tcp";
933 else if (strcmp(
l->mode,
"connect") == 0) mode =
"connect";
934 else mode = "a";
935
936
942
943 if (
l->name[0] ==
'\0')
944 {
945 if (strcmp(mode,"fork")==0)
946 {
952
953 int pc[2];
954 int cp[2];
955 pipe(pc);
956 pipe(cp);
957 pid_t pid = fork();
958 if (pid == -1 && errno == EAGAIN)
959 {
961 pid = fork();
962 }
963 if (pid == -1)
964 {
966 }
967 if (pid==0)
968 {
969
970 sigset_t sigint;
971 sigemptyset(&sigint);
972 sigaddset(&sigint, SIGINT);
973 sigprocmask(SIG_BLOCK, &sigint,
NULL);
974
976
978
980 {
990 hh=nn;
991 }
993#ifdef HAVE_SIMPLEIPC
995#endif
996 si_close(pc[1]); si_close(cp[0]);
1001
1002
1008
1011 {
1014 }
1016 {
1021 {
1022
1025 }
1029 }
1030
1031 }
1032 else if (pid>0)
1033 {
1035 si_close(pc[0]); si_close(cp[1]);
1042
1043
1044 }
1045 else
1046 {
1047 Werror(
"fork failed (%d)",errno);
1051 }
1052 }
1053
1054 else if (strcmp(mode,"tcp")==0)
1055 {
1056 int sockfd, newsockfd, portno, clilen;
1057 struct sockaddr_in serv_addr, cli_addr;
1058 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1059 if(sockfd < 0)
1060 {
1061 WerrorS(
"ERROR opening socket");
1066 }
1067 memset((char *) &serv_addr,0, sizeof(serv_addr));
1068 portno = 1025;
1069 serv_addr.sin_family = AF_INET;
1070 serv_addr.sin_addr.s_addr = INADDR_ANY;
1071 do
1072 {
1073 portno++;
1074 serv_addr.sin_port = htons(portno);
1075 if(portno > 50000)
1076 {
1077 WerrorS(
"ERROR on binding (no free port available?)");
1082 }
1083 }
1084 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1086 listen(sockfd,1);
1087 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1088 if(newsockfd < 0)
1089 {
1095 }
1096 PrintS(
"client accepted\n");
1100 d->
f_write = fdopen(newsockfd,
"w");
1102 si_close(sockfd);
1103 }
1104
1105 else
1106 {
1107 Werror(
"invalid mode >>%s<< for ssi",mode);
1112 }
1113 }
1114
1115 else
1116 {
1117
1118 if(strcmp(mode,"tcp")==0)
1119 {
1120 int sockfd, newsockfd, portno, clilen;
1121 struct sockaddr_in serv_addr, cli_addr;
1122 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1123 if(sockfd < 0)
1124 {
1125 WerrorS(
"ERROR opening socket");
1130 }
1131 memset((char *) &serv_addr,0, sizeof(serv_addr));
1132 portno = 1025;
1133 serv_addr.sin_family = AF_INET;
1134 serv_addr.sin_addr.s_addr = INADDR_ANY;
1135 do
1136 {
1137 portno++;
1138 serv_addr.sin_port = htons(portno);
1139 if(portno > 50000)
1140 {
1141 WerrorS(
"ERROR on binding (no free port available?)");
1145 }
1146 }
1147 while(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0);
1148
1149 listen(sockfd,1);
1150 char* cli_host = (
char*)
omAlloc(256);
1151 char* path = (
char*)
omAlloc(1024);
1152 int r = si_sscanf(
l->name,
"%255[^:]:%s",cli_host,path);
1153 if(r == 0)
1154 {
1155 WerrorS(
"ERROR: no host specified");
1162 }
1163 else if(r == 1)
1164 {
1165 WarnS(
"program not specified, using /usr/local/bin/Singular");
1167 strcpy(path,"/usr/local/bin/Singular");
1168 }
1169 char* ssh_command = (
char*)
omAlloc(256);
1170 char* ser_host = (
char*)
omAlloc(64);
1171 gethostname(ser_host,64);
1172 if (strcmp(cli_host,"localhost")==0)
1173 sprintf(ssh_command,"%s -q --batch --link=ssi --MPhost=%s --MPport=%d &",path,ser_host,portno);
1174 else
1175 sprintf(ssh_command,"ssh %s %s -q --batch --link=ssi --MPhost=%s --MPport=%d &",cli_host,path,ser_host,portno);
1176
1180 system(ssh_command);
1183 clilen = sizeof(cli_addr);
1184 newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
1185 if(newsockfd < 0)
1186 {
1192 }
1193
1197 d->
f_write = fdopen(newsockfd,
"w");
1198 si_close(sockfd);
1207 }
1208
1209 else if(strcmp(mode,"connect")==0)
1210 {
1211 char* host = (
char*)
omAlloc(256);
1212 int sockfd, portno;
1213 struct sockaddr_in serv_addr;
1214 struct hostent *server;
1215
1216 si_sscanf(
l->name,
"%255[^:]:%d",host,&portno);
1217
1218 if (portno!=0)
1219 {
1220 sockfd = socket(AF_INET, SOCK_STREAM, 0);
1221 if (sockfd < 0)
1222 {
1223 WerrorS(
"ERROR opening socket");
1226 }
1227 server = gethostbyname(host);
1229 {
1230 WerrorS(
"ERROR, no such host");
1233 }
1234 memset((char *) &serv_addr, 0, sizeof(serv_addr));
1235 serv_addr.sin_family = AF_INET;
1236 memcpy((char *)&serv_addr.sin_addr.s_addr,
1237 (char *)server->h_addr,
1238 server->h_length);
1239 serv_addr.sin_port = htons(portno);
1240 if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
1241 {
1242 Werror(
"ERROR connecting(errno=%d)",errno);
1245 }
1246
1249 d->
f_write=fdopen(sockfd,
"w");
1253 }
1254 else
1255 {
1260 }
1261 }
1262
1263 else
1264 {
1265
1266 FILE *outfile;
1267 char *filename=
l->name;
1268
1269 if(filename[0]=='>')
1270 {
1271 if (filename[1]=='>')
1272 {
1273 filename+=2;
1274 mode = "a";
1275 }
1276 else
1277 {
1278 filename++;
1279 mode="w";
1280 }
1281 }
1282 outfile=
myfopen(filename,mode);
1284 {
1285 if (strcmp(
l->mode,
"r")==0)
1286 {
1287 fclose(outfile);
1289 }
1290 else
1291 {
1294 }
1295 }
1296 else
1297 {
1302 }
1303 }
1304 }
1305 }
1306
1308}
Class used for (list of) interpreter objects.
VAR BOOLEAN singular_in_batchmode
FILE * myfopen(const char *path, const char *mode)
const char * feSetOptValue(feOptIndex opt, char *optarg)
VAR char my_yylinebuf[80]
char * fe_fgets_dummy(const char *, char *, int)
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
EXTERN_VAR omBin sleftv_bin
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
void PrintS(const char *s)
s_buff s_open_by_name(const char *n)
VAR int sem_acquired[SIPC_MAX_SEMAPHORES]
#define SI_LINK_SET_OPEN_P(l, flag)
#define SI_LINK_OPEN_P(l)
#define SI_LINK_CLOSE_P(l)
#define SIPC_MAX_SEMAPHORES