From b9ca74d7c7990b1fc77a9e7eb4a586f9bd19d3ac Mon Sep 17 00:00:00 2001 From: martii Date: Tue, 24 Dec 2013 16:17:47 +0100 Subject: [PATCH] gui/hdd_menu: Permit AAM if hd-idle is installed, but don't show the configuration option if there's only the busybox hdparm variant available. Signed-off-by: Jacek Jendrzej Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/4b44d47acf81605a21fede81d55b6d2b807bf8f7 Author: martii Date: 2013-12-24 (Tue, 24 Dec 2013) ------------------ This commit was generated by Migit --- src/gui/hdd_menu.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index c0b1b3aa7..e35910d92 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -147,9 +147,18 @@ int CHDDMenuHandler::doMenu () mc->setHint("", LOCALE_MENU_HINT_HDD_SLEEP); hddmenu->addItem(mc); - 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); - hddmenu->addItem(mc); + const char hdparm[] = "/sbin/hdparm"; + bool hdparm_link = false; + struct stat stat_buf; + if(::lstat(hdparm, &stat_buf) == 0) + if( S_ISLNK(stat_buf.st_mode) ) + 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->setHint("", LOCALE_MENU_HINT_HDD_NOISE); + hddmenu->addItem(mc); + } //if(n > 0) hddmenu->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_HDD_MANAGE)); @@ -271,7 +280,10 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) if (n < 0) return 0; - if (!access("/sbin/hd-idle", X_OK)) { + 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; switch (sleep_seconds) { @@ -285,8 +297,7 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) sleep_seconds *= 5; } if (sleep_seconds) - my_system(3, "/sbin/hd-idle", "-i", to_string(sleep_seconds).c_str()); - return 1; + my_system(3, hdidle, "-i", to_string(sleep_seconds).c_str()); } const char hdparm[] = "/sbin/hdparm"; @@ -302,10 +313,13 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) snprintf(S_opt, sizeof(S_opt),"-S%d", g_settings.hdd_sleep); snprintf(opt, sizeof(opt),"/dev/%s",namelist[i]->d_name); - if(hdparm_link){ + if (have_hdidle) { + snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise); + my_system(3, hdparm, M_opt, opt); + } else if(hdparm_link) { //hdparm -M is not included in busybox hdparm! my_system(3, hdparm, S_opt, opt); - }else{ + } else { snprintf(M_opt, sizeof(M_opt),"-M%d", g_settings.hdd_noise); my_system(4, hdparm, M_opt, S_opt, opt); }