Bug 242641

Summary: [Feature] Include dslimit utility in RHEL5 Distribution
Product: Red Hat Enterprise MRG Reporter: IBM Bug Proxy <bugproxy>
Component: realtime-kernelAssignee: Guy Streeter <streeter>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: 1.0CC: nobody
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 1-2 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-07-26 14:44:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
dslimit script
none
dslimit
none
dslimit
none
dslimit
none
dslimit.1
none
proposed patch
none
dslimit.patch
none
dslimit
none
dslimit.1
none
RPM-packaged dslimit. none

Description IBM Bug Proxy 2007-06-05 09:17:30 UTC
LTC Owner is: dvhltc.com
LTC Originator is: dvhltc.com


dslimit
-------

Purpose
~~~~~~~
'dslimit' is a program to dynamically modify the soft cpu time limit for a
process, without affecting the default time limits of the current shell. This is
very useful while developing applications.

Design
~~~~~~
The program makes use of the 'ulimit' command to change the soft cpu time
limit of a process. 'ulimit' and the program are executed as
sub-commands and so the modified limit is applicable only for that run
of the process and the shell defaults are retained.

Usage
~~~~~
-------------------------------------------------------------------
dslimit [seconds | unlimited] [program [program parameters]]
-------------------------------------------------------------------

dslimit without options prints the current soft cpu time limit.
If no time limit is specified, the program would run with default soft
cpu timeout else, the program is run with the mentioned time, in
seconds, as the soft cpu time limit.

Example 1,
This example runs an application without any cpu time limit in the
background
# dslimit unlimited app &

Example 2,
This example runs a java program with a 60 second timeout
# dslimit 60 javaprog

Category
~~~~~~~~
Debugging tool

Creating an attachment (LTC id 28366)
dslimit script
Attaching dslimit source. ..

Comment 1 IBM Bug Proxy 2007-06-05 09:19:18 UTC
Created attachment 156190 [details]
dslimit script

(This is LTC attachment id 28366)

Comment 3 Guy Streeter 2007-06-26 20:00:01 UTC
The attached script contains an IBM copyright, and does not have a licsense
statement providing for redistribution. I think we need an explicitly
redistributable version.

Comment 4 IBM Bug Proxy 2007-06-26 20:20:51 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|OPEN                        |ASSIGNED




------- Additional Comments From nivedita.com (prefers email at niv.com)  2007-06-26 16:17 EDT -------
Yep, this should be GPL, but the licensing stuff was sitting independently in
our tree. Copyright also needs an update. I'll post an updated version here
by tmrw. --Nivedita 

Comment 5 IBM Bug Proxy 2007-06-28 00:05:40 UTC
Created attachment 158080 [details]
dslimit

Comment 6 IBM Bug Proxy 2007-06-28 00:05:46 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28366|0                           |1
        is obsolete|                            |




------- Additional Comments From nivedita.com (prefers email at niv.com)  2007-06-27 20:01 EDT -------
 
Updated dslimit script

Updated dslimit patch with later version, and added GPL verbage. 

Comment 7 IBM Bug Proxy 2007-06-28 00:06:18 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |FIXEDAWAITINGTEST
         Resolution|                            |FIX_BY_IBM




------- Additional Comments From nivedita.com (prefers email at niv.com)  2007-06-27 20:03 EDT -------
Attached an updated dslimit script which is our current version,
and has license info etc. Please let me know if anything else is
needed. 

Comment 8 Guy Streeter 2007-06-28 21:26:52 UTC
I'm not clear on what dslimit with a single argument is supposed to do. What is
the purpose of these lines?

