vserver 1.9.3
[linux-2.6.git] / kernel / exit.c
1 /*
2  *  linux/kernel/exit.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 #include <linux/config.h>
8 #include <linux/mm.h>
9 #include <linux/slab.h>
10 #include <linux/interrupt.h>
11 #include <linux/smp_lock.h>
12 #include <linux/module.h>
13 #include <linux/completion.h>
14 #include <linux/personality.h>
15 #include <linux/tty.h>
16 #include <linux/namespace.h>
17 #include <linux/security.h>
18 #include <linux/cpu.h>
19 #include <linux/acct.h>
20 #include <linux/file.h>
21 #include <linux/binfmts.h>
22 #include <linux/ptrace.h>
23 #include <linux/profile.h>
24 #include <linux/mount.h>
25 #include <linux/proc_fs.h>
26 #include <linux/mempolicy.h>
27 #include <linux/vs_limit.h>
28
29 #include <asm/uaccess.h>
30 #include <asm/unistd.h>
31 #include <asm/pgtable.h>
32 #include <asm/mmu_context.h>
33
34 extern void sem_exit (void);
35 extern struct task_struct *child_reaper;
36
37 int getrusage(struct task_struct *, int, struct rusage __user *);
38
39 static void __unhash_process(struct task_struct *p)
40 {
41         nr_threads--;
42         /* tasklist_lock is held, is this sufficient? */
43         if (p->vx_info) {
44                 atomic_dec(&p->vx_info->cvirt.nr_threads);
45                 vx_nproc_dec(p);
46         }
47         detach_pid(p, PIDTYPE_PID);
48         detach_pid(p, PIDTYPE_TGID);
49         if (thread_group_leader(p)) {
50                 detach_pid(p, PIDTYPE_PGID);
51                 detach_pid(p, PIDTYPE_SID);
52                 if (p->pid)
53                         __get_cpu_var(process_counts)--;
54         }
55
56         REMOVE_LINKS(p);
57 }
58
59 void release_task(struct task_struct * p)
60 {
61         int zap_leader;
62         task_t *leader;
63         struct dentry *proc_dentry;
64
65 repeat: 
66         atomic_dec(&p->user->processes);
67         spin_lock(&p->proc_lock);
68         proc_dentry = proc_pid_unhash(p);
69         write_lock_irq(&tasklist_lock);
70         if (unlikely(p->ptrace))
71                 __ptrace_unlink(p);
72         BUG_ON(!list_empty(&p->ptrace_list) || !list_empty(&p->ptrace_children));
73         __exit_signal(p);
74         __exit_sighand(p);
75         __unhash_process(p);
76
77         /*
78          * If we are the last non-leader member of the thread
79          * group, and the leader is zombie, then notify the
80          * group leader's parent process. (if it wants notification.)
81          */
82         zap_leader = 0;
83         leader = p->group_leader;
84         if (leader != p && thread_group_empty(leader) && leader->state == TASK_ZOMBIE) {
85                 BUG_ON(leader->exit_signal == -1);
86                 do_notify_parent(leader, leader->exit_signal);
87                 /*
88                  * If we were the last child thread and the leader has
89                  * exited already, and the leader's parent ignores SIGCHLD,
90                  * then we are the one who should release the leader.
91                  *
92                  * do_notify_parent() will have marked it self-reaping in
93                  * that case.
94                  */
95                 zap_leader = (leader->exit_signal == -1);
96         }
97
98         sched_exit(p);
99         write_unlock_irq(&tasklist_lock);
100         spin_unlock(&p->proc_lock);
101         proc_pid_flush(proc_dentry);
102         release_thread(p);
103         put_task_struct(p);
104
105         p = leader;
106         if (unlikely(zap_leader))
107                 goto repeat;
108 }
109
110 /* we are using it only for SMP init */
111
112 void unhash_process(struct task_struct *p)
113 {
114         struct dentry *proc_dentry;
115
116         spin_lock(&p->proc_lock);
117         proc_dentry = proc_pid_unhash(p);
118         write_lock_irq(&tasklist_lock);
119         __unhash_process(p);
120         write_unlock_irq(&tasklist_lock);
121         spin_unlock(&p->proc_lock);
122         proc_pid_flush(proc_dentry);
123 }
124
125 /*
126  * This checks not only the pgrp, but falls back on the pid if no
127  * satisfactory pgrp is found. I dunno - gdb doesn't work correctly
128  * without this...
129  */
130 int session_of_pgrp(int pgrp)
131 {
132         struct task_struct *p;
133         int sid = -1;
134
135         read_lock(&tasklist_lock);
136         do_each_task_pid(pgrp, PIDTYPE_PGID, p) {
137                 if (p->signal->session > 0) {
138                         sid = p->signal->session;
139                         goto out;
140                 }
141         } while_each_task_pid(pgrp, PIDTYPE_PGID, p);
142         p = find_task_by_pid(pgrp);
143         if (p)
144                 sid = p->signal->session;
145 out:
146         read_unlock(&tasklist_lock);
147         
148         return sid;
149 }
150
151 /*
152  * Determine if a process group is "orphaned", according to the POSIX
153  * definition in 2.2.2.52.  Orphaned process groups are not to be affected
154  * by terminal-generated stop signals.  Newly orphaned process groups are
155  * to receive a SIGHUP and a SIGCONT.
156  *
157  * "I ask you, have you ever known what it is to be an orphan?"
158  */
159 static int will_become_orphaned_pgrp(int pgrp, task_t *ignored_task)
160 {
161         struct task_struct *p;
162         int ret = 1;
163
164         do_each_task_pid(pgrp, PIDTYPE_PGID, p) {
165                 if (p == ignored_task
166                                 || p->state >= TASK_ZOMBIE 
167                                 || p->real_parent->pid == 1)
168                         continue;
169                 if (process_group(p->real_parent) != pgrp
170                             && p->real_parent->signal->session == p->signal->session) {
171                         ret = 0;
172                         break;
173                 }
174         } while_each_task_pid(pgrp, PIDTYPE_PGID, p);
175         return ret;     /* (sighing) "Often!" */
176 }
177
178 int is_orphaned_pgrp(int pgrp)
179 {
180         int retval;
181
182         read_lock(&tasklist_lock);
183         retval = will_become_orphaned_pgrp(pgrp, NULL);
184         read_unlock(&tasklist_lock);
185
186         return retval;
187 }
188
189 static inline int has_stopped_jobs(int pgrp)
190 {
191         int retval = 0;
192         struct task_struct *p;
193
194         do_each_task_pid(pgrp, PIDTYPE_PGID, p) {
195                 if (p->state != TASK_STOPPED)
196                         continue;
197
198                 /* If p is stopped by a debugger on a signal that won't
199                    stop it, then don't count p as stopped.  This isn't
200                    perfect but it's a good approximation.  */
201                 if (unlikely (p->ptrace)
202                     && p->exit_code != SIGSTOP
203                     && p->exit_code != SIGTSTP
204                     && p->exit_code != SIGTTOU
205                     && p->exit_code != SIGTTIN)
206                         continue;
207
208                 retval = 1;
209                 break;
210         } while_each_task_pid(pgrp, PIDTYPE_PGID, p);
211         return retval;
212 }
213
214 /**
215  * reparent_to_init() - Reparent the calling kernel thread to the init task.
216  *
217  * If a kernel thread is launched as a result of a system call, or if
218  * it ever exits, it should generally reparent itself to init so that
219  * it is correctly cleaned up on exit.
220  *
221  * The various task state such as scheduling policy and priority may have
222  * been inherited from a user process, so we reset them to sane values here.
223  *
224  * NOTE that reparent_to_init() gives the caller full capabilities.
225  */
226 void reparent_to_init(void)
227 {
228         write_lock_irq(&tasklist_lock);
229
230         ptrace_unlink(current);
231         /* Reparent to init */
232         REMOVE_LINKS(current);
233         /* FIXME handle vchild_reaper/initpid */
234         current->parent = child_reaper;
235         current->real_parent = child_reaper;
236         SET_LINKS(current);
237
238         /* Set the exit signal to SIGCHLD so we signal init on exit */
239         current->exit_signal = SIGCHLD;
240
241         if ((current->policy == SCHED_NORMAL) && (task_nice(current) < 0))
242                 set_user_nice(current, 0);
243         /* cpus_allowed? */
244         /* rt_priority? */
245         /* signals? */
246         security_task_reparent_to_init(current);
247         memcpy(current->rlim, init_task.rlim, sizeof(*(current->rlim)));
248         atomic_inc(&(INIT_USER->__count));
249         switch_uid(INIT_USER);
250
251         write_unlock_irq(&tasklist_lock);
252 }
253
254 void __set_special_pids(pid_t session, pid_t pgrp)
255 {
256         struct task_struct *curr = current;
257
258         if (curr->signal->session != session) {
259                 detach_pid(curr, PIDTYPE_SID);
260                 curr->signal->session = session;
261                 attach_pid(curr, PIDTYPE_SID, session);
262         }
263         if (process_group(curr) != pgrp) {
264                 detach_pid(curr, PIDTYPE_PGID);
265                 curr->signal->pgrp = pgrp;
266                 attach_pid(curr, PIDTYPE_PGID, pgrp);
267         }
268 }
269
270 void set_special_pids(pid_t session, pid_t pgrp)
271 {
272         write_lock_irq(&tasklist_lock);
273         __set_special_pids(session, pgrp);
274         write_unlock_irq(&tasklist_lock);
275 }
276
277 /*
278  * Let kernel threads use this to say that they
279  * allow a certain signal (since daemonize() will
280  * have disabled all of them by default).
281  */
282 int allow_signal(int sig)
283 {
284         if (sig < 1 || sig > _NSIG)
285                 return -EINVAL;
286
287         spin_lock_irq(&current->sighand->siglock);
288         sigdelset(&current->blocked, sig);
289         if (!current->mm) {
290                 /* Kernel threads handle their own signals.
291                    Let the signal code know it'll be handled, so
292                    that they don't get converted to SIGKILL or
293                    just silently dropped */
294                 current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
295         }
296         recalc_sigpending();
297         spin_unlock_irq(&current->sighand->siglock);
298         return 0;
299 }
300
301 EXPORT_SYMBOL(allow_signal);
302
303 int disallow_signal(int sig)
304 {
305         if (sig < 1 || sig > _NSIG)
306                 return -EINVAL;
307
308         spin_lock_irq(&current->sighand->siglock);
309         sigaddset(&current->blocked, sig);
310         recalc_sigpending();
311         spin_unlock_irq(&current->sighand->siglock);
312         return 0;
313 }
314
315 EXPORT_SYMBOL(disallow_signal);
316
317 /*
318  *      Put all the gunge required to become a kernel thread without
319  *      attached user resources in one place where it belongs.
320  */
321
322 void daemonize(const char *name, ...)
323 {
324         va_list args;
325         struct fs_struct *fs;
326         sigset_t blocked;
327
328         va_start(args, name);
329         vsnprintf(current->comm, sizeof(current->comm), name, args);
330         va_end(args);
331
332         /*
333          * If we were started as result of loading a module, close all of the
334          * user space pages.  We don't need them, and if we didn't close them
335          * they would be locked into memory.
336          */
337         exit_mm(current);
338
339         set_special_pids(1, 1);
340         current->signal->tty = NULL;
341
342         /* Block and flush all signals */
343         sigfillset(&blocked);
344         sigprocmask(SIG_BLOCK, &blocked, NULL);
345         flush_signals(current);
346
347         /* Become as one with the init task */
348
349         exit_fs(current);       /* current->fs->count--; */
350         fs = init_task.fs;
351         current->fs = fs;
352         atomic_inc(&fs->count);
353         exit_files(current);
354         current->files = init_task.files;
355         atomic_inc(&current->files->count);
356
357         reparent_to_init();
358 }
359
360 EXPORT_SYMBOL(daemonize);
361
362 static inline void close_files(struct files_struct * files)
363 {
364         int i, j;
365
366         j = 0;
367         for (;;) {
368                 unsigned long set;
369                 i = j * __NFDBITS;
370                 if (i >= files->max_fdset || i >= files->max_fds)
371                         break;
372                 set = files->open_fds->fds_bits[j++];
373                 while (set) {
374                         if (set & 1) {
375                                 struct file * file = xchg(&files->fd[i], NULL);
376                                 if (file)
377                                         filp_close(file, files);
378                                 // vx_openfd_dec(i);
379                         }
380                         i++;
381                         set >>= 1;
382                 }
383         }
384 }
385
386 struct files_struct *get_files_struct(struct task_struct *task)
387 {
388         struct files_struct *files;
389
390         task_lock(task);
391         files = task->files;
392         if (files)
393                 atomic_inc(&files->count);
394         task_unlock(task);
395
396         return files;
397 }
398
399 void fastcall put_files_struct(struct files_struct *files)
400 {
401         if (atomic_dec_and_test(&files->count)) {
402                 close_files(files);
403                 /*
404                  * Free the fd and fdset arrays if we expanded them.
405                  */
406                 if (files->fd != &files->fd_array[0])
407                         free_fd_array(files->fd, files->max_fds);
408                 if (files->max_fdset > __FD_SETSIZE) {
409                         free_fdset(files->open_fds, files->max_fdset);
410                         free_fdset(files->close_on_exec, files->max_fdset);
411                 }
412                 kmem_cache_free(files_cachep, files);
413         }
414 }
415
416 EXPORT_SYMBOL(put_files_struct);
417
418 static inline void __exit_files(struct task_struct *tsk)
419 {
420         struct files_struct * files = tsk->files;
421
422         if (files) {
423                 task_lock(tsk);
424                 tsk->files = NULL;
425                 task_unlock(tsk);
426                 put_files_struct(files);
427         }
428 }
429
430 void exit_files(struct task_struct *tsk)
431 {
432         __exit_files(tsk);
433 }
434
435 static inline void __put_fs_struct(struct fs_struct *fs)
436 {
437         /* No need to hold fs->lock if we are killing it */
438         if (atomic_dec_and_test(&fs->count)) {
439                 dput(fs->root);
440                 mntput(fs->rootmnt);
441                 dput(fs->pwd);
442                 mntput(fs->pwdmnt);
443                 if (fs->altroot) {
444                         dput(fs->altroot);
445                         mntput(fs->altrootmnt);
446                 }
447                 kmem_cache_free(fs_cachep, fs);
448         }
449 }
450
451 void put_fs_struct(struct fs_struct *fs)
452 {
453         __put_fs_struct(fs);
454 }
455
456 static inline void __exit_fs(struct task_struct *tsk)
457 {
458         struct fs_struct * fs = tsk->fs;
459
460         if (fs) {
461                 task_lock(tsk);
462                 tsk->fs = NULL;
463                 task_unlock(tsk);
464                 __put_fs_struct(fs);
465         }
466 }
467
468 void exit_fs(struct task_struct *tsk)
469 {
470         __exit_fs(tsk);
471 }
472
473 EXPORT_SYMBOL_GPL(exit_fs);
474
475 /*
476  * Turn us into a lazy TLB process if we
477  * aren't already..
478  */
479 static inline void __exit_mm(struct task_struct * tsk)
480 {
481         struct mm_struct *mm = tsk->mm;
482
483         mm_release(tsk, mm);
484         if (!mm)
485                 return;
486         /*
487          * Serialize with any possible pending coredump.
488          * We must hold mmap_sem around checking core_waiters
489          * and clearing tsk->mm.  The core-inducing thread
490          * will increment core_waiters for each thread in the
491          * group with ->mm != NULL.
492          */
493         down_read(&mm->mmap_sem);
494         if (mm->core_waiters) {
495                 up_read(&mm->mmap_sem);
496                 down_write(&mm->mmap_sem);
497                 if (!--mm->core_waiters)
498                         complete(mm->core_startup_done);
499                 up_write(&mm->mmap_sem);
500
501                 wait_for_completion(&mm->core_done);
502                 down_read(&mm->mmap_sem);
503         }
504         atomic_inc(&mm->mm_count);
505         if (mm != tsk->active_mm) BUG();
506         /* more a memory barrier than a real lock */
507         task_lock(tsk);
508         tsk->mm = NULL;
509         up_read(&mm->mmap_sem);
510         enter_lazy_tlb(mm, current);
511         task_unlock(tsk);
512         mmput(mm);
513 }
514
515 void exit_mm(struct task_struct *tsk)
516 {
517         __exit_mm(tsk);
518 }
519
520 EXPORT_SYMBOL(exit_mm);
521
522 static inline void choose_new_parent(task_t *p, task_t *reaper, task_t *child_reaper)
523 {
524         /*
525          * Make sure we're not reparenting to ourselves and that
526          * the parent is not a zombie.
527          */
528         BUG_ON(p == reaper || reaper->state >= TASK_ZOMBIE);
529         p->real_parent = reaper;
530         if (p->parent == p->real_parent)
531                 BUG();
532 }
533
534 static inline void reparent_thread(task_t *p, task_t *father, int traced)
535 {
536         /* We don't want people slaying init.  */
537         if (p->exit_signal != -1)
538                 p->exit_signal = SIGCHLD;
539         p->self_exec_id++;
540
541         if (p->pdeath_signal)
542                 /* We already hold the tasklist_lock here.  */
543                 group_send_sig_info(p->pdeath_signal, (void *) 0, p);
544
545         /* Move the child from its dying parent to the new one.  */
546         if (unlikely(traced)) {
547                 /* Preserve ptrace links if someone else is tracing this child.  */
548                 list_del_init(&p->ptrace_list);
549                 if (p->parent != p->real_parent)
550                         list_add(&p->ptrace_list, &p->real_parent->ptrace_children);
551         } else {
552                 /* If this child is being traced, then we're the one tracing it
553                  * anyway, so let go of it.
554                  */
555                 p->ptrace = 0;
556                 list_del_init(&p->sibling);
557                 p->parent = p->real_parent;
558                 list_add_tail(&p->sibling, &p->parent->children);
559
560                 /* If we'd notified the old parent about this child's death,
561                  * also notify the new parent.
562                  */
563                 if (p->state == TASK_ZOMBIE && p->exit_signal != -1 &&
564                     thread_group_empty(p))
565                         do_notify_parent(p, p->exit_signal);
566                 else if (p->state == TASK_TRACED) {
567                         /*
568                          * If it was at a trace stop, turn it into
569                          * a normal stop since it's no longer being
570                          * traced.
571                          */
572                         p->state = TASK_STOPPED;
573                 }
574         }
575
576         /*
577          * process group orphan check
578          * Case ii: Our child is in a different pgrp
579          * than we are, and it was the only connection
580          * outside, so the child pgrp is now orphaned.
581          */
582         if ((process_group(p) != process_group(father)) &&
583             (p->signal->session == father->signal->session)) {
584                 int pgrp = process_group(p);
585
586                 if (will_become_orphaned_pgrp(pgrp, NULL) && has_stopped_jobs(pgrp)) {
587                         __kill_pg_info(SIGHUP, (void *)1, pgrp);
588                         __kill_pg_info(SIGCONT, (void *)1, pgrp);
589                 }
590         }
591 }
592
593 /*
594  * When we die, we re-parent all our children.
595  * Try to give them to another thread in our thread
596  * group, and if no such member exists, give it to
597  * the global child reaper process (ie "init")
598  */
599 static inline void forget_original_parent(struct task_struct * father,
600                                           struct list_head *to_release)
601 {
602         struct task_struct *p, *reaper = father;
603         struct list_head *_p, *_n;
604
605         /* FIXME handle vchild_reaper/initpid */
606         do {
607                 reaper = next_thread(reaper);
608                 if (reaper == father) {
609                         reaper = child_reaper;
610                         break;
611                 }
612         } while (reaper->state >= TASK_ZOMBIE);
613
614         /*
615          * There are only two places where our children can be:
616          *
617          * - in our child list
618          * - in our ptraced child list
619          *
620          * Search them and reparent children.
621          */
622         list_for_each_safe(_p, _n, &father->children) {
623                 int ptrace;
624                 p = list_entry(_p,struct task_struct,sibling);
625
626                 ptrace = p->ptrace;
627
628                 /* if father isn't the real parent, then ptrace must be enabled */
629                 BUG_ON(father != p->real_parent && !ptrace);
630
631                 if (father == p->real_parent) {
632                         /* reparent with a reaper, real father it's us */
633                         choose_new_parent(p, reaper, child_reaper);
634                         reparent_thread(p, father, 0);
635                 } else {
636                         /* reparent ptraced task to its real parent */
637                         __ptrace_unlink (p);
638                         if (p->state == TASK_ZOMBIE && p->exit_signal != -1 &&
639                             thread_group_empty(p))
640                                 do_notify_parent(p, p->exit_signal);
641                 }
642
643                 /*
644                  * if the ptraced child is a zombie with exit_signal == -1
645                  * we must collect it before we exit, or it will remain
646                  * zombie forever since we prevented it from self-reap itself
647                  * while it was being traced by us, to be able to see it in wait4.
648                  */
649                 if (unlikely(ptrace && p->state == TASK_ZOMBIE && p->exit_signal == -1))
650                         list_add(&p->ptrace_list, to_release);
651         }
652         list_for_each_safe(_p, _n, &father->ptrace_children) {
653                 p = list_entry(_p,struct task_struct,ptrace_list);
654                 choose_new_parent(p, reaper, child_reaper);
655                 reparent_thread(p, father, 1);
656         }
657 }
658
659 /*
660  * Send signals to all our closest relatives so that they know
661  * to properly mourn us..
662  */
663 static void exit_notify(struct task_struct *tsk)
664 {
665         int state;
666         struct task_struct *t;
667         struct list_head ptrace_dead, *_p, *_n;
668
669         if (signal_pending(tsk) && !tsk->signal->group_exit
670             && !thread_group_empty(tsk)) {
671                 /*
672                  * This occurs when there was a race between our exit
673                  * syscall and a group signal choosing us as the one to
674                  * wake up.  It could be that we are the only thread
675                  * alerted to check for pending signals, but another thread
676                  * should be woken now to take the signal since we will not.
677                  * Now we'll wake all the threads in the group just to make
678                  * sure someone gets all the pending signals.
679                  */
680                 read_lock(&tasklist_lock);
681                 spin_lock_irq(&tsk->sighand->siglock);
682                 for (t = next_thread(tsk); t != tsk; t = next_thread(t))
683                         if (!signal_pending(t) && !(t->flags & PF_EXITING)) {
684                                 recalc_sigpending_tsk(t);
685                                 if (signal_pending(t))
686                                         signal_wake_up(t, 0);
687                         }
688                 spin_unlock_irq(&tsk->sighand->siglock);
689                 read_unlock(&tasklist_lock);
690         }
691
692         write_lock_irq(&tasklist_lock);
693
694         /*
695          * This does two things:
696          *
697          * A.  Make init inherit all the child processes
698          * B.  Check to see if any process groups have become orphaned
699          *      as a result of our exiting, and if they have any stopped
700          *      jobs, send them a SIGHUP and then a SIGCONT.  (POSIX 3.2.2.2)
701          */
702
703         INIT_LIST_HEAD(&ptrace_dead);
704         forget_original_parent(tsk, &ptrace_dead);
705         BUG_ON(!list_empty(&tsk->children));
706         BUG_ON(!list_empty(&tsk->ptrace_children));
707
708         /*
709          * Check to see if any process groups have become orphaned
710          * as a result of our exiting, and if they have any stopped
711          * jobs, send them a SIGHUP and then a SIGCONT.  (POSIX 3.2.2.2)
712          *
713          * Case i: Our father is in a different pgrp than we are
714          * and we were the only connection outside, so our pgrp
715          * is about to become orphaned.
716          */
717          
718         t = tsk->real_parent;
719         
720         if ((process_group(t) != process_group(tsk)) &&
721             (t->signal->session == tsk->signal->session) &&
722             will_become_orphaned_pgrp(process_group(tsk), tsk) &&
723             has_stopped_jobs(process_group(tsk))) {
724                 __kill_pg_info(SIGHUP, (void *)1, process_group(tsk));
725                 __kill_pg_info(SIGCONT, (void *)1, process_group(tsk));
726         }
727
728         /* Let father know we died 
729          *
730          * Thread signals are configurable, but you aren't going to use
731          * that to send signals to arbitary processes. 
732          * That stops right now.
733          *
734          * If the parent exec id doesn't match the exec id we saved
735          * when we started then we know the parent has changed security
736          * domain.
737          *
738          * If our self_exec id doesn't match our parent_exec_id then
739          * we have changed execution domain as these two values started
740          * the same after a fork.
741          *      
742          */
743         
744         if (tsk->exit_signal != SIGCHLD && tsk->exit_signal != -1 &&
745             ( tsk->parent_exec_id != t->self_exec_id  ||
746               tsk->self_exec_id != tsk->parent_exec_id)
747             && !capable(CAP_KILL))
748                 tsk->exit_signal = SIGCHLD;
749
750
751         /* If something other than our normal parent is ptracing us, then
752          * send it a SIGCHLD instead of honoring exit_signal.  exit_signal
753          * only has special meaning to our real parent.
754          */
755         if (tsk->exit_signal != -1 && thread_group_empty(tsk)) {
756                 int signal = tsk->parent == tsk->real_parent ? tsk->exit_signal : SIGCHLD;
757                 do_notify_parent(tsk, signal);
758         } else if (tsk->ptrace) {
759                 do_notify_parent(tsk, SIGCHLD);
760         }
761
762         state = TASK_ZOMBIE;
763         if (tsk->exit_signal == -1 && tsk->ptrace == 0)
764                 state = TASK_DEAD;
765         tsk->state = state;
766
767         /*
768          * Clear these here so that update_process_times() won't try to deliver
769          * itimer, profile or rlimit signals to this task while it is in late exit.
770          */
771         tsk->it_virt_value = 0;
772         tsk->it_prof_value = 0;
773         tsk->rlim[RLIMIT_CPU].rlim_cur = RLIM_INFINITY;
774
775         write_unlock_irq(&tasklist_lock);
776
777         list_for_each_safe(_p, _n, &ptrace_dead) {
778                 list_del_init(_p);
779                 t = list_entry(_p,struct task_struct,ptrace_list);
780                 release_task(t);
781         }
782
783         /* If the process is dead, release it - nobody will wait for it */
784         if (state == TASK_DEAD)
785                 release_task(tsk);
786
787         /* PF_DEAD causes final put_task_struct after we schedule. */
788         preempt_disable();
789         tsk->flags |= PF_DEAD;
790 }
791
792 asmlinkage NORET_TYPE void do_exit(long code)
793 {
794         struct task_struct *tsk = current;
795
796         profile_task_exit(tsk);
797
798         if (unlikely(in_interrupt()))
799                 panic("Aiee, killing interrupt handler!");
800         if (unlikely(!tsk->pid))
801                 panic("Attempted to kill the idle task!");
802         if (unlikely(tsk->pid == 1))
803                 panic("Attempted to kill init!");
804         if (tsk->io_context)
805                 exit_io_context();
806         tsk->flags |= PF_EXITING;
807         del_timer_sync(&tsk->real_timer);
808
809         if (unlikely(in_atomic()))
810                 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n",
811                                 current->comm, current->pid,
812                                 preempt_count());
813
814         if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
815                 current->ptrace_message = code;
816                 ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
817         }
818
819         acct_process(code);
820         __exit_mm(tsk);
821
822         exit_sem(tsk);
823         __exit_files(tsk);
824         __exit_fs(tsk);
825         exit_namespace(tsk);
826         exit_thread();
827
828         if (tsk->signal->leader)
829                 disassociate_ctty(1);
830
831         module_put(tsk->thread_info->exec_domain->module);
832         if (tsk->binfmt)
833                 module_put(tsk->binfmt->module);
834
835         tsk->exit_code = code;
836         exit_notify(tsk);
837 #ifdef CONFIG_NUMA
838         mpol_free(tsk->mempolicy);
839         tsk->mempolicy = NULL;
840 #endif
841         schedule();
842         BUG();
843         /* Avoid "noreturn function does return".  */
844         for (;;) ;
845 }
846
847 NORET_TYPE void complete_and_exit(struct completion *comp, long code)
848 {
849         if (comp)
850                 complete(comp);
851         
852         do_exit(code);
853 }
854
855 EXPORT_SYMBOL(complete_and_exit);
856
857 asmlinkage long sys_exit(int error_code)
858 {
859         do_exit((error_code&0xff)<<8);
860 }
861
862 task_t fastcall *next_thread(const task_t *p)
863 {
864 #ifdef CONFIG_SMP
865         if (!p->sighand)
866                 BUG();
867         if (!spin_is_locked(&p->sighand->siglock) &&
868                                 !rwlock_is_locked(&tasklist_lock))
869                 BUG();
870 #endif
871         return pid_task(p->pids[PIDTYPE_TGID].pid_list.next, PIDTYPE_TGID);
872 }
873
874 EXPORT_SYMBOL(next_thread);
875
876 /*
877  * Take down every thread in the group.  This is called by fatal signals
878  * as well as by sys_exit_group (below).
879  */
880 NORET_TYPE void
881 do_group_exit(int exit_code)
882 {
883         BUG_ON(exit_code & 0x80); /* core dumps don't get here */
884
885         if (current->signal->group_exit)
886                 exit_code = current->signal->group_exit_code;
887         else if (!thread_group_empty(current)) {
888                 struct signal_struct *const sig = current->signal;
889                 struct sighand_struct *const sighand = current->sighand;
890                 read_lock(&tasklist_lock);
891                 spin_lock_irq(&sighand->siglock);
892                 if (sig->group_exit)
893                         /* Another thread got here before we took the lock.  */
894                         exit_code = sig->group_exit_code;
895                 else {
896                         sig->group_exit = 1;
897                         sig->group_exit_code = exit_code;
898                         zap_other_threads(current);
899                 }
900                 spin_unlock_irq(&sighand->siglock);
901                 read_unlock(&tasklist_lock);
902         }
903
904         do_exit(exit_code);
905         /* NOTREACHED */
906 }
907
908 /*
909  * this kills every thread in the thread group. Note that any externally
910  * wait4()-ing process will get the correct exit code - even if this
911  * thread is not the thread group leader.
912  */
913 asmlinkage void sys_exit_group(int error_code)
914 {
915         do_group_exit((error_code & 0xff) << 8);
916 }
917
918 static int eligible_child(pid_t pid, int options, task_t *p)
919 {
920         if (pid > 0) {
921                 if (p->pid != pid)
922                         return 0;
923         } else if (!pid) {
924                 if (process_group(p) != process_group(current))
925                         return 0;
926         } else if (pid != -1) {
927                 if (process_group(p) != -pid)
928                         return 0;
929         }
930
931         /*
932          * Do not consider detached threads that are
933          * not ptraced:
934          */
935         if (p->exit_signal == -1 && !p->ptrace)
936                 return 0;
937
938         /* Wait for all children (clone and not) if __WALL is set;
939          * otherwise, wait for clone children *only* if __WCLONE is
940          * set; otherwise, wait for non-clone children *only*.  (Note:
941          * A "clone" child here is one that reports to its parent
942          * using a signal other than SIGCHLD.) */
943         if (((p->exit_signal != SIGCHLD) ^ ((options & __WCLONE) != 0))
944             && !(options & __WALL))
945                 return 0;
946         /*
947          * Do not consider thread group leaders that are
948          * in a non-empty thread group:
949          */
950         if (current->tgid != p->tgid && delay_group_leader(p))
951                 return 2;
952
953         if (security_task_wait(p))
954                 return 0;
955
956         return 1;
957 }
958
959 static int wait_noreap_copyout(task_t *p, pid_t pid, uid_t uid,
960                                int why, int status,
961                                struct siginfo __user *infop,
962                                struct rusage __user *rusagep)
963 {
964         int retval = rusagep ? getrusage(p, RUSAGE_BOTH, rusagep) : 0;
965         put_task_struct(p);
966         if (!retval)
967                 retval = put_user(SIGCHLD, &infop->si_signo);
968         if (!retval)
969                 retval = put_user(0, &infop->si_errno);
970         if (!retval)
971                 retval = put_user((short)why, &infop->si_code);
972         if (!retval)
973                 retval = put_user(pid, &infop->si_pid);
974         if (!retval)
975                 retval = put_user(uid, &infop->si_uid);
976         if (!retval)
977                 retval = put_user(status, &infop->si_status);
978         if (!retval)
979                 retval = pid;
980         return retval;
981 }
982
983 /*
984  * Handle sys_wait4 work for one task in state TASK_ZOMBIE.  We hold
985  * read_lock(&tasklist_lock) on entry.  If we return zero, we still hold
986  * the lock and this task is uninteresting.  If we return nonzero, we have
987  * released the lock and the system call should return.
988  */
989 static int wait_task_zombie(task_t *p, int noreap,
990                             struct siginfo __user *infop,
991                             int __user *stat_addr, struct rusage __user *ru)
992 {
993         unsigned long state;
994         int retval;
995         int status;
996
997         if (unlikely(noreap)) {
998                 pid_t pid = p->pid;
999                 uid_t uid = p->uid;
1000                 int exit_code = p->exit_code;
1001                 int why, status;
1002
1003                 if (unlikely(p->state != TASK_ZOMBIE))
1004                         return 0;
1005                 if (unlikely(p->exit_signal == -1 && p->ptrace == 0))
1006                         return 0;
1007                 get_task_struct(p);
1008                 read_unlock(&tasklist_lock);
1009                 if ((exit_code & 0x7f) == 0) {
1010                         why = CLD_EXITED;
1011                         status = exit_code >> 8;
1012                 } else {
1013                         why = (exit_code & 0x80) ? CLD_DUMPED : CLD_KILLED;
1014                         status = exit_code & 0x7f;
1015                 }
1016                 return wait_noreap_copyout(p, pid, uid, why,
1017                                            status, infop, ru);
1018         }
1019
1020         /*
1021          * Try to move the task's state to DEAD
1022          * only one thread is allowed to do this:
1023          */
1024         state = xchg(&p->state, TASK_DEAD);
1025         if (state != TASK_ZOMBIE) {
1026                 BUG_ON(state != TASK_DEAD);
1027                 return 0;
1028         }
1029         if (unlikely(p->exit_signal == -1 && p->ptrace == 0)) {
1030                 /*
1031                  * This can only happen in a race with a ptraced thread
1032                  * dying on another processor.
1033                  */
1034                 return 0;
1035         }
1036
1037         if (likely(p->real_parent == p->parent) && likely(p->signal)) {
1038                 /*
1039                  * The resource counters for the group leader are in its
1040                  * own task_struct.  Those for dead threads in the group
1041                  * are in its signal_struct, as are those for the child
1042                  * processes it has previously reaped.  All these
1043                  * accumulate in the parent's signal_struct c* fields.
1044                  *
1045                  * We don't bother to take a lock here to protect these
1046                  * p->signal fields, because they are only touched by
1047                  * __exit_signal, which runs with tasklist_lock
1048                  * write-locked anyway, and so is excluded here.  We do
1049                  * need to protect the access to p->parent->signal fields,
1050                  * as other threads in the parent group can be right
1051                  * here reaping other children at the same time.
1052                  */
1053                 spin_lock_irq(&p->parent->sighand->siglock);
1054                 p->parent->signal->cutime +=
1055                         p->utime + p->signal->utime + p->signal->cutime;
1056                 p->parent->signal->cstime +=
1057                         p->stime + p->signal->stime + p->signal->cstime;
1058                 p->parent->signal->cmin_flt +=
1059                         p->min_flt + p->signal->min_flt + p->signal->cmin_flt;
1060                 p->parent->signal->cmaj_flt +=
1061                         p->maj_flt + p->signal->maj_flt + p->signal->cmaj_flt;
1062                 p->parent->signal->cnvcsw +=
1063                         p->nvcsw + p->signal->nvcsw + p->signal->cnvcsw;
1064                 p->parent->signal->cnivcsw +=
1065                         p->nivcsw + p->signal->nivcsw + p->signal->cnivcsw;
1066                 spin_unlock_irq(&p->parent->sighand->siglock);
1067         }
1068
1069         /*
1070          * Now we are sure this task is interesting, and no other
1071          * thread can reap it because we set its state to TASK_DEAD.
1072          */
1073         read_unlock(&tasklist_lock);
1074
1075         retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
1076         status = p->signal->group_exit
1077                 ? p->signal->group_exit_code : p->exit_code;
1078         if (!retval && stat_addr)
1079                 retval = put_user(status, stat_addr);
1080         if (!retval && infop)
1081                 retval = put_user(SIGCHLD, &infop->si_signo);
1082         if (!retval && infop)
1083                 retval = put_user(0, &infop->si_errno);
1084         if (!retval && infop) {
1085                 int why;
1086
1087                 if ((status & 0x7f) == 0) {
1088                         why = CLD_EXITED;
1089                         status >>= 8;
1090                 } else {
1091                         why = (status & 0x80) ? CLD_DUMPED : CLD_KILLED;
1092                         status &= 0x7f;
1093                 }
1094                 retval = put_user((short)why, &infop->si_code);
1095                 if (!retval)
1096                         retval = put_user(status, &infop->si_status);
1097         }
1098         if (!retval && infop)
1099                 retval = put_user(p->pid, &infop->si_pid);
1100         if (!retval && infop)
1101                 retval = put_user(p->uid, &infop->si_uid);
1102         if (retval) {
1103                 p->state = TASK_ZOMBIE;
1104                 return retval;
1105         }
1106         retval = p->pid;
1107         if (p->real_parent != p->parent) {
1108                 write_lock_irq(&tasklist_lock);
1109                 /* Double-check with lock held.  */
1110                 if (p->real_parent != p->parent) {
1111                         __ptrace_unlink(p);
1112                         p->state = TASK_ZOMBIE;
1113                         /*
1114                          * If this is not a detached task, notify the parent.
1115                          * If it's still not detached after that, don't release
1116                          * it now.
1117                          */
1118                         if (p->exit_signal != -1) {
1119                                 do_notify_parent(p, p->exit_signal);
1120                                 if (p->exit_signal != -1)
1121                                         p = NULL;
1122                         }
1123                 }
1124                 write_unlock_irq(&tasklist_lock);
1125         }
1126         if (p != NULL)
1127                 release_task(p);
1128         BUG_ON(!retval);
1129         return retval;
1130 }
1131
1132 /*
1133  * Handle sys_wait4 work for one task in state TASK_STOPPED.  We hold
1134  * read_lock(&tasklist_lock) on entry.  If we return zero, we still hold
1135  * the lock and this task is uninteresting.  If we return nonzero, we have
1136  * released the lock and the system call should return.
1137  */
1138 static int wait_task_stopped(task_t *p, int delayed_group_leader, int noreap,
1139                              struct siginfo __user *infop,
1140                              int __user *stat_addr, struct rusage __user *ru)
1141 {
1142         int retval, exit_code;
1143
1144         if (!p->exit_code)
1145                 return 0;
1146         if (delayed_group_leader && !(p->ptrace & PT_PTRACED) &&
1147             p->signal && p->signal->group_stop_count > 0)
1148                 /*
1149                  * A group stop is in progress and this is the group leader.
1150                  * We won't report until all threads have stopped.
1151                  */
1152                 return 0;
1153
1154         /*
1155          * Now we are pretty sure this task is interesting.
1156          * Make sure it doesn't get reaped out from under us while we
1157          * give up the lock and then examine it below.  We don't want to
1158          * keep holding onto the tasklist_lock while we call getrusage and
1159          * possibly take page faults for user memory.
1160          */
1161         get_task_struct(p);
1162         read_unlock(&tasklist_lock);
1163
1164         if (unlikely(noreap)) {
1165                 pid_t pid = p->pid;
1166                 uid_t uid = p->uid;
1167                 int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
1168
1169                 exit_code = p->exit_code;
1170                 if (unlikely(!exit_code) ||
1171                     unlikely(p->state > TASK_STOPPED))
1172                         goto bail_ref;
1173                 return wait_noreap_copyout(p, pid, uid,
1174                                            why, (exit_code << 8) | 0x7f,
1175                                            infop, ru);
1176         }
1177
1178         write_lock_irq(&tasklist_lock);
1179
1180         /*
1181          * This uses xchg to be atomic with the thread resuming and setting
1182          * it.  It must also be done with the write lock held to prevent a
1183          * race with the TASK_ZOMBIE case.
1184          */
1185         exit_code = xchg(&p->exit_code, 0);
1186         if (unlikely(p->state >= TASK_ZOMBIE)) {
1187                 /*
1188                  * The task resumed and then died.  Let the next iteration
1189                  * catch it in TASK_ZOMBIE.  Note that exit_code might
1190                  * already be zero here if it resumed and did _exit(0).
1191                  * The task itself is dead and won't touch exit_code again;
1192                  * other processors in this function are locked out.
1193                  */
1194                 p->exit_code = exit_code;
1195                 exit_code = 0;
1196         }
1197         if (unlikely(exit_code == 0)) {
1198                 /*
1199                  * Another thread in this function got to it first, or it
1200                  * resumed, or it resumed and then died.
1201                  */
1202                 write_unlock_irq(&tasklist_lock);
1203 bail_ref:
1204                 put_task_struct(p);
1205                 read_lock(&tasklist_lock);
1206                 return 0;
1207         }
1208
1209         /* move to end of parent's list to avoid starvation */
1210         remove_parent(p);
1211         add_parent(p, p->parent);
1212
1213         write_unlock_irq(&tasklist_lock);
1214
1215         retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
1216         if (!retval && stat_addr)
1217                 retval = put_user((exit_code << 8) | 0x7f, stat_addr);
1218         if (!retval && infop)
1219                 retval = put_user(SIGCHLD, &infop->si_signo);
1220         if (!retval && infop)
1221                 retval = put_user(0, &infop->si_errno);
1222         if (!retval && infop)
1223                 retval = put_user((short)((p->ptrace & PT_PTRACED)
1224                                           ? CLD_TRAPPED : CLD_STOPPED),
1225                                   &infop->si_code);
1226         if (!retval && infop)
1227                 retval = put_user(exit_code, &infop->si_status);
1228         if (!retval && infop)
1229                 retval = put_user(p->pid, &infop->si_pid);
1230         if (!retval && infop)
1231                 retval = put_user(p->uid, &infop->si_uid);
1232         if (!retval)
1233                 retval = p->pid;
1234         put_task_struct(p);
1235
1236         BUG_ON(!retval);
1237         return retval;
1238 }
1239
1240 static long do_wait(pid_t pid, int options, struct siginfo __user *infop,
1241                     int __user *stat_addr, struct rusage __user *ru)
1242 {
1243         DECLARE_WAITQUEUE(wait, current);
1244         struct task_struct *tsk;
1245         int flag, retval;
1246
1247         add_wait_queue(&current->wait_chldexit,&wait);
1248 repeat:
1249         flag = 0;
1250         current->state = TASK_INTERRUPTIBLE;
1251         read_lock(&tasklist_lock);
1252         tsk = current;
1253         do {
1254                 struct task_struct *p;
1255                 struct list_head *_p;
1256                 int ret;
1257
1258                 list_for_each(_p,&tsk->children) {
1259                         p = list_entry(_p,struct task_struct,sibling);
1260
1261                         ret = eligible_child(pid, options, p);
1262                         if (!ret)
1263                                 continue;
1264                         flag = 1;
1265
1266                         switch (p->state) {
1267                         case TASK_TRACED:
1268                                 if (!(p->ptrace & PT_PTRACED))
1269                                         continue;
1270                                 /*FALLTHROUGH*/
1271                         case TASK_STOPPED:
1272                                 if (!(options & WUNTRACED) &&
1273                                     !(p->ptrace & PT_PTRACED))
1274                                         continue;
1275                                 retval = wait_task_stopped(p, ret == 2,
1276                                                            (options & WNOWAIT),
1277                                                            infop,
1278                                                            stat_addr, ru);
1279                                 if (retval != 0) /* He released the lock.  */
1280                                         goto end;
1281                                 break;
1282                         case TASK_ZOMBIE:
1283                                 /*
1284                                  * Eligible but we cannot release it yet:
1285                                  */
1286                                 if (ret == 2)
1287                                         goto check_continued;
1288                                 if (!likely(options & WEXITED))
1289                                         continue;
1290                                 retval = wait_task_zombie(
1291                                         p, (options & WNOWAIT),
1292                                         infop, stat_addr, ru);
1293                                 if (retval != 0) /* He released the lock.  */
1294                                         goto end;
1295                                 break;
1296                         case TASK_DEAD:
1297                                 continue;
1298                         default:
1299 check_continued:
1300                                 if (!unlikely(options & WCONTINUED))
1301                                         continue;
1302                                 if (unlikely(!p->signal))
1303                                         continue;
1304                                 spin_lock_irq(&p->sighand->siglock);
1305                                 if (p->signal->stop_state < 0) {
1306                                         pid_t pid;
1307                                         uid_t uid;
1308
1309                                         if (!(options & WNOWAIT))
1310                                                 p->signal->stop_state = 0;
1311                                         spin_unlock_irq(&p->sighand->siglock);
1312                                         pid = p->pid;
1313                                         uid = p->uid;
1314                                         get_task_struct(p);
1315                                         read_unlock(&tasklist_lock);
1316                                         retval = wait_noreap_copyout(p, pid,
1317                                                         uid, CLD_CONTINUED,
1318                                                         SIGCONT, infop, ru);
1319                                         BUG_ON(retval == 0);
1320                                         goto end;
1321                                 }
1322                                 spin_unlock_irq(&p->sighand->siglock);
1323                                 break;
1324                         }
1325                 }
1326                 if (!flag) {
1327                         list_for_each(_p, &tsk->ptrace_children) {
1328                                 p = list_entry(_p, struct task_struct,
1329                                                 ptrace_list);
1330                                 if (!eligible_child(pid, options, p))
1331                                         continue;
1332                                 flag = 1;
1333                                 break;
1334                         }
1335                 }
1336                 if (options & __WNOTHREAD)
1337                         break;
1338                 tsk = next_thread(tsk);
1339                 if (tsk->signal != current->signal)
1340                         BUG();
1341         } while (tsk != current);
1342
1343         read_unlock(&tasklist_lock);
1344         if (flag) {
1345                 retval = 0;
1346                 if (options & WNOHANG)
1347                         goto end;
1348                 retval = -ERESTARTSYS;
1349                 if (signal_pending(current))
1350                         goto end;
1351                 schedule();
1352                 goto repeat;
1353         }
1354         retval = -ECHILD;
1355 end:
1356         current->state = TASK_RUNNING;
1357         remove_wait_queue(&current->wait_chldexit,&wait);
1358         if (infop) {
1359                 if (retval > 0)
1360                 retval = 0;
1361                 else {
1362                         /*
1363                          * For a WNOHANG return, clear out all the fields
1364                          * we would set so the user can easily tell the
1365                          * difference.
1366                          */
1367                         if (!retval)
1368                                 retval = put_user(0, &infop->si_signo);
1369                         if (!retval)
1370                                 retval = put_user(0, &infop->si_errno);
1371                         if (!retval)
1372                                 retval = put_user(0, &infop->si_code);
1373                         if (!retval)
1374                                 retval = put_user(0, &infop->si_pid);
1375                         if (!retval)
1376                                 retval = put_user(0, &infop->si_uid);
1377                         if (!retval)
1378                                 retval = put_user(0, &infop->si_status);
1379                 }
1380         }
1381         return retval;
1382 }
1383
1384 asmlinkage long sys_waitid(int which, pid_t pid,
1385                            struct siginfo __user *infop, int options,
1386                            struct rusage __user *ru)
1387 {
1388         long ret;
1389
1390         if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED))
1391                 return -EINVAL;
1392         if (!(options & (WEXITED|WSTOPPED|WCONTINUED)))
1393                 return -EINVAL;
1394
1395         switch (which) {
1396         case P_ALL:
1397                 pid = -1;
1398                 break;
1399         case P_PID:
1400                 if (pid <= 0)
1401                         return -EINVAL;
1402                 break;
1403         case P_PGID:
1404                 if (pid <= 0)
1405                         return -EINVAL;
1406                 pid = -pid;
1407                 break;
1408         default:
1409                 return -EINVAL;
1410         }
1411
1412         ret = do_wait(pid, options, infop, NULL, ru);
1413
1414         /* avoid REGPARM breakage on x86: */
1415         prevent_tail_call(ret);
1416         return ret;
1417 }
1418
1419 asmlinkage long sys_wait4(pid_t pid, int __user *stat_addr,
1420                           int options, struct rusage __user *ru)
1421 {
1422         long ret;
1423
1424         if (options & ~(WNOHANG|WUNTRACED|__WNOTHREAD|__WCLONE|__WALL))
1425                 return -EINVAL;
1426         ret = do_wait(pid, options | WEXITED, NULL, stat_addr, ru);
1427
1428         /* avoid REGPARM breakage on x86: */
1429         prevent_tail_call(ret);
1430         return ret;
1431 }
1432
1433 #ifdef __ARCH_WANT_SYS_WAITPID
1434
1435 /*
1436  * sys_waitpid() remains for compatibility. waitpid() should be
1437  * implemented by calling sys_wait4() from libc.a.
1438  */
1439 asmlinkage long sys_waitpid(pid_t pid, int __user *stat_addr, int options)
1440 {
1441         return sys_wait4(pid, stat_addr, options, NULL);
1442 }
1443
1444 #endif