DragonFly BSD
DragonFly submit List (threaded) for 2005-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: [PATCH] setenv|putenv rc checking (usr.bin)


From: Alexey Slynko <slynko@xxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Oct 2005 21:48:15 +0400

Well, another patch version has submitted. I removed my stupid error about ENOME.

About warnings - it's much more clearly to see, that the running program aborted with the message about exhausted memory, than it will continue with warning and the result will be differ, than expected (IMHO)



Index: du/du.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/du/du.c,v
retrieving revision 1.8
diff -u -r1.8 du.c
--- du/du.c	1 Sep 2005 22:19:26 -0000	1.8
+++ du/du.c	29 Sep 2005 02:12:28 -0000
@@ -155,13 +155,15 @@
 				cflag = 1;
 				break;
 			case 'h':
-				putenv("BLOCKSIZE=512");
+				if (putenv("BLOCKSIZE=512") != 0)
+					err(1, "putenv: cannot set BLOCKSIZE=512");
 				hflag = 1;
 				valp = vals_base2;
 				break;
 			case 'k':
 				hflag = 0;
-				putenv("BLOCKSIZE=1024");
+				if (putenv("BLOCKSIZE=1024") != 0)
+					err(1, "putenv: cannot set BLOCKSIZE=1024");
 				break;
 			case 'r':		 /* Compatibility. */
 				break;
Index: env/env.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/env/env.c,v
retrieving revision 1.4
diff -u -r1.4 env.c
--- env/env.c	8 Dec 2004 20:17:12 -0000	1.4
+++ env/env.c	29 Sep 2005 01:46:45 -0000
@@ -65,8 +65,8 @@
 			usage();
 		}
 	for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
-		if (setenv(*argv, ++p, 1) == -1)
-			err(1, "%s", *argv);
+		if (setenv(*argv, ++p, 1) != 0)
+			err(1, "setenv: cannot set %s=%s", *argv, p);
 	}

 	if (*argv) {
Index: fetch/fetch.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/fetch/fetch.c,v
retrieving revision 1.5
diff -u -r1.5 fetch.c
--- fetch/fetch.c	4 Jan 2005 23:08:13 -0000	1.5
+++ fetch/fetch.c	29 Sep 2005 01:45:25 -0000
@@ -905,8 +905,10 @@
 	/* authentication */
 	if (v_tty)
 		fetchAuthMethod = query_auth;
-	if (N_filename != NULL)
-		setenv("NETRC", N_filename, 1);
+	if (N_filename != NULL) {
+		if (setenv("NETRC", N_filename, 1) != 0)
+			err(1, "setenv: cannot set NETRC=%s", N_filename);
+	}

 	while (argc) {
 		if ((p = strrchr(*argv, '/')) == NULL)
Index: ldd/ldd.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/ldd/ldd.c,v
retrieving revision 1.5
diff -u -r1.5 ldd.c
--- ldd/ldd.c	24 Jul 2005 15:04:56 -0000	1.5
+++ ldd/ldd.c	29 Sep 2005 01:50:48 -0000
@@ -98,11 +99,16 @@
 #endif

 	/* ld.so magic */
-	setenv("LD_TRACE_LOADED_OBJECTS", "1", 1);
-	if (fmt1)
-		setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
-	if (fmt2)
-		setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1);
+	if (setenv("LD_TRACE_LOADED_OBJECTS", "1", 1) != 0)
+		err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS=1");
+	if (fmt1) {
+		if (setenv("LD_TRACE_LOADED_OBJECTS_FMT1", fmt1, 1) != 0)
+			err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_FMT1=%s", fmt1);
+	}
+	if (fmt2) {
+		if (setenv("LD_TRACE_LOADED_OBJECTS_FMT2", fmt2, 1) != 0)
+			err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_FMT2=%s", fmt2);
+	}

 	rval = 0;
 	for ( ;  argc > 0;  argc--, argv++) {
@@ -180,7 +186,8 @@
 			continue;
 		}

-		setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1);
+		if (setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1) != 0)
+			err(1, "setenv: cannot set LD_TRACE_LOADED_OBJECTS_PROGNAME=%s", *argv);
 		if (fmt1 == NULL && fmt2 == NULL)
 			/* Default formats */
 			printf("%s:\n", *argv);
Index: limits/limits.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/limits/limits.c,v
retrieving revision 1.4
diff -u -r1.4 limits.c
--- limits/limits.c	12 Jan 2005 01:20:26 -0000	1.4
+++ limits/limits.c	29 Sep 2005 01:53:36 -0000
@@ -433,8 +433,10 @@
 	login_close(lc);

 	/* set leading environment variables, like eval(1) */
