Confdump Agent
1.4.0
|
00001 /* 00002 * Confdump-Agent - Dump static and runtime system configuration 00003 * Copyright (C) 2009-2012 Straton IT, SAS 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 3 as 00007 * published by the Free Software Foundation. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 extern "C" 00019 { 00020 #include <unistd.h> 00021 } 00022 00023 #include "QDir" 00024 #include "boost/system/system_error.hpp" 00025 #include "boost/foreach.hpp" 00026 #include "Confdump/System/LinuxDumper.hpp" 00027 #include "Confdump/System/Linux/RcdScript.hpp" 00028 00029 using boost::shared_ptr; 00030 00031 namespace Confdump 00032 { 00033 00034 namespace System 00035 { 00036 00037 namespace Linux 00038 { 00039 00040 /* FIXME: use SystemContext 00041 * 00042 * FIXME: use boost::fs and a custom status to get full stat(2) information, error checking, etc 00043 * 00044 * FIXME: integrate this in some directory listing table 00045 */ 00046 00047 00048 RcdScript::RcdScript( QString fullPath ) 00049 { 00050 QFileInfo info( fullPath ); 00051 fullPath_ = info.absoluteFilePath(); 00052 if ( !info.exists() ) 00053 throw RuntimeError( QObject::tr( "RcdScript: %1 does not exist" ).arg( fullPath ) ); 00054 00055 QRegExp classicPath( "/etc/rc(\\w)\\.d/([SK])(\\d{2})(.*)" ); 00056 if ( classicPath.exactMatch( fullPath_ ) ) 00057 { 00058 runLevel_ = classicPath.cap( 1 ).at( 0 ); 00059 startStop_ = classicPath.cap( 2 ).at( 0 ); 00060 priority_ = classicPath.cap( 3 ).toUInt(); 00061 name_ = classicPath.cap( 4 ); 00062 } 00063 00064 if ( info.isSymLink() ) 00065 { 00066 char linksToRaw[1024]; 00067 ssize_t linksToSize = readlink( fullPath.toLocal8Bit().data(), linksToRaw, sizeof( linksToRaw ) ); 00068 if ( linksToSize < 0 ) 00069 throw boost::system::system_error( errno, boost::system::system_category, "readlink " + fullPath.toLocal8Bit() ); 00070 linksTo_ = QString::fromLocal8Bit( linksToRaw, linksToSize ); 00071 } 00072 } 00073 00074 RcdScript::~RcdScript() 00075 { 00076 } 00077 00078 QString RcdScript::fullPath() const 00079 { 00080 return fullPath_; 00081 } 00082 00083 QString RcdScript::linksTo() const 00084 { 00085 return linksTo_; 00086 } 00087 00088 QString RcdScript::name() const 00089 { 00090 return name_; 00091 } 00092 00093 Result RcdScript::allRcdScripts( boost::shared_ptr<LinuxDumper> driver ) 00094 { 00095 QDir etc( "/etc", "rc?.d", QDir::Name, QDir::Dirs | QDir::System ); 00096 QStringList rcDirs = etc.entryList(); 00097 00098 Result result; 00099 BOOST_FOREACH ( QString rcDirPath, rcDirs ) 00100 { 00101 QDir rcDir( "/etc/" + rcDirPath, "", QDir::Name, QDir::Files | QDir::Executable | QDir::System ); 00102 QStringList rcScriptsNames = rcDir.entryList(); 00103 00104 BOOST_FOREACH( QString name, rcScriptsNames ) 00105 { 00106 result.push_back( shared_ptr<RcdScript>( new RcdScript( "/etc/" + rcDirPath + "/" + name ) ) ); 00107 } 00108 } 00109 00110 return result; 00111 } 00112 00113 } // ns Linux 00114 } // ns System 00115 } // ns Confdump 00116