00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "eg_config.h"
00023 #include "eg_macros.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 void EGlib_info(void)
00038 {
00039 int rval;
00040 struct utsname uts;
00041 rval = uname(&uts);
00042 if(rval)
00043 {
00044 fprintf(stderr,"Can't get host info\n");
00045 }
00046 else
00047 {
00048 fprintf(stderr,"Host: %s, %s %s %s\nCurrent process id: %d\n",uts.nodename, uts.sysname, uts.release, uts.machine ,(int)getpid());
00049 }
00050 }
00051
00052
00053 jmp_buf __EGljmp;
00054
00055 void EGsighandler(int s)
00056 {
00057 switch(s)
00058 {
00059 case SIGXCPU:
00060
00061 fprintf(stderr,"\nTIME_LIMIT_REACHED (ending now)\n");
00062 longjmp(__EGljmp,s);
00063 break;
00064 case SIGINT:
00065 case SIGTERM:
00066 case SIGTSTP:
00067
00068 fprintf(stderr,"\nUSER_INTERRUPT (ending now)\n");
00069 longjmp(__EGljmp,s);
00070 break;
00071 case SIGSEGV:
00072
00073 fprintf(stderr,"\nMEMORY_LIMIT_REACHED (ending now)\n");
00074 longjmp(__EGljmp,s);
00075 break;
00076 default:
00077 fprintf(stderr,"Unkown signal %d\n",s);
00078 fprintf(stderr,"Ending with status %d\n",s);
00079 exit(s);
00080 }
00081 }
00082
00083 void __EGsigSetSignal(void)
00084 {
00085 signal(SIGXCPU,EGsighandler);
00086 signal(SIGINT,EGsighandler);
00087 signal(SIGSEGV,EGsighandler);
00088 }
00089
00090 void EGsetLimits(double max_rtime, unsigned long memlimit)
00091 {
00092 struct rlimit mlim;
00093 WARNIF(getrlimit(RLIMIT_CPU,&mlim));
00094 MESSAGE(0, "Cur rtime limit %ld, trying to set to %lg", mlim.rlim_cur, max_rtime);
00095 if(max_rtime > mlim.rlim_max) max_rtime = (double)mlim.rlim_max;
00096 mlim.rlim_cur = (rlim_t)max_rtime;
00097 WARNIF(setrlimit(RLIMIT_CPU,&mlim));
00098 MESSAGE(0, "New rtime limit %ld (%.3lg)", mlim.rlim_cur, max_rtime);
00099 WARNIF(getrlimit(RLIMIT_DATA,&mlim));
00100 MESSAGE(0, "Cur data limit %ld,%ld (soft,hard)", mlim.rlim_cur,
00101 mlim.rlim_max);
00102 mlim.rlim_cur = memlimit;
00103 WARNIF( setrlimit(RLIMIT_DATA,&mlim));
00104 WARNIF( getrlimit(RLIMIT_DATA,&mlim));
00105 MESSAGE(0, "New data limit %ld,%ld (soft,hard)", mlim.rlim_cur,
00106 mlim.rlim_max);
00107 WARNIF( getrlimit(RLIMIT_AS,&mlim));
00108 MESSAGE(0, "Cur address space limit %ld,%ld (soft,hard)",
00109 mlim.rlim_cur, mlim.rlim_max);
00110 mlim.rlim_cur = memlimit;
00111 WARNIF( setrlimit(RLIMIT_AS,&mlim));
00112 WARNIF( getrlimit(RLIMIT_AS,&mlim));
00113 MESSAGE(0, "New address space limit %ld,%ld (soft,hard)",
00114 mlim.rlim_cur, mlim.rlim_max);
00115 mlim.rlim_cur = 0;
00116 WARNIF( setrlimit(RLIMIT_CORE,&mlim));
00117 WARNIF( getrlimit(RLIMIT_CORE,&mlim));
00118 MESSAGE(0, "New core dump space limit %ld,%ld (soft,hard)",
00119 mlim.rlim_cur, mlim.rlim_max);
00120 return;
00121 }
00122
00123