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

Re: [PATCH] setenv|putenv rc checking (lib)


From: Alexey Slynko <slynko@xxxxxxxxx>
Date: Thu, 29 Sep 2005 21:34:24 +0400

joerg@xxxxxxxxxxxxxxxxx пишет:
On Thu, Sep 29, 2005 at 03:43:08PM +0400, Alexey Slynko wrote:


Index: libutil/login_class.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/lib/libutil/login_class.c,v
retrieving revision 1.4
diff -u -r1.4 login_class.c
--- libutil/login_class.c	4 Mar 2005 04:31:11 -0000	1.4
+++ libutil/login_class.c	29 Sep 2005 01:22:16 -0000
@@ -31,6 +31,7 @@
#include <sys/resource.h>
#include <sys/rtprio.h>

+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
@@ -210,10 +211,12 @@
	char * np  = substvar(var, pwd, hlen, pch, nlen);

	if (np != NULL) {
-	    setenv(vars->var, np, vars->overwrite);
+	    if (setenv(vars->var, np, vars->overwrite) == ENOMEM)
+		err(1, "setenv: cannot set %s=%s", vars->var, np);
	    free(np);
	} else if (vars->def != NULL) {
-	    setenv(vars->var, vars->def, 0);
+	    if (setenv(vars->var, vars->def, 0) == ENOMEM)
+		err(1, "setenv: cannot set %s=%s", vars->var, vars->def);
	}
	++vars;
    }
@@ -234,7 +237,8 @@

		    *p++ = '\0';
		    if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) {
-			setenv(*set_env, np, 1);
+			if (setenv(*set_env, np, 1) == ENOMEM)
+				err(1, "setenv: cannot set %s=%s", *set_env, np);
			free(np);
		    }
		}


No err from a library function!
Agree, it's my mistake

Either return a sane return value or
change the interface if it doesn't allow error handling.
Well, I havn't found setclassenvironment in POSIX. Can we change the result code to int?



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