{
SystemCmd cmd(string(LVMBIN " version"));
- if (cmd.retcode() != 0)
+ if (cmd.retcode() != 0 || cmd.stdout().empty())
{
y2war("Couldn't get LVM version info");
}
{
Regex rx(".*LVM[[:space:]]+version:[[:space:]]+([0-9]+)\\.([0-9]+)\\.([0-9]+).*$");
- if (!rx.match(cmd.getLine(0)))
+ if (!rx.match(cmd.stdout().front()))
{
y2war("LVM version format didn't match");
}
boost::unique_lock<boost::shared_mutex> unique_lock(lv_mutex);
SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg->get_vg_name() + "/" + lv_name));
-
- if (cmd.retcode() != 0 || cmd.numLines() < 1)
+ if (cmd.retcode() != 0 || cmd.stdout().empty())
{
y2err("lvm cache: failed to get info about " << vg->get_vg_name() << "/" << lv_name);
throw LvmCacheException();
}
vector<string> args;
- const string tmp = boost::trim_copy(cmd.getLine(0));
+ const string tmp = boost::trim_copy(cmd.stdout().front());
boost::split(args, tmp, boost::is_any_of(" \t\n"), boost::token_compress_on);
if (args.size() < 1)
throw LvmCacheException();
else
{
SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg_name + "/" + lv_name));
- if (cmd.retcode() != 0 || cmd.numLines() < 1)
+ if (cmd.retcode() != 0 || cmd.stdout().empty())
{
y2err("lvm cache: failed to get info about " << vg_name << "/" << lv_name);
throw LvmCacheException();
}
vector<string> args;
- const string tmp = boost::trim_copy(cmd.getLine(0));
+ const string tmp = boost::trim_copy(cmd.stdout().front());
boost::split(args, tmp, boost::is_any_of(" \t\n"), boost::token_compress_on);
if (args.size() < 1)
throw LvmCacheException();
}
-int
-SystemCmd::select( const string& Pat_Cv, OutputStream Idx_iv )
- {
- if( Idx_iv > 1 )
- {
- y2err("invalid index " << Idx_iv);
- }
- string Search_Ci( Pat_Cv );
- bool BeginOfLine_bi = Search_Ci.length()>0 && Search_Ci[0]=='^';
- if( BeginOfLine_bi )
- {
- Search_Ci.erase( 0, 1 );
- }
- SelLines_aC[Idx_iv].resize(0);
- int Size_ii = 0;
- int End_ii = Lines_aC[Idx_iv].size();
- for( int I_ii=0; I_ii<End_ii; I_ii++ )
- {
- string::size_type Pos_ii = Lines_aC[Idx_iv][I_ii].find( Search_Ci );
- if( Pos_ii>0 && BeginOfLine_bi )
- {
- Pos_ii = string::npos;
- }
- if (Pos_ii != string::npos)
- {
- SelLines_aC[Idx_iv].resize( Size_ii+1 );
- SelLines_aC[Idx_iv][Size_ii] = &Lines_aC[Idx_iv][I_ii];
- y2deb("Select Added Line " << Size_ii << " \"" << *SelLines_aC[Idx_iv][Size_ii] << "\"");
- Size_ii++;
- }
- }
-
- y2mil("Pid:" << Pid_i << " Idx:" << Idx_iv << " Pattern:\"" << Pat_Cv << "\" Lines:" << Size_ii);
- return Size_ii;
- }
-
-
void
SystemCmd::invalidate()
{
/*
- * Copyright (c) [2004-2012] Novell, Inc.
+ * Copyright (c) [2004-2014] Novell, Inc.
*
* All Rights Reserved.
*
virtual ~SystemCmd();
+ protected:
+
int execute(const string& Command_Cv);
int executeBackground(const string& Command_Cv);
int executeRestricted(const string& Command_Cv,
unsigned long MaxTimeSec, unsigned long MaxLineOut,
bool& ExceedTime, bool& ExceedLines);
+ public:
+
const vector<string>& stdout() const { return Lines_aC[IDX_STDOUT]; }
const vector<string>& stderr() const { return Lines_aC[IDX_STDERR]; }
string cmd() const { return lastCmd; }
int retcode() const { return Ret_i; }
- int select(const string& Reg_Cv, OutputStream Idx_ii = IDX_STDOUT);
+ protected:
+
unsigned numLines(bool Selected_bv = false, OutputStream Idx_ii = IDX_STDOUT) const;
string getLine(unsigned Num_iv, bool Selected_bv = false, OutputStream Idx_ii = IDX_STDOUT) const;
static void setTestmode(bool testmode = true);
+ public:
+
/**
* Quotes and protects a single string for shell execution.
*/