Date: Tue, 27 Sep 2005 08:59:45 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 84335 for review Message-ID: <200509270859.j8R8xjra078404@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=84335 Change 84335 by rwatson@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; }help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509270859.j8R8xjra078404>
