> > 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.
> ...

And now find attached a patch for the

 static void pushlimit(int resource, struct RLIMIT_STRUCT_TAG *rlp,
                       int trace_rlimit)

procedure from

 source/daemons/shepherd/setrlimits.c

that does away with the backspace construct.

The "many eyes" will no doubt also note that in the block near
the end for

#if defined(NECSX4) || defined(NECSX5)

the string that got created following a failure was never presented
to a shepherd_trace() for output, so I've fixed that too !

The patch is made against a ge-V62u5_TAG source tree.

Hoping this is useful: it is for me,
Kevin

-- 
Kevin M. Buckley                                  Room:  CO327
School of Engineering and                         Phone: +64 4 463 5971
 Computer Science
Victoria University of Wellington
New Zealand
Get rid of non printable character in output that will cause some MUA's to
base64 encode the shepherd trace output.

--- source/daemons/shepherd/setrlimits.c.orig	2009-07-08 20:28:16.000000000 +1200
+++ source/daemons/shepherd/setrlimits.c	2011-08-09 16:10:04.000000000 +1200
@@ -610,10 +610,23 @@
 {
    const char *limit_str;
    char trace_str[1024];
+   char trace_str2[1024];
    struct RLIMIT_STRUCT_TAG dlp;
    int resource_type;
    int ret;
 
+#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
+
    if (get_resource_info(resource, &limit_str, &resource_type)) {
       sprintf(trace_str, "no %d-resource-limits set because "
          "unknown resource", resource);
@@ -635,18 +648,6 @@
       if (rlp->rlim_max < rlp->rlim_cur)
          rlp->rlim_cur = rlp->rlim_max;
 
-#if defined(NECSX4) || defined(NECSX5) || defined(NETBSD_ALPHA) || defined(NETBSD_X86_64) || defined(NETBSD_SPARC64)
-#  define limit_fmt "%ld%s"
-#elif defined(IRIX) || defined(HPUX) || defined(DARWIN) || defined(FREEBSD) || defined(NETBSD) || defined(INTERIX)
-#  define limit_fmt "%lld%s"
-#elif (defined(LINUX) && defined(TARGET_32BIT))
-#  define limit_fmt "%llu%s"
-#elif defined(ALPHA) || defined(SOLARIS) || defined(LINUX)
-#  define limit_fmt "%lu%s"
-#else
-#  define limit_fmt "%d%s"
-#endif
-
       sge_switch2start_user();
 #if defined(IRIX)
       ret = setrlimit64(resource, rlp);
@@ -656,9 +657,26 @@
       sge_switch2admin_user();  
       if (ret) {
          /* exit or not exit ? */
-         sprintf(trace_str, "setrlimit(%s, {"limit_fmt", "limit_fmt"}) failed: %s",
-            limit_str, FORMAT_LIMIT(rlp->rlim_cur), FORMAT_LIMIT(rlp->rlim_max), strerror(errno));
-            shepherd_trace(trace_str);
+         sprintf(trace_str, "setrlimit(%s, {", limit_str ) ;
+         if( rlp->rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, rlp->rlim_cur ) ;
+         }
+ 
+         strcat(trace_str2, ", ") ;
+         if( rlp->rlim_max == RLIMIT_INFINITY ) {
+           sprintf(trace_str, "%sINFINITY", trace_str2 ) ;
+         }
+         else {
+           strcat(trace_str2, limit_fmt) ;
+           sprintf(trace_str, trace_str2, rlp->rlim_max ) ;
+         }
+         sprintf(trace_str2, "%s) failed: %s", trace_str, strerror(errno) ) ;
+
+         shepherd_trace(trace_str2);
       } else {
 #if defined(IRIX)
          getrlimit64(resource,&dlp);
@@ -668,13 +686,43 @@
       }
 
       if (trace_rlimit) {
-         sprintf(trace_str, "%s setting: (soft "limit_fmt" hard "limit_fmt") "
-            "resulting: (soft "limit_fmt" hard "limit_fmt")",
-            limit_str,
-            FORMAT_LIMIT(rlp->rlim_cur),
-            FORMAT_LIMIT(rlp->rlim_max),
-            FORMAT_LIMIT(dlp.rlim_cur),
-            FORMAT_LIMIT(dlp.rlim_max));
+         sprintf(trace_str, "%s setting: (soft ", limit_str ) ;
+         if( rlp->rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, rlp->rlim_cur ) ;
+         }
+ 
+         strcat(trace_str2, " hard ") ;
+         if( rlp->rlim_max == RLIMIT_INFINITY ) {
+           sprintf(trace_str, "%sINFINITY", trace_str2 ) ;
+         }
+         else {
+           strcat(trace_str2, limit_fmt) ;
+           sprintf(trace_str, trace_str2, rlp->rlim_max ) ;
+         }
+
+         strcat(trace_str, ") resulting: (soft " ) ;
+         if( dlp.rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, dlp.rlim_cur ) ;
+         }
+ 
+         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 ) ;
+         }
+         strcat(trace_str, ")" ) ;
+
          shepherd_trace(trace_str);
       }
    }
