FreeBSD kernel kern code
kern_acct.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/acct.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/syslog.h>
#include <sys/sysproto.h>
#include <sys/tty.h>
#include <sys/vnode.h>
#include <security/mac/mac_framework.h>
Include dependency graph for kern_acct.c:

Go to the source code of this file.

Macros

#define FLT_MANT_DIG   24 /* p */
 
#define FLT_MAX_EXP   128 /* emax */
 
#define ACCT_RUNNING   1 /* Accounting kthread is running. */
 
#define ACCT_EXITREQ   2 /* Accounting kthread should exit. */
 
#define MANT_MASK   ((1 << (FLT_MANT_DIG - 1)) - 1)
 
#define CALC_BITS   28
 
#define LOG2_1M   20
 

Functions

 __FBSDID ("$FreeBSD$")
 
 _Static_assert (sizeof(struct acctv3) - offsetof(struct acctv3, ac_trailer)==sizeof(struct acctv2) - offsetof(struct acctv2, ac_trailer), "trailer")
 
 _Static_assert (sizeof(struct acctv3) - offsetof(struct acctv3, ac_len2)==sizeof(struct acctv2) - offsetof(struct acctv2, ac_len2), "len2")
 
static uint32_t encode_timeval (struct timeval)
 
static uint32_t encode_long (long)
 
static void acctwatch (void)
 
static void acct_thread (void *)
 
static int acct_disable (struct thread *, int)
 
 SX_SYSINIT (acct, &acct_sx, "acct_sx")
 
 SYSCTL_INT (_kern, OID_AUTO, acct_suspend, CTLFLAG_RW, &acctsuspend, 0, "percentage of free disk space below which accounting stops")
 
 SYSCTL_INT (_kern, OID_AUTO, acct_resume, CTLFLAG_RW, &acctresume, 0, "percentage of free disk space above which accounting resumes")
 
static int sysctl_acct_chkfreq (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_kern, OID_AUTO, acct_chkfreq, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, &acctchkfreq, 0, sysctl_acct_chkfreq, "I", "frequency for checking the free space")
 
 SYSCTL_INT (_kern, OID_AUTO, acct_configured, CTLFLAG_RD, &acct_configured, 0, "Accounting configured or not")
 
 SYSCTL_INT (_kern, OID_AUTO, acct_suspended, CTLFLAG_RD, &acct_suspended, 0, "Accounting suspended or not")
 
int sys_acct (struct thread *td, struct acct_args *uap)
 
int acct_process (struct thread *td)
 

Variables

static int acct_configured
 
static int acct_suspended
 
static struct vnode * acct_vp
 
static struct ucred * acct_cred
 
static int acct_flags
 
static struct sx acct_sx
 
static int acct_state
 
static int acctsuspend = 2
 
static int acctresume = 4
 
static int acctchkfreq = 15
 

Macro Definition Documentation

◆ ACCT_EXITREQ

#define ACCT_EXITREQ   2 /* Accounting kthread should exit. */

Definition at line 155 of file kern_acct.c.

◆ ACCT_RUNNING

#define ACCT_RUNNING   1 /* Accounting kthread is running. */

Definition at line 154 of file kern_acct.c.

◆ CALC_BITS

#define CALC_BITS   28

Definition at line 452 of file kern_acct.c.

◆ FLT_MANT_DIG

#define FLT_MANT_DIG   24 /* p */

Definition at line 121 of file kern_acct.c.

◆ FLT_MAX_EXP

#define FLT_MAX_EXP   128 /* emax */

Definition at line 122 of file kern_acct.c.

◆ LOG2_1M

#define LOG2_1M   20

Definition at line 455 of file kern_acct.c.

◆ MANT_MASK

#define MANT_MASK   ((1 << (FLT_MANT_DIG - 1)) - 1)

Definition at line 444 of file kern_acct.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _Static_assert() [1/2]

_Static_assert ( sizeof(struct acctv3) - offsetof(struct acctv3, ac_len2)  = =sizeof(struct acctv2) - offsetof(struct acctv2, ac_len2),
"len2"   
)

◆ _Static_assert() [2/2]

_Static_assert ( sizeof(struct acctv3) - offsetof(struct acctv3, ac_trailer)  = =sizeof(struct acctv2) - offsetof(struct acctv2, ac_trailer),
"trailer"   
)

◆ acct_disable()

static int acct_disable ( struct thread *  td,
int  logging 
)
static

Definition at line 314 of file kern_acct.c.

References acct_configured, acct_cred, acct_flags, acct_sx, acct_vp, crfree(), log(), and vn_close().

