[PATCH] setenv|putenv rc checking (bin)

Simon 'corecode' Schubert corecode at fs.ei.tum.de
Thu Sep 29 05:12:50 PDT 2005


Alexey Slynko wrote:
because there is no reaction on my previous patch (except Max Okumoto),
I split it into smaller pieces
hey, sorry, we are kinda busy at the moment.

see my comments inline.



------------------------------------------------------------------------

Index: date/date.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/bin/date/date.c,v
retrieving revision 1.13
diff -u -r1.13 date.c
--- date/date.c	20 Jul 2005 19:51:56 -0000	1.13
+++ date/date.c	29 Sep 2005 01:01:48 -0000
@@ -41,6 +41,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <langinfo.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -117,7 +118,8 @@
 			set_timezone = 1;
 			break;
 		case 'u':		/* do everything in UTC */
-			setenv("TZ", "UTC0", 1);
+			if (setenv("TZ", "UTC0", 1) == ENOMEM)
+				err(1, "setenv: cannot set TZ=UTC0");
 			break;
 		case 'v':
 			v = vary_append(v, optarg);
okay

Index: df/df.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/bin/df/df.c,v
retrieving revision 1.5
diff -u -r1.5 df.c
--- df/df.c	7 Nov 2004 20:54:51 -0000	1.5
+++ df/df.c	29 Sep 2005 00:55:17 -0000
@@ -144,11 +144,13 @@
 		case 'b':
 				/* FALLTHROUGH */
 		case 'P':
-			putenv("BLOCKSIZE=512");
+			if (putenv("BLOCKSIZE=512") == ENOMEM)
+				err(1, "putenv: cannot set BLOCKSIZE=512");
 			hflag = 0;
 			break;
 		case 'g':
-			putenv("BLOCKSIZE=1g");
+			if (putenv("BLOCKSIZE=1g") == ENOMEM)
+				err(1, "putenv: cannot set BLOCKSIZE=1g");
 			hflag = 0;
 			break;
 		case 'H':
@@ -163,7 +165,8 @@
 			iflag = 1;
 			break;
 		case 'k':
-			putenv("BLOCKSIZE=1k");
+			if (putenv("BLOCKSIZE=1k") == ENOMEM)
+				err(1, "putenv: cannot set BLOCKSIZE=1k");
 			hflag = 0;
 			break;
 		case 'l':
@@ -172,7 +175,8 @@
 			vfslist = makevfslist(makenetvfslist());
 			break;
 		case 'm':
-			putenv("BLOCKSIZE=1m");
+			if (putenv("BLOCKSIZE=1m") == ENOMEM)
+				err(1, "putenv: cannot set BLOCKSIZE=1m");
 			hflag = 0;
 			break;
 		case 'n':
not sure if we want to bail out or just warn?

Index: ls/ls.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/bin/ls/ls.c,v
retrieving revision 1.14
diff -u -r1.14 ls.c
--- ls/ls.c	18 Sep 2005 18:01:49 -0000	1.14
+++ ls/ls.c	29 Sep 2005 00:48:06 -0000
@@ -221,7 +221,8 @@
 			fts_options |= FTS_COMFOLLOW;
 			break;
 		case 'G':
-			setenv("CLICOLOR", "", 1);
+			if (setenv("CLICOLOR", "", 1) == ENOMEM)
+				err(1, "setenv: cannot set CLICOLOR");
 			break;
 		case 'L':
 			fts_options &= ~FTS_PHYSICAL;
just warn

Index: sh/var.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/bin/sh/var.c,v
retrieving revision 1.8
diff -u -r1.8 var.c
--- sh/var.c	19 Apr 2005 05:18:19 -0000	1.8
+++ sh/var.c	29 Sep 2005 01:02:35 -0000
@@ -40,6 +40,7 @@
 
 #include <unistd.h>
 #include <stdlib.h>
+#include <errno.h>
 
 /*
  * Shell variables.
@@ -316,7 +317,8 @@
 			if (vp == &vmpath || (vp == &vmail && ! mpathset()))
 				chkmail(1);
 			if ((vp->flags & VEXPORT) && localevar(s)) {
-				putenv(s);
+				if (putenv(s) == ENOMEM)
+					err(1, "putenv: cannot set %s", s);
 				setlocale(LC_ALL, "");
 			}
 			INTON;
in any case, just warn and set $? !

@@ -332,7 +334,8 @@
 	INTOFF;
 	*vpp = vp;
 	if ((vp->flags & VEXPORT) && localevar(s)) {
-		putenv(s);
+		if (putenv(s) == ENOMEM)
+			err(1, "putenv: cannot set %s", s);
 		setlocale(LC_ALL, "");
 	}
 	INTON;
same here

@@ -553,7 +556,8 @@
 
 						vp->flags |= flag;
 						if ((vp->flags & VEXPORT) && localevar(vp->text)) {
-							putenv(vp->text);
+							if (putenv(vp->text) == ENOMEM)
+								err(1, "putenv: cannot set %s", vp->text);
 							setlocale(LC_ALL, "");
 						}
 						goto found;
dito

--
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low $$$ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \




More information about the Submit mailing list