2017-05-18 17:36:26 +03:00
/* -------------------------------------------------------------------------- */
2019-01-16 13:27:59 +03:00
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
2017-05-18 17:36:26 +03:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
2019-09-09 15:43:51 +03:00
# ifndef EXECUTE_HOOK_H_
# define EXECUTE_HOOK_H_
# define EXECUTE_HOOK_MAX_ARG 50
2017-05-18 17:36:26 +03:00
# include <string>
2019-09-09 15:43:51 +03:00
# include <sstream>
# include <iostream>
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <pthread.h>
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
extern " C " void * execute_thread ( void * arg ) ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
class ExecuteHook
2017-05-18 17:36:26 +03:00
{
public :
2019-09-09 15:43:51 +03:00
ExecuteHook ( const std : : string & _name , const std : : string & _cmd ,
const std : : string & _arg , const std : : string & rl ) ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
virtual ~ ExecuteHook ( ) = default ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
void execute ( ) ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
private :
friend void * execute_thread ( void * arg ) ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
/**
* Name of the Hook
*/
std : : string name ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
/**
* The command to be executed
*/
std : : string cmd ;
/**
* The arguments for the command
*/
const char * c_args [ EXECUTE_HOOK_MAX_ARG ] ;
2017-05-18 17:36:26 +03:00
2019-09-09 15:43:51 +03:00
std : : string args [ EXECUTE_HOOK_MAX_ARG ] ;
2017-05-18 17:36:26 +03:00
} ;
# endif