installer: change `atacontrol' to `natacontrol'
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / installer / fn_diagnostic.c
blob1fb0f5b9bfd8b375923f72395b6f7dde0842c13a
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.
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.
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.
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.
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 $
40 #include <sys/types.h>
42 #include <dirent.h>
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
48 #ifdef ENABLE_NLS
49 #include <libintl.h>
50 #define _(String) gettext (String)
51 #else
52 #define _(String) (String)
53 #endif
55 #include "libaura/mem.h"
56 #include "libaura/buffer.h"
58 #include "libdfui/dfui.h"
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"
67 #include "fn.h"
68 #include "pathnames.h"
70 /*** DIAGNOSTIC FUNCTIONS ***/
72 void
73 fn_memtest(struct i_fn_args *a)
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;
82 f = dfui_form_create(
83 "memtest",
84 _("Memory test"),
85 _("Memory test - Enter the size in values such as 400M, 1G."),
86 "",
88 "f", "memtestsize", _("Memory test size"),
89 _("Enter the amount of memory you would like to check:"), "",
91 "a", "ok", _("OK"), "", "",
92 "a", "cancel", _("Cancel Memory Test"), "", "",
93 "p", "accelerator", "ESC",
95 NULL
98 ds = dfui_dataset_new();
99 dfui_dataset_celldata_add(ds, "memtestsize", "");
100 dfui_form_dataset_add(f, ds);
102 if (!dfui_be_present(a->c, f, &r))
103 abort_backend();
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."));
140 commands_free(cmds);
143 dfui_form_free(f);
144 dfui_response_free(r);
147 void
148 view_memtest_log(struct i_fn_args *a)
150 struct aura_buffer *error_log;
151 struct dfui_form *f;
152 struct dfui_response *r;
154 error_log = aura_buffer_new(1024);
155 aura_buffer_cat_file(error_log, "%smemtest.log", a->tmp);
157 f = dfui_form_create(
158 "error_log",
159 _("Error Log"),
160 aura_buffer_buf(error_log),
163 "p", "role", "informative",
164 "p", "minimum_width", "72",
165 "p", "monospaced", "true",
167 "a", "ok", _("OK"), "", "",
168 "p", "accelerator", "ESC",
170 NULL
173 if (!dfui_be_present(a->c, f, &r))
174 abort_backend();
176 dfui_form_free(f);
177 dfui_response_free(r);
179 aura_buffer_free(error_log);
182 void
183 fn_show_dmesg(struct i_fn_args *a)
185 struct aura_buffer *e;
186 struct dfui_form *f;
187 struct dfui_response *r;
189 e = aura_buffer_new(1024);
190 aura_buffer_cat_file(e, "%s%s", a->os_root, cmd_name(a, "DMESG_BOOT"));
192 f = dfui_form_create(
193 "dmesg",
194 _("System Startup Messages (dmesg)"),
195 aura_buffer_buf(e),
198 "p", "role", "informative",
199 "p", "minimum_width", "72",
200 "p", "monospaced", "true",
202 "a", "ok", _("OK"), "", "",
203 "p", "accelerator", "ESC",
205 NULL
208 if (!dfui_be_present(a->c, f, &r))
209 abort_backend();
211 dfui_form_free(f);
212 dfui_response_free(r);
214 aura_buffer_free(e);
217 void
218 fn_show_pciconf(struct i_fn_args *a)
220 struct aura_buffer *e;
221 struct dfui_form *f;
222 struct dfui_response *r;
224 e = aura_buffer_new(1024);
225 aura_buffer_cat_pipe(e, "pciconf -l -v");
227 f = dfui_form_create(
228 "pciconf",
229 _("PCI Devices"),
230 aura_buffer_buf(e),
233 "p", "role", "informative",
234 "p", "minimum_width", "72",
235 "p", "monospaced", "true",
237 "a", "ok", _("OK"), "", "",
238 "p", "accelerator", "ESC",
240 NULL
243 if (!dfui_be_present(a->c, f, &r))
244 abort_backend();
246 dfui_form_free(f);
247 dfui_response_free(r);
249 aura_buffer_free(e);
252 void
253 fn_show_pnpinfo(struct i_fn_args *a)
255 struct aura_buffer *e;
256 struct dfui_form *f;
257 struct dfui_response *r;
259 e = aura_buffer_new(1024);
260 aura_buffer_cat_pipe(e, "pnpinfo");
262 f = dfui_form_create(
263 "pnpinfo",
264 _("ISA PnP Devices"),
265 aura_buffer_buf(e),
268 "p", "role", "informative",
269 "p", "minimum_width", "72",
270 "p", "monospaced", "true",
272 "a", "ok", _("OK"), "", "",
273 "p", "accelerator", "ESC",
275 NULL
278 if (!dfui_be_present(a->c, f, &r))
279 abort_backend();
281 dfui_form_free(f);
282 dfui_response_free(r);
284 aura_buffer_free(e);
287 void
288 fn_show_natacontrol(struct i_fn_args *a)
290 struct aura_buffer *e;
291 struct dfui_form *f;
292 struct dfui_response *r;
294 e = aura_buffer_new(1024);
295 aura_buffer_cat_pipe(e, "natacontrol list");
297 f = dfui_form_create(
298 "natacontrol",
299 _("ATA Devices"),
300 aura_buffer_buf(e),
303 "p", "role", "informative",
304 "p", "minimum_width", "72",
305 "p", "monospaced", "true",
307 "a", "ok", _("OK"), "", "",
308 "p", "accelerator", "ESC",
310 NULL
313 if (!dfui_be_present(a->c, f, &r))
314 abort_backend();
316 dfui_form_free(f);
317 dfui_response_free(r);
319 aura_buffer_free(e);
322 void
323 show_ifconfig(struct dfui_connection *c, char *ifname)
325 struct aura_buffer *e;
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);