-	while (*argv && (p = strchr(*argv, '=')))
-	    (void)setenv(*argv++, ++p, 1);
+	while (*argv && (p = strchr(*argv, '='))) {
+	    if (setenv(*argv++, ++p, 1) != 0)
+		err(1, "setenv: cannot set %s=%s", *argv, p);
+	}

 	/* Set limits */
 	for (rcswhich = 0; rcswhich < RLIM_NLIMITS; rcswhich++) {
Index: login/login.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/login/login.c,v
retrieving revision 1.5
diff -u -r1.5 login.c
--- login/login.c	13 Jul 2005 12:34:22 -0000	1.5
+++ login/login.c	29 Sep 2005 02:13:21 -0000
@@ -656,16 +656,24 @@
 		exit(1);
 	}

-	(void)setenv("SHELL", pwd->pw_shell, 1);
-	(void)setenv("HOME", pwd->pw_dir, 1);
-	if (term != NULL && *term != '\0')
-		(void)setenv("TERM", term, 1);		/* Preset overrides */
+	if (setenv("SHELL", pwd->pw_shell, 1) != 0)
+		err(1, "setenv: cannot set SHELL=%s", pwd->pw_shell);
+	if (setenv("HOME", pwd->pw_dir, 1) != 0)
+		err(1, "setenv: cannot set HOME=%s", pwd->pw_dir);
+	if (term != NULL && *term != '\0') {
+		if (setenv("TERM", term, 1) != 0)		/* Preset overrides */
+			err(1, "setenv: cannot set TERM=%s", term);
+	}
 	else {
-		(void)setenv("TERM", stypeof(tty), 0);	/* Fallback doesn't */
+		if (setenv("TERM", stypeof(tty), 0) != 0)	/* Fallback doesn't */
+			err(1, "setenv: cannot set TERM=%s", stypeof(tty));
 	}
-	(void)setenv("LOGNAME", username, 1);
-	(void)setenv("USER", username, 1);
-	(void)setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0);
+	if (setenv("LOGNAME", username, 1) != 0)
+		err(1, "setenv: cannot set LOGNAME=%s", username);
+	if (setenv("USER", username, 1) != 0)
+		err(1, "setenv: cannot set USER=%s", username);
+	if (setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0) != 0)
+		err(1, "setenv: cannot set PATH=%s", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH);

 	if (!quietlog) {
 		char	*cw;
@@ -857,8 +865,10 @@
 	char	**pp;

 	for (pp = environ_pam; *pp != NULL; pp++) {
-		if (ok_to_export(*pp))
-			(void) putenv(*pp);
+		if (ok_to_export(*pp)) {
+			if (putenv(*pp) != 0)
+				err(1, "putenv: cannot set %s", *pp);
+		}
 		free(*pp);
 	}
 	return PAM_SUCCESS;
Index: objformat/objformat.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/objformat/objformat.c,v
retrieving revision 1.17
diff -u -r1.17 objformat.c
--- objformat/objformat.c	20 Apr 2005 21:39:00 -0000	1.17
+++ objformat/objformat.c	29 Sep 2005 02:00:47 -0000
@@ -169,7 +170,8 @@

path = strdup(objformat_path);

-	setenv("OBJFORMAT", objformat, 1);
+	if (setenv("OBJFORMAT", objformat, 1) != 0)
+		err(1, "setenv: cannot set OBJFORMAT=%s", objformat);

 	/*
 	 * objformat_path could be sequence of colon-separated paths.
Index: su/su.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/su/su.c,v
retrieving revision 1.8
diff -u -r1.8 su.c
--- su/su.c	14 Mar 2005 11:55:33 -0000	1.8
+++ su/su.c	29 Sep 2005 02:04:18 -0000
@@ -396,21 +396,30 @@
 			/* set the su'd user's environment & umask */
 			setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETPATH|LOGIN_SETUMASK|LOGIN_SETENV);
 #else
-			setenv("PATH", _PATH_DEFPATH, 1);
+			if (setenv("PATH", _PATH_DEFPATH, 1) != 0)
+				err(1, "setenv: cannot set PATH=%s", _PATH_DEFPATH);
 #endif
-			if (p)
-				setenv("TERM", p, 1);
+			if (p) {
+				if (setenv("TERM", p, 1) != 0)
+					err(1, "setenv: cannot set TERM=%s", p);
+			}
 #ifdef KERBEROS5
-			if (ccname)
-				setenv("KRB5CCNAME", ccname, 1);
+			if (ccname) {
+				if (setenv("KRB5CCNAME", ccname, 1) != 0)
+					err(1, "setenv: cannot set KRB5CCNAME=%s", ccname);
+			}
 #endif
 			if (chdir(pwd->pw_dir) < 0)
 				errx(1, "no directory");
 		}
