Deleted Added
full compact
kern_acct.c (225617) kern_acct.c (234927)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * Copyright (c) 2005 Robert N. M. Watson
6 * All rights reserved.
7 *
8 * All or some portions of this file are derived from material licensed

--- 54 unchanged lines hidden (view full) ---

63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)kern_acct.c 8.1 (Berkeley) 6/14/93
68 */
69
70#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * Copyright (c) 2005 Robert N. M. Watson
6 * All rights reserved.
7 *
8 * All or some portions of this file are derived from material licensed

--- 54 unchanged lines hidden (view full) ---

63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)kern_acct.c 8.1 (Berkeley) 6/14/93
68 */
69
70#include <sys/cdefs.h>
71__FBSDID("$FreeBSD: head/sys/kern/kern_acct.c 225617 2011-09-16 13:58:51Z kmacy $");
71__FBSDID("$FreeBSD: head/sys/kern/kern_acct.c 234927 2012-05-02 14:25:39Z jhb $");
72
73#include <sys/param.h>
74#include <sys/systm.h>
75#include <sys/acct.h>
76#include <sys/fcntl.h>
77#include <sys/kernel.h>
78#include <sys/kthread.h>
79#include <sys/limits.h>

--- 37 unchanged lines hidden (view full) ---

117 * Internal accounting functions.
118 * The former's operation is described in Leffler, et al., and the latter
119 * was provided by UCB with the 4.4BSD-Lite release
120 */
121static uint32_t encode_timeval(struct timeval);
122static uint32_t encode_long(long);
123static void acctwatch(void);
124static void acct_thread(void *);
72
73#include <sys/param.h>
74#include <sys/systm.h>
75#include <sys/acct.h>
76#include <sys/fcntl.h>
77#include <sys/kernel.h>
78#include <sys/kthread.h>
79#include <sys/limits.h>

--- 37 unchanged lines hidden (view full) ---

117 * Internal accounting functions.
118 * The former's operation is described in Leffler, et al., and the latter
119 * was provided by UCB with the 4.4BSD-Lite release
120 */
121static uint32_t encode_timeval(struct timeval);
122static uint32_t encode_long(long);
123static void acctwatch(void);
124static void acct_thread(void *);
125static int acct_disable(struct thread *);
125static int acct_disable(struct thread *, int);
126
127/*
128 * Accounting vnode pointer, saved vnode pointer, and flags for each.
129 * acct_sx protects against changes to the active vnode and credentials
130 * while accounting records are being committed to disk.
131 */
132static int acct_configured;
133static int acct_suspended;

--- 57 unchanged lines hidden (view full) ---

