Back to index

glibc  2.9
waitid.c
Go to the documentation of this file.
00001 /* Linux implementation of waitid.
00002    Copyright (C) 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stddef.h>
00021 #include <errno.h>
00022 #include <sys/wait.h>
00023 #include <kernel-features.h>
00024 #include <sysdep.h>
00025 
00026 
00027 #ifdef __NR_waitid
00028 
00029 # if __ASSUME_WAITID_SYSCALL > 0
00030 
00031 static inline int
00032 do_waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
00033 {
00034   /* The unused fifth argument is a `struct rusage *' that we could
00035      pass if we were using waitid to simulate wait3/wait4.  */
00036   return INLINE_SYSCALL (waitid, 5, idtype, id, infop, options, NULL);
00037 }
00038 # define NO_DO_WAITID
00039 
00040 # else
00041 
00042 static int do_compat_waitid (idtype_t idtype, id_t id,
00043                           siginfo_t *infop, int options);
00044 # define DO_WAITID do_compat_waitid
00045 
00046 static int
00047 do_waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
00048 {
00049   static int waitid_works;
00050   if (waitid_works > 0)
00051     return INLINE_SYSCALL (waitid, 5, idtype, id, infop, options, NULL);
00052   if (waitid_works == 0)
00053     {
00054       int result = INLINE_SYSCALL (waitid, 5,
00055                                idtype, id, infop, options, NULL);
00056       if (result < 0 && errno == ENOSYS)
00057        waitid_works = -1;
00058       else
00059        {
00060          waitid_works = 1;
00061          return result;
00062        }
00063     }
00064   return do_compat_waitid (idtype, id, infop, options);
00065 }
00066 
00067 # endif
00068 
00069 #endif
00070 
00071 #include "sysdeps/posix/waitid.c"