Skip to content

Commit

Permalink
OMI changes to apply log settings dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
rahsing committed Oct 27, 2020
1 parent 2cd827b commit 0091017
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 3 deletions.
55 changes: 55 additions & 0 deletions Unix/agent/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <provmgr/provmgr.h>
#include <pal/strings.h>
#include <base/log.h>
#include <base/conf.h>
#include <base/env.h>
#include <base/paths.h>
#include <base/omigetopt.h>
Expand All @@ -22,6 +23,7 @@
#include <sys/resource.h>
#include <pwd.h>
#include <grp.h>
#include <signal.h>

STRAND_DEBUGNAME( IdleNotification )

Expand Down Expand Up @@ -85,6 +87,56 @@ static void FUNCTION_NEVER_RETURNS err(const ZChar* fmt, ...)
exit(1);
}

void ResetLog()
{
char path[PAL_MAX_PATH_SIZE];
Conf* conf;

/* Form the configuration file path */
Strlcpy(path, OMI_GetPath(ID_CONFIGFILE), sizeof(path));

/* Open the configuration file */
conf = Conf_Open(path);
if (!conf)
{
err(ZT("failed to open configuration file: %s"), scs(path));
}

/* For each key=value pair in configuration file */
for (;;)
{
const char* key;
const char* value;
int r = Conf_Read(conf, &key, &value);

if (r == -1)
{
err(ZT("%s: %s\n"), path, scs(Conf_Error(conf)));
}

if (r == 1)
break;

if (strcmp(key, "loglevel") == 0)
{
Log_SetLevelFromString(value);
}
}

/* Close configuration file */
Conf_Close(conf);

return;
}

void HandleSIGUSR2(int sig)
{
if(sig==SIGUSR2)
{
ResetLog();
}
}

/* enable core dump for current process */
static void _EnableCoreDump()
{
Expand Down Expand Up @@ -370,6 +422,9 @@ int agent_main(int argc, const char* argv[])
}
}

/* Watch for SIGUSR2 signals */
SetSignalHandler(SIGUSR2, HandleSIGUSR2);

/* selector */
{
/* Initialize the network */
Expand Down
45 changes: 43 additions & 2 deletions Unix/configeditor/configeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include <list>
#include <sstream>
#include <string>

#include <base/pidfile.h>
#include <base/omigetopt.h>
#include <pal/format.h>
#include <pal/strings.h>
#include <signal.h>

using namespace std;

Expand All @@ -36,6 +37,8 @@ OPTIONS:\n\
-h, --help Print this help message.\n\
-v, --version Print version information.\n\
--debug Enable debug output.\n\
--reconfigure Apply omiserver.conf file changes dynamically\n\
Currently we are only supporting loglevel\n\
\n\
Actions:\n\
\n\
Expand Down Expand Up @@ -95,12 +98,13 @@ struct Options

bool comment;
bool uncomment;
bool reconfig;
string add;
string remove;
string set;
string query;

Options() : debug(false), help(false), comment(false), uncomment(false)
Options() : debug(false), help(false), comment(false), uncomment(false), reconfig(false)
{
}
};
Expand Down Expand Up @@ -130,6 +134,7 @@ static void GetCommandLineOptions(
"--uncomment",
"-q:",
"--query:",
"--reconfigure",
NULL
};

Expand Down Expand Up @@ -213,6 +218,10 @@ static void GetCommandLineOptions(
if (options.query.find(",") != string::npos)
err(ZT("Not allowed to query element with embedded comma: %s"), scs(state.arg));
}
else if (strcmp(state.opt, "--reconfigure") == 0)
{
options.reconfig = true;
}
else
{
err(ZT("Invalid option specified: %s"), scs(state.opt));
Expand Down Expand Up @@ -307,6 +316,8 @@ int MI_MAIN_CALL main(int argc, const char** argv)

// Get command-line options.
Options opts;
int status = -1;
int pid = -1;

GetCommandLineOptions(argc, argv, opts);

Expand All @@ -316,6 +327,36 @@ int MI_MAIN_CALL main(int argc, const char** argv)
Ftprintf(stderr, USAGE, arg0);
exit(1);
}

