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_show_dmesg(struct i_fn_args *a)
74 {
75 	struct aura_buffer *e;
76 	struct dfui_form *f;
77 	struct dfui_response *r;
78 
79 	e = aura_buffer_new(1024);
80 	aura_buffer_cat_file(e, "%s%s", a->os_root, cmd_name(a, "DMESG_BOOT"));
81 
82 	f = dfui_form_create(
83 	    "dmesg",
84 	    _("System Startup Messages (dmesg)"),
85 	    aura_buffer_buf(e),
86 	    "",
87 
88 	    "p", "role", "informative",
89 	    "p", "minimum_width", "72",
90 	    "p", "monospaced", "true",
91 
92 	    "a", "ok", _("OK"), "", "",
93 	    "p", "accelerator", "ESC",
94 
95 	    NULL
96 	);
97 
98 	if (!dfui_be_present(a->c, f, &r))
99 		abort_backend();
100 
101 	dfui_form_free(f);
102 	dfui_response_free(r);
103 
104 	aura_buffer_free(e);
105 }
106 
107 void
108 fn_show_pciconf(struct i_fn_args *a)
109 {
110 	struct aura_buffer *e;
111 	struct dfui_form *f;
112 	struct dfui_response *r;
113 
114 	e = aura_buffer_new(1024);
115 	aura_buffer_cat_pipe(e, "pciconf -l -v");
116 
117 	f = dfui_form_create(
118 	    "pciconf",
119 	    _("PCI Devices"),
120 	    aura_buffer_buf(e),
121 	    "",
122 
123 	    "p", "role", "informative",
124 	    "p", "minimum_width", "72",
125 	    "p", "monospaced", "true",
126 
127 	    "a", "ok", _("OK"), "", "",
128 	    "p", "accelerator", "ESC",
129 
130 	    NULL
131 	);
132 
133 	if (!dfui_be_present(a->c, f, &r))
134 		abort_backend();
135 
136 	dfui_form_free(f);
137 	dfui_response_free(r);
138 
139 	aura_buffer_free(e);
140 }
141 
142 void
143 fn_show_natacontrol(struct i_fn_args *a)
144 {
145 	struct aura_buffer *e;
146 	struct dfui_form *f;
147 	struct dfui_response *r;
148 
149 	e = aura_buffer_new(1024);
150 	aura_buffer_cat_pipe(e, "natacontrol list");
151 
152 	f = dfui_form_create(
153 	    "natacontrol",
154 	    _("ATA Devices"),
155 	    aura_buffer_buf(e),
156 	    "",
157 
158 	    "p", "role", "informative",
159 	    "p", "minimum_width", "72",
160 	    "p", "monospaced", "true",
161 
162 	    "a", "ok", _("OK"), "", "",
163 	    "p", "accelerator", "ESC",
164 
165 	    NULL
166 	);
167 
168 	if (!dfui_be_present(a->c, f, &r))
169 		abort_backend();
170 
171 	dfui_form_free(f);
172 	dfui_response_free(r);
173 
174 	aura_buffer_free(e);
175 }
176 
177 void
178 show_ifconfig(struct dfui_connection *c, char *ifname)
179 {
180 	struct aura_buffer *e;
181 
182 	e = aura_buffer_new(1024);
183 	aura_buffer_cat_pipe(e, "/sbin/ifconfig %s", ifname);
184 	inform(c, "%s", aura_buffer_buf(e));
185 	aura_buffer_free(e);
186 }
187