libexplain  1.4.D001
libexplain/buffer/errno/wait4.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2011, 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,
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 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/resource.h>
00021 #include <libexplain/ac/unistd.h>
00022 
00023 #include <libexplain/buffer/efault.h>
00024 #include <libexplain/buffer/errno/wait4.h>
00025 #include <libexplain/buffer/errno/waitpid.h>
00026 #include <libexplain/buffer/pid_t_star.h>
00027 #include <libexplain/buffer/pointer.h>
00028 #include <libexplain/buffer/waitpid_options.h>
00029 #include <libexplain/explanation.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 
00033 static void
00034 explain_buffer_errno_wait4_system_call(explain_string_buffer_t *sb,
00035     int errnum, int pid, int *status, int options, struct rusage *rusage)
00036 {
00037     (void)errnum;
00038     explain_string_buffer_puts(sb, "wait4(pid = ");
00039     explain_buffer_pid_t(sb, pid);
00040     if (pid == 0)
00041     {
00042         explain_string_buffer_puts(sb, " = process group ");
00043         explain_buffer_pid_t(sb, getpgrp());
00044     }
00045     else if (pid < -1)
00046     {
00047         explain_string_buffer_puts(sb, " = process group ");
00048         explain_buffer_pid_t(sb, -pid);
00049     }
00050     explain_string_buffer_puts(sb, ", status = ");
00051     explain_buffer_pointer(sb, status);
00052     explain_string_buffer_puts(sb, ", options = ");
00053     explain_buffer_waitpid_options(sb, options);
00054     explain_string_buffer_puts(sb, ", rusage = ");
00055     explain_buffer_pointer(sb, rusage);
00056     explain_string_buffer_putc(sb, ')');
00057 }
00058 
00059 
00060 void
00061 explain_buffer_errno_wait4_explanation(explain_string_buffer_t *sb,
00062     int errnum, const char *syscall_name, int pid, int *status, int options,
00063     struct rusage *rusage)
00064 {
00065     switch (errnum)
00066     {
00067     case EFAULT:
00068         if (rusage && explain_is_efault_pointer(rusage, sizeof(*rusage)))
00069         {
00070             explain_buffer_efault(sb, "rusage");
00071             break;
00072         }
00073         if (explain_is_efault_pointer(status, sizeof(*status)))
00074         {
00075             explain_buffer_efault(sb, "status");
00076             break;
00077         }
00078         break;
00079 
00080     default:
00081         explain_buffer_errno_waitpid_explanation
00082         (
00083             sb,
00084             errnum,
00085             syscall_name,
00086             pid,
00087             status,
00088             options
00089         );
00090         break;
00091     }
00092 }
00093 
00094 
00095 void
00096 explain_buffer_errno_wait4(explain_string_buffer_t *sb, int errnum,
00097     int pid, int *status, int options, struct rusage *rusage)
00098 {
00099     explain_explanation_t exp;
00100 
00101     explain_explanation_init(&exp, errnum);
00102     explain_buffer_errno_wait4_system_call
00103     (
00104         &exp.system_call_sb,
00105         errnum,
00106         pid,
00107         status,
00108         options,
00109         rusage
00110     );
00111     explain_buffer_errno_wait4_explanation
00112     (
00113         &exp.explanation_sb,
00114         errnum,
00115         "wait4",
00116         pid,
00117         status,
00118         options,
00119         rusage
00120     );
00121     explain_explanation_assemble(&exp, sb);
00122 }
00123 
00124 
00125 /* vim: set ts=8 sw=4 et : */