Added utility getParentName() (name of parent process)
This commit is contained in:
		
							
								
								
									
										24
									
								
								utils.cpp
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								utils.cpp
									
									
									
									
									
								
							| @@ -2,6 +2,8 @@ | |||||||
| #include "message_handler.h" | #include "message_handler.h" | ||||||
| #include "git/git_client.h" | #include "git/git_client.h" | ||||||
|  |  | ||||||
|  | #include "unistd.h" | ||||||
|  |  | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QTextStream> | #include <QTextStream> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
| @@ -169,3 +171,25 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2, | |||||||
|  |  | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | QString Utils::getParentName() { // get name of parent process | ||||||
|  |     QString ppid = QString("/proc/%1/status").arg(getppid()); | ||||||
|  |     QFile f(ppid); | ||||||
|  |     if (f.exists()) { | ||||||
|  |         if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||||||
|  |             QTextStream in(&f); | ||||||
|  |             in.setCodec("UTF-8"); | ||||||
|  |             while(!in.atEnd()) { | ||||||
|  |                 // Name:   ATBQT | ||||||
|  |                 QStringList line = in.readLine().split(':'); | ||||||
|  |                 if (line.size() == 2) { | ||||||
|  |                     if (line[0].trimmed() == "Name") { | ||||||
|  |                         return line[1].trimmed(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return ""; | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								utils.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								utils.h
									
									
									
									
									
								
							| @@ -19,6 +19,9 @@ namespace Utils { | |||||||
|     QString rstrip(QString const &str); |     QString rstrip(QString const &str); | ||||||
|     bool sameFilesInDirs(QDir const &dir1, QDir const &dir2, |     bool sameFilesInDirs(QDir const &dir1, QDir const &dir2, | ||||||
|                          QStringList const &nameFilters = {"*.json"}); |                          QStringList const &nameFilters = {"*.json"}); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     QString getParentName(); | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif // UTILS_H_INCLUDED | #endif // UTILS_H_INCLUDED | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user