top: generalize handling of questionable rcfile issues
Previously top would warn users if an older version of an rcfile was about to be overwritten. That's assuming that RCFILE_NOERR was not defined. This left, however, other potential rcfile issues or questions unattended. For example, if a faulty 'inspect' redirected echo had overwritten all window entries or if the inspect entry was not 'pipe' or 'file' (actually, just a 'p' or 'f') then top would silently accept it but look no further. With this commit top will try to process every inspect entry, while preserving unrecognized entries. Plus all other non-fatal rcfile errors will now alert a user to the potential overwrite when the 'W' command is given. (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
a99f410d41
commit
8292f7b8ec
36
top/top.c
36
top/top.c
@ -73,9 +73,7 @@ static char *Myname;
|
|||||||
/* The 'local' config file support */
|
/* The 'local' config file support */
|
||||||
static char Rc_name [OURPATHSZ];
|
static char Rc_name [OURPATHSZ];
|
||||||
static RCF_t Rc = DEF_RCFILE;
|
static RCF_t Rc = DEF_RCFILE;
|
||||||
#ifndef WARN_CFG_OFF
|
static int Rc_questions;
|
||||||
static int Rc_converted;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The run-time acquired page stuff */
|
/* The run-time acquired page stuff */
|
||||||
static unsigned Page_size;
|
static unsigned Page_size;
|
||||||
@ -2900,9 +2898,7 @@ static int config_cvt (WIN_t *q) {
|
|||||||
x = q->rc.sortindx;
|
x = q->rc.sortindx;
|
||||||
q->rc.sortindx = fields_src[x] - FLD_OFFSET;
|
q->rc.sortindx = fields_src[x] - FLD_OFFSET;
|
||||||
|
|
||||||
#ifndef WARN_CFG_OFF
|
Rc_questions = 1;
|
||||||
Rc_converted = 1;
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
} // end: config_cvt
|
} // end: config_cvt
|
||||||
|
|
||||||
@ -2949,6 +2945,7 @@ static void configs_read (void) {
|
|||||||
, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%f, Curwin=%d\n"
|
, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%f, Curwin=%d\n"
|
||||||
, &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_delay, &i)) {
|
, &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_delay, &i)) {
|
||||||
p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
|
p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
|
||||||
|
Rc_questions = -1;
|
||||||
goto try_inspect_entries; // maybe a faulty 'inspect' echo
|
goto try_inspect_entries; // maybe a faulty 'inspect' echo
|
||||||
}
|
}
|
||||||
// you saw that, right? (fscanf stickin' it to 'i')
|
// you saw that, right? (fscanf stickin' it to 'i')
|
||||||
@ -2979,13 +2976,14 @@ static void configs_read (void) {
|
|||||||
case 'f': // 3.3.0 thru 3.3.3 (procps-ng)
|
case 'f': // 3.3.0 thru 3.3.3 (procps-ng)
|
||||||
SETw(w, Show_JRNUMS); // fall through !
|
SETw(w, Show_JRNUMS); // fall through !
|
||||||
case 'g': // current RCF_VERSION_ID
|
case 'g': // current RCF_VERSION_ID
|
||||||
|
default: // and future versions?
|
||||||
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
|
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
|
||||||
goto default_or_error;
|
goto default_or_error;
|
||||||
for (x = 0; x < P_MAXPFLGS; ++x)
|
for (x = 0; x < P_MAXPFLGS; ++x)
|
||||||
if (P_MAXPFLGS <= FLDget(w, x))
|
if (P_MAXPFLGS <= FLDget(w, x))
|
||||||
goto default_or_error;
|
goto default_or_error;
|
||||||
break;
|
break;
|
||||||
default: // 3.2.8 (former procps)
|
case 'a': // 3.2.8 (former procps)
|
||||||
if (config_cvt(w))
|
if (config_cvt(w))
|
||||||
goto default_or_error;
|
goto default_or_error;
|
||||||
break;
|
break;
|
||||||
@ -3013,11 +3011,11 @@ try_inspect_entries:
|
|||||||
Inspect.tab = alloc_r(Inspect.tab, sizeof(struct I_entry) * (i + 1));
|
Inspect.tab = alloc_r(Inspect.tab, sizeof(struct I_entry) * (i + 1));
|
||||||
p = fmtmk(N_fmt(YINSP_rcfile_fmt), i +1);
|
p = fmtmk(N_fmt(YINSP_rcfile_fmt), i +1);
|
||||||
|
|
||||||
if (!(s = strtok(fbuf, "\t\n"))) goto default_or_error;
|
if (!(s = strtok(fbuf, "\t\n"))) { Rc_questions = 1; continue; }
|
||||||
iT(type) = strdup(s);
|
iT(type) = strdup(s);
|
||||||
if (!(s = strtok(NULL, "\t\n"))) goto default_or_error;
|
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; continue; }
|
||||||
iT(name) = strdup(s);
|
iT(name) = strdup(s);
|
||||||
if (!(s = strtok(NULL, "\t\n"))) goto default_or_error;
|
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; continue; }
|
||||||
iT(fmts) = strdup(s);
|
iT(fmts) = strdup(s);
|
||||||
|
|
||||||
switch (toupper(fbuf[0])) {
|
switch (toupper(fbuf[0])) {
|
||||||
@ -3028,10 +3026,13 @@ try_inspect_entries:
|
|||||||
iT(func) = insp_do_pipe;
|
iT(func) = insp_do_pipe;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto default_or_error;
|
Rc_questions = 1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
iT(farg) = (strstr(iT(fmts), "%d")) ? 1 : 0;
|
iT(farg) = (strstr(iT(fmts), "%d")) ? 1 : 0;
|
||||||
|
|
||||||
|
if (Rc_questions < 0) Rc_questions = 1;
|
||||||
++i;
|
++i;
|
||||||
#undef iT
|
#undef iT
|
||||||
} // end: for ('inspect' entries)
|
} // end: for ('inspect' entries)
|
||||||
@ -3053,6 +3054,10 @@ try_inspect_entries:
|
|||||||
Inspect.demo = 1;
|
Inspect.demo = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (Rc_questions < 0) {
|
||||||
|
p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
|
||||||
|
goto default_or_error;
|
||||||
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} // end: if (fp)
|
} // end: if (fp)
|
||||||
|
|
||||||
@ -3068,6 +3073,7 @@ default_or_error:
|
|||||||
Rc = rcdef;
|
Rc = rcdef;
|
||||||
for (i = 0 ; i < GROUPSMAX; i++)
|
for (i = 0 ; i < GROUPSMAX; i++)
|
||||||
Winstk[i].rc = Rc.win[i];
|
Winstk[i].rc = Rc.win[i];
|
||||||
|
Rc_questions = 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
error_exit(p);
|
error_exit(p);
|
||||||
@ -3526,14 +3532,12 @@ static void file_writerc (void) {
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#ifndef WARN_CFG_OFF
|
if (Rc_questions) {
|
||||||
if (Rc_converted) {
|
|
||||||
show_pmt(N_txt(XTRA_warncfg_txt));
|
show_pmt(N_txt(XTRA_warncfg_txt));
|
||||||
if ('y' != tolower(keyin(0)))
|
if ('y' != tolower(keyin(0)))
|
||||||
return;
|
return;
|
||||||
Rc_converted = 0;
|
Rc_questions = 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (!(fp = fopen(Rc_name, "w"))) {
|
if (!(fp = fopen(Rc_name, "w"))) {
|
||||||
show_msg(fmtmk(N_fmt(FAIL_rc_open_fmt), Rc_name, strerror(errno)));
|
show_msg(fmtmk(N_fmt(FAIL_rc_open_fmt), Rc_name, strerror(errno)));
|
||||||
return;
|
return;
|
||||||
@ -3557,7 +3561,7 @@ static void file_writerc (void) {
|
|||||||
// any new addition(s) last, for older rcfiles compatibility...
|
// any new addition(s) last, for older rcfiles compatibility...
|
||||||
fprintf(fp, "Fixed_widest=%d\n", Rc.fixed_widest);
|
fprintf(fp, "Fixed_widest=%d\n", Rc.fixed_widest);
|
||||||
|
|
||||||
if (!Inspect.demo && Inspect.total)
|
if (Inspect.raw)
|
||||||
fputs(Inspect.raw, fp);
|
fputs(Inspect.raw, fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
//#define TREE_NORESET /* sort keys do NOT force forest view OFF */
|
//#define TREE_NORESET /* sort keys do NOT force forest view OFF */
|
||||||
//#define USE_X_COLHDR /* emphasize header vs. whole col, for 'x' */
|
//#define USE_X_COLHDR /* emphasize header vs. whole col, for 'x' */
|
||||||
//#define VALIDATE_NLS /* validate integrity of all 3 nls tables */
|
//#define VALIDATE_NLS /* validate integrity of all 3 nls tables */
|
||||||
//#define WARN_CFG_OFF /* warning OFF when overwriting old rcfile */
|
|
||||||
|
|
||||||
|
|
||||||
/*###### Notes, etc. ###################################################*/
|
/*###### Notes, etc. ###################################################*/
|
||||||
|
@ -368,9 +368,7 @@ static void build_norm_nlstab (void) {
|
|||||||
Norm_nlstab[GET_find_str_txt] = _("Locate string");
|
Norm_nlstab[GET_find_str_txt] = _("Locate string");
|
||||||
Norm_nlstab[FIND_no_find_fmt] = _("%s\"%s\" not found");
|
Norm_nlstab[FIND_no_find_fmt] = _("%s\"%s\" not found");
|
||||||
Norm_nlstab[XTRA_fixwide_fmt] = _("width incr is %d, change to (0 default, -1 auto)");
|
Norm_nlstab[XTRA_fixwide_fmt] = _("width incr is %d, change to (0 default, -1 auto)");
|
||||||
#ifndef WARN_CFG_OFF
|
Norm_nlstab[XTRA_warncfg_txt] = _("Overwrite existing obsolete/corrupted rcfile?");
|
||||||
Norm_nlstab[XTRA_warncfg_txt] = _("Overwrite existing old style rcfile?");
|
|
||||||
#endif
|
|
||||||
#ifndef INSP_OFFDEMO
|
#ifndef INSP_OFFDEMO
|
||||||
Norm_nlstab[YINSP_demo01_txt] = _("Open Files");
|
Norm_nlstab[YINSP_demo01_txt] = _("Open Files");
|
||||||
Norm_nlstab[YINSP_demo02_txt] = _("NUMA Info");
|
Norm_nlstab[YINSP_demo02_txt] = _("NUMA Info");
|
||||||
|
Loading…
Reference in New Issue
Block a user