gui/hdd_menu: cleanup (untested)

Signed-off-by: Jacek Jendrzej <crashdvb@googlemail.com>


Origin commit data
------------------
Commit: 993b21bf7a
Author: martii <m4rtii@gmx.de>
Date: 2013-12-25 (Wed, 25 Dec 2013)
This commit is contained in:
martii
2013-12-25 10:55:16 +01:00
committed by Jacek Jendrzej
parent e4222d9171
commit cd5ab72c03

View File

@@ -148,13 +148,9 @@ int CHDDMenuHandler::doMenu ()
hddmenu->addItem(mc); hddmenu->addItem(mc);
const char hdparm[] = "/sbin/hdparm"; const char hdparm[] = "/sbin/hdparm";
bool hdparm_link = false;
struct stat stat_buf; struct stat stat_buf;
if(::lstat(hdparm, &stat_buf) == 0) bool have_nonbb_hdparm = !::lstat(hdparm, &stat_buf) && !S_ISLNK(stat_buf.st_mode);
if( S_ISLNK(stat_buf.st_mode) ) if (have_nonbb_hdparm) {
hdparm_link = true;
if (!hdparm_link) {
mc = new CMenuOptionChooser(LOCALE_HDD_NOISE, &g_settings.hdd_noise, HDD_NOISE_OPTIONS, HDD_NOISE_OPTION_COUNT, true); mc = new CMenuOptionChooser(LOCALE_HDD_NOISE, &g_settings.hdd_noise, HDD_NOISE_OPTIONS, HDD_NOISE_OPTION_COUNT, true);
mc->setHint("", LOCALE_MENU_HINT_HDD_NOISE); mc->setHint("", LOCALE_MENU_HINT_HDD_NOISE);
hddmenu->addItem(mc); hddmenu->addItem(mc);
@@ -272,13 +268,11 @@ int CHDDMenuHandler::doMenu ()
int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
{ {
char M_opt[50],S_opt[50];
char opt[100];
struct dirent **namelist; struct dirent **namelist;
int n = scandir("/sys/block", &namelist, my_filter, alphasort); int n = scandir("/sys/block", &namelist, my_filter, alphasort);
if (n < 0) if (n < 0)
return 0; return menu_return::RETURN_NONE;
const char hdidle[] = "/sbin/hd-idle"; const char hdidle[] = "/sbin/hd-idle";
bool have_hdidle = !access(hdidle, X_OK); bool have_hdidle = !access(hdidle, X_OK);
@@ -301,32 +295,32 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&)
} }
const char hdparm[] = "/sbin/hdparm"; const char hdparm[] = "/sbin/hdparm";
bool hdparm_link = false; bool have_hdparm = !access(hdparm, X_OK);
if (!have_hdparm)
return menu_return::RETURN_NONE;
struct stat stat_buf; struct stat stat_buf;
if(::lstat(hdparm, &stat_buf) == 0) bool have_nonbb_hdparm = !::lstat(hdparm, &stat_buf) && !S_ISLNK(stat_buf.st_mode);
if( S_ISLNK(stat_buf.st_mode) )
hdparm_link = true;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
printf("CHDDDestExec: noise %d sleep %d /dev/%s\n", printf("CHDDDestExec: noise %d sleep %d /dev/%s\n",
g_settings.hdd_noise, g_settings.hdd_sleep, namelist[i]->d_name); g_settings.hdd_noise, g_settings.hdd_sleep, namelist[i]->d_name);
snprintf(S_opt, sizeof(S_opt),"-S%d", g_settings.hdd_sleep);
snprintf(opt, sizeof(opt),"/dev/%s",namelist[i]->d_name);
if (have_hdidle) { char M_opt[50],S_opt[50], opt[100];
snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise); snprintf(S_opt, sizeof(S_opt), "-S%d", g_settings.hdd_sleep);
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); my_system(3, hdparm, M_opt, opt);
} else if(hdparm_link) { else if (have_nonbb_hdparm)
//hdparm -M is not included in busybox hdparm!
my_system(3, hdparm, S_opt, opt);
} else {
snprintf(M_opt, sizeof(M_opt),"-M%d", g_settings.hdd_noise);
my_system(4, hdparm, M_opt, S_opt, opt); 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[i]);
} }
free(namelist); free(namelist);
return 1; return menu_return::RETURN_NONE;
} }
static int check_and_umount(char * dev, char * path) static int check_and_umount(char * dev, char * path)