static int au_hin_alloc(struct au_hnotify *hn, struct inode *h_inode)
{
	int err;
	s32 wd;
	struct inotify_watch *watch;

	err = -EEXIST;
	wd = inotify_find_watch(au_hin_handle, h_inode, &watch);
	if (wd >= 0) {
		put_inotify_watch(watch);
		goto out;
	}

	err = 0;
	inotify_init_watch(&hn->hn_watch);
	wd = inotify_add_watch(au_hin_handle, &hn->hn_watch, h_inode,
			       AuHinMask);
	if (unlikely(wd < 0)) {
		err = wd;
		put_inotify_watch(&hn->hn_watch);
	}

out:
	return err;
}
Пример #2
0
/* Initialize a parent watch entry. */
static struct audit_parent *audit_init_parent(struct nameidata *ndp)
{
	struct audit_parent *parent;
	s32 wd;

	parent = kzalloc(sizeof(*parent), GFP_KERNEL);
	if (unlikely(!parent))
		return ERR_PTR(-ENOMEM);

	INIT_LIST_HEAD(&parent->watches);
	parent->flags = 0;

	inotify_init_watch(&parent->wdata);
	/* grab a ref so inotify watch hangs around until we take audit_filter_mutex */
	get_inotify_watch(&parent->wdata);
	wd = inotify_add_watch(audit_ih, &parent->wdata, ndp->dentry->d_inode,
			       AUDIT_IN_WATCH);
	if (wd < 0) {
		audit_free_parent(&parent->wdata);
		return ERR_PTR(wd);
	}

	return parent;
}