summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-02-09 21:24:45 +0100
committerJiri Moskovcak <jmoskovc@redhat.com>2009-02-09 21:24:45 +0100
commit3192f468fa5e7f10c664cca671246f962d1d36d1 (patch)
tree67d0dbb2c06149eb66c06b9d639144233e3149fe /lib
parent7a14f59368f7221274bd74504700fc36031e9c3f (diff)
parentf48e217149c36a49cb64221bfca752c53d8c1bee (diff)
downloadabrt-3192f468fa5e7f10c664cca671246f962d1d36d1.tar.gz
abrt-3192f468fa5e7f10c664cca671246f962d1d36d1.tar.xz
abrt-3192f468fa5e7f10c664cca671246f962d1d36d1.zip
Merge branch 'master' of git://git.fedorahosted.org/git/crash-catcher
Diffstat (limited to 'lib')
-rw-r--r--lib/MiddleWare/test.cpp2
-rw-r--r--lib/Utils/DebugDump.cpp13
-rw-r--r--lib/Utils/Makefile.am4
-rw-r--r--lib/Utils/Packages.cpp112
-rw-r--r--lib/Utils/Packages.h48
5 files changed, 173 insertions, 6 deletions
diff --git a/lib/MiddleWare/test.cpp b/lib/MiddleWare/test.cpp
index 9d54b0b..b75bab9 100644
--- a/lib/MiddleWare/test.cpp
+++ b/lib/MiddleWare/test.cpp
@@ -45,8 +45,6 @@ int main(int argc, char** argv)
dd.SaveText(FILENAME_LANGUAGE, "CCpp");
dd.SaveBinary(FILENAME_BINARYDATA1, "ass0-9as", sizeof("ass0-9as"));
dd.SaveText(FILENAME_TIME, "1111111111");
- dd.SaveText(FILENAME_EXECUTABLE, "test");
- dd.SaveText(FILENAME_PACKAGE, "test-1.0-1.f10");
middleWare.SaveDebugDumpToDatabase(std::string(DEBUG_DUMPS_DIR)+"/"+pid);
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index e35ec4d..9fd887f 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -20,6 +20,7 @@
*/
#include "DebugDump.h"
+#include "Packages.h"
#include <fstream>
#include <iostream>
#include <sstream>
@@ -223,12 +224,20 @@ void CDebugDump::SaveProc(const std::string& pPID)
std::string path = "/proc/"+pPID+"/exe";
std::string data;
char executable[PATH_MAX];
+ int len;
- if (readlink(path.c_str(), executable, PATH_MAX) == 0)
+ if ((len = readlink(path.c_str(), executable, PATH_MAX)) != -1)
{
+ executable[len] = '\0';
SaveText(FILENAME_EXECUTABLE, executable);
}
+ CPackages packages;
+ while (!packages.SearchFile(executable)) {}
+ while (!packages.GetStatus()) {}
+ std::string package = packages.GetSearchFileReply();
+ SaveText(FILENAME_PACKAGE, package);
+
path = "/proc/"+pPID+"/status";
std::string uid = "0";
int ii = 0;
@@ -242,6 +251,4 @@ void CDebugDump::SaveProc(const std::string& pPID)
ii++;
}
SaveText(FILENAME_UID, uid);
-
- // TODO: Use packagekit
}
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index 71a8e98..2b47b1e 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -1,6 +1,8 @@
lib_LTLIBRARIES = libUtils.la
-libUtils_la_SOURCES = DebugDump.cpp DebugDump.h
+libUtils_la_SOURCES = DebugDump.cpp DebugDump.h Packages.cpp Packages.h
libUtils_la_LDFLAGS = -version-info 0:1:0
+libUtils_la_CPPFLAGS = $(PACKAGEKIT_GLIB_CFLAGS)
+libUtils_la_LIBADD = $(PACKAGEKIT_GLIB_LIBS)
install-data-local:
$(mkdir_p) '$(DEBUG_DUMPS_DIR)' \ No newline at end of file
diff --git a/lib/Utils/Packages.cpp b/lib/Utils/Packages.cpp
new file mode 100644
index 0000000..ed406b0
--- /dev/null
+++ b/lib/Utils/Packages.cpp
@@ -0,0 +1,112 @@
+/*
+ Packages.cpp - PackageKit wrapper
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "Packages.h"
+
+CPackages::CPackages() :
+ m_pPkClient(NULL),
+ m_bBusy(false)
+{
+ g_type_init();
+ m_pPkClient = pk_client_new();
+// pk_client_set_synchronous (m_pPkClient, TRUE, NULL);
+}
+
+CPackages::~CPackages()
+{
+ g_object_unref(m_pPkClient);
+}
+
+bool CPackages::SearchFile(const std::string& pPath)
+{
+ if (m_bBusy)
+ {
+ return false;
+ }
+ m_bBusy = true;
+ GError *error = NULL;
+ gboolean ret = pk_client_search_file (m_pPkClient,
+ pk_bitfield_value (PK_FILTER_ENUM_INSTALLED),
+ pPath.c_str(),
+ &error);
+ if (ret == FALSE)
+ {
+ std::string err = error->message;
+ g_error_free(error);
+ error = NULL;
+ throw std::string("CPackages::SearchFile(): ") + err;
+ }
+ return true;
+}
+
+bool CPackages::Install(const std::string& pPackage)
+{
+ // TODO: write this
+}
+
+
+bool CPackages::GetStatus()
+{
+ GError *error = NULL;
+ PkStatusEnum status;
+ gboolean ret = pk_client_get_status(m_pPkClient, &status, &error);
+ if (ret == FALSE)
+ {
+ std::string err = error->message;
+ g_error_free(error);
+ error = NULL;
+ throw std::string("CPackages::SearchFile(): ") + err;
+ }
+ if (status != PK_STATUS_ENUM_FINISHED)
+ {
+ return false;
+ }
+ return true;
+}
+
+std::string CPackages::GetSearchFileReply()
+{
+ GError *error = NULL;
+ std::string packageName = "";
+ gchar *package;
+ gboolean ret = pk_client_get_package (m_pPkClient, &package, &error);
+ if (ret == FALSE)
+ {
+ std::string err = error->message;
+ g_error_free(error);
+ if (err == "No package data available")
+ {
+ return "";
+ }
+ throw std::string("CPackages::SearchFile(): ") + err;
+ }
+ packageName = package;
+ packageName[packageName.find(";")] = '-';
+ packageName = packageName.substr(0, packageName.find(";"));
+
+ m_bBusy = false;
+ return packageName;
+}
+
+bool CPackages::GetInstallReply()
+{
+ // TODO: write this
+}
diff --git a/lib/Utils/Packages.h b/lib/Utils/Packages.h
new file mode 100644
index 0000000..2228acc
--- /dev/null
+++ b/lib/Utils/Packages.h
@@ -0,0 +1,48 @@
+/*
+ Packages.h - PackageKit wrapper
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PACKAGES_H_
+#define PACKAGES_H_
+
+#include <glib.h>
+#include <packagekit-glib/packagekit.h>
+#include <string>
+
+class CPackages
+{
+ private:
+
+ PkClient *m_pPkClient;
+ bool m_bBusy;
+
+ public:
+ CPackages();
+ ~CPackages();
+ bool SearchFile(const std::string& pPath);
+ bool Install(const std::string& pPackage);
+ bool GetStatus();
+
+ std::string GetSearchFileReply();
+ bool GetInstallReply();
+
+};
+
+#endif /* PACKAGES_H_ */