PERFORCE change 84335 for review

Robert Watson rwatson at FreeBSD.org
Tue Sep 27 08:59:45 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=84335

Change 84335 by rwatson at rwatson_zoo on 2005/09/27 08:59:23

	When creating a log file with open(), don't just drop the file
	descriptor on the floor, close() it.  This closes a file descriptor
	leak that occurs when the log cycle is cycled.

Affected files ...

.. //depot/projects/trustedbsd/audit3/contrib/audit_supt/auditd/auditd.c#12 edit

Differences ...

==== //depot/projects/trustedbsd/audit3/contrib/audit_supt/auditd/auditd.c#12 (text+ko) ====

@@ -166,6 +166,7 @@
 	char *fn;
 	char TS[POSTFIX_LEN];
 	struct dir_ent *dirent;
+	int fd;
 
 	if(getTSstr(TS, POSTFIX_LEN) != 0) {
 		return -1;
@@ -182,19 +183,26 @@
 			return -1;
 		}
 
+		/*
+		 * Create and open the file; then close and pass to the
+		 * kernel if all went well.
+		 */
 		syslog(LOG_INFO, "New audit file is %s\n", fn);
-		if (open(fn, O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP) < 0) {
+		fd = open(fn, O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP);
+		if (fd < 0) {
 			perror("File open");
 		}
 		else if (auditctl(fn) != 0) {
 			syslog(LOG_ERR, 
 				"auditctl failed setting log file! : %s\n", 
 				strerror(errno));
+			close(fd);
 		}
 		else {
 			/* Success */ 
 			close_lastfile(TS);
 			lastfile = fn;
+			close(fd);
 			return 0;
 		}
 
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list