static int acct_on(char *name) { struct file *file; int error; /* Difference from BSD - they don't do O_APPEND */ file = filp_open(name, O_WRONLY|O_APPEND|O_LARGEFILE, 0); if (IS_ERR(file)) return PTR_ERR(file); if (!S_ISREG(file->f_path.dentry->d_inode->i_mode)) { filp_close(file, NULL); return -EACCES; } if (!file->f_op->write) { filp_close(file, NULL); return -EIO; } error = security_acct(file); if (error) { filp_close(file, NULL); return error; } spin_lock(&acct_globals.lock); mnt_pin(file->f_path.mnt); acct_file_reopen(file); spin_unlock(&acct_globals.lock); mntput(file->f_path.mnt); /* it's pinned, now give up active reference */ return 0; }
static int acct_on(char *name) { struct file *file; struct vfsmount *mnt; int error; struct pid_namespace *ns; struct bsd_acct_struct *acct = NULL; /* Difference from BSD - they don't do O_APPEND */ file = filp_open(name, O_WRONLY|O_APPEND|O_LARGEFILE, 0); if (IS_ERR(file)) return PTR_ERR(file); if (!S_ISREG(file->f_path.dentry->d_inode->i_mode)) { filp_close(file, NULL); return -EACCES; } if (!file->f_op->write) { filp_close(file, NULL); return -EIO; } ns = task_active_pid_ns(current); if (ns->bacct == NULL) { acct = kzalloc(sizeof(struct bsd_acct_struct), GFP_KERNEL); if (acct == NULL) { filp_close(file, NULL); return -ENOMEM; } } error = security_acct(file); if (error) { kfree(acct); filp_close(file, NULL); return error; } spin_lock(&acct_lock); if (ns->bacct == NULL) { ns->bacct = acct; acct = NULL; } mnt = file->f_path.mnt; mnt_pin(mnt); acct_file_reopen(ns->bacct, file, ns); spin_unlock(&acct_lock); mntput(mnt); /* it's pinned, now give up active reference */ kfree(acct); return 0; }