libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2013, 2014 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 of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 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/fcntl.h> 00021 00022 #include <libexplain/buffer/errno/open.h> 00023 #include <libexplain/buffer/errno/gethostid.h> 00024 #include <libexplain/buffer/pathname.h> 00025 #include <libexplain/explanation.h> 00026 00027 00028 #ifndef HOSTIDFILE 00029 #define HOSTIDFILE "/etc/hostid" 00030 #endif 00031 00032 00033 static void 00034 explain_buffer_errno_gethostid_system_call(explain_string_buffer_t *sb, 00035 int errnum) 00036 { 00037 explain_string_buffer_puts(sb, "gethostid("); 00038 if (errnum == ENOENT) 00039 { 00040 explain_string_buffer_puts(sb, "pathname = "); 00041 explain_buffer_pathname(sb, "/etc/hostid"); 00042 } 00043 explain_string_buffer_puts(sb, ")"); 00044 } 00045 00046 00047 void 00048 explain_buffer_errno_gethostid_explanation(explain_string_buffer_t *sb, 00049 int errnum, const char *syscall_name) 00050 { 00051 /* 00052 * Probably actually an 00053 * 00054 * open(HOSTIDFILE, O_RDONLY) 00055 * 00056 * error. 00057 */ 00058 explain_buffer_errno_open_explanation 00059 ( 00060 sb, 00061 errnum, 00062 syscall_name, 00063 HOSTIDFILE, 00064 O_RDONLY, 00065 0 00066 ); 00067 } 00068 00069 00070 void 00071 explain_buffer_errno_gethostid(explain_string_buffer_t *sb, int errnum) 00072 { 00073 explain_explanation_t exp; 00074 00075 explain_explanation_init(&exp, errnum); 00076 explain_buffer_errno_gethostid_system_call(&exp.system_call_sb, errnum); 00077 explain_buffer_errno_gethostid_explanation(&exp.explanation_sb, errnum, 00078 "gethostid"); 00079 explain_explanation_assemble(&exp, sb); 00080 } 00081 00082 00083 /* vim: set ts=8 sw=4 et : */