libexplain  1.4.D001
libexplain/buffer/errno/acct.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,
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 
00021 #include <libexplain/buffer/dac.h>
00022 #include <libexplain/buffer/eacces.h>
00023 #include <libexplain/buffer/efault.h>
00024 #include <libexplain/buffer/eio.h>
00025 #include <libexplain/buffer/eisdir.h>
00026 #include <libexplain/buffer/eloop.h>
00027 #include <libexplain/buffer/enametoolong.h>
00028 #include <libexplain/buffer/enoent.h>
00029 #include <libexplain/buffer/enomem.h>
00030 #include <libexplain/buffer/enfile.h>
00031 #include <libexplain/buffer/enosys.h>
00032 #include <libexplain/buffer/enotdir.h>
00033 #include <libexplain/buffer/erofs.h>
00034 #include <libexplain/buffer/errno/acct.h>
00035 #include <libexplain/buffer/errno/generic.h>
00036 #include <libexplain/buffer/errno/path_resolution.h>
00037 #include <libexplain/buffer/gettext.h>
00038 #include <libexplain/buffer/pathname.h>
00039 #include <libexplain/explanation.h>
00040 
00041 
00042 static void
00043 explain_buffer_errno_acct_system_call(explain_string_buffer_t *sb, int errnum,
00044     const char *pathname)
00045 {
00046     (void)errnum;
00047     explain_string_buffer_puts(sb, "acct(pathname = ");
00048     explain_buffer_pathname(sb, pathname);
00049     explain_string_buffer_putc(sb, ')');
00050 }
00051 
00052 
00053 static void
00054 explain_buffer_errno_acct_explanation(explain_string_buffer_t *sb, int errnum,
00055     const char *pathname)
00056 {
00057     explain_final_t final_component;
00058 
00059     explain_final_init(&final_component);
00060 
00061     /*
00062      * http://www.opengroup.org/onlinepubs/009695399/functions/acct.html
00063      */
00064     switch (errnum)
00065     {
00066     case EACCES:
00067         explain_buffer_eacces(sb, pathname, "pathname", &final_component);
00068         break;
00069 
00070     case EFAULT:
00071         explain_buffer_efault(sb, pathname);
00072         break;
00073 
00074     case EIO:
00075         explain_buffer_eio(sb);
00076         break;
00077 
00078     case EISDIR:
00079         if (explain_buffer_eisdir(sb, pathname, "pathname"))
00080             break;
00081         goto generic;
00082 
00083     case ELOOP:
00084         explain_buffer_eloop(sb, pathname, "pathname", &final_component);
00085         break;
00086 
00087     case ENAMETOOLONG:
00088         explain_buffer_enametoolong(sb, pathname, "pathname", &final_component);
00089         break;
00090 
00091     case ENFILE:
00092         explain_buffer_enfile(sb);
00093         break;
00094 
00095     case ENOENT:
00096         explain_buffer_enoent(sb, pathname, "pathname", &final_component);
00097         break;
00098 
00099     case ENOMEM:
00100 #ifdef EUSERS
00101     case EUSERS:
00102 #endif
00103         explain_buffer_enomem_kernel(sb);
00104         break;
00105 
00106     case ENOSYS:
00107 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS
00108     case EOPNOTSUPP:
00109 #endif
00110 #ifdef __linux__
00111         explain_buffer_gettext
00112         (
00113             sb,
00114             /*
00115              * xgettext: this error message is issued when the acct(2)
00116              * system call is used against a Linux kernel that does not
00117              * have BSD process accounting compiled in.
00118              */
00119             i18n("BSD process accounting has not been enabled when the "
00120             "operating system kernel was compiled (the kernel configuration "
00121             "parameter controlling this feature is CONFIG_BSD_PROCESS_ACCT)")
00122         );
00123         break;
00124 #else
00125         explain_buffer_enosys_pathname(sb, pathname, "pathname", "acct");
00126         break;
00127 #endif
00128 
00129     case ENOTDIR:
00130         explain_buffer_enotdir(sb, pathname, "pathname", &final_component);
00131         break;
00132 
00133     case EPERM:
00134         explain_buffer_gettext
00135         (
00136             sb,
00137             /*
00138              * xgettext: This error message is issued when a process
00139              * attempts to enable or disable process accounting without
00140              * sufficient privilege.
00141              */
00142             i18n("the process has insufficient privilege to control process "
00143                 "accounting")
00144         );
00145         explain_buffer_dac_sys_pacct(sb);
00146         break;
00147 
00148     case EROFS:
00149         explain_buffer_erofs(sb, pathname, "pathname");
00150         break;
00151 
00152     default:
00153         generic:
00154         explain_buffer_errno_generic(sb, errnum, "acct");
00155         break;
00156     }
00157 }
00158 
00159 
00160 void
00161 explain_buffer_errno_acct(explain_string_buffer_t *sb, int errnum, const char
00162     *pathname)
00163 {
00164     explain_explanation_t exp;
00165 
00166     explain_explanation_init(&exp, errnum);
00167     explain_buffer_errno_acct_system_call(&exp.system_call_sb, errnum,
00168         pathname);
00169     explain_buffer_errno_acct_explanation(&exp.explanation_sb, errnum,
00170         pathname);
00171     explain_explanation_assemble(&exp, sb);
00172 }
00173 
00174 
00175 /* vim: set ts=8 sw=4 et : */