6 * My contributions are in the public domain.
8 * Parts of this file are also blatently stolen from Poul-Henning Kamp's
9 * previous version of sysinstall, and as such fall under his "BEERWARE license"
10 * so buy him a beer if you like it! Buy him a beer for me, too!
11 * Heck, get him completely drunk and send me pictures! :-)
17 #include <sys/param.h>
18 #include <sys/reboot.h>
19 #include <sys/consio.h>
20 #include <sys/fcntl.h>
21 #include <sys/ioctl.h>
22 #include <sys/mount.h>
24 #include <sys/sysctl.h>
25 #include <ufs/ufs/ufsmount.h>
28 /* Where we stick our temporary expanded doc file */
29 #define DOC_TMP_DIR "/tmp/.doc"
30 #define DOC_TMP_FILE "/tmp/.doc/doc.tmp"
33 * Handle interrupt signals - this probably won't work in all cases
34 * due to our having bogotified the internal state of dialog or curses,
35 * but we'll give it a try.
38 intr_continue(dialogMenuItem *self)
40 return DITEM_LEAVE_MENU;
44 intr_restart(dialogMenuItem *self)
49 fdmax = getdtablesize();
50 for (fd = 3; fd < fdmax; fd++)
52 ret = execl(StartName, StartName, "-restart", (char *)NULL);
53 msgDebug("execl failed (%s)\n", strerror(errno));
58 static dialogMenuItem intrmenu[] = {
59 { "Restart", "Restart the program", NULL, intr_restart, NULL, NULL, 0, 0, 0, 0 },
60 { "Continue", "Continue without restarting", NULL, intr_continue, NULL, NULL, 0, 0, 0, 0 },
67 WINDOW *save = savescr();
72 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
75 (void)dialog_menu("Installation interrupt",
76 "Do you want to abort the installation?",
77 -1, -1, 2, -2, intrmenu, NULL, NULL, NULL);
81 /* Expand a file into a convenient location, nuking it each time */
85 char *gunzip = "/usr/bin/gunzip";
87 if (!directory_exists(DOC_TMP_DIR)) {
89 if (chown(DOC_TMP_DIR, 0, 0) < 0)
91 if (chmod(DOC_TMP_DIR, S_IRWXU) < 0)
96 if (!file_readable(fname) || vsystem("%s < %s > %s", gunzip, fname, DOC_TMP_FILE))
101 /* Initialize system defaults */
103 systemInitialize(int argc, char **argv)
109 signal(SIGINT, SIG_IGN);
112 i = sizeof(boothowto);
113 if (!sysctlbyname("debug.boothowto", &boothowto, &i, NULL, 0) &&
114 (i == sizeof(boothowto)) && (boothowto & RB_VERBOSE))
115 variable_set2(VAR_DEBUG, "YES", 0);
117 if (set_termcap() == -1) {
118 printf("Can't find terminal entry\n");
122 /* XXX - libdialog has particularly bad return value checking */
125 /* If we haven't crashed I guess dialog is running ! */
128 /* Make sure HOME is set for those utilities that need it */
129 signal(SIGINT, handle_intr);
131 * Make sure we can be interrupted even if we were re-executed
134 sigemptyset(&signalset);
135 sigaddset(&signalset, SIGINT);
136 sigprocmask(SIG_UNBLOCK, &signalset, NULL);
138 (void)vsystem("rm -rf %s", DOC_TMP_DIR);
141 /* Run some general command */
143 systemExecute(char *command)
147 WINDOW *w = savescr();
152 DialogActive = FALSE;
153 if (tcgetattr(0, &foo) != -1) {
154 foo.c_cc[VERASE] = '\010';
155 tcsetattr(0, TCSANOW, &foo);
158 status = system(command);
161 msgDebug("systemExecute: Faked execution of `%s'\n", command);
168 /* suspend/resume libdialog/curses screen */
172 systemSuspendDialog(void)
179 DialogActive = FALSE;
183 systemResumeDialog(void)
190 /* Display a help file in a filebox */
192 systemDisplayHelp(char *file)
195 char buf[FILENAME_MAX];
197 WINDOW *w = savescr();
200 fname = systemHelpFile(file, buf);
202 snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
205 dialog_mesgbox("Sorry!", buf, -1, -1);
211 dialog_textbox(file, fname, LINES, COLS);
218 systemHelpFile(char *file, char *buf)
224 snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp.gz", file);
225 if (file_readable(buf))
227 snprintf(buf, FILENAME_MAX, "/stand/help/%s.hlp", file);
228 if (file_readable(buf))
230 snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT.gz", file);
231 if (file_readable(buf))
233 snprintf(buf, FILENAME_MAX, "/stand/help/%s.TXT", file);
234 if (file_readable(buf))
236 snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/%s/help/%s.hlp", ProgName,
238 if (file_readable(buf))
240 snprintf(buf, FILENAME_MAX, "/usr/src/usr.sbin/%s/help/%s.TXT", ProgName,
242 if (file_readable(buf))
248 vsystem(const char *fmt, ...)
254 sig_t intsave, quitsave;
259 cmd = (char *)alloca(FILENAME_MAX);
262 vsnprintf(cmd, FILENAME_MAX, fmt, args);
265 omask = sigblock(sigmask(SIGCHLD));
267 msgDebug("vsystem: Faked execution of `%s'\n", cmd);
271 msgDebug("Executing command `%s'\n", cmd);
274 (void)sigsetmask(omask);
277 else if (!pid) { /* Junior */
278 (void)sigsetmask(omask);
285 close(1); open("/dev/null", O_WRONLY);
288 if (stat("/stand/sh", &sb) == 0)
289 execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
291 execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
295 intsave = signal(SIGINT, SIG_IGN);
296 quitsave = signal(SIGQUIT, SIG_IGN);
297 pid = waitpid(pid, &pstat, 0);
298 (void)sigsetmask(omask);
299 (void)signal(SIGINT, intsave);
300 (void)signal(SIGQUIT, quitsave);
301 i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
303 msgDebug("Command `%s' returns status of %d\n", cmd, i);