diff options
author | OBATA Akio <obache@wizdas.com> | 2019-04-06 16:49:26 +0900 |
---|---|---|
committer | OBATA Akio <obache@wizdas.com> | 2019-08-18 14:45:26 +0900 |
commit | 2a88ec3c02ab46c8b816cfa348ea53075f57a59c (patch) | |
tree | e7029145d265a0a6a31601a1eb476a719d6dd4b5 | |
parent | df19ff6b7dc7adcdb88e86d50d9d88d622a09d88 (diff) | |
download | tdebase-2a88ec3c02ab46c8b816cfa348ea53075f57a59c.tar.gz tdebase-2a88ec3c02ab46c8b816cfa348ea53075f57a59c.zip |
Revive NetBSD support
Catch up to TDE and OS changes
Signed-off-by: OBATA Akio <obache@wizdas.com>
29 files changed, 504 insertions, 201 deletions
diff --git a/kcontrol/info/info_netbsd.cpp b/kcontrol/info/info_netbsd.cpp index c2b7b953a..2fced7e40 100644 --- a/kcontrol/info/info_netbsd.cpp +++ b/kcontrol/info/info_netbsd.cpp @@ -41,6 +41,7 @@ #include <tqfontmetrics.h> #include <tqstrlist.h> #include <tqtextstream.h> +#include <tqregexp.h> #include <kdebug.h> #include <tdeio/global.h> /* for TDEIO::convertSize() */ @@ -123,7 +124,7 @@ static bool GetDmesgInfo(TQListView *lBox, const char *filter, } TQListViewItem *olditem = NULL; - while(!(s = t->readLine().local8Bit()).isEmpty()) { + while(!(s = t->readLine().local8Bit()).isNull()) { if (!seencpu) { if (s.contains("cpu")) seencpu = true; @@ -134,9 +135,7 @@ static bool GetDmesgInfo(TQListView *lBox, const char *filter, s.contains("WARNING: old BSD partition ID!")) break; - if (!filter - || (filter[0] == '^' && s.find(&filter[1]) == 0) - || (filter[0] != '^' && s.contains(filter))) { + if (!filter || s.contains(TQRegExp(filter))) { if (func) func(lBox, s); else @@ -163,7 +162,7 @@ AddIRQLine(TQListView *lBox, TQString s) int pos, irqnum; char numstr[3]; - pos = s.find(" irq "); + pos = s.find(TQRegExp("[ (]irq ")); irqnum = (pos < 0) ? 0 : atoi(&s.ascii()[pos+5]); if (irqnum) snprintf(numstr, 3, "%02d", irqnum); @@ -181,7 +180,7 @@ bool GetInfo_IRQ (TQListView *lBox) lBox->addColumn(i18n("Device")); lBox->setSorting(0); lBox->setShowSortIndicator(FALSE); - (void) GetDmesgInfo(lBox, " irq ", AddIRQLine); + (void) GetDmesgInfo(lBox, "[ (]irq ", AddIRQLine); return true; } @@ -265,9 +264,12 @@ bool GetInfo_SCSI (TQListView *lbox) bool GetInfo_Partitions (TQListView *lbox) { int num; // number of mounts - // FIXME: older pkgsrc patches checked ST_RDONLY for this declaration - // what is ST_RDONLY and how does it affect getmntinfo? +#ifdef HAVE_STATVFS + struct statvfs *mnt; // mount data pointer +#else struct statfs *mnt; // mount data pointer +#endif + TQString MB(i18n("MB")); /* "MB" = "Mega-Byte" */ // get mount info if (!(num=getmntinfo(&mnt, MNT_WAIT))) { @@ -290,24 +292,31 @@ bool GetInfo_Partitions (TQListView *lbox) unsigned long long big[2]; TQString vv[5]; +#ifdef HAVE_STATVFS + big[0] = big[1] = mnt->f_frsize; // coerce the product +#else big[0] = big[1] = mnt->f_bsize; // coerce the product +#endif big[0] *= mnt->f_blocks; big[1] *= mnt->f_bavail; // FIXME: use f_bfree if root? // convert to strings - vv[0] = TDEIO::convertSize(big[0]); - vv[1] = TQString::fromLatin1("%1 (%2%%)") - .arg(TDEIO::convertSize(big[1])) + vv[0] = Value((int) (((big[0] / 1024) + 512) / 1024), 6) + MB; + vv[1] = TQString("%1 (%2%)") + .arg(Value((int) (((big[1] / 1024) + 512) / 1024), 6) + MB) .arg(mnt->f_blocks ? mnt->f_bavail*100/mnt->f_blocks : 0); - // FIXME: these two are large enough to punctuate - vv[2] = TQString::number(mnt->f_files); - vv[3] = TQString::fromLatin1("%1 (%2%%) ") + vv[2] = TQString("%L1").arg(mnt->f_files); + vv[3] = TQString("%1 (%2%) ") .arg(mnt->f_ffree) .arg(mnt->f_files ? mnt->f_ffree*100/mnt->f_files : 0); vv[4] = TQString::null; +#ifdef HAVE_STATVFS +#define MNTF(x) if (mnt->f_flag & ST_##x) vv[4] += TQString::fromLatin1(#x " "); +#else #define MNTF(x) if (mnt->f_flags & MNT_##x) vv[4] += TQString::fromLatin1(#x " "); +#endif MNTF(ASYNC) MNTF(DEFEXPORTED) MNTF(EXKERB) @@ -316,7 +325,9 @@ bool GetInfo_Partitions (TQListView *lbox) MNTF(EXPORTED) MNTF(EXPUBLIC) MNTF(EXRDONLY) +#ifndef HAVE_STATVFS MNTF(IGNORE) +#endif MNTF(LOCAL) MNTF(NOATIME) MNTF(NOCOREDUMP) diff --git a/kcontrol/info/memory_netbsd.cpp b/kcontrol/info/memory_netbsd.cpp index 39beeaa33..015fdd0ec 100644 --- a/kcontrol/info/memory_netbsd.cpp +++ b/kcontrol/info/memory_netbsd.cpp @@ -22,7 +22,7 @@ void KMemoryWidget::update() int mib[2]; size_t len; #ifdef UVM -#if __NetBSD_Version__ > 499000100 /* 4.99.2+ */ +#if __NetBSD_Version__ > 106000000 /* 1.6+ */ struct uvmexp_sysctl uvmexp; #else struct uvmexp uvmexp; @@ -53,7 +53,7 @@ void KMemoryWidget::update() #ifdef UVM mib[0] = CTL_VM; -#if __NetBSD_Version__ > 499000100 /* 4.99.2+ */ +#if __NetBSD_Version__ > 106000000 /* 1.6+ */ mib[1] = VM_UVMEXP2; #else mib[1] = VM_UVMEXP; diff --git a/kcontrol/tdefontinst/tdefontinst/GetPid.c b/kcontrol/tdefontinst/tdefontinst/GetPid.c index 1a633a76b..e4159f40a 100644 --- a/kcontrol/tdefontinst/tdefontinst/GetPid.c +++ b/kcontrol/tdefontinst/tdefontinst/GetPid.c @@ -28,6 +28,10 @@ //////////////////////////////////////////////////////////////////////////////// */ +#ifdef __NetBSD__ +#define _KMEMUSER +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -173,7 +177,9 @@ unsigned int kfi_getPid(const char *proc, unsigned int ppid) #endif #include <sys/sysctl.h> #include <sys/time.h> +#if defined(__FreeBSD__) || defined(__DragonFly__) #include <sys/user.h> +#endif #include <unistd.h> unsigned int kfi_getPid(const char *proc, unsigned int ppid) { diff --git a/kcontrol/usbview/usbdevices.cpp b/kcontrol/usbview/usbdevices.cpp index d8322612a..87f3a7ee5 100644 --- a/kcontrol/usbview/usbdevices.cpp +++ b/kcontrol/usbview/usbdevices.cpp @@ -27,7 +27,7 @@ #include <math.h> -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include <sys/ioctl.h> #include <sys/param.h> #endif @@ -197,7 +197,7 @@ TQString USBDevice::dump() if (!prname.isEmpty()) pr += "<td>(" + prname +")</td>"; r += i18n("<tr><td><i>Protocol</i></td>%1</tr>").arg(pr); -#ifndef Q_OS_FREEBSD +#if !(defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) r += i18n("<tr><td><i>USB Version</i></td><td>%1.%2</td></tr>") .arg(_verMajor,0,16) .arg(TQString::number(_verMinor,16).prepend('0').right(2)); @@ -221,7 +221,7 @@ TQString USBDevice::dump() r += i18n("<tr><td><i>Speed</i></td><td>%1 Mbit/s</td></tr>").arg(_speed); r += i18n("<tr><td><i>Channels</i></td><td>%1</td></tr>").arg(_channels); -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) if ( _power ) r += i18n("<tr><td><i>Power Consumption</i></td><td>%1 mA</td></tr>").arg(_power); else @@ -249,7 +249,7 @@ TQString USBDevice::dump() } -#ifndef Q_OS_FREEBSD +#if !(defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) bool USBDevice::parse(TQString fname) { _devices.clear(); @@ -325,18 +325,29 @@ bool USBDevice::parseSys(TQString dname) * only little modification on NetBSD. */ +#ifdef Q_OS_FREEBSD void USBDevice::collectData(struct libusb20_backend *pbe, struct libusb20_device *pdev) +#else +void USBDevice::collectData( int fd, int leve, usb_device_info &di, int parent) +#endif { +#ifdef Q_OS_FREEBSD char tempbuf[32]; struct usb_device_info di; if (libusb20_dev_get_info(pdev, &di)) memset(&di, 0, sizeof(di)); +#endif // determine data for this device +#ifdef Q_OS_FREEBSD _level = 0; _parent = 0; +#else + _level = level; + _parent = parent; +#endif _bus = di.udi_bus; _device = di.udi_addr; @@ -354,15 +365,22 @@ void USBDevice::collectData(struct libusb20_backend *pbe, // determine the speed switch (di.udi_speed) { +#ifdef Q_OS_FREEBSD case LIBUSB20_SPEED_LOW: _speed = 1.5; break; case LIBUSB20_SPEED_FULL: _speed = 12.0; break; case LIBUSB20_SPEED_HIGH: _speed = 480.0; break; case LIBUSB20_SPEED_VARIABLE: _speed = 480.0; break; case LIBUSB20_SPEED_SUPER: _speed = 4800.0; break; default: _speed = 480.0; break; +#else + case USB_SPEED_LOW: _speed = 1.5; break; + case USB_SPEED_FULL: _speed = 12.0; break; + case USB_SPEED_HIGH: _speed = 480.0; break; +#endif } // Get all attached devicenodes +#ifdef Q_OS_FREEBSD for (int i = 0; i < 32; ++i) { if (libusb20_dev_get_iface_desc(pdev, i, tempbuf, sizeof(tempbuf)) == 0) { _devnodes << tempbuf; @@ -370,19 +388,52 @@ void USBDevice::collectData(struct libusb20_backend *pbe, break; } } +#else + for (int i = 0; i < USB_MAX_DEVNAMES; ++i) + if ( di.udi_devnames[i][0] ) + _devnodes << di.udi_devnames[i]; +#endif // For compatibility, split the revision number sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor ); +#ifndef Q_OS_FREEBSD + // Cycle through the attached devices if tehre are any + for (int p = 0; p < di.udi_nports; ++p) { + // Get data for device + struct usb_device_info di2; + + di2.udi_addr = di.udi_ports[p]; + + if ( di2.udi_addr >= USB_MAX_DEVICES ) + continue; + + if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1) + continue; + + // Only add the device if we don't detect it, yet + if (!find( di2.udi_us, di2.udi_addr ) ) + { + USBDevice *device = new USBDevice(); + device->collectData( fd, level + 1, di2, di.udi_addr ); + } + } +#endif } bool USBDevice::parse(TQString fname) { +#ifdef Q_OS_FREEBSD struct libusb20_backend *pbe; struct libusb20_device *pdev; +#else + static bool showErrorMessage = true; + bool error = false; +#endif _devices.clear(); +#ifdef Q_OS_FREEBSD pbe = libusb20_be_alloc_default(); if (pbe == NULL) return (false); @@ -395,6 +446,42 @@ bool USBDevice::parse(TQString fname) } libusb20_be_free(pbe); +#else + TQFile controller("?dev/usb0"); + int i = 1; + while ( controller.exists() ) + { + // If the deivicenode exists, continue with further inspection + if ( controller.open(IO_ReadOnly) ) + { + for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) + { + struct usb_device_info di; + + di.udi_addr = addr; + if ( ioctl(controller.handle(), USB_DEVICEINFO, &d1) != -1) + { + if (!find( di.udi_bus, di.udi_addr) ) + { + USBDevice *device = new USBDevice(); + device->collectData( controller.handle(), 0, di, 0); + } + } + } + controller.close(); +#ifndef Q_OS_NETBSD + } else { + error = true; +#endif + } + controller.setName( TQString::formLocal8Bit("/dev/usb%1".arg(i++) ); + } + + if ( showErrorMessage && error ) { + showErroeMessage = false; + KMessageBox::error( 0, i18n("Could not open one or more USB controller, Make sure you have read access to all BSD controllers that shoudl be listed here.")); + } +#endif return true; } diff --git a/kcontrol/usbview/usbdevices.h b/kcontrol/usbview/usbdevices.h index d7a62fbfa..f655ef9a3 100644 --- a/kcontrol/usbview/usbdevices.h +++ b/kcontrol/usbview/usbdevices.h @@ -20,6 +20,9 @@ #include <libusb20.h> #include <dev/usb/usb_ioctl.h> #endif +#ifdef Q_OS_NETBSD +#include <dev/usb/usb.h> +#endif class USBDB; @@ -66,7 +69,7 @@ private: unsigned int _vendorID, _prodID, _revMajor, _revMinor; -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) void collectData(struct libusb20_backend *, struct libusb20_device *); TQStringList _devnodes; #endif diff --git a/kicker/applets/naughty/CMakeLists.txt b/kicker/applets/naughty/CMakeLists.txt index 6f6b9d47a..b4fdcc9b0 100644 --- a/kicker/applets/naughty/CMakeLists.txt +++ b/kicker/applets/naughty/CMakeLists.txt @@ -11,6 +11,12 @@ # FIXME seems that on freebsd is needed smth named LIB_KVM +if ( ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD" ) + set( LIB_KVM "-lkvm") +else() + set( LIB_KVM "") +endif() + include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/kicker/libkicker @@ -35,6 +41,6 @@ tde_add_kpart( naughty_panelapplet AUTOMOC SOURCES NaughtyProcessMonitor.cpp NaughtyConfigDialog.cpp NaughtyApplet.cpp - LINK kickermain-shared + LINK kickermain-shared ${LIB_KVM} DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/kicker/applets/naughty/NaughtyProcessMonitor.cpp b/kicker/applets/naughty/NaughtyProcessMonitor.cpp index 4409f9650..09c02cbf9 100644 --- a/kicker/applets/naughty/NaughtyProcessMonitor.cpp +++ b/kicker/applets/naughty/NaughtyProcessMonitor.cpp @@ -20,8 +20,9 @@ /* OpenBSD support by Jean-Yves Burlett <jean-yves@burlett.org> */ -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) || defined(__NetBSD__) #include <sys/param.h> +#include <sys/time.h> #include <sys/proc.h> #include <sys/sysctl.h> #include <sys/ucred.h> @@ -29,6 +30,11 @@ #include <stdlib.h> #endif +#ifdef __NetBSD__ +#include <kvm.h> +#include <sys/sched.h> +#endif + #include <sys/types.h> #include <signal.h> #include <unistd.h> @@ -67,10 +73,13 @@ class NaughtyProcessMonitorPrivate TQTimer * timer_; TQMap<ulong, uint> loadMap_; TQMap<ulong, uint> scoreMap_; -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) || defined(__NetBSD__) TQMap<ulong, uint> cacheLoadMap_; TQMap<ulong, uid_t> uidMap_; #endif +#ifdef __NetBSD__ + kvm_t *kd; +#endif uint oldLoad_; uint triggerLevel_; @@ -95,11 +104,17 @@ NaughtyProcessMonitor::NaughtyProcessMonitor d->interval_ = interval * 1000; d->triggerLevel_ = triggerLevel; d->timer_ = new TQTimer(this, "NaughtyProcessMonitorPrivate::timer"); +#ifdef __NetBSD__ + d->kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open"); +#endif connect(d->timer_, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotTimeout())); } NaughtyProcessMonitor::~NaughtyProcessMonitor() { +#ifdef __NetBSD__ + kvm_close(d->kd); +#endif delete d; } @@ -219,7 +234,7 @@ NaughtyProcessMonitor::canKill(ulong pid) const // uint d(l[4].toUInt()); return geteuid() == a; -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) // simply check if entry exists in the uid map and use it if (!d->uidMap_.contains(pid)) return false ; @@ -234,7 +249,7 @@ NaughtyProcessMonitor::canKill(ulong pid) const TQString NaughtyProcessMonitor::processName(ulong pid) const { -#if defined(__linux__) || defined(__OpenBSD__) +#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) #ifdef __linux__ TQFile f("/proc/" + TQString::number(pid) + "/cmdline"); @@ -257,6 +272,29 @@ NaughtyProcessMonitor::processName(ulong pid) const // Now strip 'tdeinit:' prefix. TQString unicode(TQString::fromLocal8Bit(s)); +#elif defined(__NetBSD__) + struct kinfo_proc2 *p; + int len; + char **argv; + + p = kvm_getproc2(d->kd, KERN_PROC_PID, pid, + sizeof(struct kinfo_proc2), &len); + if (len < 1) { + return i18n("Unknown"); + } + + // Now strip 'tdeinit:' prefix. + TQString unicode(TQString::fromLocal8Bit(p->p_comm)); + + if (unicode == "tdeinit") { + argv = kvm_getargv2(d->kd, p, 100); + while (argv != NULL && (*argv == "tdeinit:")) { + argv++; + } + if (argv != NULL) { + unicode = *argv; + } + } #elif defined(__OpenBSD__) int mib[4] ; size_t size ; @@ -328,9 +366,13 @@ NaughtyProcessMonitor::cpuLoad() const d->oldLoad_ = load; return (forgetThisOne ? 0 : diff); -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) int mib[2] ; +#ifdef __NetBSD__ + u_int64_t cp_time[CPUSTATES] ; +#else long cp_time[CPUSTATES] ; +#endif size_t size ; uint load, diff ; bool forgetThisOne = 0 == d->oldLoad_; @@ -338,9 +380,9 @@ NaughtyProcessMonitor::cpuLoad() const // fetch CPU time statistics mib[0] = CTL_KERN ; - mib[1] = KERN_CPTIME ; + mib[1] = KERN_CP_TIME ; - size = CPUSTATES * sizeof(long) ; + size = CPUSTATES * sizeof(cp_time[0]) ; if (-1 == sysctl (mib, 2, cp_time, &size, NULL, 0)) return 0 ; @@ -368,6 +410,31 @@ NaughtyProcessMonitor::pidList() const pl << (*it).toUInt(); return pl; +#elif defined(__NetBSD__) + struct kinfo_proc2 *kp; + int nentries; + int i; + TQValueList<ulong> l; + + kp = kvm_getproc2(d->kd, KERN_PROC_ALL, 0, + sizeof(struct kinfo_proc2), &nentries); + + // time statictics and euid data are fetched only for proceses in + // the pidList, so, instead of doing on sysctl per process for + // getLoad and canKill calls, simply cache the data we already have. + + d->cacheLoadMap_.clear(); + d->uidMap_.clear(); + for (i = 0; i < nentries; i++) { + i << (unsigned long) kp[i].p_pid; + d->cacheLoadMap_.insert (kp[i].p_pid, + kp[i].p_cpticks); + d->uidMap_.insert (kp[i].p_pid, + kp[i].p_uid); + } + + return l; + #elif defined(__OpenBSD__) int mib[3] ; int nprocs = 0, nentries ; @@ -456,7 +523,7 @@ NaughtyProcessMonitor::getLoad(ulong pid, uint & load) const load = userTime + sysTime; return true; -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) // use cache if (!d->cacheLoadMap_.contains(pid)) return false ; @@ -473,7 +540,7 @@ NaughtyProcessMonitor::getLoad(ulong pid, uint & load) const bool NaughtyProcessMonitor::kill(ulong pid) const { -#if defined(__linux__) || defined(__OpenBSD__) +#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) return 0 == ::kill(pid, SIGKILL); #else Q_UNUSED( pid ); diff --git a/kicker/kicker/ui/k_new_mnu.cpp b/kicker/kicker/ui/k_new_mnu.cpp index de97b592b..b1357caf1 100644 --- a/kicker/kicker/ui/k_new_mnu.cpp +++ b/kicker/kicker/ui/k_new_mnu.cpp @@ -95,7 +95,7 @@ #include "flipscrollview.h" #include "itemview.h" #include <dmctl.h> -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) #include <sys/statvfs.h> #include <sys/param.h> #include <sys/mount.h> @@ -122,6 +122,10 @@ #include <hal/libhal.h> #endif // COMPILE_HALBACKEND +#ifdef __NetBSD__ +#define statfs statvfs +#endif + #define WAIT_BEFORE_QUERYING 700 #define IDS_PER_CATEGORY 20 diff --git a/ksysguard/gui/ksgrd/SensorManager.cc b/ksysguard/gui/ksgrd/SensorManager.cc index 7794d9c10..237e73b23 100644 --- a/ksysguard/gui/ksgrd/SensorManager.cc +++ b/ksysguard/gui/ksgrd/SensorManager.cc @@ -60,6 +60,11 @@ SensorManager::SensorManager() mDict.insert( "used", new TQString( i18n( "Used Memory" ) ) ); mDict.insert( "application", new TQString( i18n( "Application Memory" ) ) ); mDict.insert( "free", new TQString( i18n( "Free Memory" ) ) ); + mDict.insert( "active", new TQString( i18n( "Active Memory" ) ) ); + mDict.insert( "inactive", new TQString( i18n( "Inactive Memory" ) ) ); + mDict.insert( "wired", new TQString( i18n( "Wired Memory" ) ) ); + mDict.insert( "execpages", new TQString( i18n( "Exec Pages" ) ) ); + mDict.insert( "filepages", new TQString( i18n( "File Pages" ) ) ); mDict.insert( "pscount", new TQString( i18n( "Process Count" ) ) ); mDict.insert( "ps", new TQString( i18n( "Process Controller" ) ) ); mDict.insert( "disk", new TQString( i18n( "Disk Throughput" ) ) ); diff --git a/ksysguard/ksysguardd/CMakeLists.txt b/ksysguard/ksysguardd/CMakeLists.txt index 58c5f2399..f90bdadb0 100644 --- a/ksysguard/ksysguardd/CMakeLists.txt +++ b/ksysguard/ksysguardd/CMakeLists.txt @@ -19,6 +19,8 @@ elseif( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) set( OS_SPECIFIC_DIR OpenBSD ) elseif( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) set( OS_SPECIFIC_DIR FreeBSD ) +elseif( ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD" ) + set( OS_SPECIFIC_DIR NetBSD ) else() tde_message_fatal( "Your operating system (${CMAKE_SYSTEM_NAME}) is not supported yet." ) endif() diff --git a/ksysguard/ksysguardd/NetBSD/CMakeLists.txt b/ksysguard/ksysguardd/NetBSD/CMakeLists.txt new file mode 100644 index 000000000..0d0765382 --- /dev/null +++ b/ksysguard/ksysguardd/NetBSD/CMakeLists.txt @@ -0,0 +1,28 @@ +################################################# +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include( ConfigureChecks.cmake ) + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/ksysguard/CContLib + ${CMAKE_SOURCE_DIR}/ksysguard/ksysguardd +) + + +##### ksysguardd (static) ####################### + +if ( HAVE_APMIO ) + set( APM_SOURCES apm.c ) +endif ( HAVE_APMIO ) + +tde_add_library( ksysguardd STATIC + SOURCES + CPU.c Memory.c ProcessList.c ${APM_SOURCES} diskstat.c loadavg.c logfile.c netdev.c + LINK kvm +) diff --git a/ksysguard/ksysguardd/NetBSD/CPU.c b/ksysguard/ksysguardd/NetBSD/CPU.c index 959924087..1d80d9bb6 100644 --- a/ksysguard/ksysguardd/NetBSD/CPU.c +++ b/ksysguard/ksysguardd/NetBSD/CPU.c @@ -19,10 +19,11 @@ */ +#include <sys/param.h> +#include <sys/sysctl.h> #include <sys/dkstat.h> #include <sys/sched.h> /* CPUSTATES */ #include <fcntl.h> -#include <kvm.h> #include <nlist.h> #include <stdio.h> #include <stdlib.h> @@ -33,20 +34,11 @@ #include "Command.h" #include "ksysguardd.h" -long percentages(int cnt, int *out, long *new, long *old, long *diffs); +void percentages(int cnt, int *out, u_int64_t *new, u_int64_t *old, u_int64_t *diffs); -struct nlist my_nlist[] = { - {"_cp_time"}, - { 0 } -}; - -kvm_t *kd; - -unsigned long cp_time_offset; - -long cp_time[CPUSTATES]; -long cp_old[CPUSTATES]; -long cp_diff[CPUSTATES]; +u_int64_t cp_time[CPUSTATES]; +u_int64_t cp_old[CPUSTATES]; +u_int64_t cp_diff[CPUSTATES]; int cpu_states[CPUSTATES]; void @@ -61,9 +53,6 @@ initCpuInfo(struct SensorModul* sm) printCPUSysInfo, sm); registerMonitor("cpu/idle", "integer", printCPUIdle, printCPUIdleInfo, sm); - kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open"); - kvm_nlist(kd, my_nlist); - cp_time_offset = my_nlist[0].n_value; updateCpuInfo(); } @@ -71,13 +60,18 @@ initCpuInfo(struct SensorModul* sm) void exitCpuInfo(void) { - kvm_close(kd); } int updateCpuInfo(void) { - kvm_read(kd, cp_time_offset, (char *)cp_time, sizeof(cp_time)); + int mib[2]; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_CP_TIME; + size = sizeof(cp_time[0]) * CPUSTATES; + sysctl(mib, 2, cp_time, &size, NULL, 0); percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); return (0); } @@ -152,20 +146,20 @@ printCPUIdleInfo(const char* cmd) * useful on BSD mchines for calculating cpu state percentages. */ -long percentages(cnt, out, new, old, diffs) +void percentages(cnt, out, new, old, diffs) int cnt; int *out; -register long *new; -register long *old; -long *diffs; +u_int64_t *new; +u_int64_t *old; +u_int64_t *diffs; { - register int i; - register long change; - register long total_change; - register long *dp; - long half_total; + int i; + u_int64_t change; + u_int64_t total_change; + u_int64_t *dp; + u_int64_t half_total; /* initialization */ total_change = 0; @@ -174,12 +168,11 @@ long *diffs; /* calculate changes for each state and the overall change */ for (i = 0; i < cnt; i++) { - if ((change = *new - *old) < 0) - { - /* this only happens when the counter wraps */ - change = (int) - ((unsigned long)*new-(unsigned long)*old); - } + /* + * Don't worry about wrapping - even at hz=1GHz, a + * u_int64_t will last at least 544 years. + */ + change = *new - *old; total_change += (*dp++ = change); *old++ = *new++; } @@ -191,16 +184,9 @@ long *diffs; } /* calculate percentages based on overall change, rounding up */ - half_total = total_change / 2l; - - /* Do not divide by 0. Causes Floating point exception */ - if(total_change) { - for (i = 0; i < cnt; i++) - { - *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); - } + half_total = total_change / 2; + for (i = 0; i < cnt; i++) + { + *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); } - - /* return the total in case the caller wants to use it */ - return(total_change); } diff --git a/ksysguard/ksysguardd/NetBSD/ConfigureChecks.cmake b/ksysguard/ksysguardd/NetBSD/ConfigureChecks.cmake new file mode 100644 index 000000000..60d0b0495 --- /dev/null +++ b/ksysguard/ksysguardd/NetBSD/ConfigureChecks.cmake @@ -0,0 +1,13 @@ +################################################# +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +# apmio +check_include_files( "sys/types.h;dev/apm/apmio.h" HAVE_DEV_APM_APMIO_H ) +if( HAVE_DEV_APM_APMIO_H ) + set( HAVE_APMIO 1 CACHE INTERNAL "" FORCE ) +endif( ) diff --git a/ksysguard/ksysguardd/NetBSD/Memory.c b/ksysguard/ksysguardd/NetBSD/Memory.c index 8e9779506..19931e62b 100644 --- a/ksysguard/ksysguardd/NetBSD/Memory.c +++ b/ksysguard/ksysguardd/NetBSD/Memory.c @@ -21,12 +21,12 @@ */ #include <fcntl.h> -#include <kvm.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/param.h> +#include <sys/resource.h> #include <sys/sysctl.h> #include <sys/types.h> #include <sys/vmmeter.h> @@ -34,6 +34,7 @@ /* Everything post 1.5.x uses uvm/uvm_* includes */ #if __NetBSD_Version__ >= 105010000 #include <uvm/uvm_param.h> +#include <uvm/uvm_extern.h> #else #include <vm/vm_param.h> #endif @@ -45,29 +46,25 @@ static size_t Total = 0; static size_t MFree = 0; static size_t Used = 0; -static size_t Buffers = 0; -static size_t Cached = 0; +static size_t Active =0; +static size_t Inactive = 0; +static size_t Wired = 0; +static size_t Execpages = 0; +static size_t Filepages = 0; static size_t STotal = 0; static size_t SFree = 0; static size_t SUsed = 0; -static kvm_t *kd; void initMemory(struct SensorModul* sm) { - char *nlistf = NULL; - char *memf = NULL; - char buf[_POSIX2_LINE_MAX]; - - if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) { - log_error("kvm_openfiles()"); - return; - } - registerMonitor("mem/physical/free", "integer", printMFree, printMFreeInfo, sm); registerMonitor("mem/physical/used", "integer", printUsed, printUsedInfo, sm); - registerMonitor("mem/physical/buf", "integer", printBuffers, printBuffersInfo, sm); - registerMonitor("mem/physical/cached", "integer", printCached, printCachedInfo, sm); + registerMonitor("mem/physical/active", "integer", printActive, printActiveInfo, sm); + registerMonitor("mem/physical/inactive", "integer", printInactive, printInactiveInfo, sm); + registerMonitor("mem/physical/wired", "integer", printWired, printWiredInfo, sm); + registerMonitor("mem/physical/execpages", "integer", printExecpages, printExecpagesInfo, sm); + registerMonitor("mem/physical/filepages", "integer", printFilepages, printFilepagesInfo, sm); registerMonitor("mem/swap/free", "integer", printSwapFree, printSwapFreeInfo, sm); registerMonitor("mem/swap/used", "integer", printSwapUsed, printSwapUsedInfo, sm); } @@ -75,7 +72,6 @@ initMemory(struct SensorModul* sm) void exitMemory(void) { - kvm_close(kd); } int @@ -83,7 +79,6 @@ updateMemory(void) { #define ARRLEN(X) (sizeof(X)/sizeof(X[0])) - long pagesize; /* using a long promotes the arithmetic */ size_t len; { @@ -95,35 +90,23 @@ updateMemory(void) } { - struct uvmexp x; - static int mib[] = { CTL_VM, VM_UVMEXP }; + struct uvmexp_sysctl x; + static int mib[] = { CTL_VM, VM_UVMEXP2 }; len = sizeof(x); STotal = SUsed = SFree = -1; - pagesize = 1; + Active = Inactive = Wired = Execpages = Filepages = MFree = Used = -1; if (-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0)) { - pagesize = x.pagesize; - STotal = (pagesize*x.swpages) >> 10; - SUsed = (pagesize*x.swpginuse) >> 10; + STotal = (x.pagesize*x.swpages) >> 10; + SUsed = (x.pagesize*x.swpginuse) >> 10; SFree = STotal - SUsed; - } - } - - /* can't find NetBSD filesystem buffer info */ - Buffers = -1; - - /* NetBSD doesn't know about vm.stats */ - Cached = -1; - - { - static int mib[]={ CTL_VM, VM_METER }; - struct vmtotal x; - - len = sizeof(x); - MFree = Used = -1; - if (sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0) > -1) { - MFree = (x.t_free * pagesize) >> 10; - Used = (x.t_rm * pagesize) >> 10; + MFree = STotal - SUsed; + Active = (x.active * x.pagesize) >> 10; + Inactive = (x.inactive * x.pagesize) >> 10; + Wired = (x.wired * x.pagesize) >> 10; + Execpages = (x.execpages * x.pagesize) >> 10; + Filepages = (x.filepages * x.pagesize) >> 10; + Used = Total - MFree; } } return 0; @@ -154,27 +137,63 @@ printUsedInfo(const char* cmd) } void -printBuffers(const char* cmd) +printActive(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Active); +} + +void +printActiveInfo(const char* cmd) +{ + fprintf(CurrentClient, "Active Memory\t0\t%dtKB\n", Total); +} + +void +printInactive(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Inactive); +} + +void +printInactiveInfo(const char* cmd) +{ + fprintf(CurrentClient, "Inctive Memory\t0\t%dtKB\n", Total); +} + +void +printWired(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Wired); +} + +void +printWiredInfo(const char* cmd) +{ + fprintf(CurrentClient, "Wired Memory\t0\t%dtKB\n", Total); +} + +void +printExecpages(const char* cmd) { - fprintf(CurrentClient, "%d\n", Buffers); + fprintf(CurrentClient, "%d\n", Execpages); } void -printBuffersInfo(const char* cmd) +printExecpagesInfo(const char* cmd) { - fprintf(CurrentClient, "Buffer Memory\t0\t%d\tKB\n", Total); + fprintf(CurrentClient, "Exec Pages\t0%d\tKB\n", Total); } void -printCached(const char* cmd) +printFilepages(const char* cmd) { - fprintf(CurrentClient, "%d\n", Cached); + fprintf(CurrentClient, "%d\n", Filepages); } void -printCachedInfo(const char* cmd) +printFilepagesInfo(const char* cmd) { - fprintf(CurrentClient, "Cached Memory\t0\t%d\tKB\n", Total); + fprintf(CurrentClient, "File Pages\t0\t%d\tKB\n", Total); } void diff --git a/ksysguard/ksysguardd/NetBSD/Memory.h b/ksysguard/ksysguardd/NetBSD/Memory.h index 57abb73a2..391306eec 100644 --- a/ksysguard/ksysguardd/NetBSD/Memory.h +++ b/ksysguard/ksysguardd/NetBSD/Memory.h @@ -31,10 +31,16 @@ void printMFree(const char* cmd); void printMFreeInfo(const char* cmd); void printUsed(const char* cmd); void printUsedInfo(const char* cmd); -void printBuffers(const char* cmd); -void printBuffersInfo(const char* cmd); -void printCached(const char* cmd); -void printCachedInfo(const char* cmd); +void printActive(const char* cmd); +void printActiveInfo(const char* cmd); +void printInactive(const char* cmd); +void printInactiveInfo(const char* cmd); +void printWired(const char* cmd); +void printWiredInfo(const char* cmd); +void printExecpages(const char* cmd); +void printExecpagesInfo(const char* cmd); +void printFilepages(const char* cmd); +void printFilepagesInfo(const char* cmd); void printSwapUsed(const char* cmd); void printSwapUsedInfo(const char* cmd); void printSwapFree(const char* cmd); diff --git a/ksysguard/ksysguardd/NetBSD/ProcessList.c b/ksysguard/ksysguardd/NetBSD/ProcessList.c index 54ab65513..13c65053d 100644 --- a/ksysguard/ksysguardd/NetBSD/ProcessList.c +++ b/ksysguard/ksysguardd/NetBSD/ProcessList.c @@ -24,15 +24,17 @@ #include <ctype.h> #include <dirent.h> +#include <errno.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <kvm.h> #include <sys/param.h> #include <sys/sysctl.h> #include <sys/time.h> #include <sys/types.h> -#include <sys/user.h> +#include <sys/resource.h> #include <unistd.h> #include <signal.h> @@ -46,6 +48,8 @@ CONTAINER ProcessList = 0; #define BUFSIZE 1024 +static kvm_t *kd; + typedef struct { /* This flag is set for all found processes at the beginning of the @@ -157,15 +161,13 @@ findProcessInList(int pid) } static int -updateProcess(int pid) +updateProcess(int pid, struct kinfo_proc2 *p) { - static char *statuses[] = { "idle","run","sleep","stop","zombie" }; + static char *statuses[] = { "", "idle","run","sleep","stop","zombie","dead","onproc" }; ProcessInfo* ps; struct passwd* pwent; - int mib[4]; - struct kinfo_proc p; - size_t len; + char **argv, **a; if ((ps = findProcessInList(pid)) == 0) { @@ -178,26 +180,18 @@ updateProcess(int pid) ps->alive = 1; - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = pid; - - len = sizeof (p); - if (sysctl(mib, 4, &p, &len, NULL, 0) == -1 || !len) - return -1; - - ps->pid = p.kp_proc.p_pid; - ps->ppid = p.kp_eproc.e_ppid; - ps->uid = p.kp_eproc.e_ucred.cr_uid; - ps->gid = p.kp_eproc.e_pgid; - ps->priority = p.kp_proc.p_priority; - ps->niceLevel = p.kp_proc.p_nice; + ps->pid = p->p_pid; + ps->ppid = p->p_ppid; + ps->uid = p->p_uid; + ps->gid = p->p_gid; + ps->priority = p->p_priority -22; /* why 22? */ + ps->niceLevel = p->p_nice - NZERO; - /* this isn't usertime -- it's total time (??) */ - ps->userTime = p.kp_proc.p_rtime.tv_sec*100+p.kp_proc.p_rtime.tv_usec/100; +#if 0 + ps->userTime = p->p_rtime_sec*100+p->p_rtime_usec/100; ps->sysTime = 0; ps->sysLoad = 0; +#endif /* memory, process name, process uid */ /* find out user name with process uid */ @@ -205,19 +199,26 @@ updateProcess(int pid) strlcpy(ps->userName,pwent&&pwent->pw_name? pwent->pw_name:"????",sizeof(ps->userName)); ps->userName[sizeof(ps->userName)-1]='\0'; - ps->userLoad = p.kp_proc.p_pctcpu / 100; - ps->vmSize = (p.kp_eproc.e_vm.vm_tsize + - p.kp_eproc.e_vm.vm_dsize + - p.kp_eproc.e_vm.vm_ssize) * getpagesize(); - ps->vmRss = p.kp_eproc.e_vm.vm_rssize * getpagesize(); - strlcpy(ps->name,p.kp_proc.p_comm ? p.kp_proc.p_comm : "????", sizeof(ps->name)); - strlcpy(ps->status,(p.kp_proc.p_stat>=1)&&(p.kp_proc.p_stat<=5)? statuses[p.kp_proc.p_stat-1]:"????", sizeof(ps->status)); + ps->userLoad = 100.0 * ((double)(p->p_pctcpu) /FSCALE); + ps->vmSize = (p->p_vm_tsize + + p->p_vm_dsize + + p->p_vm_ssize) * getpagesize(); + ps->vmRss = p->p_vm_rssize * getpagesize(); + strlcpy(ps->name,p->p_comm ? p->p_comm : "????", sizeof(ps->name)); + strlcpy(ps->status,(p->p_stat<=7)? statuses[p->p_stat]:"????", sizeof(ps->status)); /* process command line */ - /* the following line causes segfaults on some FreeBSD systems... why? - strncpy(ps->cmdline, p.kp_proc.p_args->ar_args, sizeof(ps->cmdline) - 1); - */ - strcpy(ps->cmdline, "????"); + argv = kvm_getargv2(kd, p, sizeof(ps->cmdline)); + ps->cmdline[0] = '\0'; + if ((a = argv) != NULL) { + while (*a) { + strlcat(ps->cmdline, *a, sizeof(ps->cmdline)); + a++; + strlcat(ps->cmdline, " ", sizeof(ps->cmdline)); + } + } else { + strcpy(ps->cmdline, "????"); + } return (0); } @@ -266,6 +267,8 @@ initProcessList(struct SensorModul* sm) registerCommand("setpriority", setPriority); } + kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open"); + updateProcessList(); } @@ -277,27 +280,22 @@ exitProcessList(void) if (ProcessList) free (ProcessList); + + kvm_close(kd); } int updateProcessList(void) { - int mib[3]; - size_t len; - size_t num; - struct kinfo_proc *p; - - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_ALL; - sysctl(mib, 3, NULL, &len, NULL, 0); - p = malloc(len); - sysctl(mib, 3, p, &len, NULL, 0); - - for (num = 0; num < len / sizeof(struct kinfo_proc); num++) - updateProcess(p[num].kp_proc.p_pid); - free(p); + int len; + int num; + struct kinfo_proc2 *p; + + p = kvm_getproc2(kd, KERN_PROC_ALL, 0, + sizeof(struct kinfo_proc2), &len); + + for (num = 0; num < len; num++) + updateProcess(p[num].p_pid, &p[num]); cleanupProcessList(); return (0); @@ -306,8 +304,8 @@ updateProcessList(void) void printProcessListInfo(const char* cmd) { - fprintf(CurrentClient, "Name\tPID\tPPID\tUID\tGID\tStatus\tUser%%\tSystem%%\tNice\tVmSize\tVmRss\tLogin\tCommand\n"); - fprintf(CurrentClient, "s\td\td\td\td\tS\tf\tf\td\tD\tD\ts\ts\n"); + fprintf(CurrentClient, "Name\tPID\tPPID\tUID\tGID\tStatus\tCPU%%\tPrio%%\tNice\tVmSize\tVmRss\tLogin\tCommand\n"); + fprintf(CurrentClient, "s\td\td\td\td\tS\tf\td\td\tD\tD\ts\ts\n"); } void @@ -318,10 +316,10 @@ printProcessList(const char* cmd) ps = first_ctnr(ProcessList); /* skip 'kernel' entry */ for (ps = next_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) { - fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%s\n", + fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%d\t%d\t%d\t%d\t%s\t%s\n", ps->name, (long)ps->pid, (long)ps->ppid, (long)ps->uid, (long)ps->gid, ps->status, - ps->userLoad, ps->sysLoad, ps->niceLevel, + ps->userLoad, ps->priority, ps->niceLevel, ps->vmSize / 1024, ps->vmRss / 1024, ps->userName, ps->cmdline); } } diff --git a/ksysguard/ksysguardd/NetBSD/apm.c b/ksysguard/ksysguardd/NetBSD/apm.c index f24887483..5929da8fc 100644 --- a/ksysguard/ksysguardd/NetBSD/apm.c +++ b/ksysguard/ksysguardd/NetBSD/apm.c @@ -20,7 +20,7 @@ #include <fcntl.h> -#include <machine/apmvar.h> +#include <dev/apm/apmio.h> #include <sys/ioctl.h> #include <unistd.h> #include <stdio.h> @@ -97,4 +97,3 @@ printApmBatTimeInfo(const char* c) { fprintf(CurrentClient, "Remaining battery time\t0\t0\tmin\n"); } - diff --git a/ksysguard/ksysguardd/NetBSD/diskstat.c b/ksysguard/ksysguardd/NetBSD/diskstat.c index 818eee1d4..e9c569065 100644 --- a/ksysguard/ksysguardd/NetBSD/diskstat.c +++ b/ksysguard/ksysguardd/NetBSD/diskstat.c @@ -63,7 +63,11 @@ char *getMntPnt(const char *cmd) int numMntPnt(void) { +#ifdef HAVE_STATVFS + struct statvfs *fs_info; +#else struct statfs *fs_info; +#endif int i, n, counter = 0; n = getmntinfo(&fs_info, MNT_WAIT); @@ -129,8 +133,13 @@ void exitDiskStat(void) int updateDiskStat(void) { +#ifdef HAVE_STATVFS + struct statvfs *fs_info; + struct statvfs fs; +#else struct statfs *fs_info; struct statfs fs; +#endif float percent; int i, mntcount; DiskInfo *disk_info; diff --git a/ksysguard/ksysguardd/NetBSD/netdev.c b/ksysguard/ksysguardd/NetBSD/netdev.c index 477acc40e..efa25cc08 100644 --- a/ksysguard/ksysguardd/NetBSD/netdev.c +++ b/ksysguard/ksysguardd/NetBSD/netdev.c @@ -269,12 +269,12 @@ void exitNetDev(void) { NDreg(0); } -void updateNetDev(void) { +int updateNetDev(void) { NetDevInfo *p, *q; int n; if (-1==(n = readSys(0))) - return; + return 0; NetDevCnt = n; /*fixme: assumes the interfaces are in the same order each time */ @@ -289,6 +289,7 @@ void updateNetDev(void) { } } + return 0; } void checkNetDev(void) { diff --git a/ksysguard/ksysguardd/NetBSD/netdev.h b/ksysguard/ksysguardd/NetBSD/netdev.h index 4287c9203..17d9c89e9 100644 --- a/ksysguard/ksysguardd/NetBSD/netdev.h +++ b/ksysguard/ksysguardd/NetBSD/netdev.h @@ -24,7 +24,7 @@ void initNetDev(struct SensorModul* sm); void exitNetDev(void); -void updateNetDev(void); +int updateNetDev(void); void checkNetDev(void); void printNetDevRecBytes(const char* cmd); diff --git a/ksysguard/ksysguardd/modules.h b/ksysguard/ksysguardd/modules.h index 06b290b27..fe66ad537 100644 --- a/ksysguard/ksysguardd/modules.h +++ b/ksysguard/ksysguardd/modules.h @@ -55,6 +55,19 @@ #include "netdev.h" #endif /* OSTYPE_FreeBSD */ +#ifdef OSTYPE_NetBSD +#include "CPU.h" +#include "Memory.h" +#include "ProcessList.h" +#ifdef HAVE_APMIO +#include "apm.h" +#endif +#include "diskstat.h" +#include "loadavg.h" +#include "logfile.h" +#include "netdev.h" +#endif /* OSTYPE_NetBSD */ + #ifdef OSTYPE_Solaris #include "LoadAvg.h" #include "Memory.h" @@ -120,6 +133,19 @@ struct SensorModul SensorModulList[] = { { "NetDev", initNetDev, exitNetDev, updateNetDev, checkNetDev, 0, NULLTIME }, #endif /* OSTYPE_FreeBSD */ +#ifdef OSTYPE_NetBSD + { "CpuInfo", initCpuInfo, exitCpuInfo, updateCpuInfo, NULLVVFUNC, 0, NULLTIME }, + { "Memory", initMemory, exitMemory, updateMemory, NULLVVFUNC, 0, NULLTIME }, + { "ProcessList", initProcessList, exitProcessList, updateProcessList, NULLVVFUNC, 0, NULLTIME }, +#ifdef HAVE_APMIO + { "Apm", initApm, exitApm, updateApm, NULLVVFUNC, 0, NULLTIME }, +#endif + { "DiskStat", initDiskStat, exitDiskStat, updateDiskStat, checkDiskStat, 0, NULLTIME }, + { "LoadAvg", initLoadAvg, exitLoadAvg, updateLoadAvg, NULLVVFUNC, 0, NULLTIME }, + { "LogFile", initLogFile, exitLogFile, NULLIVFUNC, NULLVVFUNC, 0, NULLTIME }, + { "NetDev", initNetDev, exitNetDev, updateNetDev, checkNetDev, 0, NULLTIME }, +#endif /* OSTYPE_NetBSD */ + #ifdef OSTYPE_Solaris { "LoadAvg", initLoadAvg, exitLoadAvg, updateLoadAvg, NULLVVFUNC, 0, NULLTIME }, { "Memory", initMemory, exitMemory, updateMemory, NULLVVFUNC, 0, NULLTIME }, diff --git a/tdeeject/tdeeject b/tdeeject/tdeeject index 7adb15570..da64451fd 100755 --- a/tdeeject/tdeeject +++ b/tdeeject/tdeeject @@ -1,6 +1,6 @@ #!/bin/sh # Script used by kdesktop to eject a removable media (CDROM/Tape/SCSI/Floppy) -# Relies on the 'eject' program, 'cdcontrol' on *BSD +# Relies on the 'eject' program, 'cdcontrol' on FreeBSD # # Copyright GPL v2 by David Faure <david@mandrakesoft.com> # @@ -43,6 +43,22 @@ case "$OS" in OpenBSD) cdio -f $device eject #>/dev/null 2>&1 ;; + NetBSD) + dev=$1 + if [ -h $1 ]; then + dev=$(readlink $dev 2> /dev/null) || dev=$1; + fi + case $(sysctl -n kern.rawpartition 2> /dev/null) in + 2) rapw=c ;; + 3) rapw=d ;; + esac + rdev=$(echo $dev | sed -E -e 's#(/dev/)#1r#; s#[a-z]$#'$rawp'#') + if [ -e $rdev]; then + eject $rdev >/dev/null 2>&1 + else + eject $dev >/dev/null 2>&1 + fi + ;; *BSD) dev=`echo $device | sed -E -e 's#/dev/##' -e 's/([0-9])./\1/'` cdcontrol -f $dev eject #>/dev/null 2>&1 diff --git a/tdeioslave/media/mediamanager/fstabbackend.cpp b/tdeioslave/media/mediamanager/fstabbackend.cpp index c0e91c228..8eca21771 100644 --- a/tdeioslave/media/mediamanager/fstabbackend.cpp +++ b/tdeioslave/media/mediamanager/fstabbackend.cpp @@ -69,7 +69,7 @@ FstabBackend::FstabBackend(MediaList &list, bool networkSharesOnly) KDirWatch::self()->startScan(); -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) connect( &m_mtabTimer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( handleMtabChange() ) ); m_mtabTimer.start(250); @@ -180,7 +180,7 @@ bool inExclusionPattern(KMountPoint *mount, bool networkSharesOnly) void FstabBackend::handleMtabChange(bool allowNotification) { TQStringList new_mtabIds; - KMountPoint::List mtab = KMountPoint::currentMountPoints(); + KMountPoint::List mtab = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName); KMountPoint::List::iterator it = mtab.begin(); KMountPoint::List::iterator end = mtab.end(); @@ -419,6 +419,8 @@ void FstabBackend::guess(const TQString &devNode, const TQString &mountPoint, || devNode.find("/dev/scd")!=-1 || devNode.find("/dev/sr")!=-1 // FREEBSD SPECIFIC || devNode.find("/acd")!=-1 || devNode.find("/scd")!=-1 + // NETBSD SPECIFIC + || devNode.find("/cd")!=-1 || devNode.find("/cd")!=-1 ) { mimeType = "media/cdrom"; diff --git a/tdeioslave/media/mediamanager/fstabbackend.h b/tdeioslave/media/mediamanager/fstabbackend.h index 24529d95a..0aed11333 100644 --- a/tdeioslave/media/mediamanager/fstabbackend.h +++ b/tdeioslave/media/mediamanager/fstabbackend.h @@ -25,7 +25,7 @@ #include <tqstringlist.h> #include <tqvariant.h> -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include <tqtimer.h> #endif @@ -60,7 +60,7 @@ private: TQStringList m_mtabIds; TQMap<TQString, TQString> m_mtabEntries; TQStringList m_fstabIds; -#ifdef Q_OS_FREEBSD +#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) TQTimer m_mtabTimer; #endif }; diff --git a/tdeioslave/media/medianotifier/medianotifier.cpp b/tdeioslave/media/medianotifier/medianotifier.cpp index d40c5ae27..88f58af2d 100644 --- a/tdeioslave/media/medianotifier/medianotifier.cpp +++ b/tdeioslave/media/medianotifier/medianotifier.cpp @@ -19,13 +19,16 @@ #include "medianotifier.h" -#if defined (__OpenBSD__) || defined(__FreeBSD__) +#if defined (__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) #include <sys/statvfs.h> #include <sys/param.h> #include <sys/mount.h> #else #include <sys/vfs.h> #endif +#if defined(__NetBSD__) +#define statfs statvfs +#endif #include <tqfile.h> #include <tqfileinfo.h> diff --git a/tdesu/tdesud/tdesud.cpp b/tdesu/tdesud/tdesud.cpp index 5fa2f5857..a4959b368 100644 --- a/tdesu/tdesud/tdesud.cpp +++ b/tdesu/tdesud/tdesud.cpp @@ -45,7 +45,7 @@ #include <pwd.h> #include <errno.h> -#if !defined(__OpenBSD__) && !defined(__FreeBSD__) +#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) #include <sys/prctl.h> #endif #include <sys/time.h> @@ -251,7 +251,7 @@ int create_socket() int main(int argc, char *argv[]) { -#if !defined(__OpenBSD__) && !defined(__FreeBSD__) +#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) prctl(PR_SET_DUMPABLE, 0); #endif diff --git a/tdm/backend/getfd.c b/tdm/backend/getfd.c index d4f4d8352..aaad616b6 100644 --- a/tdm/backend/getfd.c +++ b/tdm/backend/getfd.c @@ -22,7 +22,7 @@ is_a_console(int fd) { char arg; arg = 0; -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) return arg; #else return (ioctl(fd, KDGKBTYPE, &arg) == 0 diff --git a/tdm/backend/sessreg.c b/tdm/backend/sessreg.c index 4167a16e3..a65c6cd87 100644 --- a/tdm/backend/sessreg.c +++ b/tdm/backend/sessreg.c @@ -70,7 +70,7 @@ from The Open Group. #endif #ifdef BSD -# if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) +# if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) /* *BSD doesn't like a ':0' type entry in utmp */ # define NO_UTMP # endif diff --git a/tdm/config.def b/tdm/config.def index 5cfc56ed5..4209c8212 100644 --- a/tdm/config.def +++ b/tdm/config.def @@ -79,6 +79,12 @@ #else # define DEF_SERVER_CMD XBINDIR "/X" #endif + +#if defined(__NetBSD__) && !defined(__powerpc__) +# define DEF_SERVER_ARGS "-nolisten tcp vt05" +#else +# define DEF_SERVER_ARGS "-nolisten tcp" +#endif </code> # The contents of this section are copied mostly verbatim to the @@ -1368,9 +1374,9 @@ Description: Key: ServerArgsLocal Type: string -Default: "-nolisten tcp" +Default: DEF_SERVER_ARGS User: core -Instance: :*/"-deferglyphs 16 -nolisten tcp" +Instance: :*/"-deferglyphs 16 " DEF_SERVER_ARGS Comment: & Description: Additional arguments for the &X-Server;s for local sessions. |