From: Matt Helsley This patch uses the task_watcher notifier chain to invoke exit_sem() at appropriate times. Signed-off-by: Matt Helsley Cc: Jes Sorensen DESC make ipc/sem.c:exit_sem() static EDESC From: Adrian Bunk exit_sem() can now become static. Signed-off-by: Adrian Bunk Cc: Matt Helsley Signed-off-by: Andrew Morton --- include/linux/sem.h | 5 ----- ipc/sem.c | 26 +++++++++++++++++++++++++- kernel/exit.c | 1 - kernel/fork.c | 4 +--- 4 files changed, 26 insertions(+), 10 deletions(-) diff -puN include/linux/sem.h~task-watchers-register-semundo-task-watcher include/linux/sem.h --- a/include/linux/sem.h~task-watchers-register-semundo-task-watcher +++ a/include/linux/sem.h @@ -141,7 +141,6 @@ struct sysv_sem { #ifdef CONFIG_SYSVIPC extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk); -extern void exit_sem(struct task_struct *tsk); #else static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk) @@ -149,10 +148,6 @@ static inline int copy_semundo(unsigned return 0; } -static inline void exit_sem(struct task_struct *tsk) -{ - return; -} #endif #endif /* __KERNEL__ */ diff -puN ipc/sem.c~task-watchers-register-semundo-task-watcher ipc/sem.c --- a/ipc/sem.c~task-watchers-register-semundo-task-watcher +++ a/ipc/sem.c @@ -78,6 +78,7 @@ #include #include #include +#include #include #include "util.h" @@ -94,6 +95,7 @@ static struct ipc_ids sem_ids; static int newary (key_t, int, int); static void freeary (struct sem_array *sma, int id); +static void exit_sem(struct task_struct *tsk); #ifdef CONFIG_PROC_FS static int sysvipc_sem_proc_show(struct seq_file *s, void *it); #endif @@ -116,6 +118,27 @@ int sem_ctls[4] = {SEMMSL, SEMMNS, SEMOP #define sc_semopm (sem_ctls[2]) #define sc_semmni (sem_ctls[3]) +static int sem_undo_task_exit(struct notifier_block *nb, unsigned long val, + void *t) +{ + switch (get_watch_event(val)) { + /* + * If it weren't for the fact that we need clone flags to call + * it we could also implement the copy_semundo portion of + * copy_process inside case WATCH_TASK_INIT + */ + case WATCH_TASK_FREE: + exit_sem(t); + return NOTIFY_OK; + default: /* Don't care */ + return NOTIFY_DONE; + } +} + +static struct notifier_block sem_watch_tasks_nb = { + .notifier_call = sem_undo_task_exit +}; + static int used_sems; void __init sem_init (void) @@ -126,6 +149,7 @@ void __init sem_init (void) " key semid perms nsems uid gid cuid cgid otime ctime\n", &sem_ids, sysvipc_sem_proc_show); + register_task_watcher(&sem_watch_tasks_nb); } /* @@ -1263,7 +1287,7 @@ int copy_semundo(unsigned long clone_fla * The current implementation does not do so. The POSIX standard * and SVID should be consulted to determine what behavior is mandated. */ -void exit_sem(struct task_struct *tsk) +static void exit_sem(struct task_struct *tsk) { struct sem_undo_list *undo_list; struct sem_undo *u, **up; diff -puN kernel/exit.c~task-watchers-register-semundo-task-watcher kernel/exit.c --- a/kernel/exit.c~task-watchers-register-semundo-task-watcher +++ a/kernel/exit.c @@ -914,7 +914,6 @@ fastcall NORET_TYPE void do_exit(long co if (group_dead) acct_process(); - exit_sem(tsk); __exit_files(tsk); __exit_fs(tsk); exit_namespace(tsk); diff -puN kernel/fork.c~task-watchers-register-semundo-task-watcher kernel/fork.c --- a/kernel/fork.c~task-watchers-register-semundo-task-watcher +++ a/kernel/fork.c @@ -1092,7 +1092,7 @@ static struct task_struct *copy_process( if ((retval = copy_semundo(clone_flags, p))) goto bad_fork_cleanup_security; if ((retval = copy_files(clone_flags, p))) - goto bad_fork_cleanup_semundo; + goto bad_fork_cleanup_security; if ((retval = copy_fs(clone_flags, p))) goto bad_fork_cleanup_files; if ((retval = copy_sighand(clone_flags, p))) @@ -1266,8 +1266,6 @@ bad_fork_cleanup_fs: exit_fs(p); /* blocking */ bad_fork_cleanup_files: exit_files(p); /* blocking */ -bad_fork_cleanup_semundo: - exit_sem(p); bad_fork_cleanup_security: security_task_free(p); notify_result = notify_watchers(WATCH_TASK_FREE, p); _