1 /* 2 * Copyright (c)2004 The DragonFly Project. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * Neither the name of the DragonFly Project nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 * OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * fn_diagnostic.c 36 * Diagnostic functions for installer. 37 * $Id: fn_diagnostic.c,v 1.21 2005/03/13 01:53:58 cpressey Exp $ 38 */ 39 40 #include <sys/types.h> 41 42 #include <dirent.h> 43 #include <stdarg.h> 44 #include <stdio.h> 45 #include <stdlib.h> 46 #include <string.h> 47 48 #ifdef ENABLE_NLS 49 #include <libintl.h> 50 #define _(String) gettext (String) 51 #else 52 #define _(String) (String) 53 #endif 54 55 #include "libaura/mem.h" 56 #include "libaura/buffer.h" 57 58 #include "libdfui/dfui.h" 59 60 #include "libinstaller/commands.h" 61 #include "libinstaller/confed.h" 62 #include "libinstaller/diskutil.h" 63 #include "libinstaller/functions.h" 64 #include "libinstaller/package.h" 65 #include "libinstaller/uiutil.h" 66 67 #include "fn.h" 68 #include "pathnames.h" 69 70 /*** DIAGNOSTIC FUNCTIONS ***/ 71 72 void 73 fn_memtest(struct i_fn_args *a) 74 { 75 struct dfui_form *f; 76 struct dfui_response *r; 77 struct dfui_dataset *ds, *new_ds; 78 struct commands *cmds; 79 struct command *cmd; 80 const char *memtestsize; 81 82 f = dfui_form_create( 83 "memtest", 84 _("Memory test"), 85 _("Memory test - Enter the size in values such as 400M, 1G."), 86 "", 87 88 "f", "memtestsize", _("Memory test size"), 89 _("Enter the amount of memory you would like to check:"), "", 90 91 "a", "ok", _("OK"), "", "", 92 "a", "cancel", _("Cancel Memory Test"), "", "", 93 "p", "accelerator", "ESC", 94 95 NULL 96 ); 97 98 ds = dfui_dataset_new(); 99 dfui_dataset_celldata_add(ds, "memtestsize", ""); 100 dfui_form_dataset_add(f, ds); 101 102 if (!dfui_be_present(a->c, f, &r)) 103 abort_backend(); 104 105 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) { 106 new_ds = dfui_response_dataset_get_first(r); 107 memtestsize = dfui_dataset_get_value(new_ds, "memtestsize"); 108 cmds = commands_new(); 109 cmd = command_add(cmds, 110 "cd %s && %s%s %s 1 --log", 111 a->tmp, 112 a->os_root, cmd_name(a, "MEMTEST"), 113 memtestsize); 114 command_set_log_mode(cmd, COMMAND_LOG_QUIET); 115 cmd = command_add(cmds, 116 "%s%s -E -v '^Unable to malloc' %smemtest.log > %smemtest.log.new", 117 a->os_root, cmd_name(a, "GREP"), 118 a->tmp, a->tmp); 119 cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log", 120 a->os_root, cmd_name(a, "MV"), 121 a->tmp, a->tmp); 122 cmd = command_add(cmds, 123 "%s%s -E -v '^Allocated.*failed' %smemtest.log > %smemtest.log.new", 124 a->os_root, cmd_name(a, "GREP"), 125 a->tmp, a->tmp); 126 cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log", 127 a->os_root, cmd_name(a, "MV"), 128 a->tmp, a->tmp); 129 if (commands_execute(a, cmds)) { 130 commands_free(cmds); 131 view_memtest_log(a); 132 cmds = commands_new(); 133 cmd = command_add(cmds, "%s%s -f %smemtest.log", 134 a->os_root, cmd_name(a, "RM"), 135 a->tmp); 136 commands_execute(a, cmds); 137 } else { 138 inform(a->c, _("Memory test could not be run.")); 139 } 140 commands_free(cmds); 141 } 142 143 dfui_form_free(f); 144 dfui_response_free(r); 145 } 146 147 void 148 view_memtest_log(struct i_fn_args *a) 149 { 150 struct aura_buffer *error_log; 151 struct dfui_form *f; 152 struct dfui_response *r; 153 154 error_log = aura_buffer_new(1024); 155 aura_buffer_cat_file(error_log, "%smemtest.log", a->tmp); 156 157 f = dfui_form_create( 158 "error_log", 159 _("Error Log"), 160 aura_buffer_buf(error_log), 161 "", 162 163 "p", "role", "informative", 164 "p", "minimum_width", "72", 165 "p", "monospaced", "true", 166 167 "a", "ok", _("OK"), "", "", 168 "p", "accelerator", "ESC", 169 170 NULL 171 ); 172 173 if (!dfui_be_present(a->c, f, &r)) 174 abort_backend(); 175 176 dfui_form_free(f); 177 dfui_response_free(r); 178 179 aura_buffer_free(error_log); 180 } 181 182 void 183 fn_show_dmesg(struct i_fn_args *a) 184 { 185 struct aura_buffer *e; 186 struct dfui_form *f; 187 struct dfui_response *r; 188 189 e = aura_buffer_new(1024); 190 aura_buffer_cat_file(e, "%s%s", a->os_root, cmd_name(a, "DMESG_BOOT")); 191 192 f = dfui_form_create( 193 "dmesg", 194 _("System Startup Messages (dmesg)"), 195 aura_buffer_buf(e), 196 "", 197 198 "p", "role", "informative", 199 "p", "minimum_width", "72", 200 "p", "monospaced", "true", 201 202 "a", "ok", _("OK"), "", "", 203 "p", "accelerator", "ESC", 204 205 NULL 206 ); 207 208 if (!dfui_be_present(a->c, f, &r)) 209 abort_backend(); 210 211 dfui_form_free(f); 212 dfui_response_free(r); 213 214 aura_buffer_free(e); 215 } 216 217 void 218 fn_show_pciconf(struct i_fn_args *a) 219 { 220 struct aura_buffer *e; 221 struct dfui_form *f; 222 struct dfui_response *r; 223 224 e = aura_buffer_new(1024); 225 aura_buffer_cat_pipe(e, "pciconf -l -v"); 226 227 f = dfui_form_create( 228 "pciconf", 229 _("PCI Devices"), 230 aura_buffer_buf(e), 231 "", 232 233 "p", "role", "informative", 234 "p", "minimum_width", "72", 235 "p", "monospaced", "true", 236 237 "a", "ok", _("OK"), "", "", 238 "p", "accelerator", "ESC", 239 240 NULL 241 ); 242 243 if (!dfui_be_present(a->c, f, &r)) 244 abort_backend(); 245 246 dfui_form_free(f); 247 dfui_response_free(r); 248 249 aura_buffer_free(e); 250 } 251 252 void 253 fn_show_pnpinfo(struct i_fn_args *a) 254 { 255 struct aura_buffer *e; 256 struct dfui_form *f; 257 struct dfui_response *r; 258 259 e = aura_buffer_new(1024); 260 aura_buffer_cat_pipe(e, "pnpinfo"); 261 262 f = dfui_form_create( 263 "pnpinfo", 264 _("ISA PnP Devices"), 265 aura_buffer_buf(e), 266 "", 267 268 "p", "role", "informative", 269 "p", "minimum_width", "72", 270 "p", "monospaced", "true", 271 272 "a", "ok", _("OK"), "", "", 273 "p", "accelerator", "ESC", 274 275 NULL 276 ); 277 278 if (!dfui_be_present(a->c, f, &r)) 279 abort_backend(); 280 281 dfui_form_free(f); 282 dfui_response_free(r); 283 284 aura_buffer_free(e); 285 } 286 287 void 288 fn_show_natacontrol(struct i_fn_args *a) 289 { 290 struct aura_buffer *e; 291 struct dfui_form *f; 292 struct dfui_response *r; 293 294 e = aura_buffer_new(1024); 295 aura_buffer_cat_pipe(e, "natacontrol list"); 296 297 f = dfui_form_create( 298 "natacontrol", 299 _("ATA Devices"), 300 aura_buffer_buf(e), 301 "", 302 303 "p", "role", "informative", 304 "p", "minimum_width", "72", 305 "p", "monospaced", "true", 306 307 "a", "ok", _("OK"), "", "", 308 "p", "accelerator", "ESC", 309 310 NULL 311 ); 312 313 if (!dfui_be_present(a->c, f, &r)) 314 abort_backend(); 315 316 dfui_form_free(f); 317 dfui_response_free(r); 318 319 aura_buffer_free(e); 320 } 321 322 void 323 show_ifconfig(struct dfui_connection *c, char *ifname) 324 { 325 struct aura_buffer *e; 326 327 e = aura_buffer_new(1024); 328 aura_buffer_cat_pipe(e, "/sbin/ifconfig %s", ifname); 329 inform(c, aura_buffer_buf(e)); 330 aura_buffer_free(e); 331 } 332