libexplain  1.4.D001
libexplain/buffer/wait_status.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 3 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/stdio.h>
00021 #include <libexplain/ac/stdlib.h>
00022 #include <libexplain/ac/signal.h>
00023 #include <libexplain/ac/sys/wait.h>
00024 
00025 #include <libexplain/buffer/wait_status.h>
00026 #include <libexplain/buffer/strsignal.h>
00027 
00028 
00029 void
00030 explain_buffer_wait_status(explain_string_buffer_t *sb, int status)
00031 {
00032     if (WIFEXITED(status))
00033     {
00034         char            name[30];
00035         int             es;
00036 
00037         es = WEXITSTATUS(status);
00038         if (es == EXIT_SUCCESS)
00039             snprintf(name, sizeof(name), "EXIT_SUCCESS (%d)", es);
00040         else if (es == EXIT_FAILURE)
00041             snprintf(name, sizeof(name), "EXIT_FAILURE (%d)", es);
00042         else
00043             snprintf(name, sizeof(name), "%d", es);
00044         explain_string_buffer_printf_gettext
00045         (
00046             sb,
00047             /*
00048              * xgettext:  This message is used when a child process
00049              * terminates normally.  The exist status is reported.
00050              */
00051             i18n("the child process terminated with exit status %s"),
00052             name
00053         );
00054     }
00055     else if (WIFSIGNALED(status))
00056     {
00057         char            name[100];
00058         explain_string_buffer_t name_sb;
00059 
00060         explain_string_buffer_init(&name_sb, name, sizeof(name));
00061         explain_buffer_strsignal(&name_sb, WTERMSIG(status));
00062         if (WCOREDUMP(status))
00063         {
00064             explain_string_buffer_printf_gettext
00065             (
00066                 sb,
00067                 /*
00068                  * xgettext: This message is used when a child process
00069                  * is terminated by the delivery of an uncaught signal.
00070                  * This also resulted in a core dump.
00071                  */
00072                 i18n("the child process was terminated by the %s signal, "
00073                     "core dumped"),
00074                 name
00075             );
00076         }
00077         else
00078         {
00079             explain_string_buffer_printf_gettext
00080             (
00081                 sb,
00082                 /*
00083                  * xgettext: This message is used when a child process
00084                  * is terminated by the delivery of an uncaught signal.
00085                  */
00086                 i18n("the child process was terminated by the %s signal"),
00087                 name
00088             );
00089         }
00090     }
00091     else if (WIFSTOPPED(status))
00092     {
00093         char            name[100];
00094         explain_string_buffer_t name_sb;
00095 
00096         explain_string_buffer_init(&name_sb, name, sizeof(name));
00097         explain_buffer_strsignal(&name_sb, WSTOPSIG(status));
00098         explain_string_buffer_printf_gettext
00099         (
00100             sb,
00101             /*
00102              * xgettext: This message is used when a child process is
00103              * stopped by delivery of a signal.  The process is still
00104              * there, is is stopped, not terminated.
00105              */
00106             i18n("the child process was stopped by delivery of the %s signal"),
00107             name
00108         );
00109     }
00110     else if (WIFCONTINUED(status))
00111     {
00112         char            name[100];
00113         explain_string_buffer_t name_sb;
00114 
00115         explain_string_buffer_init(&name_sb, name, sizeof(name));
00116         explain_buffer_strsignal(&name_sb, SIGCONT);
00117         explain_string_buffer_printf_gettext
00118         (
00119             sb,
00120             /*
00121              * xgettext:  This message is used when a child process is
00122              * resumed by delivering a signal (SIGCONT).
00123              */
00124             i18n("the child process was resumed by delivery of the %s signal"),
00125             name
00126         );
00127     }
00128     else
00129     {
00130         explain_string_buffer_printf
00131         (
00132             sb,
00133             /* This is supposed to be impossible, not xgettext msg needed. */
00134             "the child process terminated with an indecipherable status 0x%04X",
00135             status
00136         );
00137     }
00138 }
00139 
00140 
00141 /* vim: set ts=8 sw=4 et : */