Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Examples

SystemAgent.cc File Reference

#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <resolv.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <linux/lp.h>
#include <string>
#include <config.h>
#include <YCP.h>
#include <ycp/pathsearch.h>
#include <ycp/Parser.h>
#include <ycp/y2log.h>
#include "SystemAgent.h"
#include "ShellCommand.h"

Functions

int return_one (const struct dirent *entry)
const void remove_directory (const string &path, int depth)
int read_file_to_string (const char *filename, string &output)
YCPMap stat2map (const struct stat &sb)
YCPMap shellcommand_output (const string &script, const string &tempdir)
string indent_output (int level)
string dump_value (int level, const YCPValue &value)
return YCPString (tempdir)
 if (arg.isNull())
 if (arg->isString())
else if (arg->isList()&&(arg->asList()->size()==2)&&(arg->asList()->value(0)->isString()))
 if (path->length()!=2)
 if (value.isNull()||!value->isString())
return YCPBoolean (WIFEXITED(exitcode)&&WEXITSTATUS(exitcode)==0)
else if (cmd=="string")
 ycp2error ("Undefined subpath for Write(%s)", path->toString().c_str())
return YCPBoolean (false)
 if (environment->isMap())
 for (YCPMapIterator pos=variables->begin();pos!=variables->end();++pos)
 if (value.isNull()||arg.isNull()||!value->isString()||!arg->isString())
 y2milestone ("symlink%s->%s", oldpath, newpath.c_str())
 remove (newpath.c_str())
return YCPBoolean (symlink(oldpath, newpath.c_str())==0)
 if (!arg.isNull())
 y2milestone ("mkdir%s", path.c_str())
 while (pos=path.find('/', pos+1), pos!=string::npos)
 mkdir (path.substr(0, pos).c_str(), mode)
return YCPBoolean (stat(path.c_str(),&sb)==0 &&S_ISDIR(sb.st_mode))
 if (value.isNull()||!value->isList())
 if (mountlist->size()< 2||!mountlist->value(0)->isString()||!mountlist->value(1)->isString())
 if (mountlist->size()==3)
return YCPBoolean (shellcommand(mountcmd)==0)
 if (!arg.isNull()&&arg->isString())
return YCPBoolean (shellcommand(umountcmd)==0)
return YCPBoolean (ret==0)
return YCPBoolean (shellcommand(insmodcmd)==0)
return YCPBoolean (shellcommand(modprobecmd)==0)
 if (value.isNull()||!value->isInteger()) return YCPError("Bad PID in Execute(.kill
 if (!arg.isNull()&&arg->isInteger()) signal=arg->asInteger()->value()
return YCPBoolean (kill(pid, signal)!=-1)
return YCPError (string("Undefined subpath for Execute(")+path->toString()+")")

Variables

YCPValue default_value = YCPNull()
string filename
string passwd = value->asString()->value()
string bashcommand
int exitcode = system(bashcommand.c_str())
YCPMap variables
string exports = ""
const char * oldpath = value->asString()->value_cstr()
const string newpath = arg->asString()->value()
string path = value->asString()->value()
int mode = 0755
size_t pos = 0
stat sb
YCPList mountlist = value->asList()
string mountcmd = "/bin/mount "
string umountcmd = "/bin/umount " + value->asString()->value()
int ret = unlink (value->asString ()->value_cstr ())
string insmodcmd = "/sbin/insmod " + value->asString()->value()
string modprobecmd = "/sbin/modprobe " + value->asString()->value()
integer pid = value->asInteger()->value()
integer integer signal = 15

Function Documentation

string dump_value int  level,
const YCPValue value
 

recursively dump value to file

for YCPMapIterator  pos = variables-,
begin();pos = variables-,
end();++  pos
 

if !arg.  isNull()&&arg->isInteger()  ) 
 

if value.  isNull()||!value->isInteger()  ) 
 

if !arg.  isNull()&&arg->isString()  ) 
 