elif [ $# -eq 1 ]; then
        ($@)


Comment 9 IBM Bug Proxy 2007-06-29 18:25:24 UTC
----- Additional Comments From jatriple.com  2007-06-29 14:23 EDT -------
Without an argument, dslimit just runs the command in a subshell.  The existing
soft CPU limit will apply to the command.

However, it looks like dslimit has a quoting bug when running commands; it uses
$@ rather than "$@", so it breaks when trying to run a script that needs
arguments.  For example:

$ cat ./countargs.sh
#!/bin/sh
echo $#
$ ./countargs.sh 1 2 3
3
$ ./countargs.sh "1 2 3"
1
$ dslimit 1 ./countargs.sh 1 2 3
3
$ dslimit 1 ./countargs.sh "1 2 3"
3 

Comment 10 IBM Bug Proxy 2007-06-29 18:30:44 UTC
Created attachment 158242 [details]
dslimit

Comment 11 IBM Bug Proxy 2007-06-29 18:30:48 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28915 [details]|0                           |1
        is obsolete|                            |




------- Additional Comments From mauery.com (prefers email at vernux.com)  2007-06-29 14:25 EDT -------
 
new version of dslimit with fixes

The usage messages shows that all arguments are optional.

With no arguments specified, dslimit merely executes ulimit -St, which prints
the current cpu time limit.

With one argument specified, dslimit executes the specified program with the
default cpu time limit (or in other words, it just executes prog [program
args...]

With more than one argument, it uses the first argument as the limit and
executes the remaining args as the program.

As I inspected this code, I feel that this is not a really good interface.  For
example, it is not possible to execute a program with one argument at the
default cpu limits.

dslimit top -d1

This would try to use 'top' as the argument for setting the cpu limit and fail.
 I feel the best way to deal with this would be to either do some fancier
parameter parsing to separate programs from arguments or get rid of the default
cpu limit case altogether.  It is not needed -- if you want to execute with the
default cpu limits, just execute the program, don't run dslimit.

I vote to remove the clause in question:
elif [ $# -eq 1 ]; then
	"$@"

I also changed the if statement to the usage clause to be more concise.  Now it
responds to /^[-]+h.*/ as a call for help, rather than just -h --h and -help (I
was going to add --help since that is my favorite, but that was just getting
too verbose). 

Comment 12 IBM Bug Proxy 2007-06-29 18:40:31 UTC
Created attachment 158244 [details]
dslimit

Comment 13 IBM Bug Proxy 2007-06-29 18:40:37 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28963|0                           |1
        is obsolete|                            |




------- Additional Comments From mauery.com (prefers email at vernux.com)  2007-06-29 14:34 EDT -------
 
dslimit fixed take 2

This version of dslimit fixes the quoting problems that josh pointed out and
uses a much simpler expression for usage (also pointed out by josh). 

Comment 14 IBM Bug Proxy 2007-06-29 18:50:18 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-06-29 14:47 EDT -------
I will write and attach a dslimit manpage this afternoon. 

Comment 15 IBM Bug Proxy 2007-06-30 02:55:35 UTC
Created attachment 158281 [details]
dslimit.1

Comment 16 IBM Bug Proxy 2007-06-30 02:55:40 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-06-29 22:44 EDT -------
 
manpage for dslimit

Manpage attached. 

Comment 17 Guy Streeter 2007-07-02 20:37:30 UTC
As written, when the command excceds its CPU limit, it prints

CPU time limit exceeded "$@"

This change will make it print the commandline:

--- dslimit~    2007-07-02 15:26:10.000000000 -0500
+++ dslimit     2007-07-02 15:28:27.000000000 -0500
@@ -47,7 +47,10 @@
 if [ $# -eq 0 ]; then
        ulimit -St
 else
-       (ulimit -St $1; shift; "$@")
+       a="$1"
+       shift
+       b="$@"
+       eval "ulimit -St $a; $b"
 fi
 
 exit 0


I'm not the shell expert, so there may be a better way to accomplish it

Comment 18 Guy Streeter 2007-07-02 20:47:01 UTC
Some more suggestions:

eval "ulimit -St $a && $b"

will cause the script to exit if ulimit fails. And changing the last line to

exit $?

will cause the script to exit with the exit status of the command (or ulimit, if
ulimit fails).


Comment 19 Guy Streeter 2007-07-02 20:58:31 UTC
Created attachment 158379 [details]
proposed patch

A single argument should be treated as a syntax error. Here is my complete
proposed change.

Comment 20 IBM Bug Proxy 2007-07-02 21:36:04 UTC
Created attachment 158381 [details]
dslimit.patch

Comment 21 IBM Bug Proxy 2007-07-02 21:36:10 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #29005|0                           |1
        is obsolete|                            |




------- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-02 17:30 EDT -------
 
No need for a subshell; print usage with one argument; set -e.

The patch in attachment 29005 breaks quoting:
$ ./dslimit 1 /tmp/countargs.sh "1 2 3"
3

This patch should address the same issues and not break quoting.  It uses set
-e to exit if any command fails, to avoid the need for &&.  Also, rather than
using a subshell, it just runs the commands in dslimit directly.  The dslimit
shell script itself provides the subshell to avoid running ulimit in the parent
shell.	Finally, this runs the command with exec rather than leaving the
dslimit shell script running.

With this patch:
$ ./dslimit 1 /tmp/countargs.sh 1 2 3
3
$ ./dslimit 1 /tmp/countargs.sh "1 2 3"
1
$ ./dslimit 1 /tmp/spin.sh
CPU time limit exceeded 

Comment 22 IBM Bug Proxy 2007-07-02 21:40:30 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-02 17:34 EDT -------
Also with the patched dslimit, to show that set -e works:

$ ./dslimit ... true
./dslimit: line 54: ulimit: ...: invalid number
$ echo $?
1 

Comment 23 Guy Streeter 2007-07-05 19:29:19 UTC
One last suggestion regarding the usage text. How about:

dslimit [LIMIT PROG [ARGS ...]]

Where LIMIT is seconds or "unlimited"
etc.


Comment 24 IBM Bug Proxy 2007-07-10 17:41:00 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-10 13:37 EDT -------
I've implemented that suggested change to usage, along with a couple of minor
cleanups: removing a redundant descriptive comment in dslimit in favor of the
usage and the manpage, and exiting unsuccessfully when given incorrect
arguments.  Will attach new dslimit and manpage. 

Comment 25 IBM Bug Proxy 2007-07-10 17:45:31 UTC
Created attachment 158874 [details]
dslimit

Comment 26 IBM Bug Proxy 2007-07-10 17:45:38 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28964|0                           |1
        is obsolete|                            |
  Attachment #29006|0                           |1
        is obsolete|                            |




------- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-10 13:39 EDT -------
 
New dslimit with requested usage fix and other cleanups. 

Comment 27 IBM Bug Proxy 2007-07-10 17:46:58 UTC
Created attachment 158875 [details]
dslimit.1

Comment 28 IBM Bug Proxy 2007-07-10 17:47:05 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28968|0                           |1
        is obsolete|                            |




------- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-10 13:42 EDT -------
 
Manpage for dslimit 

Comment 29 Guy Streeter 2007-07-16 20:25:50 UTC
Created attachment 159371 [details]
RPM-packaged dslimit.

Comment 30 Guy Streeter 2007-07-16 20:27:42 UTC
This is my first pass at a src rpm for the dslimit package.

Comment 31 IBM Bug Proxy 2007-07-23 20:06:27 UTC
changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |FIXEDAWAITINGTEST
         Resolution|                            |FIX_BY_IBM




------- Additional Comments From jstultz.com (prefers email at johnstul.com)  2007-07-23 16:03 EDT -------
dslimit package is available in rh's repo. marking this as fixed awaiting test. 

Comment 32 IBM Bug Proxy 2007-07-23 20:18:45 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-23 16:12 EDT -------
ftp://partners.redhat.com/f227cee111ab00ba82e0e42dc49c63a2/x86_64/src/dslimit-1-1.el5rt.src.rpm
seems a bit broken; it contains a file named .tar.bz2 which actually contains a
*gzipped* tarball:
dslimit.tar.bz2: gzip compressed data, from Unix, last modified: Thu Jul 12
13:53:54 2007 

Comment 33 Guy Streeter 2007-07-23 20:26:20 UTC
I believe you are mistaken. I downloaded the file from the URL and looked at it:

$ rpm2cpio dslimit-1-1.el5rt.src.rpm |cpio -tv
-rw-r--r--   1 root     root          723 Jul 17 14:48 dslimit.spec
-rw-r--r--   1 root     root         1265 Jul 17 14:48 dslimit.tar.bz2

I installed it with rpm -i and looked in the SOURCES directory:

$ ll SOURCES/
total 8
-rw-r--r-- 1 streeter streeter 1265 Jul 17 14:48 dslimit.tar.bz2


Comment 34 IBM Bug Proxy 2007-07-23 20:55:14 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-23 16:51 EDT -------
The output you just showed doesn't contradict what I said.  The rpm does have a
file named .tar.bz2, as you point out, but the contents of that file actually
have a gzipped tarball, not a bzip2ed tarball as the filename would suggest:

$ rpm2cpio dslimit-1-1.el5rt.src.rpm | cpio -iv
dslimit.spec
dslimit.tar.bz2
5 blocks
$ file dslimit.tar.bz2
dslimit.tar.bz2: gzip compressed data, from Unix, last modified: Thu Jul 12
13:53:54 2007
$ tar tvvjf dslimit.tar.bz2
bzip2: (stdin) is not a bzip2 file.
tar: Child returned status 2
tar: Error exit delayed from previous errors
$ tar tvvzf dslimit.tar.bz2
drwxrwxr-x streeter/streeter 0 2007-07-12 13:53 dslimit-1/
-rw-r--r-- streeter/streeter 123 2007-07-12 13:53 dslimit-1/Makefile
-rw-r--r-- streeter/streeter 1200 2007-07-12 12:09 dslimit-1/dslimit
-rw-r--r-- streeter/streeter 1199 2007-07-12 12:09 dslimit-1/dslimit.1 

Comment 35 Guy Streeter 2007-07-23 21:03:14 UTC
I misunderstood. When you said there was a file named .tar.bz2, I though you
meant there was a file named .tar.bz2, not a filename ending in .tar.bz2

I'll try to figure out the best way to fix that. It isn't a bad bug, since rpm
does the right thing with it, but we may as well get it right.

Comment 36 IBM Bug Proxy 2007-07-23 22:05:40 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-23 18:02 EDT -------
Ah, sorry.  Poor choice of words; a file named with a .tar.bz2 extension, yes. :) 

Comment 37 Guy Streeter 2007-07-25 21:11:48 UTC
I have pushed dslimit-1-2, which has a properly bzipped file.

Comment 38 IBM Bug Proxy 2007-07-30 20:15:35 UTC
----- Additional Comments From jatriple.com (prefers email at josht.ibm.com)  2007-07-30 16:09 EDT -------
Confirmed; dslimit-1-2 includes dslimit.tar.bz2 as a properly bzipped tarball. 
Thanks! 

Comment 39 IBM Bug Proxy 2008-01-31 10:16:51 UTC
------- Comment From sripathi.com 2008-01-31 05:13 EDT-------
Closing.