//For Reconfigure setting dynamically
if(opts.reconfig)
{
status = PIDFile_Read(&pid);
if (!status && pid != -1)
{
if(kill(pid, SIGUSR2) == 0)
{
//Send signal to all omiagents
#if defined(linux)
system("ps -A -o pid,comm | awk '$2~/omiagent/{print $1}' | xargs -r kill -s SIGUSR2");
#elif defined(sun)
system("ps -A -o pid,comm | awk '$2~/omiagent/{print $1}' | xargs kill -s USR2");
#else
system("ps -A -o pid,comm | awk '$2~/omiagent/{print $1}' | xargs kill -s SIGUSR2");
#endif
Ftprintf(stderr, ZT("Settings has been applied Dynamically\n"));
}
else
{
Ftprintf(stderr, ZT("Must have root privileges for this operation.\nNot able to communicate with OMI Server\n"));
}
}
else
{
err(ZT("Server is not running\n"));
}
exit(1);
}

// Check number of arguments.
if (argc != 2)
Expand Down
4 changes: 3 additions & 1 deletion Unix/engine/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ int enginemain(int argc, const char* argv[])
{
err(ZT("cannot set sighandler, errno %d"), errno);
}


/* Watch for SIGUSR2 signals */
SetSignalHandler(SIGUSR2, HandleSIGUSR2);
#endif

/* Change directory to 'rundir' */
Expand Down
3 changes: 3 additions & 0 deletions Unix/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ int servermain(int argc, const char* argv[], const char *envp[])

/* Watch for SIGCHLD signals */
SetSignalHandler(SIGCHLD, HandleSIGCHLD);

/* Watch for SIGUSR2 signals */
SetSignalHandler(SIGUSR2, HandleSIGUSR2);
#endif

/* Change directory to 'rundir' */
Expand Down
1 change: 1 addition & 0 deletions Unix/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void GetConfigFileOptions();
void HandleSIGTERM(int sig);
void HandleSIGHUP(int sig);
void HandleSIGUSR1(int sig);
void HandleSIGUSR2(int sig);
void HandleSIGCHLD(int sig);
void RequestCallback(_Inout_ InteractionOpenParams* interactionParams);
void FUNCTION_NEVER_RETURNS err(const ZChar* fmt, ...);
Expand Down
47 changes: 47 additions & 0 deletions Unix/server/servercommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,41 @@ void OpenLogFile()
}
}

void ResetLog()
{
char path[PAL_MAX_PATH_SIZE];
Conf* conf;
/* Form the configuration file path */
Strlcpy(path, OMI_GetPath(ID_CONFIGFILE), sizeof(path));
/* Open the configuration file */
conf = Conf_Open(path);
if (!conf)
{
err(ZT("failed to open configuration file: %s"), scs(path));
}
/* For each key=value pair in configuration file */
for (;;)
{
const char* key;
const char* value;
int r = Conf_Read(conf, &key, &value);
if (r == -1)
{
err(ZT("%s: %s\n"), path, scs(Conf_Error(conf)));
}
if (r == 1)
break;

if (strcmp(key, "loglevel") == 0)
{
Log_SetLevelFromString(value);
}
}
/* Close configuration file */
Conf_Close(conf);
return;
}

#if defined(CONFIG_POSIX)

void HandleSIGTERM(int sig)
Expand Down Expand Up @@ -521,6 +556,18 @@ void HandleSIGCHLD(int sig)
}
}

void HandleSIGUSR2(int sig)
{
if(sig==SIGUSR2)
{
if (serverType == OMI_SERVER && s_dataPtr->enginePid > 0 && getpid() != s_dataPtr->enginePid)
{
kill(s_dataPtr->enginePid, SIGUSR2);
}
ResetLog();
}
}

#endif /* defined(CONFIG_POSIX) */

void _ParsePermissionGroups(PermissionGroups *list, char *value)
Expand Down

0 comments on commit 0091017

Please sign in to comment.