Skip to content

Commit 4006553

Browse files
Ulrich Dreppertorvalds
authored andcommitted
flag parameters: inotify_init
This patch introduces the new syscall inotify_init1 (note: the 1 stands for the one parameter the syscall takes, as opposed to no parameter before). The values accepted for this parameter are function-specific and defined in the inotify.h header. Here the values must match the O_* flags, though. In this patch CLOEXEC support is introduced. The following test must be adjusted for architectures other than x86 and x86-64 and in case the syscall numbers changed. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <sys/syscall.h> #ifndef __NR_inotify_init1 # ifdef __x86_64__ # define __NR_inotify_init1 294 # elif defined __i386__ # define __NR_inotify_init1 332 # else # error "need __NR_inotify_init1" # endif #endif #define IN_CLOEXEC O_CLOEXEC int main (void) { int fd; fd = syscall (__NR_inotify_init1, 0); if (fd == -1) { puts ("inotify_init1(0) failed"); return 1; } int coe = fcntl (fd, F_GETFD); if (coe == -1) { puts ("fcntl failed"); return 1; } if (coe & FD_CLOEXEC) { puts ("inotify_init1(0) set close-on-exit"); return 1; } close (fd); fd = syscall (__NR_inotify_init1, IN_CLOEXEC); if (fd == -1) { puts ("inotify_init1(IN_CLOEXEC) failed"); return 1; } coe = fcntl (fd, F_GETFD); if (coe == -1) { puts ("fcntl failed"); return 1; } if ((coe & FD_CLOEXEC) == 0) { puts ("inotify_init1(O_CLOEXEC) does not set close-on-exit"); return 1; } close (fd); puts ("OK"); return 0; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [akpm@linux-foundation.org: add sys_ni stub] Signed-off-by: Ulrich Drepper <drepper@redhat.com> Acked-by: Davide Libenzi <davidel@xmailserver.org> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ed8cae8 commit 4006553

File tree

8 files changed

+22
-2
lines changed

8 files changed

+22
-2
lines changed

arch/x86/ia32/ia32entry.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,5 @@ ia32_sys_call_table:
831831
.quad sys_epoll_create2
832832
.quad sys_dup3 /* 330 */
833833
.quad sys_pipe2
834+
.quad sys_inotify_init1
834835
ia32_syscall_end:

arch/x86/kernel/syscall_table_32.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,4 @@ ENTRY(sys_call_table)
331331
.long sys_epoll_create2
332332
.long sys_dup3 /* 330 */
333333
.long sys_pipe2
334+
.long sys_inotify_init1

fs/inotify_user.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,18 @@ static const struct inotify_operations inotify_user_ops = {
566566
.destroy_watch = free_inotify_user_watch,
567567
};
568568

569-
asmlinkage long sys_inotify_init(void)
569+
asmlinkage long sys_inotify_init1(int flags)
570570
{
571571
struct inotify_device *dev;
572572
struct inotify_handle *ih;
573573
struct user_struct *user;
574574
struct file *filp;
575575
int fd, ret;
576576

577-
fd = get_unused_fd();
577+
if (flags & ~IN_CLOEXEC)
578+
return -EINVAL;
579+
580+
fd = get_unused_fd_flags(flags & O_CLOEXEC);
578581
if (fd < 0)
579582
return fd;
580583

@@ -638,6 +641,11 @@ asmlinkage long sys_inotify_init(void)
638641
return ret;
639642
}
640643

644+
asmlinkage long sys_inotify_init(void)
645+
{
646+
return sys_inotify_init1(0);
647+
}
648+
641649
asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
642650
{
643651
struct inode *inode;

include/asm-x86/unistd_32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
#define __NR_epoll_create2 329
338338
#define __NR_dup3 330
339339
#define __NR_pipe2 331
340+
#define __NR_inotify_init1 332
340341

341342
#ifdef __KERNEL__
342343

include/asm-x86/unistd_64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ __SYSCALL(__NR_epoll_create2, sys_epoll_create2)
651651
__SYSCALL(__NR_dup3, sys_dup3)
652652
#define __NR_pipe2 293
653653
__SYSCALL(__NR_pipe2, sys_pipe2)
654+
#define __NR_inotify_init1 294
655+
__SYSCALL(__NR_inotify_init1, sys_inotify_init1)
654656

655657

656658
#ifndef __NO_STUBS

include/linux/inotify.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef _LINUX_INOTIFY_H
88
#define _LINUX_INOTIFY_H
99

10+
/* For O_CLOEXEC */
11+
#include <linux/fcntl.h>
1012
#include <linux/types.h>
1113

1214
/*
@@ -63,6 +65,9 @@ struct inotify_event {
6365
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \
6466
IN_MOVE_SELF)
6567

68+
/* Flags for sys_inotify_init1. */
69+
#define IN_CLOEXEC O_CLOEXEC
70+
6671
#ifdef __KERNEL__
6772

6873
#include <linux/dcache.h>

include/linux/syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ asmlinkage long sys_get_mempolicy(int __user *policy,
547547
unsigned long addr, unsigned long flags);
548548

549549
asmlinkage long sys_inotify_init(void);
550+
asmlinkage long sys_inotify_init1(int flags);
550551
asmlinkage long sys_inotify_add_watch(int fd, const char __user *path,
551552
u32 mask);
552553
asmlinkage long sys_inotify_rm_watch(int fd, u32 wd);

kernel/sys_ni.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ cond_syscall(sys_keyctl);
9696
cond_syscall(compat_sys_keyctl);
9797
cond_syscall(compat_sys_socketcall);
9898
cond_syscall(sys_inotify_init);
99+
cond_syscall(sys_inotify_init1);
99100
cond_syscall(sys_inotify_add_watch);
100101
cond_syscall(sys_inotify_rm_watch);
101102
cond_syscall(sys_migrate_pages);

0 commit comments

Comments
 (0)