libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 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 your 00008 * option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful,but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00013 * 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/sys/ioctl.h> 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/linux/vt.h> 00022 00023 #include <libexplain/buffer/einval.h> 00024 #include <libexplain/buffer/eperm.h> 00025 #include <libexplain/buffer/vt_mode.h> 00026 #include <libexplain/capability.h> 00027 #include <libexplain/iocontrol/generic.h> 00028 #include <libexplain/iocontrol/vt_setmode.h> 00029 #include <libexplain/is_efault.h> 00030 00031 #ifdef VT_SETMODE 00032 00033 00034 static void 00035 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00036 errnum, int fildes, int request, const void *data) 00037 { 00038 (void)p; 00039 (void)errnum; 00040 (void)fildes; 00041 (void)request; 00042 explain_buffer_vt_mode(sb, data); 00043 } 00044 00045 00046 static void 00047 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00048 errnum, int fildes, int request, const void *data) 00049 { 00050 switch (errnum) 00051 { 00052 case EPERM: 00053 if (!explain_capability_sys_tty_config()) 00054 { 00055 explain_buffer_eperm_sys_tty_config(sb, "ioctl VT_SETMODE"); 00056 break; 00057 } 00058 goto generic; 00059 00060 case EINVAL: 00061 { 00062 const struct vt_mode *arg; 00063 00064 arg = data; 00065 if (!explain_is_efault_pointer(arg, sizeof(*arg))) 00066 { 00067 if (arg->mode != VT_AUTO && arg->mode != VT_PROCESS) 00068 { 00069 explain_buffer_einval_vague(sb, "data.mode"); 00070 break; 00071 } 00072 } 00073 } 00074 goto generic; 00075 00076 default: 00077 generic: 00078 explain_iocontrol_generic_print_explanation 00079 ( 00080 p, 00081 sb, 00082 errnum, 00083 fildes, 00084 request, 00085 data 00086 ); 00087 break; 00088 } 00089 } 00090 00091 00092 const explain_iocontrol_t explain_iocontrol_vt_setmode = 00093 { 00094 "VT_SETMODE", /* name */ 00095 VT_SETMODE, /* value */ 00096 0, /* disambiguate */ 00097 0, /* print_name */ 00098 print_data, 00099 print_explanation, 00100 0, /* print_data_returned */ 00101 sizeof(struct vt_mode), /* data_size */ 00102 "struct vt_mode *", /* data_type */ 00103 IOCONTROL_FLAG_SIZE_DOES_NOT_AGREE, /* flags */ 00104 __FILE__, 00105 __LINE__, 00106 }; 00107 00108 #else /* ndef VT_SETMODE */ 00109 00110 const explain_iocontrol_t explain_iocontrol_vt_setmode = 00111 { 00112 0, /* name */ 00113 0, /* value */ 00114 0, /* disambiguate */ 00115 0, /* print_name */ 00116 0, /* print_data */ 00117 0, /* print_explanation */ 00118 0, /* print_data_returned */ 00119 0, /* data_size */ 00120 0, /* data_type */ 00121 0, /* flags */ 00122 __FILE__, 00123 __LINE__, 00124 }; 00125 00126 #endif /* VT_SETMODE */ 00127 00128 00129 /* vim: set ts=8 sw=4 et : */