2 * The new sysinstall program.
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
10 * Andrey A. Chernov. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer,
17 * verbatim and that no modifications are made prior to this
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY ANDREY A. CHERNOV ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL ANDREY A. CHERNOV OR HIS PETS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include "sysinstall.h"
42 #define _X_EXTENSION ".XXXXXX"
50 char sq, *line, *p, *q, *cp, *tptr;
51 char templ[sizeof(_PATH_TTYS) + sizeof(_X_EXTENSION) - 1];
54 if ((cp = variable_get(VAR_CONSTERM)) == NULL ||
55 strcmp(cp, "NO") == 0)
57 if (!file_readable(_PATH_TTYS)) {
58 msgConfirm("%s not exist or not readable", _PATH_TTYS);
61 if ((fp = fopen(_PATH_TTYS, "r")) == NULL) {
62 msgConfirm("Can't open %s for read: %s", _PATH_TTYS,
66 strcpy(templ, _PATH_TTYS _X_EXTENSION);
67 if ((t = mkstemp(templ)) < 0) {
68 msgConfirm("Can't create %s: %s", templ, strerror(errno));
72 if (fchmod(t, 0644)) {
73 msgConfirm("Can't fchmod %s: %s", templ, strerror(errno));
77 if ((np = fdopen(t, "w")) == NULL) {
78 msgConfirm("Can't fdopen %s: %s", templ, strerror(errno));
85 while ((line = fgetln(fp, &len)) != NULL) {
87 while (p < (line + len) && isspace((unsigned char)*p))
89 if (strncmp(p, "ttyv", 4) != 0) {
91 if (fwrite(line, len, 1, np) != 1) {
93 msgConfirm("%s: write error: %s", templ, strerror(errno));
101 while(q < (line + len) && !isspace((unsigned char)*q))
103 if (!isspace((unsigned char)*q))
109 if (tnam == NULL || tnam->ty_type == NULL ||
110 strcmp(tnam->ty_type, cp) == 0 ||
111 strncmp(tnam->ty_type, "cons", 4) != 0 ||
112 !isdigit((unsigned char)tnam->ty_type[4])
115 tlen = strlen(tnam->ty_type);
118 while(p < (line + len)) {
119 if (strncmp(p, tnam->ty_type, tlen) == 0) {
128 if (fwrite(line, tptr - line, 1, np) != 1 ||
131 len - (tptr + tlen - line), 1, np) != 1)
136 msgConfirm("%s: read error: %s", _PATH_TTYS, strerror(errno));
145 msgConfirm("%s: close error: %s", templ, strerror(errno));
147 variable_set2(VAR_CONSTERM, "NO", 0);
153 variable_set2(VAR_CONSTERM, "NO", 0);
156 if (rename(templ, _PATH_TTYS)) {
157 msgConfirm("Can't rename %s to %s: %s", templ, _PATH_TTYS,
161 variable_set2(VAR_CONSTERM, "NO", 0);