if mountlist->  size() = = 3  ) 
 

if mountlist->  size()< 2||!mountlist->value(0)->isString()||!mountlist->value(1)->isString()  ) 
 

if value.  isNull()||!value->isList()  ) 
 

if !arg.  isNull()  ) 
 

if value.  isNull()||arg.isNull()||!value->isString()||!arg->isString()  ) 
 

if environment->  isMap()  ) 
 

else if cmd  = = "string"  ) 
 

if value.  isNull()||!value->isString()  ) 
 

if path->length()!  = 2  ) 
 

else if arg->  isList()&&(arg->asList()->size()==2)&&(arg->asList()->value(0)->isString())  ) 
 

if arg->  isString()  ) 
 

if arg.  isNull()  ) 
 

string indent_output int  level  ) 
 

indent output by level

mkdir path substr(0, pos).c_str(),
mode 
 

int read_file_to_string const char *  filename,
string &  output
[static]
 

Read file to string

remove newpath c_str()  ) 
 

const void remove_directory const string &  path,
int  depth
[static]
 

remove directory and all its subfiles and subdirectories. Depth is maximal depth it goes to.

Parameters:
path path to remove
depth max. depth

int return_one const struct dirent *  entry  )  [static]
 

Filter . and ..

Returns:
0 if . or .. are file names

YCPMap shellcommand_output const string &  script,
const string &  tempdir
[static]
 

Run shell command and returns its output.

YCPMap stat2map const struct stat &  sb  )  [static]
 

Fills a ycp map with informations of a stat structure.

while pos  = path.find('/', pos + 1),
pos = string::npos
 

y2milestone "mkdir%s ,
path c_str()
 

y2milestone "symlink%s->%s ,
oldpath  ,
newpath c_str()
 

ycp2error "Undefined subpath for Write(%s)"  ,
path->  toString().c_str()
 

return YCPBoolean kill(pid, signal)!  = -1  ) 
 

return YCPBoolean shellcommand(modprobecmd = =0  ) 
 

return YCPBoolean shellcommand(insmodcmd = =0  ) 
 

return YCPBoolean ret  = =0  ) 
 

return YCPBoolean shellcommand(umountcmd = =0  ) 
 

return YCPBoolean shellcommand(mountcmd = =0  ) 
 

return YCPBoolean stat(path.c_str(),&sb = =0 &&S_ISDIR(sb.st_mode)  ) 
 

return YCPBoolean symlink(oldpath, newpath.c_str())  = =0  ) 
 

integer integer YCPBoolean false   ) 
 

return YCPBoolean WIFEXITED(exitcode)&&WEXITSTATUS(exitcode = =0  ) 
 

return YCPError string("Undefined subpath for Execute(")+path->toString()+")"   ) 
 

return YCPString tempdir   ) 
 


Variable Documentation

string bashcommand
 

Initial value:

            string ("/bin/echo '") +
            path->component_str (1).c_str () + ":" + passwd +
            "' |/usr/sbin/chpasswd -e >/dev/null 2>&1"

YCPValue default_value = YCPNull()
 

int exitcode = system(bashcommand.c_str())
 

string exports = ""
 

string filename
 

string insmodcmd = "/sbin/insmod " + value->asString()->value()
 

int mode = 0755
 

string modprobecmd = "/sbin/modprobe " + value->asString()->value()
 

string mountcmd = "/bin/mount "
 

YCPList mountlist = value->asList()
 

const string newpath = arg->asString()->value()
 

const char* oldpath = value->asString()->value_cstr()
 

string passwd = value->asString()->value()
 

string path = value->asString()->value()
 

int pid = value->asInteger()->value()
 

size_t pos = 0
 

int ret = unlink (value->asString ()->value_cstr ())
 

struct stat sb
 

int signal = 15
 

string umountcmd = "/bin/umount " + value->asString()->value()
 

YCPMap variables
 


Generated on Fri Nov 9 18:15:23 2007 for yast2-core by doxygen 1.3.6