diff options
| author | Karel Klic <kklic@redhat.com> | 2009-12-14 10:41:51 +0100 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2009-12-14 10:41:51 +0100 |
| commit | a24d2906c51e3740e6e0acf8f0093827b4e35bc3 (patch) | |
| tree | 1022bf70766a88d45dc71d6ea413ccd0fa14d07c /lib/Utils | |
| parent | b7ea0e53e3375de6298b2f510302f75ebef4be4e (diff) | |
| parent | 42f0375d09931903965b36c87f17f805def956bf (diff) | |
| download | abrt-a24d2906c51e3740e6e0acf8f0093827b4e35bc3.tar.gz abrt-a24d2906c51e3740e6e0acf8f0093827b4e35bc3.tar.xz abrt-a24d2906c51e3740e6e0acf8f0093827b4e35bc3.zip | |
Merge branch 'master' of git://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils')
| -rw-r--r-- | lib/Utils/ABRTException.cpp | 15 | ||||
| -rw-r--r-- | lib/Utils/CrashTypesSocket.cpp | 4 | ||||
| -rw-r--r-- | lib/Utils/DebugDump.cpp | 28 | ||||
| -rw-r--r-- | lib/Utils/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/Utils/Reporter.h | 2 | ||||
| -rw-r--r-- | lib/Utils/abrt_dbus.h | 22 | ||||
| -rw-r--r-- | lib/Utils/abrt_xmlrpc.cpp | 2 | ||||
| -rw-r--r-- | lib/Utils/logging.cpp | 11 | ||||
| -rw-r--r-- | lib/Utils/xfuncs.cpp | 4 |
9 files changed, 50 insertions, 41 deletions
diff --git a/lib/Utils/ABRTException.cpp b/lib/Utils/ABRTException.cpp new file mode 100644 index 0000000..aa6c99d --- /dev/null +++ b/lib/Utils/ABRTException.cpp @@ -0,0 +1,15 @@ +#include "ABRTException.h" + +CABRTException::CABRTException(abrt_exception_t type, const char* fmt, ...) +{ + m_type = type; + va_list ap; + va_start(ap, fmt); + m_what = xvasprintf(fmt, ap); + va_end(ap); +} + +CABRTException::CABRTException(const CABRTException& rhs): + m_type(rhs.m_type), + m_what(xstrdup(rhs.m_what)) +{} diff --git a/lib/Utils/CrashTypesSocket.cpp b/lib/Utils/CrashTypesSocket.cpp index 7c206de..f16e2a9 100644 --- a/lib/Utils/CrashTypesSocket.cpp +++ b/lib/Utils/CrashTypesSocket.cpp @@ -73,7 +73,7 @@ std::string crash_data_to_string(const map_crash_data_t& pCrashData) std::stringstream sCD; map_crash_data_t::const_iterator it_cd; sCD << "(" << pCrashData.size() << ")"; - for(it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) + for (it_cd = pCrashData.begin(); it_cd != pCrashData.end(); it_cd++) { sCD << "(" << it_cd->first.length() << ")"; sCD << it_cd->first; @@ -150,7 +150,7 @@ map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len) sField = message.substr(ii, nSize); message.erase(0, ii + nSize); len += ii + nSize; - switch(nField % 4) + switch (nField % 4) { case 0: name = sField; diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index 3e226f9..765b514 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -77,7 +77,7 @@ void CDebugDump::Open(const char *pDir) m_sDebugDumpDir = RemoveBackSlashes(pDir); if (!ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, m_sDebugDumpDir + " does not exist"); + throw CABRTException(EXCEP_DD_OPEN, "'%s' does not exist", m_sDebugDumpDir.c_str()); } Lock(); m_bOpened = true; @@ -197,7 +197,7 @@ void CDebugDump::Lock() sprintf(pid_buf, "%u", (unsigned)getpid()); while ((m_bLocked = GetAndSetLock(lockFile.c_str(), pid_buf)) != true) { - usleep(500000); + sleep(1); /* was 0.5 seconds */ } } @@ -222,7 +222,7 @@ void CDebugDump::Create(const char *pDir, int64_t uid) m_sDebugDumpDir = RemoveBackSlashes(pDir); if (ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, ssprintf("'%s' already exists", m_sDebugDumpDir.c_str())); + throw CABRTException(EXCEP_DD_OPEN, "'%s' already exists", m_sDebugDumpDir.c_str()); } Lock(); @@ -232,13 +232,13 @@ void CDebugDump::Create(const char *pDir, int64_t uid) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't create dir '%s'", pDir)); + throw CABRTException(EXCEP_DD_OPEN, "Can't create dir '%s'", pDir); } if (chmod(m_sDebugDumpDir.c_str(), 0700) == -1) { UnLock(); m_bOpened = false; - throw CABRTException(EXCEP_DD_OPEN, ssprintf("Can't change mode of '%s'", pDir)); + throw CABRTException(EXCEP_DD_OPEN, "Can't change mode of '%s'", pDir); } struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; @@ -272,7 +272,7 @@ static void DeleteFileDir(const char *pDir) if (errno != EISDIR) { closedir(dir); - throw CABRTException(EXCEP_DD_DELETE, ssprintf("Can't remove dir %s", fullPath.c_str())); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove dir %s", fullPath.c_str()); } DeleteFileDir(fullPath.c_str()); } @@ -280,7 +280,7 @@ static void DeleteFileDir(const char *pDir) closedir(dir); if (remove(pDir) == -1) { - throw CABRTException(EXCEP_DD_DELETE, ssprintf("Can't remove dir %s", pDir)); + throw CABRTException(EXCEP_DD_DELETE, "Can't remove dir %s", pDir); } } @@ -325,7 +325,7 @@ static void LoadTextFile(const char *pPath, std::string& pData) FILE *fp = fopen(pPath, "r"); if (!fp) { - throw CABRTException(EXCEP_DD_LOAD, ssprintf("Can't open file '%s'", pPath)); + throw CABRTException(EXCEP_DD_LOAD, "Can't open file '%s'", pPath); } pData = ""; int ch; @@ -348,13 +348,13 @@ static void SaveBinaryFile(const char *pPath, const char* pData, unsigned pSize) int fd = open(pPath, O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd < 0) { - throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't open file '%s'", pPath)); + throw CABRTException(EXCEP_DD_SAVE, "Can't open file '%s'", pPath); } unsigned r = full_write(fd, pData, pSize); close(fd); if (r != pSize) { - throw CABRTException(EXCEP_DD_SAVE, ssprintf("Can't save file '%s'", pPath)); + throw CABRTException(EXCEP_DD_SAVE, "Can't save file '%s'", pPath); } } @@ -362,7 +362,7 @@ void CDebugDump::LoadText(const char* pName, std::string& pData) { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::LoadText(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); LoadTextFile(fullPath.c_str(), pData); @@ -372,7 +372,7 @@ void CDebugDump::SaveText(const char* pName, const char* pData) { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::SaveText(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); SaveBinaryFile(fullPath.c_str(), pData, strlen(pData)); @@ -381,7 +381,7 @@ void CDebugDump::SaveBinary(const char* pName, const char* pData, unsigned pSize { if (!m_bOpened) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::SaveBinary(): DebugDump is not opened."); + throw CABRTException(EXCEP_DD_OPEN, "DebugDump is not opened"); } std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName); SaveBinaryFile(fullPath.c_str(), pData, pSize); @@ -400,7 +400,7 @@ void CDebugDump::InitGetNextFile() m_pGetNextFileDir = opendir(m_sDebugDumpDir.c_str()); if (m_pGetNextFileDir == NULL) { - throw CABRTException(EXCEP_DD_OPEN, "Can't open dir " + m_sDebugDumpDir); + throw CABRTException(EXCEP_DD_OPEN, "Can't open dir '%s'", m_sDebugDumpDir.c_str()); } } diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index 297007a..9618751 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -17,7 +17,8 @@ libABRTUtils_la_SOURCES = \ popen_and_save_output.cpp \ stringops.cpp \ dirsize.cpp \ - DebugDump.h DebugDump.cpp + DebugDump.h DebugDump.cpp \ + ABRTException.cpp libABRTUtils_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../../inc \ diff --git a/lib/Utils/Reporter.h b/lib/Utils/Reporter.h index f278899..0a06a7c 100644 --- a/lib/Utils/Reporter.h +++ b/lib/Utils/Reporter.h @@ -42,7 +42,7 @@ class CReporter : public CPlugin */ virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, - const std::string& pArgs) = 0; + const char *pArgs) = 0; }; #endif /* REPORTER_H_ */ diff --git a/lib/Utils/abrt_dbus.h b/lib/Utils/abrt_dbus.h index b31a015..bc9889a 100644 --- a/lib/Utils/abrt_dbus.h +++ b/lib/Utils/abrt_dbus.h @@ -194,17 +194,19 @@ static int load_vector(DBusMessageIter* iter, std::vector<E>& val) int r; //int cnt = 0; - //type = dbus_message_iter_get_arg_type(&sub_iter); - /* here "type" is the element's type, and it will be checked by load_val */ - // if (type != DBUS_TYPE_INVALID) - not needed? - do { - E elem; + /* When the vector has 0 elements, we see DBUS_TYPE_INVALID here */ + type = dbus_message_iter_get_arg_type(&sub_iter); + if (type != DBUS_TYPE_INVALID) + { + do { + E elem; //cnt++; - r = load_val(&sub_iter, elem); - if (r < 0) - return r; - val.push_back(elem); - } while (r == ABRT_DBUS_MORE_FIELDS); + r = load_val(&sub_iter, elem); + if (r < 0) + return r; + val.push_back(elem); + } while (r == ABRT_DBUS_MORE_FIELDS); + } //log("%s: %d elems", __func__, cnt); return dbus_message_iter_next(iter); diff --git a/lib/Utils/abrt_xmlrpc.cpp b/lib/Utils/abrt_xmlrpc.cpp index 11c431b..7205316 100644 --- a/lib/Utils/abrt_xmlrpc.cpp +++ b/lib/Utils/abrt_xmlrpc.cpp @@ -13,7 +13,7 @@ void throw_if_xml_fault_occurred(xmlrpc_env *env) xmlrpc_env_clean(env); // this is needed ONLY if fault_occurred xmlrpc_env_init(env); // just in case user catches ex and _continues_ to use env error_msg("%s", errmsg.c_str()); // show error in daemon log - throw CABRTException(EXCEP_PLUGIN, errmsg); + throw CABRTException(EXCEP_PLUGIN, errmsg.c_str()); } } diff --git a/lib/Utils/logging.cpp b/lib/Utils/logging.cpp index cae609b..53b83d7 100644 --- a/lib/Utils/logging.cpp +++ b/lib/Utils/logging.cpp @@ -60,6 +60,7 @@ static void verror_msg_helper(const char *s, va_list p, const char* strerr, int fflush(stdout); full_write(STDERR_FILENO, msg, used + msgeol_len); } + msg[used] = '\0'; /* remove msg_eol (usually "\n") */ if (flags & LOGMODE_SYSLOG) { syslog(LOG_ERR, "%s", msg + prefix_len); } @@ -118,16 +119,6 @@ void perror_msg(const char *s, ...) va_end(p); } -void simple_perror_msg_and_die(const char *s) -{ - perror_msg_and_die("%s", s); -} - -void simple_perror_msg(const char *s) -{ - perror_msg("%s", s); -} - void die_out_of_memory(void) { error_msg_and_die("Out of memory, exiting"); diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index b1941f7..0e57639 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -8,12 +8,12 @@ /* Turn on nonblocking I/O on a fd */ int ndelay_on(int fd) { - return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) | O_NONBLOCK); + return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); } int ndelay_off(int fd) { - return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) & ~O_NONBLOCK); + return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK); } int close_on_exec_on(int fd) |
