2014-11-13 11:53:49 +01:00
|
|
|
$NetBSD: patch-src_ProcessInfo.cpp,v 1.3 2014/11/13 10:53:49 markd Exp $
|
2012-03-20 06:07:48 +01:00
|
|
|
|
2014-11-13 11:53:49 +01:00
|
|
|
--- src/ProcessInfo.cpp.orig 2014-11-01 04:17:02.000000000 +0000
|
2012-03-20 06:07:48 +01:00
|
|
|
+++ src/ProcessInfo.cpp
|
2014-11-13 11:53:49 +01:00
|
|
|
@@ -1012,6 +1012,171 @@ private:
|
|
|
|
}
|
2012-03-20 06:07:48 +01:00
|
|
|
}
|
2013-04-03 12:51:43 +02:00
|
|
|
};
|
2014-11-13 11:53:49 +01:00
|
|
|
+#elif defined(Q_OS_NETBSD)
|
2012-03-20 06:07:48 +01:00
|
|
|
+class NetBSDProcessInfo : public UnixProcessInfo
|
|
|
|
+{
|
|
|
|
+public:
|
|
|
|
+ NetBSDProcessInfo(int pid, bool env) :
|
|
|
|
+ UnixProcessInfo(pid,env)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+private:
|
|
|
|
+ virtual bool readProcInfo(int pid)
|
|
|
|
+ {
|
|
|
|
+ // indicies of various fields within the process status file which
|
|
|
|
+ // contain various information about the process
|
|
|
|
+ const int PARENT_PID_FIELD = 2;
|
|
|
|
+ const int PROCESS_NAME_FIELD = 0;
|
|
|
|
+ const int GROUP_PROCESS_FIELD = 3;
|
|
|
|
+ const int UID_PROCESS_FIELD = 11;
|
|
|
|
+
|
|
|
|
+ QString parentPidString;
|
|
|
|
+ QString processNameString;
|
|
|
|
+ QString foregroundPidString;
|
|
|
|
+ QString uidString;
|
|
|
|
+
|
|
|
|
+ // read process status file ( /proc/<pid/status )
|
|
|
|
+ //
|
|
|
|
+ // the expected file format is a list of fields separated by spaces, using
|
|
|
|
+ // parenthesies to escape fields such as the process name which may itself contain
|
|
|
|
+ // spaces:
|
|
|
|
+ //
|
|
|
|
+ // FIELD FIELD (FIELD WITH SPACES) FIELD FIELD
|
|
|
|
+ //
|
|
|
|
+ QFile processInfo( QString("/proc/%1/status").arg(pid) );
|
|
|
|
+ if ( processInfo.open(QIODevice::ReadOnly) )
|
|
|
|
+ {
|
|
|
|
+ QTextStream stream(&processInfo);
|
|
|
|
+ QString data = stream.readAll();
|
|
|
|
+
|
|
|
|
+ int stack = 0;
|
|
|
|
+ int field = 0;
|
|
|
|
+ int pos = 0;
|
|
|
|
+
|
|
|
|
+ while (pos < data.count())
|
|
|
|
+ {
|
|
|
|
+ QChar c = data[pos];
|
|
|
|
+
|
|
|
|
+ if ( c == '(' )
|
|
|
|
+ stack++;
|
|
|
|
+ else if ( c == ')' )
|
|
|
|
+ stack--;
|
|
|
|
+ else if ( stack == 0 && c == ' ' )
|
|
|
|
+ field++;
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ switch ( field )
|
|
|
|
+ {
|
|
|
|
+ case PARENT_PID_FIELD:
|
|
|
|
+ parentPidString.append(c);
|
|
|
|
+ break;
|
|
|
|
+ case PROCESS_NAME_FIELD:
|
|
|
|
+ processNameString.append(c);
|
|
|
|
+ break;
|
|
|
|
+ case GROUP_PROCESS_FIELD:
|
|
|
|
+ foregroundPidString.append(c);
|
|
|
|
+ break;
|
|
|
|
+ case UID_PROCESS_FIELD:
|
|
|
|
+ uidString.append(c);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pos++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ setFileError( processInfo.error() );
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // check that data was read successfully
|
|
|
|
+ bool ok = false;
|
|
|
|
+
|
|
|
|
+ // uid string must be less than 5 chars (uint)
|
|
|
|
+ if (uidString.size() > 5)
|
|
|
|
+ uidString.clear();
|
|
|
|
+
|
|
|
|
+ int uid = uidString.toInt(&ok);
|
|
|
|
+ if (ok)
|
|
|
|
+ setUserId(uid);
|
|
|
|
+ readUserName();
|
|
|
|
+
|
|
|
|
+ int foregroundPid = foregroundPidString.toInt(&ok);
|
|
|
|
+ if (ok)
|
|
|
|
+ setForegroundPid(foregroundPid);
|
|
|
|
+
|
|
|
|
+ int parentPid = parentPidString.toInt(&ok);
|
|
|
|
+ if (ok)
|
|
|
|
+ setParentPid(parentPid);
|
|
|
|
+
|
|
|
|
+ if (!processNameString.isEmpty())
|
|
|
|
+ setName(processNameString);
|
|
|
|
+
|
|
|
|
+ // update object state
|
|
|
|
+ setPid(pid);
|
|
|
|
+
|
|
|
|
+ return ok;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ virtual bool readArguments(int pid)
|
|
|
|
+ {
|
|
|
|
+ // read command-line arguments file found at /proc/<pid>/cmdline
|
|
|
|
+ // the expected format is a list of strings delimited by null characters,
|
|
|
|
+ // and ending in a double null character pair.
|
|
|
|
+
|
|
|
|
+ QFile argumentsFile( QString("/proc/%1/cmdline").arg(pid) );
|
|
|
|
+ if ( argumentsFile.open(QIODevice::ReadOnly) )
|
|
|
|
+ {
|
|
|
|
+ QTextStream stream(&argumentsFile);
|
|
|
|
+ QString data = stream.readAll();
|
|
|
|
+
|
|
|
|
+ QStringList argList = data.split( QChar('\0') );
|
|
|
|
+
|
|
|
|
+ foreach ( const QString &entry , argList )
|
|
|
|
+ {
|
|
|
|
+ if (!entry.isEmpty())
|
|
|
|
+ addArgument(entry);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ setFileError( argumentsFile.error() );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ virtual bool readCurrentDir(int pid)
|
|
|
|
+ {
|
|
|
|
+ QFileInfo info( QString("/proc/%1/cwd").arg(pid) );
|
|
|
|
+
|
|
|
|
+ const bool readable = info.isReadable();
|
|
|
|
+
|
|
|
|
+ if ( readable && info.isSymLink() )
|
|
|
|
+ {
|
|
|
|
+ setCurrentDir( info.symLinkTarget() );
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if ( !readable )
|
|
|
|
+ setError( PermissionsError );
|
|
|
|
+ else
|
|
|
|
+ setError( UnknownError );
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ virtual bool readEnvironment(int pid)
|
|
|
|
+ {
|
|
|
|
+ // Not supported in NetBSD
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+} ;
|
2014-11-13 11:53:49 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-20 06:07:48 +01:00
|
|
|
SSHProcessInfo::SSHProcessInfo(const ProcessInfo& process)
|
2014-11-13 11:53:49 +01:00
|
|
|
@@ -1168,6 +1333,8 @@ ProcessInfo* ProcessInfo::newInstance(in
|
2013-04-03 12:51:43 +02:00
|
|
|
return new LinuxProcessInfo(aPid, enableEnvironmentRead);
|
2012-03-20 06:07:48 +01:00
|
|
|
#elif defined(Q_OS_SOLARIS)
|
2013-04-03 12:51:43 +02:00
|
|
|
return new SolarisProcessInfo(aPid, enableEnvironmentRead);
|
2012-03-20 06:07:48 +01:00
|
|
|
+#elif defined(Q_OS_NETBSD)
|
2013-04-03 12:51:43 +02:00
|
|
|
+ return new NetBSDProcessInfo(aPid, enableEnvironmentRead);
|
2012-03-20 06:07:48 +01:00
|
|
|
#elif defined(Q_OS_MAC)
|
2013-04-03 12:51:43 +02:00
|
|
|
return new MacProcessInfo(aPid, enableEnvironmentRead);
|
2012-03-20 06:07:48 +01:00
|
|
|
#elif defined(Q_OS_FREEBSD)
|