Remove dependency on lsof. Much prodded by deraadt@. :)

Switch out from devel/gettext in MODULES while there.
This commit is contained in:
zhuk 2016-04-30 00:37:36 +00:00
parent fad3629661
commit 596e13596f
3 changed files with 152 additions and 4 deletions

View File

@ -1,8 +1,8 @@
# $OpenBSD: Makefile,v 1.48 2016/01/03 16:53:34 zhuk Exp $
# $OpenBSD: Makefile,v 1.49 2016/04/30 00:37:36 zhuk Exp $
COMMENT = KDE workspace
DISTNAME = kde-workspace-4.11.21
REVISION = 7
REVISION = 8
MASTER_SITES = ${MASTER_SITE_KDE:=stable/applications/15.04.3/src/}
@ -84,7 +84,7 @@ WANTLIB += ck-connector cln dbus-1 dbusmenu-qt glib-2.0 gps jpeg kvm png
WANTLIB += prison qalculate qimageblitz qjson soprano streamanalyzer
WANTLIB += usb xml2 xmms
MODULES = devel/gettext multimedia/phonon lang/python lang/ruby
MODULES = multimedia/phonon lang/python lang/ruby
MODKDE4_USE = pim
MODRUBY_BUILDDEP = No
@ -93,8 +93,8 @@ BUILD_DEPENDS = misc/shared-desktop-ontologies \
${MODKDE4_DEP_DIR}/py-kde>=${MODKDE4_DEP_VERSION} \
RUN_DEPENDS = devel/desktop-file-utils \
devel/gettext \
misc/shared-desktop-ontologies \
sysutils/lsof \
x11/gtk+3,-guic \
x11/polkit-qt, \
${MODKDE4_DEP_DIR}/base-artwork>=${MODKDE4_DEP_VERSION} \

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-libs_ksysguard_lsofui_CMakeLists_txt,v 1.1 2016/04/30 00:37:36 zhuk Exp $
Use kvm_getfiles() instead of starting lsof(1).
--- libs/ksysguard/lsofui/CMakeLists.txt.orig Sat Apr 30 02:55:52 2016
+++ libs/ksysguard/lsofui/CMakeLists.txt Sat Apr 30 02:55:33 2016
@@ -12,6 +12,11 @@ kde4_add_ui_files( lsofui_LIB_SRCS
kde4_add_library(lsofui SHARED ${lsofui_LIB_SRCS})
target_link_libraries(lsofui ${KDE4_KIO_LIBS} )
+if( ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" )
+ message(STATUS "Adding kvm library on NetBSD/OpenBSD")
+ target_link_libraries(lsofui kvm)
+ add_definitions(-DHAVE_KVM_H=1)
+endif()
set_target_properties(lsofui PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
install(TARGETS lsofui EXPORT kdeworkspaceLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS} )

View File

@ -0,0 +1,132 @@
$OpenBSD: patch-libs_ksysguard_lsofui_lsof_cpp,v 1.1 2016/04/30 00:37:36 zhuk Exp $
Use kvm_getfiles() instead of starting lsof(1).
--- libs/ksysguard/lsofui/lsof.cpp.orig Fri Jun 26 06:17:21 2015
+++ libs/ksysguard/lsofui/lsof.cpp Sat Apr 30 03:14:56 2016
@@ -1,12 +1,25 @@
#include <QString>
-#include <QProcess>
+#ifdef HAVE_KVM_H
+# include <sys/types.h>
+# include <sys/sysctl.h>
+# include <fcntl.h>
+# include <kvm.h>
+# include <limits.h>
+#else
+# include <QProcess>
+#endif
#include <klocale.h>
#include "lsof.h"
struct KLsofWidgetPrivate {
qlonglong pid;
+#ifdef HAVE_KVM_H
+ kvm_t *kd;
+ char errbuf[_POSIX2_LINE_MAX];
+#else
QProcess *process;
+#endif
};
KLsofWidget::KLsofWidget(QWidget *parent) : QTreeWidget(parent), d(new KLsofWidgetPrivate)
@@ -19,12 +32,23 @@ KLsofWidget::KLsofWidget(QWidget *parent) : QTreeWidge
setSortingEnabled(true);
setAllColumnsShowFocus(true);
setHeaderLabels(QStringList() << i18nc("Short for File Descriptor", "FD") << i18n("Type") << i18n("Object"));
+#ifdef HAVE_KVM_H
+ d->kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, d->errbuf);
+#else
d->process = new QProcess(this);
connect(d->process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
+#endif
}
KLsofWidget::~KLsofWidget()
{
+#ifdef HAVE_KVM_H
+ if (d->kd)
+ kvm_close(d->kd);
+#else
+ if (d->process)
+ delete d->process;
+#endif
delete d;
}
@@ -38,9 +62,68 @@ void KLsofWidget::setPid(qlonglong pid) {
update();
}
+#ifdef HAVE_KVM_H
+
+static QString fileTypeName(int ftype, int vtype) {
+ static QString vtype_names[] = {
+ QString::fromLatin1("no type"),
+ QString::fromLatin1("file"),
+ QString::fromLatin1("directory"),
+ QString::fromLatin1("blockdev"),
+ QString::fromLatin1("chardev"),
+ QString::fromLatin1("symlink"),
+ QString::fromLatin1("socket"),
+ QString::fromLatin1("named pipe"),
+ QString::fromLatin1("bad")
+ };
+
+// taken from sys/file.h on OpenBSD 5.9-CURRENT
+#ifndef DTYPE_VNODE
+# define DTYPE_VNODE 1 /* file */
+# define DTYPE_SOCKET 2 /* communications endpoint */
+# define DTYPE_PIPE 3 /* pipe */
+# define DTYPE_KQUEUE 4 /* event queue */
+#endif
+
+ switch (ftype) {
+ case DTYPE_SOCKET:
+ return QString::fromLatin1("socket");
+ case DTYPE_PIPE:
+ return QString::fromLatin1("pipe");
+ case DTYPE_KQUEUE:
+ return QString::fromLatin1("kqueue");
+ case DTYPE_VNODE:
+ if (vtype >= 0 && vtype <= sizeof(vtype_names)/sizeof(vtype_names[0]))
+ return vtype_names[vtype];
+ }
+ return QString::fromLatin1("unknown");
+}
+
bool KLsofWidget::update()
{
+ struct kinfo_file *files;
+ int cnt;
+
clear();
+ if (d->kd == NULL)
+ return false;
+ if ((files = kvm_getfiles(d->kd, KERN_FILE_BYPID, (int)d->pid, sizeof(struct kinfo_file), &cnt)) == NULL)
+ return false;
+
+ for (int i = 0; i < cnt; i++) {
+ QTreeWidgetItem *process = new QTreeWidgetItem(this);
+ process->setText(0, QString::number(files[i].fd_fd));
+ process->setText(1, fileTypeName(files[i].f_type, files[i].v_type));
+ process->setText(2, QString::fromLocal8Bit(files[i].f_mntonname));
+ }
+ return true;
+}
+
+#else // HAVE_KVM_H
+
+bool KLsofWidget::update()
+{
+ clear();
QStringList args;
d->process->waitForFinished();
args << "-Fftn";
@@ -85,5 +168,7 @@ void KLsofWidget::finished ( int exitCode, QProcess::E
}
}
}
+
+#endif // HAVE_KVM_H
#include "lsof.moc"