-		if (asthem || pwd->pw_uid)
-			setenv("USER", pwd->pw_name, 1);
-		setenv("HOME", pwd->pw_dir, 1);
-		setenv("SHELL", shell, 1);
+		if (asthem || pwd->pw_uid) {
+			if (setenv("USER", pwd->pw_name, 1) != 0)
+				err(1, "setenv: cannot set USER=%s", pwd->pw_name);
+		}
+		if (setenv("HOME", pwd->pw_dir, 1) != 0)
+			err(1, "setenv: cannot set HOME=%s", pwd->pw_dir);
+		if (setenv("SHELL", shell, 1) != 0)
+			err(1, "setenv: cannot set SHELL=%s", shell);
 	}
 	if (iscsh == YES) {
 		if (fastlogin)
Index: tabs/tabs.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/tabs/tabs.c,v
retrieving revision 1.1
diff -u -r1.1 tabs.c
--- tabs/tabs.c	19 Jun 2004 22:03:08 -0000	1.1
+++ tabs/tabs.c	29 Sep 2005 02:05:34 -0000
@@ -108,12 +108,15 @@
 				errx(1, "%s: invalid increment", arg + 1);
 		} else if (arg[1] == 'T') {
 			/* -Ttype or -T type */
-			if (arg[2] != '\0')
-				setenv("TERM", arg + 2, 1);
+			if (arg[2] != '\0') {
+				if (setenv("TERM", arg + 2, 1) != 0)
+					err(1, "setenv: cannot set TERM=%s", arg + 2);
+			}
 			else {
 				if ((arg = *++argv) == NULL)
 					usage();
-				setenv("TERM", arg, 1);
+				if (setenv("TERM", arg, 1) != 0)
+					err(1, "setenv: cannot set TERM=%s", arg);
 			}
 		} else if (arg[1] == '-') {
 			arg = *++argv;
Index: whereis/whereis.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/whereis/whereis.c,v
retrieving revision 1.3
diff -u -r1.3 whereis.c
--- whereis/whereis.c	31 Aug 2005 16:45:51 -0000	1.3
+++ whereis/whereis.c	29 Sep 2005 02:06:40 -0000
@@ -383,7 +383,8 @@
 		errx(EX_DATAERR, "no directories to search");

 	if (opt_m) {
-		setenv("MANPATH", colonify(mandirs), 1);
+		if (setenv("MANPATH", colonify(mandirs), 1) != 0)
+			err(1, "setenv: cannot set MANPATH=%s", colonify(mandirs));
 		if ((i = regcomp(&re, MANWHEREISMATCH, REG_EXTENDED)) != 0) {
 			regerror(i, &re, buf, BUFSIZ - 1);
 			errx(EX_UNAVAILABLE, "regcomp(%s) failed: %s",
Index: window/wwenviron.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/window/wwenviron.c,v
retrieving revision 1.2
diff -u -r1.2 wwenviron.c
--- window/wwenviron.c	17 Jun 2003 04:29:34 -0000	1.2
+++ window/wwenviron.c	29 Sep 2005 02:10:24 -0000
@@ -92,9 +93,11 @@
 	 */
 	(void) sprintf(buf, "%sco#%d:li#%d:%s",
 		WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap);
-	(void) setenv("TERMCAP", buf, 1);
+	if (setenv("TERMCAP", buf, 1) != 0)
+		err(1, "setenv: cannot set TERMCAP=%s", buf);
 	(void) sprintf(buf, "%d", wp->ww_id + 1);
-	(void) setenv("WINDOW_ID", buf, 1);
+	if (setenv("WINDOW_ID", buf, 1) != 0)
+		err(1, "setenv: cannot set WINDOW_ID=%s", buf);
 	return 0;
 bad:
 	wwerrno = WWE_SYS;
Index: window/wwinit.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/window/wwinit.c,v
retrieving revision 1.2
diff -u -r1.2 wwinit.c
--- window/wwinit.c	17 Jun 2003 04:29:34 -0000	1.2
+++ window/wwinit.c	29 Sep 2005 02:10:50 -0000
@@ -303,7 +304,8 @@
 	 * since tt_init() has already made its own copy of it and
 	 * wwterm now points to the copy.
 	 */
-	(void) setenv("TERM", WWT_TERM, 1);
+	if (setenv("TERM", WWT_TERM, 1) != 0)
+		err(1, "setenv: cannot set TERM=%s", WWT_TERM);
 #ifdef TERMINFO
 	if (wwterminfoinit() < 0)
 		goto bad;
Index: window/wwterminfo.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/usr.bin/window/wwterminfo.c,v
retrieving revision 1.2
diff -u -r1.2 wwterminfo.c
--- window/wwterminfo.c	17 Jun 2003 04:29:34 -0000	1.2
+++ window/wwterminfo.c	29 Sep 2005 02:09:47 -0000
@@ -68,7 +68,8 @@
 		wwerrno = WWE_SYS;
 		return -1;
 	}
-	(void) setenv("TERMINFO", wwterminfopath, 1);
+	if (setenv("TERMINFO", wwterminfopath, 1) != 0)
+		err(1, "setenv: cannot set TERMINFO=%s", wwterminfopath);
 		/* make a termcap entry and turn it into terminfo */
 	(void) sprintf(buf, "%s/cap", wwterminfopath);
 	if ((fp = fopen(buf, "w")) == NULL) {



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]