From e18675bf67805971cf3637fcc866ae30c2f60835 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 4 Mar 2011 22:37:21 +0100 Subject: [PATCH] feature #407: Refactor of base classes to include names and uid. Also the pool now has an index to get objects by name --- include/Host.h | 21 ----- include/HostPool.h | 2 +- include/Image.h | 37 --------- include/ImagePool.h | 33 ++------ include/ObjectXML.h | 2 +- include/PoolObjectSQL.h | 33 +++++++- include/PoolSQL.h | 103 ++++++++++++++++++++++++- include/VirtualNetwork.h | 32 +------- include/VirtualNetworkPool.h | 23 +++--- src/host/Host.cc | 9 +-- src/host/HostHook.cc | 4 +- src/host/HostPool.cc | 2 +- src/host/test/HostPoolTest.cc | 2 +- src/im/InformationManager.cc | 4 +- src/image/Image.cc | 4 +- src/image/ImagePool.cc | 56 +++----------- src/image/test/ImagePoolTest.cc | 20 ++--- src/pool/PoolSQL.cc | 66 ++++++++++++++-- src/rm/RequestManagerAllocate.cc | 4 +- src/rm/RequestManagerDeploy.cc | 2 +- src/rm/RequestManagerMigrate.cc | 2 +- src/template/template_parser.c | 4 +- src/vm/VirtualMachine.cc | 15 +--- src/vm/vm_var_parser.c | 4 +- src/vm/vm_var_syntax.cc | 22 +++--- src/vm/vm_var_syntax.h | 6 +- src/vm/vm_var_syntax.y | 2 +- src/vnm/VirtualNetwork.cc | 17 ++-- src/vnm/VirtualNetworkPool.cc | 75 +++--------------- src/vnm/test/VirtualNetworkPoolTest.cc | 16 ++-- src/xml/expr_arith.cc | 20 ++--- src/xml/expr_arith.h | 6 +- src/xml/expr_parser.c | 4 +- 33 files changed, 308 insertions(+), 344 deletions(-) diff --git a/include/Host.h b/include/Host.h index eca9f80cce..905ceac12d 100644 --- a/include/Host.h +++ b/include/Host.h @@ -64,15 +64,6 @@ public: */ int from_xml(const string &xml_str); - /** - * Get the Host unique identifier HID, that matches the OID of the object - * @return HID Host identifier - */ - int get_hid() const - { - return oid; - }; - /** * Check if the host is enabled * @return true if the host is enabled @@ -121,15 +112,6 @@ public: state = INIT; }; - /** - * Returns host host_name - * @return host_name Host's hostname - */ - const string& get_hostname() const - { - return hostname; - }; - /** Update host counters and update the whole host on the DB * @param parse_str string with values to be parsed * @return 0 on success @@ -379,9 +361,6 @@ private: // ------------------------------------------------------------------------- // Host Description // ------------------------------------------------------------------------- - - string hostname; - /** * The state of the Host */ diff --git a/include/HostPool.h b/include/HostPool.h index fdf1fb901e..13bc69d3b6 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -68,7 +68,7 @@ public: { return static_cast(PoolSQL::get(oid,lock)); }; - + /** * Bootstraps the database table(s) associated to the Host pool */ diff --git a/include/Image.h b/include/Image.h index d6d8020005..5d11f88f81 100644 --- a/include/Image.h +++ b/include/Image.h @@ -74,33 +74,6 @@ public: */ int from_xml(const string &xml_str); - /** - * Get the Image unique identifier IID, that matches the OID of the object - * @return IID Image identifier - */ - int get_iid() const - { - return oid; - }; - - /** - * Gets the uid of the owner of the Image - * @return uid - **/ - int get_uid() - { - return uid; - } - - /** - * Returns Image's name - * @return name Image's name - */ - const string& get_name() const - { - return name; - }; - /** * Returns true if the image is public * @return true if the image is public @@ -356,21 +329,11 @@ private: // Image Description // ------------------------------------------------------------------------- - /** - * Owner of the image - */ - int uid; - /** * Image owner's name */ string user_name; - /** - * The name of the Image - */ - string name; - /** * Type of the Image */ diff --git a/include/ImagePool.h b/include/ImagePool.h index 3cff085aaa..9415ee7321 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -83,18 +83,10 @@ public: */ Image * get( const string& name, + int uid, bool lock) { - map::iterator index; - - index = image_names.find(name); - - if ( index != image_names.end() ) - { - return get((int)index->second,lock); - } - - return 0; + return static_cast(PoolSQL::get(name,uid,lock)); } /** Update a particular Image @@ -112,14 +104,7 @@ public: */ int drop(Image * image) { - int rc = PoolSQL::drop(image); - - if ( rc == 0) - { - image_names.erase(image->get_name()); - } - - return rc; + return PoolSQL::drop(image); }; /** @@ -146,18 +131,21 @@ public: * @param index number of datablock images used by the same VM. Will be * automatically increased. * @param img_type will be set to the used image's type + * @param uid owner of the VM (to look for the image id within its images) * @return 0 on success, -1 error, -2 not using the pool */ int disk_attribute(VectorAttribute * disk, int disk_id, int * index, - Image::ImageType * img_type); + Image::ImageType * img_type, + int uid); /** * Generates an Authorization token for the DISK attribute * @param disk the disk to be authorized + * @param uid owner of the VM (to look for the image id within its images) * @param ar the AuthRequest */ - void authorize_disk(VectorAttribute * disk, AuthRequest * ar); + void authorize_disk(VectorAttribute * disk, int uid, AuthRequest * ar); static const string& source_prefix() { @@ -196,11 +184,6 @@ private: //-------------------------------------------------------------------------- // Pool Attributes // ------------------------------------------------------------------------- - /** - * This map stores the association between IIDs and Image names - */ - map image_names; - /** * Factory method to produce Image objects * @return a pointer to the new Image diff --git a/include/ObjectXML.h b/include/ObjectXML.h index c492fdf78b..3b7bfffd7d 100644 --- a/include/ObjectXML.h +++ b/include/ObjectXML.h @@ -122,7 +122,7 @@ public: * returned as pointers to the object nodes. * @return the number of nodes found */ - int get_nodes (const char * xpath_expr, vector& content); + int get_nodes(const char * xpath_expr, vector& content); /** * Updates the object representation with a new XML document. Previous diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 354a29d7b4..8667c3406f 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -38,8 +38,9 @@ class PoolObjectSQL : public ObjectSQL, public ObjectXML public: //TODO remove Defaults for Constructor Attributes - PoolObjectSQL(int id=-1, const char * _table = 0) - :ObjectSQL(),ObjectXML(),oid(id),valid(true),table(_table) + PoolObjectSQL(int id=-1, const string& _name ="", int _uid=0,const char *_table = 0) + :ObjectSQL(),ObjectXML(),oid(id),name(_name),uid(_uid), + valid(true),table(_table) { pthread_mutex_init(&mutex,0); }; @@ -51,11 +52,25 @@ public: pthread_mutex_destroy(&mutex); }; + /* --------------------------------------------------------------------- */ + int get_oid() const { return oid; }; + const string& get_name() const + { + return name; + }; + + int get_uid() + { + return uid; + }; + + /* --------------------------------------------------------------------- */ + /** * Check if the object is valid * @return true if object is valid @@ -209,12 +224,22 @@ protected: /** * The object's unique ID */ - int oid; + int oid; + + /** + * The object's name + */ + string name; + + /** + * Object's owner + */ + int uid; /** * The contents of this object are valid */ - bool valid; + bool valid; private: diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 187fb066e2..a750d04b80 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -45,8 +45,10 @@ public: * @param _db a pointer to the database * @param table the name of the table supporting the pool (to set the oid * counter). If null the OID counter is not updated. + * @param with_uid the Pool objects have an owner id (uid) */ - PoolSQL(SqlDB * _db, const char * table); + //TODO REmove defaults + PoolSQL(SqlDB * _db, const char * table, bool with_uid=false); virtual ~PoolSQL(); @@ -68,10 +70,33 @@ public: * * @return a pointer to the object, 0 in case of failure */ - virtual PoolObjectSQL * get( + PoolObjectSQL * get( int oid, bool lock); + /** + * Gets an object from the pool (if needed the object is loaded from the + * database). + * @param name of the object + * @param uid id of owner + * @param lock locks the object if true + * + * @return a pointer to the object, 0 in case of failure + */ + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + int oid; + + oid = get_oid_by_name(name, uid); + + if (oid == -1) + { + return 0; + } + + return get(oid,lock); + } + /** * Finds a set objects that satisfies a given condition * @param oids a vector with the oids of the objects. @@ -116,6 +141,8 @@ public: virtual int drop( PoolObjectSQL * objsql) { + erase(objsql->name,objsql->uid); + return objsql->drop(db); }; @@ -164,6 +191,12 @@ private: */ map pool; + /** + * This is a name index for the pool map. The key is the name of the object + * , that may be combained with the owner id. + */ + map name_index; + /** * Factory method, must return an ObjectSQL pointer to an allocated pool * specific object. @@ -200,6 +233,72 @@ private: */ void replace(); + /* ------------------------------------------------------------------------ */ + /* Functions to manage the name index */ + /* ------------------------------------------------------------------------ */ + + /** + * Generate an index key for the object + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @return the key, a string + */ + string key(const string& name, int uid) + { + ostringstream key; + + key << name << ':' << uid; + + return key.str(); + }; + + /** + * Adds a new key-object_oid entry in the index + * @param name of the object + * @param oid of the object + * @param uid owner of the object, only used if needed + */ + void insert(const string& name, int oid, int uid) + { + name_index.insert(make_pair(key(name,uid),oid)); + }; + + /** + * Deletes a key-object_oid entry in the index + * @param name of the object + * @param uid owner of the object, only used if needed + */ + void erase(const string& name, int uid) + { + name_index.erase(key(name,uid)); + }; + + /** + * Looks for the oid of an object in the in memory index + * @param name of the object + * @param uid owner of the object, only used if needed + * + * @returns oid or -1 if the object was not found + */ + int get_oid_by_name(const string& name, int uid) + { + map::iterator index; + int oid = -1; + + index = name_index.find(key(name,uid)); + + if ( index != name_index.end() ) + { + oid = static_cast(index->second); + } + + return oid; + }; + + /* ------------------------------------------------------------------------ */ + /* ------------------------------------------------------------------------ */ + /** * Callback to set the lastOID (PoolSQL::PoolSQL) */ diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 2591a01531..e5e13e6a09 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -58,24 +58,6 @@ public: // Virtual Network Public Methods // ************************************************************************* - /** - * Get the Vnet unique identifier VNID, that matches the OID of the object - * @return VNID Image identifier - */ - int get_vnid() const - { - return oid; - }; - - /** - * Gets the uid of the owner of the Virtual Network - * @return uid - **/ - int get_uid() - { - return uid; - } - /** * Returns true if the Virtual Network is public * @return true if the Virtual Network is public @@ -265,16 +247,6 @@ private: // ------------------------------------------------------------------------- // Identification variables // ------------------------------------------------------------------------- - /** - * Name of the Virtual Network - */ - string name; - - /** - * Owner of the Virtual Network - */ - int uid; - /** * Owner's name */ @@ -369,7 +341,9 @@ protected: // Constructor //************************************************************************** - VirtualNetwork(string _user_name,VirtualNetworkTemplate * _vn_template = 0); + VirtualNetwork(int uid, + string _user_name, + VirtualNetworkTemplate * _vn_template = 0); ~VirtualNetwork(); diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index 0a4faae146..340e9ab5d2 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -71,12 +71,17 @@ public: * Function to get a VN from the pool using the network name * If the object is not in memory it is loaded from the DB * @param name VN unique name + * @param uid of the VN owner * @param lock locks the VN mutex * @return a pointer to the VN, 0 if the VN could not be loaded */ VirtualNetwork * get( const string& name, - bool lock); + int uid, + bool lock) + { + return static_cast(PoolSQL::get(name,uid,lock)); + }; //-------------------------------------------------------------------------- // Virtual Network DB access functions @@ -89,14 +94,14 @@ public: * @param vid of the VM requesting the lease * @return 0 on success, -1 error, -2 not using the pool */ - int nic_attribute(VectorAttribute * nic, int vid); + int nic_attribute(VectorAttribute * nic, int uid, int vid); /** * Generates an Authorization token for a NIC attribute * @param nic the nic to be authorized * @param ar the AuthRequest */ - void authorize_nic(VectorAttribute * nic, AuthRequest * ar); + void authorize_nic(VectorAttribute * nic, int uid, AuthRequest * ar); /** * Bootstraps the database table(s) associated to the VirtualNetwork pool @@ -151,7 +156,7 @@ private: */ PoolObjectSQL * create() { - return new VirtualNetwork("", 0); + return new VirtualNetwork(0,"",0); }; /** @@ -163,16 +168,6 @@ private: * @return 0 on success */ int dump_cb(void * _oss, int num, char **values, char **names); - - /** - * Callback function to get the ID of a given virtual network - * (VirtualNetworkPool::get) - * @param num the number of columns read from the DB - * @param names the column names - * @param vaues the column values - * @return 0 on success - */ - int get_cb(void * _oss, int num, char **values, char **names); }; #endif /*VIRTUAL_NETWORK_POOL_H_*/ diff --git a/src/host/Host.cc b/src/host/Host.cc index d5c53f0ed2..94eb975841 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -33,8 +33,7 @@ Host::Host( string _im_mad_name, string _vmm_mad_name, string _tm_mad_name): - PoolObjectSQL(id,table), - hostname(_hostname), + PoolObjectSQL(id,_hostname,0,table), state(INIT), im_mad_name(_im_mad_name), vmm_mad_name(_vmm_mad_name), @@ -102,7 +101,7 @@ int Host::insert_replace(SqlDB *db, bool replace) // Update the Host - sql_hostname = db->escape_str(hostname.c_str()); + sql_hostname = db->escape_str(name.c_str()); if ( sql_hostname == 0 ) { @@ -202,7 +201,7 @@ string& Host::to_xml(string& xml) const oss << "" "" << oid << "" << - "" << hostname << "" << + "" << name << "" << "" << state << "" << "" << im_mad_name << "" << "" << vmm_mad_name << "" << @@ -233,7 +232,7 @@ int Host::from_xml(const string& xml) // Get class base attributes rc += xpath(oid, "/HOST/ID", -1); - rc += xpath(hostname, "/HOST/NAME", "not_found"); + rc += xpath(name, "/HOST/NAME", "not_found"); rc += xpath(int_state, "/HOST/STATE", 0); rc += xpath(im_mad_name, "/HOST/IM_MAD", "not_found"); diff --git a/src/host/HostHook.cc b/src/host/HostHook.cc index 2c3017b5fe..d43fa072f9 100644 --- a/src/host/HostHook.cc +++ b/src/host/HostHook.cc @@ -55,7 +55,7 @@ void HostAllocateHook::do_hook(void *arg) { hmd->execute(host->get_oid(), name, - host->get_hostname(), + host->get_name(), cmd, parsed_args); } @@ -179,7 +179,7 @@ void HostStateHook::do_hook(void *arg) { hmd->execute(host->get_oid(), name, - host->get_hostname(), + host->get_name(), cmd, parsed_args); } diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index e01d4fa084..cfa1c715a5 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -45,7 +45,7 @@ int HostPool::init_cb(void *nil, int num, char **values, char **names) HostPool::HostPool(SqlDB* db, vector hook_mads, const string& hook_location) - : PoolSQL(db,Host::table) + : PoolSQL(db,Host::table,false) { // ------------------ Initialize Cluster Array ---------------------- diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index 76363b3ed3..475c869725 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -186,7 +186,7 @@ protected: CPPUNIT_ASSERT( obj != 0 ); string xml_str = ""; - string name = host->get_hostname(); + string name = host->get_name(); CPPUNIT_ASSERT( name == names[index] ); diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 36f521dcd1..259fa69a65 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -201,7 +201,7 @@ void InformationManager::timer_action() (thetime - host->get_last_monitored() >= monitor_period)) { oss.str(""); - oss << "Monitoring host " << host->get_hostname() + oss << "Monitoring host " << host->get_name() << " (" << it->first << ")"; NebulaLog::log("InM",Log::INFO,oss); @@ -225,7 +225,7 @@ void InformationManager::timer_action() update_remotes = true; } - imd->monitor(it->first,host->get_hostname(),update_remotes); + imd->monitor(it->first,host->get_name(),update_remotes); host->set_state(Host::MONITORING); } diff --git a/src/image/Image.cc b/src/image/Image.cc index 9d6d4a47c9..f957ccdab0 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -33,10 +33,8 @@ /* ************************************************************************ */ Image::Image(int _uid, string _user_name, ImageTemplate * _image_template): - PoolObjectSQL(-1,table), - uid(_uid), + PoolObjectSQL(-1,"",_uid,table), user_name(_user_name), - name(""), type(OS), regtime(time(0)), source(""), diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 3434cc7116..362185e696 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -27,31 +27,16 @@ string ImagePool::_source_prefix; string ImagePool::_default_type; string ImagePool::_default_dev_prefix; -int ImagePool::init_cb(void *nil, int num, char **values, char **names) -{ - if ( num == 0 || values == 0 || values[0] == 0 ) - { - return -1; - } - - image_names.insert(make_pair(values[1],atoi(values[0]))); - - return 0; -} - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - ImagePool::ImagePool( SqlDB * db, const string& __source_prefix, const string& __default_type, const string& __default_dev_prefix): - - PoolSQL(db,Image::table) + PoolSQL(db,Image::table,true) { - ostringstream sql; - int rc; + ostringstream sql; // Init static defaults _source_prefix = __source_prefix; @@ -63,25 +48,9 @@ ImagePool::ImagePool( SqlDB * db, _default_type != "CDROM" && _default_type != "DATABLOCK" ) { - NebulaLog::log("IMG", Log::ERROR, - "Bad default for image type, setting OS"); + NebulaLog::log("IMG", Log::ERROR, "Bad default for image type, setting OS"); _default_type = "OS"; } - - // Read from the DB the existing images, and build the ID:Name map - set_callback(static_cast(&ImagePool::init_cb)); - - sql << "SELECT oid, name FROM " << Image::table; - - rc = db->exec(sql, this); - - unset_callback(); - - if ( rc != 0 ) - { - NebulaLog::log("IMG", Log::ERROR, - "Could not load the existing images from the DB."); - } } /* -------------------------------------------------------------------------- */ @@ -109,14 +78,6 @@ int ImagePool::allocate ( // --------------------------------------------------------------------- *oid = PoolSQL::allocate(img, error_str); - // --------------------------------------------------------------------- - // Add the image name to the map of image_names - // --------------------------------------------------------------------- - if ( *oid != -1 ) - { - image_names.insert(make_pair(name, *oid)); - } - return *oid; } @@ -167,7 +128,8 @@ int ImagePool::dump(ostringstream& oss, const string& where) int ImagePool::disk_attribute(VectorAttribute * disk, int disk_id, int * index, - Image::ImageType * img_type) + Image::ImageType * img_type, + int uid) { string source; Image * img = 0; @@ -202,7 +164,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, } else { - img = get(source,true); + img = get(source,uid,true); if (img == 0) { @@ -253,7 +215,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void ImagePool::authorize_disk(VectorAttribute * disk, AuthRequest * ar) +void ImagePool::authorize_disk(VectorAttribute * disk,int uid, AuthRequest * ar) { string source; Image * img = 0; @@ -282,7 +244,7 @@ void ImagePool::authorize_disk(VectorAttribute * disk, AuthRequest * ar) } else { - img = get(source,true); + img = get(source,uid,true); } if (img == 0) @@ -291,7 +253,7 @@ void ImagePool::authorize_disk(VectorAttribute * disk, AuthRequest * ar) } ar->add_auth(AuthRequest::IMAGE, - img->get_iid(), + img->get_oid(), AuthRequest::USE, img->get_uid(), img->isPublic()); diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 13254ffa3b..51aed2ff65 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -192,7 +192,7 @@ public: ImagePool * imp; Image * img; - // Allocate 2 users, so they are written to the DB. + // Allocate 2 images, so they are written to the DB. allocate(0); allocate(2); @@ -200,13 +200,13 @@ public: // allocated images. imp = new ImagePool(db, "source_prefix", "OS", "hd"); - img = imp->get(names[0], false); + img = imp->get(names[0], uids[0], false); CPPUNIT_ASSERT( img != 0 ); - img = imp->get(names[1], false); + img = imp->get(names[1], uids[1], false); CPPUNIT_ASSERT( img == 0 ); - img = imp->get(names[2], false); + img = imp->get(names[2], uids[2], false); CPPUNIT_ASSERT( img != 0 ); @@ -297,7 +297,7 @@ public: check(0, obj); // Get using its name - obj = imp->get(names[1], true); + obj = imp->get(names[1], uids[1], true); CPPUNIT_ASSERT( obj != 0 ); obj->unlock(); @@ -309,7 +309,7 @@ public: pool->clean(); // Get first object and check its integrity - obj = imp->get(names[0], false); + obj = imp->get(names[0], uids[0], false); check(0, obj); // Get using its name @@ -326,14 +326,14 @@ public: // The pool is empty // Non existing name - obj = imp->get("Wrong name", true); + obj = imp->get("Wrong name", 0, true); CPPUNIT_ASSERT( obj == 0 ); // Allocate an object allocate(0); // Ask again for a non-existing name - obj = imp->get("Non existing name", true); + obj = imp->get("Non existing name",uids[0], true); CPPUNIT_ASSERT( obj == 0 ); } @@ -632,7 +632,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE", "Image 0"); - ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0); value = ""; value = disk->vector_value("TARGET"); @@ -649,7 +649,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "1"); - ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0); value = ""; value = disk->vector_value("TARGET"); diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 1565a652b8..d5cda83b00 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -38,11 +38,39 @@ const unsigned int PoolSQL::MAX_POOL_SIZE = 15000; int PoolSQL::init_cb(void *nil, int num, char **values, char **names) { - lastOID = -1; + int uid = 0; + int oid; - if ( values[0] != 0 ) + if (num ==3) //with uid { - lastOID = atoi(values[0]); + if ((values[0] == 0) || (values[1] == 0) || (values[2] == 0)) + { + return -1; + } + + uid = atoi(values[2]); + } + else if (num == 2) + { + if ((values[0] == 0) || (values[1] == 0)) + { + return -1; + } + + uid = 0; + } + else + { + return -1; + } + + oid = atoi(values[0]); + + name_index.insert(make_pair(key(values[1],uid),oid)); + + if (lastOID < oid) + { + lastOID = oid; } return 0; @@ -50,19 +78,33 @@ int PoolSQL::init_cb(void *nil, int num, char **values, char **names) /* -------------------------------------------------------------------------- */ -PoolSQL::PoolSQL(SqlDB * _db, const char * table): db(_db), lastOID(-1) +PoolSQL::PoolSQL(SqlDB * _db, const char * table, bool with_uid):db(_db), lastOID(-1) { ostringstream oss; + int rc; pthread_mutex_init(&mutex,0); set_callback(static_cast(&PoolSQL::init_cb)); - oss << "SELECT MAX(oid) FROM " << table; + if (with_uid == true) + { + oss << "SELECT oid, name, uid FROM " << table; + } + else + { + oss << "SELECT oid, name FROM " << table; + } - db->exec(oss,this); + rc = db->exec(oss,this); unset_callback(); + + if ( rc == -1 ) + { + throw runtime_error("Could not load the existing pool objects from the DB."); + } + }; /* -------------------------------------------------------------------------- */ @@ -86,6 +128,7 @@ PoolSQL::~PoolSQL() pthread_mutex_destroy(&mutex); } + /* ************************************************************************** */ /* PoolSQL public interface */ /* ************************************************************************** */ @@ -120,6 +163,7 @@ int PoolSQL::allocate( else { rc = lastOID; + insert(objsql->get_name(),rc,objsql->get_uid()); } do_hooks(objsql, Hook::ALLOCATE); @@ -187,6 +231,7 @@ PoolObjectSQL * PoolSQL::get( pool.insert(make_pair(objectsql->oid,objectsql)); + if ( olock == true ) { objectsql->lock(); @@ -238,7 +283,14 @@ void PoolSQL::replace() { PoolObjectSQL * tmp_ptr; + string name; + int uid; + tmp_ptr = index->second; + + name = tmp_ptr->get_name(); + uid = tmp_ptr->get_uid(); + pool.erase(index); delete tmp_ptr; @@ -272,6 +324,7 @@ void PoolSQL::clean() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + int PoolSQL:: search_cb(void * _oids, int num, char **values, char **names) { vector * oids; @@ -309,3 +362,4 @@ int PoolSQL::search( return rc; } + diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 21b78f3823..ea83042503 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -94,7 +94,7 @@ void RequestManager::VirtualMachineAllocate::execute( continue; } - VirtualMachineAllocate::ipool->authorize_disk(vector,&ar); + VirtualMachineAllocate::ipool->authorize_disk(vector,uid,&ar); } num = vm_template->get("NIC",vectors); @@ -108,7 +108,7 @@ void RequestManager::VirtualMachineAllocate::execute( continue; } - VirtualMachineAllocate::vnpool->authorize_nic(vector,&ar); + VirtualMachineAllocate::vnpool->authorize_nic(vector,uid,&ar); } ar.add_auth(AuthRequest::VM, diff --git a/src/rm/RequestManagerDeploy.cc b/src/rm/RequestManagerDeploy.cc index 499278da95..e6b60b11e4 100644 --- a/src/rm/RequestManagerDeploy.cc +++ b/src/rm/RequestManagerDeploy.cc @@ -107,7 +107,7 @@ void RequestManager::VirtualMachineDeploy::execute( goto error_host_get; } - hostname = host->get_hostname(); + hostname = host->get_name(); vmm_mad = host->get_vmm_mad(); tm_mad = host->get_tm_mad(); diff --git a/src/rm/RequestManagerMigrate.cc b/src/rm/RequestManagerMigrate.cc index 58cbdfb9ca..fae0a50261 100644 --- a/src/rm/RequestManagerMigrate.cc +++ b/src/rm/RequestManagerMigrate.cc @@ -67,7 +67,7 @@ void RequestManager::VirtualMachineMigrate::execute( goto error_host_get; } - hostname = host->get_hostname(); + hostname = host->get_name(); vmm_mad = host->get_vmm_mad(); tm_mad = host->get_tm_mad(); diff --git a/src/template/template_parser.c b/src/template/template_parser.c index 1fef1b3b2c..c186da105b 100644 --- a/src/template/template_parser.c +++ b/src/template/template_parser.c @@ -641,7 +641,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( template_text, template_leng, 1, template_out ) +#define ECHO do { if (fwrite( template_text, template_leng, 1, template_out )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -652,7 +652,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( template_in )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index bd032d6582..534d0fe69d 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -124,9 +124,7 @@ int VirtualMachine::select(SqlDB * db) return rc; } - //Get the History Records - // First history record is built in from_xml() (if any). - // Check if there is a previous history to be loaded from the DB: + //Get History Records. Current history is record is built in from_xml() (if any). if( hasHistory() ) { last_seq = history->seq; @@ -145,7 +143,6 @@ int VirtualMachine::select(SqlDB * db) } //Create support directory for this VM - oss.str(""); oss << nd.get_var_location() << oid; @@ -153,7 +150,6 @@ int VirtualMachine::select(SqlDB * db) chmod(oss.str().c_str(), 0777); //Create Log support for this VM - try { _log = new FileLog(nd.get_vm_log_filename(oid),Log::DEBUG); @@ -168,11 +164,6 @@ int VirtualMachine::select(SqlDB * db) return 0; -error_history: - ose << "Can not get history for VM id: " << oid; - log("ONE", Log::ERROR, ose); - return -1; - error_previous_history: ose << "Can not get previous history record (seq:" << history->seq << ") for VM id: " << oid; @@ -698,7 +689,7 @@ int VirtualMachine::get_disk_images(string& error_str) continue; } - rc = ipool->disk_attribute(disk, i, &index, &img_type); + rc = ipool->disk_attribute(disk, i, &index, &img_type, uid); if (rc == 0 ) { @@ -841,7 +832,7 @@ int VirtualMachine::get_network_leases() continue; } - rc = vnpool->nic_attribute(nic, oid); + rc = vnpool->nic_attribute(nic, uid, oid); if (rc == -1) { diff --git a/src/vm/vm_var_parser.c b/src/vm/vm_var_parser.c index 4a52569078..0aeef94884 100644 --- a/src/vm/vm_var_parser.c +++ b/src/vm/vm_var_parser.c @@ -620,7 +620,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( vm_var_text, vm_var_leng, 1, vm_var_out ) +#define ECHO do { if (fwrite( vm_var_text, vm_var_leng, 1, vm_var_out )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -631,7 +631,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( vm_var_in )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ diff --git a/src/vm/vm_var_syntax.cc b/src/vm/vm_var_syntax.cc index 20669d6c37..a4f2f659cf 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/vm/vm_var_syntax.cc @@ -1,9 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +45,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.2" +#define YYBISON_VERSION "2.4.3" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -180,7 +180,7 @@ void get_network_attribute(VirtualMachine * vm, return; } - vn = vnpool->get(network,true); + vn = vnpool->get(network, vm->get_uid(), true); if ( vn == 0 ) { @@ -1374,7 +1374,7 @@ YYLTYPE yylloc; YYLTYPE *yylsp; /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[2]; + YYLTYPE yyerror_range[3]; YYSIZE_T yystacksize; @@ -1754,7 +1754,7 @@ yyerrlab: #endif } - yyerror_range[0] = yylloc; + yyerror_range[1] = yylloc; if (yyerrstatus == 3) { @@ -1791,7 +1791,7 @@ yyerrorlab: if (/*CONSTCOND*/ 0) goto yyerrorlab; - yyerror_range[0] = yylsp[1-yylen]; + yyerror_range[1] = yylsp[1-yylen]; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); @@ -1825,7 +1825,7 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - yyerror_range[0] = *yylsp; + yyerror_range[1] = *yylsp; yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp, mc, vm, parsed, errmsg); YYPOPSTACK (1); @@ -1835,10 +1835,10 @@ yyerrlab1: *++yyvsp = yylval; - yyerror_range[1] = yylloc; + yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); *++yylsp = yyloc; /* Shift the error token. */ diff --git a/src/vm/vm_var_syntax.h b/src/vm/vm_var_syntax.h index f68317f8a9..f14220c3a3 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/vm/vm_var_syntax.h @@ -1,9 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton interface for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/vm/vm_var_syntax.y b/src/vm/vm_var_syntax.y index ea4753c89b..e8d2628b3a 100644 --- a/src/vm/vm_var_syntax.y +++ b/src/vm/vm_var_syntax.y @@ -118,7 +118,7 @@ void get_network_attribute(VirtualMachine * vm, return; } - vn = vnpool->get(network,true); + vn = vnpool->get(network, vm->get_uid(), true); if ( vn == 0 ) { diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 00731c01f6..6b39f77329 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -29,11 +29,10 @@ /* Virtual Network :: Constructor/Destructor */ /* ************************************************************************** */ -VirtualNetwork::VirtualNetwork(string _user_name, +VirtualNetwork::VirtualNetwork(int uid, + string _user_name, VirtualNetworkTemplate *_vn_template): - PoolObjectSQL(-1, table), - name(""), - uid(-1), + PoolObjectSQL(-1,"",uid,table), user_name(_user_name), bridge(""), type(UNINITIALIZED), @@ -71,11 +70,11 @@ VirtualNetwork::~VirtualNetwork() const char * VirtualNetwork::table = "network_pool"; -const char * VirtualNetwork::db_names = "oid, name, body"; +const char * VirtualNetwork::db_names = "oid, name, body, uid"; const char * VirtualNetwork::db_bootstrap = "CREATE TABLE IF NOT EXISTS" - " network_pool " - "(oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name))"; + " network_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256)," + " body TEXT, uid INTEGER, UNIQUE(name))"; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -92,7 +91,6 @@ int VirtualNetwork::select(SqlDB * db) unsigned int default_size = VirtualNetworkPool::default_size(); unsigned int mac_prefix = VirtualNetworkPool::mac_prefix(); - // Rebuld the VirtualNetwork object rc = PoolObjectSQL::select(db); @@ -404,7 +402,8 @@ int VirtualNetwork::insert_replace(SqlDB *db, bool replace) oss << " INTO " << table << " (" << db_names << ") VALUES (" << oid << "," << "'" << sql_name << "'," - << "'" << sql_xml << "')"; + << "'" << sql_xml << "'," + << uid << ")"; rc = db->exec(oss); diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index c75ff4ea50..a8d2f20a59 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -32,7 +32,7 @@ unsigned int VirtualNetworkPool::_default_size; VirtualNetworkPool::VirtualNetworkPool(SqlDB * db, const string& prefix, int __default_size): - PoolSQL(db,VirtualNetwork::table) + PoolSQL(db,VirtualNetwork::table,true) { istringstream iss; size_t pos = 0; @@ -78,9 +78,7 @@ int VirtualNetworkPool::allocate ( { VirtualNetwork * vn; - vn = new VirtualNetwork(user_name, vn_template); - - vn->uid = uid; + vn = new VirtualNetwork(uid, user_name, vn_template); *oid = PoolSQL::allocate(vn, error_str); @@ -90,63 +88,6 @@ int VirtualNetworkPool::allocate ( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualNetworkPool::get_cb(void * _oid, int num, char **values,char **names) -{ - int * oid; - - oid = static_cast(_oid); - - if ( oid == 0 || values == 0 || values[0] == 0 ) - { - return -1; - } - - *oid = atoi(values[0]); - - return 0; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -VirtualNetwork * VirtualNetworkPool::get(const string& name, bool lock) -{ - ostringstream oss; - - int oid = -1; - int rc; - - char * sql_name = db->escape_str(name.c_str()); - - if ( sql_name == 0 ) - { - return 0; - } - - set_callback( - static_cast(&VirtualNetworkPool::get_cb), - static_cast(&oid)); - - oss << "SELECT oid FROM " << VirtualNetwork::table << " WHERE name = '" - << sql_name << "'"; - - rc = db->exec(oss, this); - - unset_callback(); - - db->free_str(sql_name); - - if (rc != 0 || oid == -1) - { - return 0; - } - - return get(oid,lock); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int VirtualNetworkPool::dump_cb(void * _oss, int num, char ** values, @@ -191,7 +132,7 @@ int VirtualNetworkPool::dump(ostringstream& oss, const string& where) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int vid) +int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int uid, int vid) { string network; VirtualNetwork * vnet = 0; @@ -220,7 +161,7 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int vid) } else { - vnet = get(network,true); + vnet = get(network, uid, true); } if (vnet == 0) @@ -238,7 +179,9 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, AuthRequest * ar) +void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, + int uid, + AuthRequest * ar) { string network; VirtualNetwork * vnet = 0; @@ -267,7 +210,7 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, AuthRequest * ar) } else { - vnet = get(network,true); + vnet = get(network, uid, true); } if (vnet == 0) @@ -276,7 +219,7 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, AuthRequest * ar) } ar->add_auth(AuthRequest::NET, - vnet->get_vnid(), + vnet->get_oid(), AuthRequest::USE, vnet->get_uid(), vnet->isPublic()); diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index 5249e68736..5259db6db4 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -27,8 +27,8 @@ using namespace std; /* ************************************************************************* */ /* ************************************************************************* */ -const int uids[] = {123, 261, 133}; -const string user_names[] = {"A user","B user","C user"}; +const int uids[] = {123, 261, 133, 78}; +const string user_names[] = {"A user","B user","C user","D user"}; const string names[] = {"Net number one", "A virtual network","Net number two"}; @@ -267,7 +267,7 @@ public: CPPUNIT_ASSERT( oid >= 0 ); // Get using its name - vn = vnpool->get(names[1], true); + vn = vnpool->get(names[1],uids[1], true); CPPUNIT_ASSERT(vn != 0); vn->unlock(); @@ -277,7 +277,7 @@ public: vnpool->clean(); // Get using its name - vn = vnpool->get(names[1], false); + vn = vnpool->get(names[1], uids[1], false); check(1, vn); }; @@ -290,14 +290,14 @@ public: VirtualNetwork * vn; // Empty Pool - vn = vnpool->get("Wrong name", true); + vn = vnpool->get("Wrong name", 0, true); CPPUNIT_ASSERT( vn == 0 ); // Allocate an object allocate(0); // Ask again for a non-existing name - vn = vnpool->get("Non existing name", true); + vn = vnpool->get("Non existing name", uids[0], true); CPPUNIT_ASSERT( vn == 0 ); } @@ -1098,7 +1098,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("NETWORK", "Net 0"); - ((VirtualNetworkPool*)vnp)->nic_attribute(disk, 0); + ((VirtualNetworkPool*)vnp)->nic_attribute(disk, 0, 0); value = ""; @@ -1128,7 +1128,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("NETWORK_ID", "1"); - ((VirtualNetworkPool*)vnp)->nic_attribute(disk, 0); + ((VirtualNetworkPool*)vnp)->nic_attribute(disk,0, 0); value = ""; value = disk->vector_value("NETWORK"); diff --git a/src/xml/expr_arith.cc b/src/xml/expr_arith.cc index 88b2b04238..b8c9394fbf 100644 --- a/src/xml/expr_arith.cc +++ b/src/xml/expr_arith.cc @@ -1,9 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +45,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.2" +#define YYBISON_VERSION "2.4.3" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -1232,7 +1232,7 @@ YYLTYPE yylloc; YYLTYPE *yylsp; /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[2]; + YYLTYPE yyerror_range[3]; YYSIZE_T yystacksize; @@ -1643,7 +1643,7 @@ yyerrlab: #endif } - yyerror_range[0] = yylloc; + yyerror_range[1] = yylloc; if (yyerrstatus == 3) { @@ -1680,7 +1680,7 @@ yyerrorlab: if (/*CONSTCOND*/ 0) goto yyerrorlab; - yyerror_range[0] = yylsp[1-yylen]; + yyerror_range[1] = yylsp[1-yylen]; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); @@ -1714,7 +1714,7 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - yyerror_range[0] = *yylsp; + yyerror_range[1] = *yylsp; yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg); YYPOPSTACK (1); @@ -1724,10 +1724,10 @@ yyerrlab1: *++yyvsp = yylval; - yyerror_range[1] = yylloc; + yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); *++yylsp = yyloc; /* Shift the error token. */ diff --git a/src/xml/expr_arith.h b/src/xml/expr_arith.h index c4371a5ad5..66cd7ebbb4 100644 --- a/src/xml/expr_arith.h +++ b/src/xml/expr_arith.h @@ -1,9 +1,9 @@ -/* A Bison parser, made by GNU Bison 2.4.2. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton interface for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software - Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/xml/expr_parser.c b/src/xml/expr_parser.c index 33c05ed989..d2c0a3bd73 100644 --- a/src/xml/expr_parser.c +++ b/src/xml/expr_parser.c @@ -611,7 +611,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( expr_text, expr_leng, 1, expr_out ) +#define ECHO do { if (fwrite( expr_text, expr_leng, 1, expr_out )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -622,7 +622,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( expr_in )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \