diff --git a/tecs/Makefile b/tecs/Makefile index 76430d40..9e0842fa 100644 --- a/tecs/Makefile +++ b/tecs/Makefile @@ -26,7 +26,7 @@ libtecsl.a: $(CLI_OBJ) ar cr libtecsl.a $(CLI_OBJ) ranlib libtecsl.a -all: libtecsl.a bin/TecsServer bin/TecsClient +all: libtecsl.a bin/TecsServer bin/TecsClient rstart keep_running tecs_plot.o: tecs_plot.f90 f90 -c -u -g tecs_plot.f90 diff --git a/tecs/keep_running.c b/tecs/keep_running.c new file mode 100644 index 00000000..6fdeafdb --- /dev/null +++ b/tecs/keep_running.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +#define MAX_CNT 10 +#define MIN_PERIOD 3600 + +int main(int argc, char *argv[]) { + int cnt, dif; + time_t tim1, tim2; + pid_t pid; + int status, i; + + if (argc<2) return 0; + cnt = MAX_CNT; + while (cnt > 0) { + time(&tim1); + pid=vfork(); + if (pid == 0) { + execvp(argv[1], argv+1); + perror("execvp"); + exit(1); + } + waitpid(pid, &status, 0); + if (status==0) { + printf("Regular exit\n"); + return 0; + } + time(&tim2); + dif = (int) difftime(tim2, tim1); + cnt += dif / MIN_PERIOD; + if (cnt > MAX_CNT) cnt = MAX_CNT; + cnt--; + printf("Status=%d. Died after %d sec", status, dif); + if (cnt > 0) { + printf(" - %d tries left - retry ...\n", cnt); + } + } + printf(" - too many restarts\n"); + return -1; +} diff --git a/tecs/rstart.c b/tecs/rstart.c new file mode 100644 index 00000000..693b1874 --- /dev/null +++ b/tecs/rstart.c @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include +#include +#include "myc_str.h" + +int rexec(char **host, int port, char *user, char *passwd, char *command, int *err_file_desc); + +int wrtRd(int fd, char *cmd, char *res, int res_len) { + int i, p, l, cnt; + char buf[8192]; + struct timeval tmo; + fd_set rmask; + + if (cmd[0]!='\0') { + l=send(fd, cmd, strlen(cmd), 0); + if (l<0) return -1; + } + tmo.tv_sec=2; + i=1; + p=0; + while (i>0 && p0) { + l=recv(fd, buf+p, sizeof(buf)-p-1, 0); + if (l<0) return -1; + p=p+l; + if (l==0) i=0; + } + } + if (p >= res_len) p=res_len-1; + buf[p]='\0'; + strcpy(res, buf); + return p; +} + +int main(int argc, char *argv[]) { + int port, i, j, l, fd; + char *host, inst[32], cmd[256], buf[256], path[256]; + char *instrHosts[]={ + "DMC","lnsa05.psi.ch", + "TOPSI","lnsa07.psi.ch", + "SANS","lnsa10.psi.ch", + "HRPT","lnsa11.psi.ch", + "TRICS","lnsa13.psi.ch", + "AMOR","lnsa14.psi.ch", + "FOCUS","lnsa16.psi.ch", + "ZOLLIKER","lnsa15.psi.ch" + }; + struct servent s; + + s=*getservbyname("exec", "tcp"); + i=0; + if (argc < 3) { + printf("not enough arguments\n"); + return 0; + } + str_upcase(inst, argv[1]); + str_copy(cmd, "\n"); + for (i=2; i0) { + if (l=wrtRd(fd, "", buf, sizeof(buf)) < 0) goto Error; + printf("%s", buf); + } + printf("\n"); + i=10; + while (i>0 && wrtRd(fd, "logout\n", buf, sizeof(buf)) >= 0) { + i--; + } + close(fd); + return 0; + Error: perror("error in wrtRd"); return 0; +}