libexplain  1.4.D001
libexplain/buffer/errno/signalfd.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 3 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty
00012  * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/errno.h>
00020 #include <libexplain/ac/sys/signalfd.h>
00021 
00022 #include <libexplain/buffer/ebadf.h>
00023 #include <libexplain/buffer/efault.h>
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/emfile.h>
00026 #include <libexplain/buffer/enfile.h>
00027 #include <libexplain/buffer/enodev.h>
00028 #include <libexplain/buffer/enomem.h>
00029 #include <libexplain/buffer/enosys.h>
00030 #include <libexplain/buffer/errno/generic.h>
00031 #include <libexplain/buffer/errno/signalfd.h>
00032 #include <libexplain/buffer/fildes.h>
00033 #include <libexplain/buffer/signalfd_flags.h>
00034 #include <libexplain/buffer/sigset_t.h>
00035 #include <libexplain/explanation.h>
00036 
00037 
00038 static void
00039 explain_buffer_errno_signalfd_system_call(explain_string_buffer_t *sb, int
00040     errnum, int fildes, const sigset_t *mask, int flags)
00041 {
00042     (void)errnum;
00043     explain_string_buffer_puts(sb, "signalfd(fildes = ");
00044     explain_buffer_fildes(sb, fildes);
00045     explain_string_buffer_puts(sb, ", mask = ");
00046     explain_buffer_sigset_t(sb, mask);
00047     explain_string_buffer_puts(sb, ", flags = ");
00048     explain_buffer_signalfd_flags(sb, flags);
00049     explain_string_buffer_putc(sb, ')');
00050 }
00051 
00052 
00053 static void
00054 explain_buffer_errno_signalfd_explanation(explain_string_buffer_t *sb,
00055     int errnum, const char *syscall_name, int fildes, const sigset_t *mask,
00056     int flags)
00057 {
00058     /*
00059      * http://www.opengroup.org/onlinepubs/009695399/functions/signalfd.html
00060      */
00061     (void)mask;
00062     (void)flags;
00063     switch (errnum)
00064     {
00065     case EBADF:
00066         explain_buffer_ebadf(sb, fildes, "fildes");
00067         break;
00068 
00069     case EFAULT:
00070         explain_buffer_efault(sb, "mask");
00071         break;
00072 
00073     case EINVAL:
00074         if (fildes >= 0)
00075             explain_buffer_einval_signalfd(sb, "fildes");
00076         else
00077             explain_buffer_einval_bits(sb, "flags");
00078         break;
00079 
00080     case EMFILE:
00081         explain_buffer_emfile(sb);
00082         break;
00083 
00084     case ENFILE:
00085         explain_buffer_enfile(sb);
00086         break;
00087 
00088     case ENODEV:
00089         explain_buffer_enodev_anon_inodes(sb, syscall_name);
00090         break;
00091 
00092     case ENOMEM:
00093         explain_buffer_enomem_kernel(sb);
00094         break;
00095 
00096     case ENOSYS:
00097         explain_buffer_enosys_vague(sb, syscall_name);
00098         break;
00099 
00100     default:
00101         explain_buffer_errno_generic(sb, errnum, syscall_name);
00102         break;
00103     }
00104 }
00105 
00106 
00107 void
00108 explain_buffer_errno_signalfd(explain_string_buffer_t *sb, int errnum, int
00109     fildes, const sigset_t *mask, int flags)
00110 {
00111     explain_explanation_t exp;
00112 
00113     explain_explanation_init(&exp, errnum);
00114     explain_buffer_errno_signalfd_system_call
00115     (
00116         &exp.system_call_sb,
00117         errnum,
00118         fildes,
00119         mask,
00120         flags
00121     );
00122     explain_buffer_errno_signalfd_explanation
00123     (
00124         &exp.explanation_sb,
00125         errnum,
00126         "signalfd",
00127         fildes,
00128         mask,
00129         flags
00130     );
00131     explain_explanation_assemble(&exp, sb);
00132 }
00133 
00134 
00135 /* vim: set ts=8 sw=4 et : */