zsh-workers
 help / color / mirror / code / Atom feed
* -M option for limit
@ 1996-01-08 17:39 Zefram
  1996-01-10  8:51 ` P.Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1996-01-08 17:39 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

The patch below adds the -M option to limit.  To make this a little
easier, it also modifies limit so that it accepts the hh:mm:ss form to
set the cputime limit.  This is the form already used for output, and
silently misinterpreted if used to set the limit.  I also improved
error detection.  Finally, it moves the test for attempts to remove
hard limits in unlimit, so that "unlimit -h foosize" is not an error if
run by a mere mortal, provided the foosize resource is already
unlimited.

I think the limit syntax would be much more consistent if it were
changed from "limit resource value" to "limit resource=value".  This
would allow arbitrary mixtures of setting and examining resource
limits, as is already possible with things like typeset and alias.  The
limit builtin is rather well-established, though, so if it's going to
be changed it really can't be delayed.  Any opinions?

 -zefram

      *** 1.7	1996/01/08 12:43:57
      --- Src/builtin.c	1996/01/08 17:03:56
      ***************
      *** 3538,3544 ****
            }
            /* without arguments, display limits */
            if (!*argv) {
      ! 	showlimits(hard, -1);
        	return 0;
            }
            while ((s = *argv++)) {
      --- 3538,3544 ----
            }
            /* without arguments, display limits */
            if (!*argv) {
      ! 	showlimits(hard, ops['M'], -1);
        	return 0;
            }
            while ((s = *argv++)) {
      ***************
      *** 3562,3584 ****
        	}
        	/* without value for limit, display the current limit */
        	if (!(s = *argv++)) {
      ! 	    showlimits(hard, lim);
        	    return 0;
        	}
        	if (lim==RLIMIT_CPU) {
      ! 	    /* time-type resource -- may be specified as seconds, or minutes or *
      ! 	     * hours with the `m' and `h' modifiers, and `:' may be used to add *
      ! 	     * together more than one of these.  It's easier to understand from *
      ! 	     * the code:                                                        */
        	    val = zstrtol(s, &s, 10);
        	    if (*s)
        		if ((*s == 'h' || *s == 'H') && !s[1])
        		    val *= 3600L;
        		else if ((*s == 'm' || *s == 'M') && !s[1])
        		    val *= 60L;
      ! 		else if (*s == ':')
        		    val = val * 60 + zstrtol(s + 1, &s, 10);
      ! 		else {
        		    zwarnnam("limit", "unknown scaling factor: %s", s, 0);
        		    return 1;
        		}
      --- 3562,3589 ----
        	}
        	/* without value for limit, display the current limit */
        	if (!(s = *argv++)) {
      ! 	    showlimits(hard, ops['M'], lim);
        	    return 0;
        	}
        	if (lim==RLIMIT_CPU) {
      ! 	    /* time-type resource -- may be specified as seconds, or minutes *
      ! 	     * or hours with the `m' and `h' modifiers, and `:' may be used  *
      ! 	     * to add together more than one of these.  It's easier to       *
      ! 	     * understand from the code:                                     */
        	    val = zstrtol(s, &s, 10);
        	    if (*s)
        		if ((*s == 'h' || *s == 'H') && !s[1])
        		    val *= 3600L;
        		else if ((*s == 'm' || *s == 'M') && !s[1])
        		    val *= 60L;
      ! 		else if (*s == ':') {
        		    val = val * 60 + zstrtol(s + 1, &s, 10);
      ! 		    if(*s == ':')
      ! 			val = val * 60 + zstrtol(s + 1, &s, 10);
      ! 		    if(*s)
      ! 			goto badscaling;
      ! 		} else {
      ! 		badscaling:
        		    zwarnnam("limit", "unknown scaling factor: %s", s, 0);
        		    return 1;
        		}
      ***************
      *** 3642,3659 ****
            zwarnnam(nam, "not available on this system", NULL, 0);
            return 1;
        #else
      !     int hard, limnum, lim;
        
      -     hard = ops['h'];
      -     /* can only remove hard limits if running as root */
      -     if (hard && geteuid()) {
      - 	zwarnnam(nam, "can't remove hard limits", NULL, 0);
      - 	return 1;
      -     }
            /* Without arguments, remove all limits. */
            if (!*argv) {
        	for (limnum = 0; limnum != RLIM_NLIMITS; limnum++) {
      ! 	    if (hard)
        		limits[limnum].rlim_max = RLIM_INFINITY;
        	    else
        		limits[limnum].rlim_cur = limits[limnum].rlim_max;
      --- 3647,3661 ----
            zwarnnam(nam, "not available on this system", NULL, 0);
            return 1;
        #else
      !     int hard=ops['h'], limnum, lim;
        
            /* Without arguments, remove all limits. */
            if (!*argv) {
        	for (limnum = 0; limnum != RLIM_NLIMITS; limnum++) {
      ! 	    if (hard && geteuid() && limits[limnum].rlim_max != RLIM_INFINITY) {
      ! 		zwarnnam(nam, "can't remove hard limits", NULL, 0);
      ! 		return 1;
      ! 	    } else if (hard)
        		limits[limnum].rlim_max = RLIM_INFINITY;
        	    else
        		limits[limnum].rlim_cur = limits[limnum].rlim_max;
      ***************
      *** 3680,3686 ****
        	    return 1;
        	}
        	/* remove specified limit */
      ! 	if (hard)
        	    limits[lim].rlim_max = RLIM_INFINITY;
        	else
        	    limits[lim].rlim_cur = limits[lim].rlim_max;
      --- 3682,3691 ----
        	    return 1;
        	}
        	/* remove specified limit */
      ! 	if (hard && geteuid() && limits[lim].rlim_max != RLIM_INFINITY) {
      ! 	    zwarnnam(nam, "can't remove hard limits", NULL, 0);
      ! 	    return 1;
      ! 	} else if (hard)
        	    limits[lim].rlim_max = RLIM_INFINITY;
        	else
        	    limits[lim].rlim_cur = limits[lim].rlim_max;
      ***************
      *** 3820,3836 ****
        #ifdef HAVE_GETRLIMIT
        /**/
        void
      ! showlimits(int hard, int lim)
        {
            int rt;
      !     RLIM_T val;
        
            /* main loop over resource types */
            for (rt = 0; rt != RLIM_NLIMITS; rt++)
        	if (rt == lim || lim == -1) {
        	    /* display limit for resource number rt */
        	    printf("%-16s", recs[rt]);
      - 	    val = (hard) ? limits[rt].rlim_max : limits[rt].rlim_cur;
        	    if (val == RLIM_INFINITY)
        		printf("unlimited\n");
        	    else if (rt==RLIMIT_CPU)
      --- 3825,3848 ----
        #ifdef HAVE_GETRLIMIT
        /**/
        void
      ! showlimits(int hard, int list, int lim)
        {
            int rt;
      !     char *H = hard ? " -h" : "";
      !     char *B = list ? "" : "B";
        
            /* main loop over resource types */
            for (rt = 0; rt != RLIM_NLIMITS; rt++)
        	if (rt == lim || lim == -1) {
        	    /* display limit for resource number rt */
      +     	    RLIM_T val = (hard) ? limits[rt].rlim_max : limits[rt].rlim_cur;
      + 	    if(list && val == RLIM_INFINITY) {
      + 		printf("unlimit%s %s\n", H, recs[rt]);
      + 		continue;
      + 	    }
      + 	    if(list)
      + 		printf("limit  %s ", H);
        	    printf("%-16s", recs[rt]);
        	    if (val == RLIM_INFINITY)
        		printf("unlimited\n");
        	    else if (rt==RLIMIT_CPU)
      ***************
      *** 3851,3863 ****
        	    else if (val >= 1024L * 1024L)
        		/* memory resource -- display with `K' or `M' modifier */
        # ifdef RLIM_T_IS_QUAD_T
      ! 		printf("%qdMB\n", val / (1024L * 1024L));
        	    else
      ! 		printf("%qdkB\n", val / 1024L);
        # else
      ! 		printf("%ldMB\n", val / (1024L * 1024L));
                    else
      ! 		printf("%ldkB\n", val / 1024L);
        # endif /* RLIM_T_IS_QUAD_T */
        	}
        }
      --- 3863,3875 ----
        	    else if (val >= 1024L * 1024L)
        		/* memory resource -- display with `K' or `M' modifier */
        # ifdef RLIM_T_IS_QUAD_T
      ! 		printf("%qdM%s\n", val / (1024L * 1024L), B);
        	    else
      ! 		printf("%qdk%s\n", val / 1024L, B);
        # else
      ! 		printf("%ldM%s\n", val / (1024L * 1024L), B);
                    else
      ! 		printf("%ldk%s\n", val / 1024L, B);
        # endif /* RLIM_T_IS_QUAD_T */
        	}
        }
      *** 1.5	1996/01/08 12:43:57
      --- Src/hashtable.h	1996/01/08 16:37:20
      ***************
      *** 278,284 ****
            {NULL, "jobs", 0, bin_fg, 0, -1, BIN_JOBS, "lpZrs", NULL},
            {NULL, "kill", 0, bin_kill, 0, -1, 0, NULL, NULL},
            {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      !     {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
            {NULL, "local", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRZilrtu", NULL},
            {NULL, "log", 0, bin_log, 0, 0, 0, NULL, NULL},
            {NULL, "logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL},
      --- 278,284 ----
            {NULL, "jobs", 0, bin_fg, 0, -1, BIN_JOBS, "lpZrs", NULL},
            {NULL, "kill", 0, bin_kill, 0, -1, 0, NULL, NULL},
            {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      !     {NULL, "limit", 0, bin_limit, 0, -1, 0, "shM", NULL},
            {NULL, "local", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRZilrtu", NULL},
            {NULL, "log", 0, bin_log, 0, 0, 0, NULL, NULL},
            {NULL, "logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL},
      *** 1.5	1996/01/08 12:43:57
      --- Doc/zshbuiltins.man	1996/01/08 17:24:47
      ***************
      *** 491,508 ****
        value of the last expression is nonzero, and 1 otherwise.
        .TP
        .PD 0
      ! \fBlimit\fP [ \-\fBh\fP ] [ \fIresource\fP [ \fIlimit\fP ] ] ...
        .TP
        \fBlimit\fP \-\fBs\fP
        .PD
        Limit the resource consumption of the current shell and its children.
        If \fIlimit\fP is not specified, print the current limit placed
      ! on \fIresource\fP; otherwise
      ! set the limit to the specified value.  If the \-\fBh\fP flag
      ! is given, use hard limits instead of soft limits.
        If no \fIresource\fP is given, print all limits.
        .RS
        .PP
        \fIresource\fP is one of:
        .PP
        .PD 0
      --- 491,518 ----
        value of the last expression is nonzero, and 1 otherwise.
        .TP
        .PD 0
      ! \fBlimit\fP [ \-\fBhM\fP ] [ \fIresource\fP [ \fIlimit\fP ] ] ...
        .TP
        \fBlimit\fP \-\fBs\fP
        .PD
        Limit the resource consumption of the current shell and its children.
        If \fIlimit\fP is not specified, print the current limit placed
      ! on \fIresource\fP; otherwise set the limit to the specified value.
      ! Multiple resources with limits may be specified.
        If no \fIresource\fP is given, print all limits.
      + When printing limits, the \-\fBM\fP flag causes the limits to be
      + printed in the form of
      + .B limit
      + and
      + .B unlimit
      + commands.
      + If the \-\fBh\fP flag is given, use hard limits instead of soft limits.
        .RS
        .PP
      + If the \-\fBs\fP flag is used, arguments are ignored, and the currently
      + selected limits are applied to the shell itself.  Otherwise, the limits
      + only apply to child processes.
      + .PP
        \fIresource\fP is one of:
        .PP
        .PD 0
      ***************
      *** 546,563 ****
        .PP
        .PD 0
        .TP
      ! \fIn\fPh
        hours.
        .TP
      ! \fIn\fPk
        kilobytes. 
        This is the default for all but cputime.
        .TP
      ! \fIn\fPm
        megabytes or minutes.
        .TP
      ! \fImm\fP:\fIss\fP
        minutes and seconds.
        .PD
        .RE
        .TP
      --- 556,576 ----
        .PP
        .PD 0
        .TP
      ! .IR n h
        hours.
        .TP
      ! .IR n k
        kilobytes. 
        This is the default for all but cputime.
        .TP
      ! .IR n m
        megabytes or minutes.
        .TP
      ! .IR mm : ss
        minutes and seconds.
      + .TP
      + .IR hh : mm : ss
      + hours, minutes and seconds.
        .PD
        .RE
        .TP

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQCVAgUBMPFWtHD/+HJTpU/hAQHP2gP+NPlKWKS+oqYD/ofZaENQBgbUdiX7m9+R
aniAYbAiMefptbWVj+WtUry9KOEAoa8jY+pY/x3T1CExGBuKqIeM1pNcNM3UgzxD
99U7tHkuPOQjfK+x35uDzCa3JRPVEwqEMfPcPJt4zf8mhrjwtBK0wbAd7yfe1bLI
X9zDIBv+Nhc=
=y6ER
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -M option for limit
  1996-01-08 17:39 -M option for limit Zefram
@ 1996-01-10  8:51 ` P.Stephenson
  1996-01-10  9:28   ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: P.Stephenson @ 1996-01-10  8:51 UTC (permalink / raw)
  To: Zsh hackers list

A.Main@dcs.warwick.ac.uk wrote:
> I think the limit syntax would be much more consistent if it were
> changed from "limit resource value" to "limit resource=value".  This
> would allow arbitrary mixtures of setting and examining resource
> limits, as is already possible with things like typeset and alias.  The
> limit builtin is rather well-established, though, so if it's going to
> be changed it really can't be delayed.  Any opinions?

I think this would be an unnecessary incompatibility.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -M option for limit
  1996-01-10  8:51 ` P.Stephenson
@ 1996-01-10  9:28   ` Zefram
  0 siblings, 0 replies; 3+ messages in thread
From: Zefram @ 1996-01-10  9:28 UTC (permalink / raw)
  To: P.Stephenson; +Cc: zsh-workers

Peter wrote:
>A.Main@dcs.warwick.ac.uk wrote:
>> I think the limit syntax would be much more consistent if it were
>> changed from "limit resource value" to "limit resource=value".  This
>> would allow arbitrary mixtures of setting and examining resource
>> limits, as is already possible with things like typeset and alias.  The
>> limit builtin is rather well-established, though, so if it's going to
>> be changed it really can't be delayed.  Any opinions?
>
>I think this would be an unnecessary incompatibility.

Actually I've come up with a good compromise.  If we simply require
limit values to start with a digit (i.e. don't allow "k" to mean "0k"),
it would be possible to unambiguously specify multiple resources on the
command line, each with an optional limit.  For example, "limit core
desc 32 vmem" would display the limits for coredumpsize and
vmemorysize, and set descriptors to 32.  bash's ulimit works much this
way, though with option flags rather than keywords.  At some point I'd
like to modify zsh's ulimit to work like bash's, and do this equivalent
to limit as well.

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-01-10  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-01-08 17:39 -M option for limit Zefram
1996-01-10  8:51 ` P.Stephenson
1996-01-10  9:28   ` Zefram

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).