191/*
192 * Accounting system call. Written based on the specification and previous
193 * implementation done by Mark Tinguely.
194 */
195int
196sys_acct(struct thread *td, struct acct_args *uap)
197{
198 struct nameidata nd;
126
127/*
128 * Accounting vnode pointer, saved vnode pointer, and flags for each.
129 * acct_sx protects against changes to the active vnode and credentials
130 * while accounting records are being committed to disk.
131 */
132static int acct_configured;
133static int acct_suspended;

--- 57 unchanged lines hidden (view full) ---

191/*
192 * Accounting system call. Written based on the specification and previous
193 * implementation done by Mark Tinguely.
194 */
195int
196sys_acct(struct thread *td, struct acct_args *uap)
197{
198 struct nameidata nd;
199 int error, flags, vfslocked;
199 int error, flags, vfslocked, replacing;
200
201 error = priv_check(td, PRIV_ACCT);
202 if (error)
203 return (error);
204
205 /*
206 * If accounting is to be started to a file, open that file for
207 * appending and make sure it's a 'normal'.

--- 33 unchanged lines hidden (view full) ---

241
242 /*
243 * Disallow concurrent access to the accounting vnode while we swap
244 * it out, in order to prevent access after close.
245 */
246 sx_xlock(&acct_sx);
247
248 /*
200
201 error = priv_check(td, PRIV_ACCT);
202 if (error)
203 return (error);
204
205 /*
206 * If accounting is to be started to a file, open that file for
207 * appending and make sure it's a 'normal'.

--- 33 unchanged lines hidden (view full) ---

241
242 /*
243 * Disallow concurrent access to the accounting vnode while we swap
244 * it out, in order to prevent access after close.
245 */
246 sx_xlock(&acct_sx);
247
248 /*
249 * Don't log spurious disable/enable messages if we are
250 * switching from one accounting file to another due to log
251 * rotation.
252 */
253 replacing = (acct_vp != NULL && uap->path != NULL);
254
255 /*
249 * If accounting was previously enabled, kill the old space-watcher,
250 * close the file, and (if no new file was specified, leave). Reset
251 * the suspended state regardless of whether accounting remains
252 * enabled.
253 */
254 acct_suspended = 0;
255 if (acct_vp != NULL) {
256 vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
256 * If accounting was previously enabled, kill the old space-watcher,
257 * close the file, and (if no new file was specified, leave). Reset
258 * the suspended state regardless of whether accounting remains
259 * enabled.
260 */
261 acct_suspended = 0;
262 if (acct_vp != NULL) {
263 vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
257 error = acct_disable(td);
264 error = acct_disable(td, !replacing);
258 VFS_UNLOCK_GIANT(vfslocked);
259 }
260 if (uap->path == NULL) {
261 if (acct_state & ACCT_RUNNING) {
262 acct_state |= ACCT_EXITREQ;
263 wakeup(&acct_state);
264 }
265 sx_xunlock(&acct_sx);

--- 28 unchanged lines hidden (view full) ---

294 acct_flags = 0;
295 sx_xunlock(&acct_sx);
296 log(LOG_NOTICE, "Unable to start accounting thread\n");
297 return (error);
298 }
299 }
300 acct_configured = 1;
301 sx_xunlock(&acct_sx);
265 VFS_UNLOCK_GIANT(vfslocked);
266 }
267 if (uap->path == NULL) {
268 if (acct_state & ACCT_RUNNING) {
269 acct_state |= ACCT_EXITREQ;
270 wakeup(&acct_state);
271 }
272 sx_xunlock(&acct_sx);

--- 28 unchanged lines hidden (view full) ---

301 acct_flags = 0;
302 sx_xunlock(&acct_sx);
303 log(LOG_NOTICE, "Unable to start accounting thread\n");
304 return (error);
305 }
306 }
307 acct_configured = 1;
308 sx_xunlock(&acct_sx);
302 log(LOG_NOTICE, "Accounting enabled\n");
309 if (!replacing)
310 log(LOG_NOTICE, "Accounting enabled\n");
303 return (error);
304}
305
306/*
307 * Disable currently in-progress accounting by closing the vnode, dropping
308 * our reference to the credential, and clearing the vnode's flags.
309 */
310static int
311 return (error);
312}
313
314/*
315 * Disable currently in-progress accounting by closing the vnode, dropping
316 * our reference to the credential, and clearing the vnode's flags.
317 */
318static int
311acct_disable(struct thread *td)
319acct_disable(struct thread *td, int logging)
312{
313 int error;
314
315 sx_assert(&acct_sx, SX_XLOCKED);
316 error = vn_close(acct_vp, acct_flags, acct_cred, td);
317 crfree(acct_cred);
318 acct_configured = 0;
319 acct_vp = NULL;
320 acct_cred = NULL;
321 acct_flags = 0;
320{
321 int error;
322
323 sx_assert(&acct_sx, SX_XLOCKED);
324 error = vn_close(acct_vp, acct_flags, acct_cred, td);
325 crfree(acct_cred);
326 acct_configured = 0;
327 acct_vp = NULL;
328 acct_cred = NULL;
329 acct_flags = 0;
322 log(LOG_NOTICE, "Accounting disabled\n");
330 if (logging)
331 log(LOG_NOTICE, "Accounting disabled\n");
323 return (error);
324}
325
326/*
327 * Write out process accounting information, on process exit.
328 * Data to be written out is specified in Leffler, et al.
329 * and are enumerated below. (They're also noted in the system
330 * "acct.h" header file.)

--- 238 unchanged lines hidden (view full) ---

569 }
570
571 /*
572 * If our vnode is no longer valid, tear it down and signal the
573 * accounting thread to die.
574 */
575 vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
576 if (acct_vp->v_type == VBAD) {
332 return (error);
333}
334
335/*
336 * Write out process accounting information, on process exit.
337 * Data to be written out is specified in Leffler, et al.
338 * and are enumerated below. (They're also noted in the system
339 * "acct.h" header file.)

--- 238 unchanged lines hidden (view full) ---

578 }
579
580 /*
581 * If our vnode is no longer valid, tear it down and signal the
582 * accounting thread to die.
583 */
584 vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount);
585 if (acct_vp->v_type == VBAD) {
577 (void) acct_disable(NULL);
586 (void) acct_disable(NULL, 1);
578 VFS_UNLOCK_GIANT(vfslocked);
579 acct_state |= ACCT_EXITREQ;
580 return;
581 }
582
583 /*
584 * Stopping here is better than continuing, maybe it will be VBAD
585 * next time around.

--- 69 unchanged lines hidden ---
587 VFS_UNLOCK_GIANT(vfslocked);
588 acct_state |= ACCT_EXITREQ;
589 return;
590 }
591
592 /*
593 * Stopping here is better than continuing, maybe it will be VBAD
594 * next time around.

--- 69 unchanged lines hidden ---