Referenced by acctwatch(), and sys_acct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acct_process()

int acct_process ( struct thread *  td)

Definition at line 337 of file kern_acct.c.

References acct_cred, acct_suspended, acct_sx, acct_vp, encode_long(), encode_timeval(), getboottime(), hz, microuptime(), proctree_lock, rufetchcalc(), st, tick, timevaladd(), timevalsub(), tty_udev(), and vn_rdwr().

Referenced by exit1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acct_thread()

static void acct_thread ( void *  dummy)
static

Definition at line 604 of file kern_acct.c.

References ACCT_EXITREQ, ACCT_RUNNING, acct_state, acct_sx, acctchkfreq, acctwatch(), hz, kproc_exit(), and sched_prio().

Referenced by sys_acct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acctwatch()

static void acctwatch ( void  )
static

Definition at line 548 of file kern_acct.c.

References acct_disable(), ACCT_EXITREQ, acct_state, acct_suspended, acct_sx, acct_vp, acctresume, acctsuspend, free(), log(), and malloc().

Referenced by acct_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_long()

static uint32_t encode_long ( long  val)
static

Definition at line 513 of file kern_acct.c.

References FLT_MANT_DIG, FLT_MAX_EXP, log(), MANT_MASK, and printf().

Referenced by acct_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_timeval()

static uint32_t encode_timeval ( struct timeval  tv)
static

Definition at line 463 of file kern_acct.c.

References CALC_BITS, FLT_MANT_DIG, FLT_MAX_EXP, LOG2_1M, MANT_MASK, and printf().

Referenced by acct_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SX_SYSINIT()

SX_SYSINIT ( acct  ,
acct_sx,
"acct_sx"   
)

◆ sys_acct()

int sys_acct ( struct thread *  td,
struct acct_args *  uap 
)

◆ sysctl_acct_chkfreq()

static int sysctl_acct_chkfreq ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 171 of file kern_acct.c.

References acctchkfreq, and value.

◆ SYSCTL_INT() [1/4]

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
acct_configured  ,
CTLFLAG_RD  ,
acct_configured,
,
"Accounting configured or not"   
)

◆ SYSCTL_INT() [2/4]

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
acct_resume  ,
CTLFLAG_RW  ,
acctresume,
,
"percentage of free disk space above which accounting resumes"   
)

◆ SYSCTL_INT() [3/4]

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
acct_suspend  ,
CTLFLAG_RW  ,
acctsuspend,
,
"percentage of free disk space below which accounting stops"   
)

◆ SYSCTL_INT() [4/4]

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
acct_suspended  ,
CTLFLAG_RD  ,
acct_suspended,
,
"Accounting suspended or not"   
)

◆ SYSCTL_PROC()

SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
acct_chkfreq  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_MPSAFE,
acctchkfreq,
,
sysctl_acct_chkfreq  ,
"I"  ,
"frequency for checking the free space"   
)

Variable Documentation

◆ acct_configured

int acct_configured
static

Definition at line 140 of file kern_acct.c.

Referenced by acct_disable(), and sys_acct().

◆ acct_cred

struct ucred* acct_cred
static

Definition at line 143 of file kern_acct.c.

Referenced by acct_disable(), acct_process(), and sys_acct().

◆ acct_flags

int acct_flags
static

Definition at line 144 of file kern_acct.c.

Referenced by acct_disable(), and sys_acct().

◆ acct_state

int acct_state
static

Definition at line 152 of file kern_acct.c.

Referenced by acct_thread(), acctwatch(), and sys_acct().

◆ acct_suspended

int acct_suspended
static

Definition at line 141 of file kern_acct.c.

Referenced by acct_process(), acctwatch(), and sys_acct().

◆ acct_sx

struct sx acct_sx
static

Definition at line 145 of file kern_acct.c.

Referenced by acct_disable(), acct_process(), acct_thread(), acctwatch(), and sys_acct().

◆ acct_vp

struct vnode* acct_vp
static

Definition at line 142 of file kern_acct.c.

Referenced by acct_disable(), acct_process(), acctwatch(), and sys_acct().

◆ acctchkfreq

int acctchkfreq = 15
static

Definition at line 168 of file kern_acct.c.

Referenced by acct_thread(), and sysctl_acct_chkfreq().

◆ acctresume

int acctresume = 4
static

Definition at line 164 of file kern_acct.c.

Referenced by acctwatch().

◆ acctsuspend

int acctsuspend = 2
static

Definition at line 160 of file kern_acct.c.

Referenced by acctwatch().