libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011-2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at 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/sys/shm.h> 00020 #include <libexplain/ac/sys/stat.h> 00021 00022 #include <libexplain/buffer/gid.h> 00023 #include <libexplain/buffer/int.h> 00024 #include <libexplain/buffer/ipc_perm.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/buffer/short.h> 00027 #include <libexplain/buffer/uid.h> 00028 #include <libexplain/is_efault.h> 00029 #include <libexplain/option.h> 00030 #include <libexplain/parse_bits.h> 00031 00032 00033 #ifdef HAVE_SYS_SHM_H 00034 00035 static void 00036 explain_buffer_ipc_perm_mode(explain_string_buffer_t *sb, int value) 00037 { 00038 static const explain_parse_bits_table_t table[] = 00039 { 00040 { "S_IRWXU", S_IRWXU }, 00041 { "S_IRUSR", S_IRUSR }, 00042 { "S_IWUSR", S_IWUSR }, 00043 { "S_IXUSR", S_IXUSR }, 00044 { "S_IRWXG", S_IRWXG }, 00045 { "S_IRGRP", S_IRGRP }, 00046 { "S_IWGRP", S_IWGRP }, 00047 { "S_IXGRP", S_IXGRP }, 00048 { "S_IRWXO", S_IRWXO }, 00049 { "S_IROTH", S_IROTH }, 00050 { "S_IWOTH", S_IWOTH }, 00051 { "S_IXOTH", S_IXOTH }, 00052 #ifdef SHM_DEST 00053 { "SHM_DEST", SHM_DEST }, 00054 #endif 00055 #ifdef SHM_LOCKED 00056 { "SHM_LOCKED", SHM_LOCKED }, 00057 #endif 00058 }; 00059 00060 if (explain_option_symbolic_mode_bits()) 00061 { 00062 explain_parse_bits_print(sb, value, table, SIZEOF(table)); 00063 } 00064 else 00065 { 00066 int lo; 00067 00068 lo = value & 0777; 00069 value &= ~0777; 00070 if (value) 00071 { 00072 explain_parse_bits_print(sb, value, table, SIZEOF(table)); 00073 if (lo) 00074 explain_string_buffer_printf(sb, " | %#o", lo); 00075 } 00076 else 00077 { 00078 explain_string_buffer_printf(sb, "%#o", lo); 00079 } 00080 } 00081 } 00082 00083 #endif 00084 00085 void 00086 explain_buffer_ipc_perm(explain_string_buffer_t *sb, 00087 const struct ipc_perm *data, int extra) 00088 { 00089 #ifdef HAVE_SYS_SHM_H 00090 if (explain_is_efault_pointer(data, sizeof(*data))) 00091 { 00092 explain_buffer_pointer(sb, data); 00093 return; 00094 } 00095 00096 explain_string_buffer_puts(sb, "{ "); 00097 if (extra) 00098 { 00099 #ifdef SYS_SHM_H_struct_ipc_perm_underscore_key 00100 explain_string_buffer_puts(sb, "__key = "); 00101 explain_buffer_int(sb, data->__key); 00102 #else 00103 explain_string_buffer_puts(sb, "key = "); 00104 explain_buffer_int(sb, data->key); 00105 #endif 00106 explain_string_buffer_puts(sb, ", "); 00107 } 00108 explain_string_buffer_puts(sb, "uid = "); 00109 explain_buffer_uid(sb, data->uid); 00110 explain_string_buffer_puts(sb, ", gid = "); 00111 explain_buffer_gid(sb, data->gid); 00112 if (extra) 00113 { 00114 explain_string_buffer_puts(sb, ", cuid = "); 00115 explain_buffer_uid(sb, data->cuid); 00116 explain_string_buffer_puts(sb, ", cgid = "); 00117 explain_buffer_gid(sb, data->cgid); 00118 } 00119 explain_string_buffer_puts(sb, ", mode = "); 00120 explain_buffer_ipc_perm_mode(sb, data->mode); 00121 if (extra) 00122 { 00123 #ifdef SYS_SHM_H_struct_ipc_perm_underscore_key 00124 explain_string_buffer_puts(sb, ", __seq = "); 00125 explain_buffer_ushort(sb, data->__seq); 00126 #else 00127 explain_string_buffer_puts(sb, ", seq = "); 00128 explain_buffer_ushort(sb, data->seq); 00129 #endif 00130 } 00131 explain_string_buffer_puts(sb, " }"); 00132 #else 00133 (void)extra; 00134 explain_buffer_pointer(sb, data); 00135 #endif 00136 } 00137 00138 00139 /* vim: set ts=8 sw=4 et : */