@@ -698,9 +746,26 @@
       sge_switch2start_user();
       if (setrlimitj(get_rlimits_os_job_id(), resource, rlp)) {
          /* exit or not exit ? */
-         sprintf(trace_str, "setrlimitj(%s, {"limit_fmt", "limit_fmt"}) "
-            "failed: %s", limit_str, FORMAT_LIMIT(rlp->rlim_cur), FORMAT_LIMIT(rlp->rlim_max),
-            strerror(errno));
+         sprintf(trace_str, "setrlimitj(%s, {", limit_str ) ;
+         if( rlp->rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, rlp->rlim_cur ) ;
+         }
+ 
+         strcat(trace_str2, ", ") ;
+         if( rlp->rlim_max == RLIMIT_INFINITY ) {
+           sprintf(trace_str, "%sINFINITY", trace_str2 ) ;
+         }
+         else {
+           strcat(trace_str2, limit_fmt) ;
+           sprintf(trace_str, trace_str2, rlp->rlim_max ) ;
+         }
+         sprintf(trace_str2, "%s) failed: %s", trace_str, strerror(errno) ) ;
+
+         shepherd_trace(trace_str2);
       } else {
          getrlimitj(get_rlimits_os_job_id(), resource,&dlp);
       }
@@ -708,13 +773,43 @@
 #endif
 
       if (trace_rlimit) {
-         sprintf(trace_str, "Job %s setting: (soft "limit_fmt" hard "limit_fmt
-            ") resulting: (soft "limit_fmt" hard "limit_fmt")",
-            limit_str,
-            FORMAT_LIMIT(rlp->rlim_cur),
-            FORMAT_LIMIT(rlp->rlim_max),
-            FORMAT_LIMIT(dlp.rlim_cur),
-            FORMAT_LIMIT(dlp.rlim_max));
+         sprintf(trace_str, "%s setting: (soft ", limit_str ) ;
+         if( rlp->rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, rlp->rlim_cur ) ;
+         }
+ 
+         strcat(trace_str2, " hard ") ;
+         if( rlp->rlim_max == RLIMIT_INFINITY ) {
+           sprintf(trace_str, "%sINFINITY", trace_str2 ) ;
+         }
+         else {
+           strcat(trace_str2, limit_fmt) ;
+           sprintf(trace_str, trace_str2, rlp->rlim_max ) ;
+         }
+
+         strcat(trace_str, ") resulting: (soft " ) ;
+         if( dlp.rlim_cur == RLIMIT_INFINITY ) {
+           sprintf(trace_str2, "%sINFINITY", trace_str ) ;
+         }
+         else {
+           strcat(trace_str, limit_fmt) ;
+           sprintf(trace_str2, trace_str, dlp.rlim_cur ) ;
+         }
+ 
+         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 ) ;
+         }
+         strcat(trace_str, ")" ) ;
+
          shepherd_trace(trace_str);
       }
    }
_______________________________________________
users mailing list
users@gridengine.org
https://gridengine.org/mailman/listinfo/users

Reply via email to