diff --git a/configure.ac b/configure.ac index e8b6309e9..76f3ca2bd 100644 --- a/configure.ac +++ b/configure.ac @@ -101,7 +101,7 @@ TUXBOX_APPS_LIB_PKGCONFIG(CURL,libcurl) TUXBOX_APPS_LIB_PKGCONFIG(FREETYPE,freetype2) AC_MSG_CHECKING([whether FreeType version is 2.5.0 or higher]) AC_TRY_CPP([ - #include + #include #include FT_FREETYPE_H #if FREETYPE_MAJOR < 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR < 5) #error Freetype version too low. diff --git a/data/scripts/install.sh b/data/scripts/install.sh index 1e3dcb8ec..26238fa8a 100755 --- a/data/scripts/install.sh +++ b/data/scripts/install.sh @@ -21,7 +21,7 @@ update_file() fi echo "update $FILE_IMAGE" rm -f $FILE_IMAGE - cp $FILE_NEW $FILE_IMAGE + cp -d $FILE_NEW $FILE_IMAGE fi } diff --git a/src/Makefile.am b/src/Makefile.am index 4e4d576d9..39dc21475 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -123,6 +123,7 @@ neutrino_LDADD = \ $(PUGIXML_LIBS) \ -ldvbsi++ \ -ljpeg \ + -lutil \ -lOpenThreads \ -lrt -lpthread diff --git a/src/eitd/edvbstring.cpp b/src/eitd/edvbstring.cpp index cb495b1cc..9267630da 100644 --- a/src/eitd/edvbstring.cpp +++ b/src/eitd/edvbstring.cpp @@ -2305,28 +2305,31 @@ const std::string convertLatin1UTF8(const std::string &string) int isUTF8(const std::string &string) { unsigned int len=string.size(); + unsigned char c; for (unsigned int i=0; i < len;) { int trailing = 0; - if (string[i] >> 7 == 0) // 0xxxxxxx + c = string[i] & 0xFF; + + if (c >> 7 == 0) // 0xxxxxxx { i++; continue; } - if (string[i] >> 5 == 6) // 110xxxxx 10xxxxxx + if (c >> 5 == 6) // 110xxxxx 10xxxxxx { if (++i >= len) return 0; trailing = 1; } - else if (string[i] >> 4 == 14) // 1110xxxx 10xxxxxx 10xxxxxx + else if (c >> 4 == 14) // 1110xxxx 10xxxxxx 10xxxxxx { if (++i >= len) return 0; trailing = 2; } - else if ((string[i] >> 3) == 30) // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + else if (c >> 3 == 30) // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx { if (++i >= len) return 0; @@ -2335,7 +2338,7 @@ int isUTF8(const std::string &string) return 0; while (trailing) { - if (i >= len || string[i] >> 6 != 2) + if (i >= len || (string[i] & 0xFF) >> 6 != 2) return 0; trailing--; i++; diff --git a/src/gui/components/cc_frm_window.cpp b/src/gui/components/cc_frm_window.cpp index 7137f76ab..80455a5ad 100644 --- a/src/gui/components/cc_frm_window.cpp +++ b/src/gui/components/cc_frm_window.cpp @@ -157,7 +157,7 @@ void CComponentsWindow::initVarWindow( const int& x_pos, const int& y_pos, const ccw_col_head = COL_MENUHEAD_PLUS_0; ccw_col_head_text = COL_MENUHEAD_TEXT; ccw_col_footer = COL_MENUFOOT_PLUS_0; - + cc_parent = NULL; page_scroll_mode = PG_SCROLL_M_OFF; //permanent disabled here, only in body used! initCCWItems(); diff --git a/src/gui/components/cc_item.cpp b/src/gui/components/cc_item.cpp index d695cbdf1..4a6f49faf 100644 --- a/src/gui/components/cc_item.cpp +++ b/src/gui/components/cc_item.cpp @@ -50,6 +50,7 @@ CComponentsItem::CComponentsItem(CComponentsForm* parent) cc_item_selected = false; cc_page_number = 0; cc_has_focus = true; + cc_parent = NULL; initParent(parent); } diff --git a/src/gui/lua/lua_curl.cpp b/src/gui/lua/lua_curl.cpp index 9bcf47ef5..fe1217512 100644 --- a/src/gui/lua/lua_curl.cpp +++ b/src/gui/lua/lua_curl.cpp @@ -267,7 +267,7 @@ Example: curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); /* enable all supported built-in compressions */ curl_easy_setopt(curl_handle, CURLOPT_ACCEPT_ENCODING, ""); - + curl_easy_setopt(curl_handle, CURLOPT_COOKIE, ""); if (!userAgent.empty()) curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, userAgent.c_str()); diff --git a/src/gui/movieinfo.cpp b/src/gui/movieinfo.cpp index def5a2f02..12398f9f8 100644 --- a/src/gui/movieinfo.cpp +++ b/src/gui/movieinfo.cpp @@ -497,6 +497,7 @@ void MI_MOVIE_INFO::clear(void) timePlay.tm_year = 100; timePlay.tm_mday = 0; timePlay.tm_mon = 1; + timePlay.tm_isdst = -1; file.Name = ""; file.Url = ""; diff --git a/src/gui/opkg_manager.cpp b/src/gui/opkg_manager.cpp index 2d014704f..229bad58d 100644 --- a/src/gui/opkg_manager.cpp +++ b/src/gui/opkg_manager.cpp @@ -11,7 +11,7 @@ Adaptions: Copyright (C) 2013 martii gitorious.org/neutrino-mp/martiis-neutrino-mp - Copyright (C) 2015-2016 Stefan Seyfried + Copyright (C) 2015-2017 Stefan Seyfried License: GPL @@ -79,6 +79,11 @@ #define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf.borken" #endif +/* script to call instead of "opkg upgrade" + * opkg fails to gracefully self-upgrade, and additionally has some ordering issues + */ +#define SYSTEM_UPDATE "system-update" + using namespace std; enum @@ -97,7 +102,7 @@ enum OM_MAX }; -static const string pkg_types[OM_MAX] = +static string pkg_types[OM_MAX] = { OPKG_CL " list ", OPKG_CL " list-installed ", @@ -216,7 +221,10 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey) { string pkg_name = fileBrowser.getSelectedFile()->Name; if (!installPackage(pkg_name)) + showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), "", pkg_name); + /* errno is never set properly, the string is totally useless. showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), strerror(errno), pkg_name); + */ *local_dir = fileBrowser.getCurrentDir(); refreshMenu(); @@ -228,7 +236,10 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey) parent->hide(); int r = execCmd(actionKey, CShellWindow::VERBOSE | CShellWindow::ACKNOWLEDGE_EVENT); if (r) { + /* errno is never set properly, the string is totally useless. showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), strerror(errno), actionKey); + */ + showError(g_Locale->getText(LOCALE_OPKG_FAILURE_UPGRADE), "", actionKey); } else installed = true; refreshMenu(); @@ -622,6 +633,11 @@ bool COPKGManager::hasOpkgSupport() return false; } + if (! find_executable(SYSTEM_UPDATE).empty()) { + dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] " SYSTEM_UPDATE " script found\n", __func__, __LINE__); + pkg_types[OM_UPGRADE] = SYSTEM_UPDATE; + } + #if 0 /* If directory /var/lib/opkg resp. /opt/opkg does not exist, it is created by opkg itself */ @@ -779,6 +795,8 @@ void COPKGManager::getPkgData(const int pkg_content_id) } } + waitpid(pid, NULL, 0); /* beware of the zombie apocalypse! */ + fclose(f); } @@ -884,9 +902,12 @@ void COPKGManager::handleShellOutput(string* cur_line, int* res, bool* ok) if (pos2 != string::npos) has_err = true; + dprintf(DEBUG_NORMAL, "[COPKGManager:%d] %s\n", __LINE__, line.c_str()); //check for collected errors and set res value if (has_err){ + /* all lines printed already dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] result: %s\n", __func__, __LINE__, line.c_str()); + */ /*duplicate option cache: option is defined in OPKG_CL_CONFIG_OPTIONS, * NOTE: if found first cache option in the opkg.conf file, this will be preferred and it's not really an error! @@ -911,13 +932,13 @@ void COPKGManager::handleShellOutput(string* cur_line, int* res, bool* ok) //download error: if (line.find("opkg_download:") != string::npos){ *res = OM_DOWNLOAD_ERR; - *ok = false; + //*ok = false; return; } //not enough space if (line.find("No space left on device") != string::npos){ *res = OM_OUT_OF_SPACE_ERR; - *ok = false; + //*ok = false; return; } //deps @@ -926,18 +947,28 @@ void COPKGManager::handleShellOutput(string* cur_line, int* res, bool* ok) *ok = false; return; } + /* hack */ + if (line.find("system-update: err_reset") != string::npos) { + *res = OM_SUCCESS; + *ok = true; + has_err = false; + return; + } //unknown error if (*ok){ - dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] ERROR: unhandled error %s\n", __func__, __LINE__, line.c_str()); + dprintf(DEBUG_DEBUG, "[COPKGManager] [%s - %d] ERROR: unhandled error %s\n", __func__, __LINE__, line.c_str()); *res = OM_UNKNOWN_ERR; - *ok = false; + //*ok = false; return; } +#if 0 + /* never reached */ if (!has_err){ *ok = true; *res = OM_SUCCESS; } +#endif } *res = _res; @@ -985,7 +1016,10 @@ bool COPKGManager::installPackage(const string& pkg_name, string options, bool f break; } default: + showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), "", pkg_types[OM_INSTALL] + opts + pkg_name); + /* errno / strerror considered useless here showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), strerror(errno), pkg_types[OM_INSTALL] + opts + pkg_name); + */ } }else{ if (force_configure) diff --git a/src/gui/widget/hintbox.cpp b/src/gui/widget/hintbox.cpp index 9be2aae6f..8e513756a 100644 --- a/src/gui/widget/hintbox.cpp +++ b/src/gui/widget/hintbox.cpp @@ -219,16 +219,13 @@ int CHintBox::exec() { res = messages_return::cancel_all; } - else if ((msg == CRCInput::RC_up) || (msg == CRCInput::RC_down)) + else if (enable_txt_scroll && (msg == CRCInput::RC_up || msg == CRCInput::RC_down)) { - if (enable_txt_scroll){ - if (msg == CRCInput::RC_up) - this->scroll_up(); - else - this->scroll_down(); - } + /* if ! enable_txt_scroll, fall through to last else branch instead */ + if (msg == CRCInput::RC_up) + this->scroll_up(); else - res = messages_return::cancel_all; + this->scroll_down(); } else if (CNeutrinoApp::getInstance()->listModeKey(msg)){ // do nothing //TODO: if passed rc messages are ignored rc messaages: has no effect here too!! diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index ba4957ecd..82a5e8e43 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -565,6 +565,7 @@ CMenuWidget::CMenuWidget() info_box = NULL; header = NULL; nextShortcut = 1; + x = y = 0; } CMenuWidget::CMenuWidget(const neutrino_locale_t Name, const std::string & Icon, const int mwidth, const mn_widget_id_t &w_index) @@ -639,6 +640,7 @@ void CMenuWidget::Init(const std::string &Icon, const int mwidth, const mn_widge nextShortcut = 1; saveScreen_width = 0; saveScreen_height = 0; + x = y = 0; } void CMenuWidget::move(int xoff, int yoff) diff --git a/src/gui/widget/shellwindow.cpp b/src/gui/widget/shellwindow.cpp index 78fa6d23e..931390243 100644 --- a/src/gui/widget/shellwindow.cpp +++ b/src/gui/widget/shellwindow.cpp @@ -7,7 +7,7 @@ Implementation: Copyright (C) 2013 martii gitorious.org/neutrino-mp/martiis-neutrino-mp - Copyright (C) 2015 Stefan Seyfried + Copyright (C) 2015-2017 Stefan Seyfried License: GPL @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,34 @@ void CShellWindow::setCommand(const std::string &Command, const int Mode, int* R exec(); } +static int read_line(int fd, struct pollfd *fds, char *b, size_t sz) +{ + int ret; + size_t i = 0; + while ((ret = read(fd, b + i, 1)) > 0) { + i++; + if (b[i - 1] == '\n') + break; + if (i >= sz) + break; + fds->revents = 0; + if (poll(fds, 1, 300) < 1) + break; + } + b[i] = 0; + return i; +} + +static std::string lines2txt(list &lines) +{ + std::string txt = ""; + for (std::list::const_iterator it = lines.begin(), end = lines.end(); it != end; ++it) { + txt += *it; + txt += '\n'; + } + return txt; +} + void CShellWindow::exec() { std::string cmd; @@ -80,11 +109,11 @@ void CShellWindow::exec() else { pid_t pid = 0; cmd = command + " 2>&1"; - FILE *f = my_popen(pid, cmd.c_str(), "r"); - if (!f) { + int f = run_pty(pid, cmd.c_str()); + if (f < 0) { if (res) *res = -1; - dprintf(DEBUG_NORMAL, "[CShellWindow] [%s:%d] Error! my_popen errno: %d command: %s\n", __func__, __LINE__, errno, cmd.c_str()); + dprintf(DEBUG_NORMAL, "[CShellWindow] [%s:%d] Error! run_pty errno: %d command: %s\n", __func__, __LINE__, errno, cmd.c_str()); return; } @@ -99,29 +128,24 @@ void CShellWindow::exec() textBox->enableSaveScreen(false); } struct pollfd fds; - fds.fd = fileno(f); + fds.fd = f; fds.events = POLLIN | POLLHUP | POLLERR; fcntl(fds.fd, F_SETFL, fcntl(fds.fd, F_GETFL, 0) | O_NONBLOCK); - struct timeval tv; - gettimeofday(&tv,NULL); - uint64_t lastPaint = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); + time_t lastPaint = time_monotonic_ms(); bool ok = true, nlseen = false, dirty = false, incomplete = false; char output[1024]; std::string txt = ""; std::string line = ""; do { - uint64_t now; + time_t now; fds.revents = 0; int r = poll(&fds, 1, 300); if (r > 0) { - if (!feof(f)) { - gettimeofday(&tv,NULL); - now = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - + if (fds.revents & POLLIN) { unsigned int lines_read = 0; - while (fgets(output, sizeof(output), f)) { + while (read_line(f, &fds, output, sizeof(output)-1)) { char *outputp = output; dirty = true; @@ -133,7 +157,9 @@ void CShellWindow::exec() *outputp = 0; break; case '\r': +#if 0 outputp = output; +#endif break; case '\n': lines_read++; @@ -168,17 +194,11 @@ void CShellWindow::exec() else dprintf(DEBUG_NORMAL, "[CShellWindow] [%s:%d] res=NULL ok=%d\n", __func__, __LINE__, ok); + now = time_monotonic_ms(); if (lines.size() > lines_max) lines.pop_front(); - txt = ""; - bool first = true; - for (std::list::const_iterator it = lines.begin(), end = lines.end(); it != end; ++it) { - if (!first) - txt += '\n'; - first = false; - txt += *it; - } - if (((lines_read == lines_max) && (lastPaint + 100000 < now)) || (lastPaint + 250000 < now)) { + if (((lines_read >= lines_max) && (lastPaint + 100 < now)) || (lastPaint + 500 < now)) { + txt = lines2txt(lines); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint(); @@ -192,9 +212,9 @@ void CShellWindow::exec() } else if (r < 0) ok = false; - gettimeofday(&tv,NULL); - now = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - if (!ok || (r < 1 && dirty && lastPaint + 250000 < now)) { + now = time_monotonic_ms(); + if (!ok || (r < 1 && dirty && lastPaint + 500 < now)) { + txt = lines2txt(lines); textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint(); @@ -204,11 +224,12 @@ void CShellWindow::exec() } while(ok); if (mode & VERBOSE) { + txt = lines2txt(lines); txt += "\n...ready"; textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); } - fclose(f); + close(f); int s; errno = 0; int r = waitpid(pid, &s, 0); diff --git a/src/gui/widget/textbox.cpp b/src/gui/widget/textbox.cpp index 05602cbbd..54968c03c 100644 --- a/src/gui/widget/textbox.cpp +++ b/src/gui/widget/textbox.cpp @@ -681,11 +681,14 @@ void CTextBox::refreshText(void) if (m_nMode & TOP) // move to top of frame y += m_nFontTextHeight + ((m_cFrameTextRel.iHeight - m_nFontTextHeight * m_nLinesPerPage) >> 1); - else if (m_nMode & BOTTOM) + else if (m_nMode & BOTTOM) { + /* if BOTTOM && !SCROLL, show the last lines if more than one page worth of text is in cLineArray */ + if (!(m_nMode & SCROLL) && (m_nNrOfLines > m_nLinesPerPage)) + m_nCurrentLine = m_nNrOfLines - m_nLinesPerPage; // move to bottom of frame y += m_cFrameTextRel.iHeight - (lines > 1 ? (lines - 1)*m_nFontTextHeight : 0) - text_Vborder_width; //m_nFontTextHeight + text_Vborder_width /*- ((m_cFrameTextRel.iHeight + m_nFontTextHeight*/ * m_nLinesPerPage/*) >> 1)*/; - else + } else // fit into mid of frame space y += m_nFontTextHeight + ((m_cFrameTextRel.iHeight - m_nFontTextHeight * lines) >> 1); diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 3bd8d1e02..1a34bc91f 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -3898,6 +3898,7 @@ void CNeutrinoApp::ExitRun(const bool /*write_si*/, int retcode) my_system("/etc/init.d/rcK"); sync(); + CFSMounter::umount(); // unreachable NFS server //NI my_system(2,"/bin/umount", "-a"); //NI sleep(1); diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 7051f2336..0cc1db2fe 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -4,7 +4,7 @@ License: GPL (C) 2012-2013 the neutrino-hd developers - (C) 2012-2015 Stefan Seyfried + (C) 2012-2017 Stefan Seyfried This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,6 +30,7 @@ #include #include #include +#include /* forkpty*/ #include #include #include @@ -352,6 +353,22 @@ FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type) } return(fp); } + +int run_pty(pid_t &pid, const char *cmdstring) +{ + int master = -1; + if ((pid = forkpty(&master, NULL, NULL, NULL)) < 0) + return -1; + else if (pid == 0) { + int maxfd = getdtablesize(); + for(int i = 3; i < maxfd; i++) + close(i); + execl("/bin/sh", "sh", "-c", cmdstring, (char *)0); + exit(0); + } + return master; +} + #if 0 int mkdirhier(const char *pathname, mode_t mode) { diff --git a/src/system/helpers.h b/src/system/helpers.h index 373d82d64..28e6deea7 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -43,6 +43,7 @@ int my_system(int argc, const char *arg, ...); /* argc is number of arguments in //int ni_system(std::string cmd, bool noshell = true, bool background = false); //NI background FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type); +int run_pty(pid_t &pid, const char *cmdstring); int safe_mkdir(const char * path); inline int safe_mkdir(std::string path) { return safe_mkdir(path.c_str()); }