zsh-workers
 help / color / mirror / code / Atom feed
* "ulimit -c junk" silently treated as "ulimit -c 0"
@ 2010-01-02 22:45 Kalle Olavi Niemitalo
  2010-01-05 15:52 ` Peter Stephenson
  2010-01-05 16:24 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Kalle Olavi Niemitalo @ 2010-01-02 22:45 UTC (permalink / raw)
  To: zsh-workers

When I switched from bash to zsh, I copied this to my .zprofile:

  ulimit -c hard

In bash, it sets the soft limit of core dump size to be the same
as the hard limit.  In zsh 4.3.10 though, I now see it just makes
the soft limit zero and returns success:

Kalle@Pulska:~ 1% ulimit -H -c 54321; ulimit -S -c 12345
Kalle@Pulska:~ 1% ulimit -H -c
54321
Kalle@Pulska:~ 1% ulimit -S -c
12345
Kalle@Pulska:~ 1% ulimit -c hard
Kalle@Pulska:~ 1% echo $?
0
Kalle@Pulska:~ 1% ulimit -H -c
54321
Kalle@Pulska:~ 1% ulimit -S -c
0
Kalle@Pulska:~ 1% 

The same appears to happen with any unsupported word such as
"junk"; it is not specific to "hard".  In bash 4.0.33, I instead
get an error message:

Kalle@Pulska:~$ ulimit -c junk
bash: ulimit: junk: invalid number
Kalle@Pulska:~$ echo $?
1
Kalle@Pulska:~$ 

I think zsh should do the same as bash here, i.e. output an error
message and return failure.


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

* Re: "ulimit -c junk" silently treated as "ulimit -c 0"
  2010-01-02 22:45 "ulimit -c junk" silently treated as "ulimit -c 0" Kalle Olavi Niemitalo
@ 2010-01-05 15:52 ` Peter Stephenson
  2010-01-05 16:24 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2010-01-05 15:52 UTC (permalink / raw)
  To: zsh-workers

> "ulimit -c junk" silently treated as "ulimit -c 0"

Yes, that's quite poor.

