mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-09-02 18:31:12 +02:00
hdd_menu: fix hd-idle/hdparm logic; fix small memleaks
Origin commit data
------------------
Commit: 0411359866
Author: vanhofen <vanhofen@gmx.de>
Date: 2017-02-06 (Mon, 06 Feb 2017)
Origin message was:
------------------
- hdd_menu: fix hd-idle/hdparm logic; fix small memleaks
This commit is contained in:
@@ -1113,12 +1113,12 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
|
||||
if (n < 0)
|
||||
return menu_return::RETURN_NONE;
|
||||
|
||||
const char hdidle[] = "/sbin/hd-idle";
|
||||
bool have_hdidle = !access(hdidle, X_OK);
|
||||
|
||||
if (g_settings.hdd_sleep > 0 && g_settings.hdd_sleep < 60)
|
||||
g_settings.hdd_sleep = 60;
|
||||
|
||||
const char hdidle[] = "/sbin/hd-idle";
|
||||
bool have_hdidle = !access(hdidle, X_OK);
|
||||
|
||||
if (have_hdidle) {
|
||||
system("kill $(pidof hd-idle)");
|
||||
int sleep_seconds = g_settings.hdd_sleep;
|
||||
@@ -1134,12 +1134,22 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
|
||||
}
|
||||
if (sleep_seconds)
|
||||
my_system(3, hdidle, "-i", to_string(sleep_seconds).c_str());
|
||||
|
||||
while (n--)
|
||||
free(namelist[i]);
|
||||
free(namelist);
|
||||
return menu_return::RETURN_NONE;
|
||||
}
|
||||
|
||||
const char hdparm[] = "/sbin/hdparm";
|
||||
bool have_hdparm = !access(hdparm, X_OK);
|
||||
if (!have_hdparm)
|
||||
{
|
||||
while (n--)
|
||||
free(namelist[i]);
|
||||
free(namelist);
|
||||
return menu_return::RETURN_NONE;
|
||||
}
|
||||
|
||||
struct stat stat_buf;
|
||||
bool have_nonbb_hdparm = !::lstat(hdparm, &stat_buf) && !S_ISLNK(stat_buf.st_mode);
|
||||
@@ -1153,12 +1163,11 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
|
||||
snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise);
|
||||
snprintf(opt, sizeof(opt), "/dev/%s",namelist[i]->d_name);
|
||||
|
||||
if (have_hdidle)
|
||||
my_system(3, hdparm, M_opt, opt);
|
||||
else if (have_nonbb_hdparm)
|
||||
if (have_nonbb_hdparm)
|
||||
my_system(4, hdparm, M_opt, S_opt, opt);
|
||||
else // busybox hdparm doesn't support "-M"
|
||||
my_system(3, hdparm, S_opt, opt);
|
||||
|
||||
free(namelist[i]);
|
||||
}
|
||||
free(namelist);
|
||||
|
Reference in New Issue
Block a user