Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Apr 2013 21:08:16 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r249593 - head/lib/libc/gen
Message-ID:  <201304172108.r3HL8Gwx056575@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Wed Apr 17 21:08:15 2013
New Revision: 249593
URL: http://svnweb.freebsd.org/changeset/base/249593

Log:
  pututxline: Don't set errno=0 in subfunctions.
  
  The functions utx_active_add(), utx_active_remove(), utx_lastlogin_add() and
  utx_log_add() set errno to 0 if they are successful. This not only violates
  POSIX if pututxline() is successful, but may also overwrite a valid error
  with 0 if, for example, utx_lastlogin_add() fails while utx_log_add()
  succeeds.
  
  Reviewed by:	ed

Modified:
  head/lib/libc/gen/pututxline.c

Modified: head/lib/libc/gen/pututxline.c
==============================================================================
--- head/lib/libc/gen/pututxline.c	Wed Apr 17 21:00:22 2013	(r249592)
+++ head/lib/libc/gen/pututxline.c	Wed Apr 17 21:08:15 2013	(r249593)
@@ -131,7 +131,8 @@ exact:
 	else
 		error = 0;
 	fclose(fp);
-	errno = error;
+	if (error != 0)
+		errno = error;
 	return (error == 0 ? 0 : 1);
 }
 
@@ -169,7 +170,8 @@ utx_active_remove(struct futx *fu)
 		}
 
 	fclose(fp);
-	errno = error;
+	if (ret != 0)
+		errno = error;
 	return (ret);
 }
 
@@ -225,7 +227,8 @@ utx_lastlogin_add(const struct futx *fu)
 		ret = -1;
 	}
 	fclose(fp);
-	errno = error;
+	if (ret == -1)
+		errno = error;
 	return (ret);
 }
 
@@ -277,7 +280,8 @@ utx_log_add(const struct futx *fu)
 	else
 		error = 0;
 	_close(fd);
-	errno = error;
+	if (error != 0)
+		errno = error;
 	return (error == 0 ? 0 : 1);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304172108.r3HL8Gwx056575>