Index: Src/Builtins/rlimits.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Builtins/rlimits.c,v
retrieving revision 1.20
diff -u -r1.20 rlimits.c
--- Src/Builtins/rlimits.c	6 Jul 2007 21:52:40 -0000	1.20
+++ Src/Builtins/rlimits.c	5 Jan 2010 15:49:59 -0000
@@ -680,7 +680,7 @@
 bin_ulimit(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 {
     int res, resmask = 0, hard = 0, soft = 0, nres = 0, all = 0, ret = 0;
-    char *options;
+    char *options, *eptr, *number;
 
     do {
 	options = *argv;
@@ -704,13 +704,18 @@
 		    continue;
 		case 'N':
 		    if (options[1]) {
-			res = (int)zstrtol(options+1, NULL, 10);
+			number = options + 1;
 		    } else if (*argv) {
-			res = (int)zstrtol(*argv++, NULL, 10);
+			number = *argv++;
 		    } else {
 			zwarnnam(name, "number required after -N");
 			return 1;
 		    }
+		    res = (int)zstrtol(number, &eptr, 10);
+		    if (*eptr) {
+			zwarnnam(name, "invalid number: %s", number);
+			return 1;
+		    }
 		    /*
 		     * fake it so it looks like we just finished an option...
 		     */
@@ -831,38 +836,43 @@
 	    /* set limit to specified value */
 	    rlim_t limit;
 
-	    limit = zstrtorlimt(*argv, NULL, 10);
-	    /* scale appropriately */
-	    switch (res) {
-	    case RLIMIT_FSIZE:
-	    case RLIMIT_CORE:
-		limit *= 512;
-		break;
-	    case RLIMIT_DATA:
-	    case RLIMIT_STACK:
+	    limit = zstrtorlimt(*argv, &eptr, 10);
+	    if (*eptr) {
+		zwarnnam(name, "invalid number: %s", *argv);
+		ret++;
+	    } else {
+		/* scale appropriately */
+		switch (res) {
+		case RLIMIT_FSIZE:
+		case RLIMIT_CORE:
+		    limit *= 512;
+		    break;
+		case RLIMIT_DATA:
+		case RLIMIT_STACK:
 # ifdef HAVE_RLIMIT_RSS
-	    case RLIMIT_RSS:
+		case RLIMIT_RSS:
 # endif /* HAVE_RLIMIT_RSS */
 # ifdef HAVE_RLIMIT_MEMLOCK
-	    case RLIMIT_MEMLOCK:
+		case RLIMIT_MEMLOCK:
 # endif /* HAVE_RLIMIT_MEMLOCK */
 /* If RLIMIT_VMEM and RLIMIT_RSS are defined and equal, avoid *
  * duplicate case statement.  Observed on QNX Neutrino 6.1.0. */
 # if defined(HAVE_RLIMIT_VMEM) && !defined(RLIMIT_VMEM_IS_RSS)
-	    case RLIMIT_VMEM:
+		case RLIMIT_VMEM:
 # endif /* HAVE_RLIMIT_VMEM */
 /* ditto RLIMIT_VMEM and RLIMIT_AS */
 # if defined(HAVE_RLIMIT_AS) && !defined(RLIMIT_VMEM_IS_AS) && !defined(RLIMIT_RSS_IS_AS)
-	    case RLIMIT_AS:
+		case RLIMIT_AS:
 # endif /* HAVE_RLIMIT_AS */
 # ifdef HAVE_RLIMIT_AIO_MEM
-	    case RLIMIT_AIO_MEM:
+		case RLIMIT_AIO_MEM:
 # endif /* HAVE_RLIMIT_AIO_MEM */
-		limit *= 1024;
-		break;
+		    limit *= 1024;
+		    break;
+		}
+		if (do_limit(name, res, limit, hard, soft, 1))
+		    ret++;
 	    }
-	    if (do_limit(name, res, limit, hard, soft, 1))
-		ret++;
 	} else {
 	    if (do_unlimit(name, res, hard, soft, 1, geteuid()))
 		ret++;

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: "ulimit -c junk" silently treated as "ulimit -c 0"
  2010-01-02 22:45 "ulimit -c junk" silently treated as "ulimit -c 0" Kalle Olavi Niemitalo
  2010-01-05 15:52 ` Peter Stephenson
@ 2010-01-05 16:24 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2010-01-05 16:24 UTC (permalink / raw)
  To: zsh-workers

On Sun, 03 Jan 2010 00:45:44 +0200
Kalle Olavi Niemitalo <kon@iki.fi> wrote:
> When I switched from bash to zsh, I copied this to my .zprofile:
> 
>   ulimit -c hard
> 
> In bash, it sets the soft limit of core dump size to be the same
> as the hard limit.

This isn't very hard, either.  I see also that the documentation specifies
that argument errors cause processing to abort immediately.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.128
diff -u -r1.128 builtins.yo
--- Doc/Zsh/builtins.yo	19 Sep 2009 16:29:16 -0000	1.128
+++ Doc/Zsh/builtins.yo	5 Jan 2010 16:20:18 -0000
@@ -1710,13 +1710,18 @@
 item(tt(ulimit) [ [ tt(-SHacdfilmnpqstvx) | tt(-N) var(resource) [ var(limit) ] ... ])(
 Set or display resource limits of the shell and the processes started by
 the shell.  The value of var(limit) can be a number in the unit specified
-below or the value `tt(unlimited)'.  By default, only soft limits are
-manipulated. If the tt(-H) flag is given use
-hard limits instead of soft limits.  If the tt(-S) flag is given
-together with the tt(-H) flag set both hard and soft limits.  If no
-options are used, the file size limit (tt(-f)) is assumed.  If
-var(limit) is omitted the current value of the specified resources are
-printed.  When more than one resource values are printed the limit name and
+below or one of the values `tt(unlimited)', which removes the limit on the
+resource, or `tt(hard)', which uses the current value of the hard limit on
+the resource.
+
+By default, only soft limits are manipulated. If the tt(-H) flag
+is given use hard limits instead of soft limits.  If the tt(-S) flag is given
+together with the tt(-H) flag set both hard and soft limits.
+
+If no options are used, the file size limit (tt(-f)) is assumed.
+
+If var(limit) is omitted the current value of the specified resources are
+printed.  When more than one resource value is printed, the limit name and
 unit is printed before each value.
 
 When looping over multiple resources, the shell will abort immediately if
Index: Src/Builtins/rlimits.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Builtins/rlimits.c,v
retrieving revision 1.21
diff -u -r1.21 rlimits.c
--- Src/Builtins/rlimits.c	5 Jan 2010 15:58:20 -0000	1.21
+++ Src/Builtins/rlimits.c	5 Jan 2010 16:20:18 -0000
@@ -836,11 +836,24 @@
 	    /* set limit to specified value */
 	    rlim_t limit;
 
-	    limit = zstrtorlimt(*argv, &eptr, 10);
-	    if (*eptr) {
-		zwarnnam(name, "invalid number: %s", *argv);
-		ret++;
+	    if (!strcmp(*argv, "hard")) {
+		struct rlimit vals;
+
+		if (getrlimit(res, &vals) < 0)
+		{
+		    zwarnnam(name, "can't read limit: %e", errno);
+		    return 1;
+		}
+		else
+		{
+		    limit = vals.rlim_max;
+		}
 	    } else {
+		limit = zstrtorlimt(*argv, &eptr, 10);
+		if (*eptr) {
+		    zwarnnam(name, "invalid number: %s", *argv);
+		    return 1;
+		}
 		/* scale appropriately */
 		switch (res) {
 		case RLIMIT_FSIZE:
@@ -870,9 +883,9 @@
 		    limit *= 1024;
 		    break;
 		}
-		if (do_limit(name, res, limit, hard, soft, 1))
-		    ret++;
 	    }
+	    if (do_limit(name, res, limit, hard, soft, 1))
+		ret++;
 	} else {
 	    if (do_unlimit(name, res, hard, soft, 1, geteuid()))
 		ret++;

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

end of thread, other threads:[~2010-01-05 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-02 22:45 "ulimit -c junk" silently treated as "ulimit -c 0" Kalle Olavi Niemitalo
2010-01-05 15:52 ` Peter Stephenson
2010-01-05 16:24 ` Peter Stephenson

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