Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
f9146175
Commit
f9146175
authored
Feb 18, 2018
by
Hisham Muhammad
Browse files
Make settings file finding sequence more straightforward
Avoid unnecessary access() call and make code read more linearly.
parent
03b25817
Changes
1
Hide whitespace changes
Inline
Side-by-side
Settings.c
View file @
f9146175
...
@@ -382,10 +382,8 @@ Settings* Settings_new(int cpuCount) {
...
@@ -382,10 +382,8 @@ Settings* Settings_new(int cpuCount) {
free
(
htopDir
);
free
(
htopDir
);
free
(
configDir
);
free
(
configDir
);
struct
stat
st
;
struct
stat
st
;
if
(
lstat
(
legacyDotfile
,
&
st
)
!=
0
)
{
int
err
=
lstat
(
legacyDotfile
,
&
st
);
st
.
st_mode
=
0
;
if
(
err
||
S_ISLNK
(
st
.
st_mode
))
{
}
if
(
access
(
legacyDotfile
,
R_OK
)
!=
0
||
S_ISLNK
(
st
.
st_mode
))
{
free
(
legacyDotfile
);
free
(
legacyDotfile
);
legacyDotfile
=
NULL
;
legacyDotfile
=
NULL
;
}
}
...
@@ -394,28 +392,33 @@ Settings* Settings_new(int cpuCount) {
...
@@ -394,28 +392,33 @@ Settings* Settings_new(int cpuCount) {
this
->
colorScheme
=
0
;
this
->
colorScheme
=
0
;
this
->
changed
=
false
;
this
->
changed
=
false
;
this
->
delay
=
DEFAULT_DELAY
;
this
->
delay
=
DEFAULT_DELAY
;
bool
ok
=
Settings_read
(
this
,
legacyDotfile
?
legacyDotfile
:
this
->
filename
);
bool
ok
=
false
;
if
(
ok
)
{
if
(
legacyDotfile
)
{
if
(
legacyDotfile
)
{
ok
=
Settings_read
(
this
,
legacyDotfile
);
if
(
ok
)
{
// Transition to new location and delete old configuration file
// Transition to new location and delete old configuration file
if
(
Settings_write
(
this
))
if
(
Settings_write
(
this
))
unlink
(
legacyDotfile
);
unlink
(
legacyDotfile
);
}
}
}
else
{
free
(
legacyDotfile
);
}
if
(
!
ok
)
{
ok
=
Settings_read
(
this
,
this
->
filename
);
}
if
(
!
ok
)
{
this
->
changed
=
true
;
this
->
changed
=
true
;
// TODO: how to get SYSCONFDIR correctly through Autoconf?
// TODO: how to get SYSCONFDIR correctly through Autoconf?
char
*
systemSettings
=
String_cat
(
SYSCONFDIR
,
"/htoprc"
);
char
*
systemSettings
=
String_cat
(
SYSCONFDIR
,
"/htoprc"
);
ok
=
Settings_read
(
this
,
systemSettings
);
ok
=
Settings_read
(
this
,
systemSettings
);
free
(
systemSettings
);
free
(
systemSettings
);
if
(
!
ok
)
{
Settings_defaultMeters
(
this
);
this
->
hideKernelThreads
=
true
;
this
->
highlightMegabytes
=
true
;
this
->
highlightThreads
=
true
;
this
->
headerMargin
=
true
;
}
}
}
free
(
legacyDotfile
);
if
(
!
ok
)
{
Settings_defaultMeters
(
this
);
this
->
hideKernelThreads
=
true
;
this
->
highlightMegabytes
=
true
;
this
->
highlightThreads
=
true
;
this
->
headerMargin
=
true
;
}
return
this
;
return
this
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment