Am 09.08.2011 um 01:23 schrieb kevin.buck...@ecs.vuw.ac.nz: >> Fine, but I'm not sure whether I suggested a suitable solution or only a >> workaround which introduces a new bug: a real set limit of zero can't be >> ouptut any longer. Well, a real limit for h_vmem or h_rt being 0 isn't >> reasonable at all... >> >> You would have to test against 0 and output 0 as a string in this case to >> get the correct output. >> >> I think the original author tried to avoid several if-then-else tests >> there, but maybe such an implementation is the only one being correct. >> >> -- Reuti > > You mean something like this, which does away with the macros > altogether. > > ------8<-------------8<-------------8<-------------8<-------------8<------- > #include <stdio.h> > #include <string.h> > #include <stdlib.h> > #include <errno.h> > > #if defined(DARWIN) || defined(FREEBSD) || defined(NETBSD) > # include <sys/time.h> > #endif > > #if defined(CRAY) > # include <sys/param.h> > # include <sys/unistd.h> > # include <sys/category.h> > #endif > > #include <sys/resource.h> > > #if defined(IRIX) > # define RLIMIT_STRUCT_TAG rlimit64 > # define RLIMIT_INFINITY RLIM64_INFINITY > #else > # define RLIMIT_STRUCT_TAG rlimit > # define RLIMIT_INFINITY RLIM_INFINITY > #endif > > int main( void ) { > > /* int resource = RLIMIT_CORE ; */ > int resource = RLIMIT_FSIZE ; > > char trace_str[1024]; > char trace_str2[1024]; > > #if defined(NECSX4) || defined(NECSX5) || defined(NETBSD_ALPHA) || > defined(NETBSD_X86_64) || defined(NETBSD_SPARC64) > char *limit_fmt = "%ld" ; > #elif defined(IRIX) || defined(HPUX) || defined(DARWIN) || > defined(FREEBSD) || defined(NETBSD) || defined(INTERIX) > char *limit_fmt = "%lld" ; > #elif (defined(LINUX) && defined(TARGET_32BIT)) > char *limit_fmt = "%llu"; > #elif defined(ALPHA) || defined(SOLARIS) || defined(LINUX) > char *limit_fmt = "%lu" ; > #else > char *limit_fmt = "%d" ; > #endif > > struct RLIMIT_STRUCT_TAG dlp; > > #if defined(IRIX) > getrlimit64(resource,&dlp); > #else > getrlimit(resource,&dlp); > #endif > > dlp.rlim_max = RLIMIT_INFINITY ; > > strcpy(trace_str, "soft ") ; > if( dlp.rlim_cur == RLIMIT_INFINITY ) { > sprintf(trace_str2, "%sINFINITY", trace_str ) ;
Yeah, exactly. But although it's tricky to use two buffers trace_str and trace_str2 for alternating assignments, I would suggest to use only one for the final string. strcat(trace_str, "INFINITY"); > } > else { > strcat(trace_str, limit_fmt) ; > sprintf(trace_str2, trace_str, dlp.rlim_cur ) ; sprintf(&trace_str[strlen(trace_str)], limit_fmt, dlp.rlim_cur); Maybe Dave can make a statement what he prefers putting into the repository. -- Reuti > } > > strcat(trace_str2, " hard ") ; > if( dlp.rlim_max == RLIMIT_INFINITY ) { > sprintf(trace_str, "%sINFINITY", trace_str2 ) ; > } > else { > strcat(trace_str2, limit_fmt) ; > sprintf(trace_str, trace_str2, dlp.rlim_max ) ; > } > printf( "%s\n", trace_str ); > > return(0); > > } > ------8<-------------8<-------------8<-------------8<-------------8<------- > > and just keep adding parts of the string required for the > shepherd trace, whilst swapping trace_str and trace_str2. > > Either that or steal the formatting code from some shell's > ulimit builtin? > > -- > Kevin M. Buckley Room: CO327 > School of Engineering and Phone: +64 4 463 5971 > Computer Science > Victoria University of Wellington > New Zealand > > _______________________________________________ > users mailing list > users@gridengine.org > https://gridengine.org/mailman/listinfo/users _______________________________________________ users mailing list users@gridengine.org https://gridengine.org/mailman/listinfo/users