Commit 932a376c authored by Marcus Nordenberg's avatar Marcus Nordenberg

format code

parent 55c43b58
...@@ -37,60 +37,68 @@ ...@@ -37,60 +37,68 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #if defined OS_LYNX
#include <sys/wait.h>
#elif defined OS_POSIX
#include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h>
#include "co_ver.h" #else
#include <unistd.h>
#endif
#include "co_dcli.h" #include "co_dcli.h"
#include "co_time.h"
#include "co_ver.h"
#include "ini.h" #include "ini.h"
#include "ini_rc.h" #include "ini_rc.h"
#include "rt_bck_load.h"
#include "rt_errh.h"
#include "rt_errh_msg.h"
#include "rt_errl.h"
#include "rt_ini_alias.h" #include "rt_ini_alias.h"
#include "rt_ini_event.h" #include "rt_ini_event.h"
#include "rt_bck_load.h" #include "rt_ini_load.h"
#include "rt_mh_util.h" #include "rt_ini_msg.h"
#include "rt_io_base.h" #include "rt_io_base.h"
#include "rt_redu.h"
#include "rt_lck.h" #include "rt_lck.h"
#include "rt_ini_msg.h" #include "rt_mh_util.h"
#include "rt_errh_msg.h"
#include "rt_pwr_msg.h" #include "rt_pwr_msg.h"
#include "rt_qcom.h"
#include "rt_qini.h"
#include "rt_redu.h"
#define RT_INI_PIDFILE "/run/pwr/pwr.pid\0" #define RT_INI_PIDFILE "/run/pwr/pwr.pid\0"
static ini_sContext* createContext(int argc, char** argv); static ini_sContext *createContext(int argc, char **argv);
static int checkErrors(ini_sContext* cp); static int checkErrors(ini_sContext *cp);
static pwr_tStatus events(ini_sContext* cp); static pwr_tStatus events(ini_sContext *cp);
static void daemonize(); static void daemonize();
static void create_pidfile(); static void create_pidfile();
static pwr_tStatus interactive(int argc, char** argv, ini_sContext* cp); static pwr_tStatus interactive(int argc, char **argv, ini_sContext *cp);
static pwr_tStatus stop(ini_sContext* cp); static pwr_tStatus stop(ini_sContext *cp);
static void create_locks(); static void create_locks();
static void delete_locks(); static void delete_locks();
static void load_backup(); static void load_backup();
static void logChanges(ini_sContext* cp); static void logChanges(ini_sContext *cp);
static void logCardinality(ini_sContext* cp); static void logCardinality(ini_sContext *cp);
static pwr_tStatus restart(ini_sContext* cp); static pwr_tStatus restart(ini_sContext *cp);
static pwr_tStatus terminate(); static pwr_tStatus terminate();
static pwr_tStatus start(ini_sContext* cp); static pwr_tStatus start(ini_sContext *cp);
static void usage(char*); static void usage(char *);
static void ini_errl_cb(void* userdata, char* str, char severity, static void ini_errl_cb(void *userdata, char *str, char severity,
pwr_tStatus sts, int anix, int message_type); pwr_tStatus sts, int anix, int message_type);
void handle_signal(int sig, siginfo_t* si, void* ctx); void handle_signal(int sig, siginfo_t *si, void *ctx);
static int pid_fd = -1; static int pid_fd = -1;
static char* pid_filename = NULL; static char* pid_filename = NULL;
void set_valid_time() void set_valid_time() { /* Set valid utc time */ }
{
/* Set valid utc time */
}
int main(int argc, char** argv) int main(int argc, char **argv) {
{ ini_sContext *cp;
ini_sContext* cp;
pwr_tStatus sts; pwr_tStatus sts;
set_valid_time(); set_valid_time();
...@@ -123,8 +131,7 @@ int main(int argc, char** argv) ...@@ -123,8 +131,7 @@ int main(int argc, char** argv)
exit(sts); exit(sts);
} }
static pwr_tStatus start(ini_sContext* cp) static pwr_tStatus start(ini_sContext *cp) {
{
pwr_tStatus sts; pwr_tStatus sts;
char console[80]; char console[80];
int state; int state;
...@@ -161,8 +168,8 @@ static pwr_tStatus start(ini_sContext* cp) ...@@ -161,8 +168,8 @@ static pwr_tStatus start(ini_sContext* cp)
cp->me = tree_Find(&sts, cp->nid_t, &cp->node.nid); cp->me = tree_Find(&sts, cp->nid_t, &cp->node.nid);
if (cp->me == NULL) { if (cp->me == NULL) {
errh_LogFatal( errh_LogFatal(&cp->log, "Cannot find my own node in %s\n",
&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name); cp->nodefile.name);
exit(QCOM__WEIRD); exit(QCOM__WEIRD);
} }
...@@ -246,8 +253,8 @@ static pwr_tStatus start(ini_sContext* cp) ...@@ -246,8 +253,8 @@ static pwr_tStatus start(ini_sContext* cp)
exit(sts); exit(sts);
} }
qcom_SignalOr( qcom_SignalOr(&sts, &qcom_cQini,
&sts, &qcom_cQini, ini_mEvent_newPlcInit | ini_mEvent_newPlcStart); ini_mEvent_newPlcInit | ini_mEvent_newPlcStart);
ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcLoad); ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcLoad);
ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcStart); ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcStart);
...@@ -260,7 +267,7 @@ static pwr_tStatus start(ini_sContext* cp) ...@@ -260,7 +267,7 @@ static pwr_tStatus start(ini_sContext* cp)
} }
qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini,
ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal); ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal);
sts = ini_SetAttributeAfterPlc(cp->aliasfile.name, cp->nodename, 0); sts = ini_SetAttributeAfterPlc(cp->aliasfile.name, cp->nodename, 0);
if (EVEN(sts) && sts != INI__FILE) if (EVEN(sts) && sts != INI__FILE)
...@@ -272,8 +279,7 @@ static pwr_tStatus start(ini_sContext* cp) ...@@ -272,8 +279,7 @@ static pwr_tStatus start(ini_sContext* cp)
return sts; return sts;
} }
static pwr_tStatus interactive(int argc, char** argv, ini_sContext* cp) static pwr_tStatus interactive(int argc, char **argv, ini_sContext *cp) {
{
pwr_tStatus sts; pwr_tStatus sts;
qcom_sQid qid; qcom_sQid qid;
qcom_sPut put; qcom_sPut put;
...@@ -337,8 +343,7 @@ static pwr_tStatus interactive(int argc, char** argv, ini_sContext* cp) ...@@ -337,8 +343,7 @@ static pwr_tStatus interactive(int argc, char** argv, ini_sContext* cp)
return sts; return sts;
} }
static pwr_tStatus stop(ini_sContext* cp) static pwr_tStatus stop(ini_sContext *cp) {
{
pwr_tStatus sts; pwr_tStatus sts;
qcom_sQid qid; qcom_sQid qid;
qcom_sPut put; qcom_sPut put;
...@@ -402,12 +407,11 @@ static pwr_tStatus stop(ini_sContext* cp) ...@@ -402,12 +407,11 @@ static pwr_tStatus stop(ini_sContext* cp)
return 0; return 0;
} }
static pwr_tStatus restart(ini_sContext* cp) static pwr_tStatus restart(ini_sContext *cp) {
{
pwr_tStatus sts; pwr_tStatus sts;
char time[24]; char time[24];
lst_sEntry* pl; lst_sEntry *pl;
ini_sProc* pp; ini_sProc *pp;
ini_CheckContext(&sts, cp); ini_CheckContext(&sts, cp);
...@@ -446,12 +450,12 @@ static pwr_tStatus restart(ini_sContext* cp) ...@@ -446,12 +450,12 @@ static pwr_tStatus restart(ini_sContext* cp)
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit);
qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini,
ini_mEvent_newPlcInitDone | cp->plc_sigmask, qcom_cTmoEternal); ini_mEvent_newPlcInitDone | cp->plc_sigmask, qcom_cTmoEternal);
errh_LogInfo(&cp->log, "Entering time critical period, stopping old PLC"); errh_LogInfo(&cp->log, "Entering time critical period, stopping old PLC");
qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask); qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask);
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStop); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStop);
qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini,
ini_mEvent_oldPlcStopDone | cp->plc_sigmask, qcom_cTmoEternal); ini_mEvent_oldPlcStopDone | cp->plc_sigmask, qcom_cTmoEternal);
qcom_SignalAnd(&sts, &qcom_cQini, ~ini_mEvent_oldPlcStop); qcom_SignalAnd(&sts, &qcom_cQini, ~ini_mEvent_oldPlcStop);
ini_UpdateBodies(&sts, cp, 0); ini_UpdateBodies(&sts, cp, 0);
...@@ -459,14 +463,14 @@ static pwr_tStatus restart(ini_sContext* cp) ...@@ -459,14 +463,14 @@ static pwr_tStatus restart(ini_sContext* cp)
qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask); qcom_SignalAnd(&sts, &qcom_cQini, ~cp->plc_sigmask);
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStart); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStart);
qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini,
ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal); ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal);
errh_LogInfo(&cp->log, "Time critical period over, new PLC is running"); errh_LogInfo(&cp->log, "Time critical period over, new PLC is running");
qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_swapDone); qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_swapDone);
for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL;
pp = lst_Succ(NULL, pl, &pl)) { pp = lst_Succ(NULL, pl, &pl)) {
if (pp->flags.m & ini_mProc_plc && pp->objectp) { if (pp->flags.m & ini_mProc_plc && pp->objectp) {
pwr_sClass_PlcProcess* plc = pp->objectp; pwr_sClass_PlcProcess *plc = pp->objectp;
time_GetTime(&plc->LastChgTime); time_GetTime(&plc->LastChgTime);
if (time_Dcomp(&plc->StartTime, &plc->StopTime) == 1) if (time_Dcomp(&plc->StartTime, &plc->StopTime) == 1)
...@@ -486,8 +490,7 @@ static pwr_tStatus restart(ini_sContext* cp) ...@@ -486,8 +490,7 @@ static pwr_tStatus restart(ini_sContext* cp)
return sts; return sts;
} }
static pwr_tStatus terminate() static pwr_tStatus terminate() {
{
pwr_tStatus sts; pwr_tStatus sts;
qcom_SignalAnd(&sts, &qcom_cQini, 0); qcom_SignalAnd(&sts, &qcom_cQini, 0);
...@@ -533,26 +536,26 @@ static pwr_tStatus terminate() ...@@ -533,26 +536,26 @@ static pwr_tStatus terminate()
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static int ask_yes_no(char* text) static int ask_yes_no(char *text) {
{
printf("%s ? (y|n) [n]: ", text); printf("%s ? (y|n) [n]: ", text);
printf("n\n"); printf("n\n");
return 0; return 0;
} }
static int checkErrors(ini_sContext* cp) static int checkErrors(ini_sContext *cp) {
{
if (cp->warnings == 0 && cp->errors == 0 && cp->fatals == 0) if (cp->warnings == 0 && cp->errors == 0 && cp->fatals == 0)
return 1; return 1;
if (cp->fatals > 0) { if (cp->fatals > 0) {
errh_LogFatal(&cp->log, errh_LogFatal(&cp->log,
"Found %d warning(s), %d error(s) and %d fatal error(s)", cp->warnings, "Found %d warning(s), %d error(s) and %d fatal error(s)",
cp->errors, cp->fatals); cp->warnings, cp->errors, cp->fatals);
if (cp->flags.b.ignoreFatal) { if (cp->flags.b.ignoreFatal) {
errh_LogInfo( errh_LogInfo(&cp->log,
&cp->log, "Ignoring fatal errors, errors and warnings, continued..."); "Ignoring fatal errors, errors and warnings, continued...");
return 1; return 1;
} else { } else {
return ask_yes_no("Do you want to continue"); return ask_yes_no("Do you want to continue");
...@@ -560,8 +563,8 @@ static int checkErrors(ini_sContext* cp) ...@@ -560,8 +563,8 @@ static int checkErrors(ini_sContext* cp)
} }
if (cp->errors > 0) { if (cp->errors > 0) {
errh_LogError(&cp->log, errh_LogError(&cp->log,
"Found %d warning(s), %d error(s) and %d fatal error(s)", cp->warnings, "Found %d warning(s), %d error(s) and %d fatal error(s)",
cp->errors, cp->fatals); cp->warnings, cp->errors, cp->fatals);
if (cp->flags.b.ignoreError) { if (cp->flags.b.ignoreError) {
errh_LogInfo(&cp->log, "Ignoring errors and warnings, continued..."); errh_LogInfo(&cp->log, "Ignoring errors and warnings, continued...");
return 1; return 1;
...@@ -571,8 +574,8 @@ static int checkErrors(ini_sContext* cp) ...@@ -571,8 +574,8 @@ static int checkErrors(ini_sContext* cp)
} }
if (cp->warnings > 0) { if (cp->warnings > 0) {
errh_LogWarning(&cp->log, errh_LogWarning(&cp->log,
"Found %d warning(s), %d error(s) and %d fatal error(s)", cp->warnings, "Found %d warning(s), %d error(s) and %d fatal error(s)",
cp->errors, cp->fatals); cp->warnings, cp->errors, cp->fatals);
if (cp->flags.b.ignoreWarning) { if (cp->flags.b.ignoreWarning) {
errh_LogInfo(&cp->log, "Ignoring warnings, continued..."); errh_LogInfo(&cp->log, "Ignoring warnings, continued...");
return 1; return 1;
...@@ -583,8 +586,7 @@ static int checkErrors(ini_sContext* cp) ...@@ -583,8 +586,7 @@ static int checkErrors(ini_sContext* cp)
return 1; return 1;
} }
static ini_sContext* createContext(int argc, char** argv) static ini_sContext *createContext(int argc, char **argv) {
{
int i, j; int i, j;
ini_sContext* cp; ini_sContext* cp;
pwr_tStatus sts; pwr_tStatus sts;
...@@ -601,13 +603,12 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -601,13 +603,12 @@ static ini_sContext* createContext(int argc, char** argv)
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { if (argv[i][0] == '-') {
int i_incr = 0; int i_incr = 0;
for (j = 1; for (j = 1; argv[i][j] != 0 && argv[i][j] != ' ' && argv[i][j] != ' ';
argv[i][j] != 0 && argv[i][j] != ' ' && argv[i][j] != ' ';
j++) { j++) {
switch (argv[i][j]) { switch (argv[i][j]) {
case 'a': case 'a':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -617,8 +618,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -617,8 +618,8 @@ static ini_sContext* createContext(int argc, char** argv)
i_incr = 1; i_incr = 1;
break; break;
case 'b': case 'b':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -626,8 +627,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -626,8 +627,8 @@ static ini_sContext* createContext(int argc, char** argv)
strcpy(cp->bootfile.name, argv[i + 1]); strcpy(cp->bootfile.name, argv[i + 1]);
break; break;
case 'c': case 'c':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -636,8 +637,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -636,8 +637,8 @@ static ini_sContext* createContext(int argc, char** argv)
i_incr = 1; i_incr = 1;
break; break;
case 'd': case 'd':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -652,8 +653,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -652,8 +653,8 @@ static ini_sContext* createContext(int argc, char** argv)
cp->flags.b.ignoreFatal = 1; cp->flags.b.ignoreFatal = 1;
break; break;
case 'h': case 'h':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -666,8 +667,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -666,8 +667,8 @@ static ini_sContext* createContext(int argc, char** argv)
cp->flags.b.interactive = 1; cp->flags.b.interactive = 1;
break; break;
case 'n': case 'n':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -677,13 +678,13 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -677,13 +678,13 @@ static ini_sContext* createContext(int argc, char** argv)
i_incr = 1; i_incr = 1;
break; break;
case 'p': case 'p':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
cp->flags.b.plcfile = 1; cp->flags.b.plcfile = 1;
cp->plcfile = (ini_sFile*)calloc(1, sizeof(ini_sFile)); cp->plcfile = (ini_sFile *)calloc(1, sizeof(ini_sFile));
cp->plcfile_cnt = 1; cp->plcfile_cnt = 1;
strcpy(cp->plcfile[0].name, argv[i + 1]); strcpy(cp->plcfile[0].name, argv[i + 1]);
cp->plcfile[0].logOpenFail = errh_LogInfo; cp->plcfile[0].logOpenFail = errh_LogInfo;
...@@ -691,8 +692,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -691,8 +692,8 @@ static ini_sContext* createContext(int argc, char** argv)
i_incr = 1; i_incr = 1;
break; break;
case 'q': case 'q':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -713,8 +714,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -713,8 +714,8 @@ static ini_sContext* createContext(int argc, char** argv)
cp->flags.b.ignoreWarning = 1; cp->flags.b.ignoreWarning = 1;
break; break;
case 'A': case 'A':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -727,8 +728,8 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -727,8 +728,8 @@ static ini_sContext* createContext(int argc, char** argv)
cp->flags.b.daemonize = 1; cp->flags.b.daemonize = 1;
break; break;
case 'P': case 'P':
if (i + 1 >= argc if (i + 1 >= argc ||
|| !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) { !(argv[i][j + 1] == ' ' || argv[i][j + 1] != ' ')) {
usage(argv[0]); usage(argv[0]);
exit(0); exit(0);
} }
...@@ -752,16 +753,15 @@ static ini_sContext* createContext(int argc, char** argv) ...@@ -752,16 +753,15 @@ static ini_sContext* createContext(int argc, char** argv)
return cp; return cp;
} }
static void usage(char* name) static void usage(char *name) {
{
#if defined OS_POSIX #if defined OS_POSIX
fprintf(stderr, "usage: %s -a arg -b arg -d arg -efg arg -hip arg -q arg -ru " fprintf(stderr, "usage: %s -a arg -b arg -d arg -efg arg -hip arg -q arg -ru "
"arg -s arg -vwA arg -H arg\n", "arg -s arg -vwA arg -H arg\n",
name); name);
#else #else
fprintf(stderr, fprintf(stderr,
"usage: %s -a arg -b arg -d arg -efhip arg -q arg -rvwA arg -H arg\n", "usage: %s -a arg -b arg -d arg -efhip arg -q arg -rvwA arg -H arg\n",
name); name);
#endif #endif
fprintf(stderr, " -? : give help\n"); fprintf(stderr, " -? : give help\n");
fprintf(stderr, " -a arg: use 'arg' as application file\n"); fprintf(stderr, " -a arg: use 'arg' as application file\n");
...@@ -784,20 +784,18 @@ static void usage(char* name) ...@@ -784,20 +784,18 @@ static void usage(char* name)
fprintf(stderr, " -v : verbose\n"); fprintf(stderr, " -v : verbose\n");
fprintf(stderr, " -w : ignore warnings\n"); fprintf(stderr, " -w : ignore warnings\n");
fprintf(stderr, " -A arg: use 'arg' as alias file\n"); fprintf(stderr, " -A arg: use 'arg' as alias file\n");
fprintf(stderr, fprintf(stderr, " -D : Daemonize rt_ini. Default PID file is /run/pwr/pwr.pid\n");
" -D : Daemonize rt_ini. Default PID file is /run/pwr/pwr.pid\n");
fprintf(stderr, " -p : PID file, implies -D\n"); fprintf(stderr, " -p : PID file, implies -D\n");
fprintf(stderr, " -H arg: use 'arg' as hostname\n"); fprintf(stderr, " -H arg: use 'arg' as hostname\n");
fprintf(stderr, " -N arg: use 'arg' as nodename\n"); fprintf(stderr, " -N arg: use 'arg' as nodename\n");
exit(1); exit(1);
} }
static void logChanges(ini_sContext* cp) static void logChanges(ini_sContext *cp) {
{ lst_sEntry *vl;
lst_sEntry* vl; lst_sEntry *ol;
lst_sEntry* ol; ivol_sVolume *vp;
ivol_sVolume* vp; ivol_sObject *iop;
ivol_sObject* iop;
int cre, upd, upd_io; int cre, upd, upd_io;
for (vp = lst_Succ(NULL, &cp->vol_lh, &vl); vp != NULL; for (vp = lst_Succ(NULL, &cp->vol_lh, &vl); vp != NULL;
...@@ -849,28 +847,26 @@ static void logChanges(ini_sContext* cp) ...@@ -849,28 +847,26 @@ static void logChanges(ini_sContext* cp)
upd++; upd++;
} }
errh_LogInfo(&cp->log, "Volume: %s, id: %d, cre: %d, upd_io: %d, upd: %d\n", errh_LogInfo(&cp->log, "Volume: %s, id: %d, cre: %d, upd_io: %d, upd: %d\n",
vp->volume.name, vp->vid, cre, upd_io, upd); vp->volume.name, vp->vid, cre, upd_io, upd);
} }
} }
static void logCardinality(ini_sContext* cp) static void logCardinality(ini_sContext *cp) {
{ lst_sEntry *vl;
lst_sEntry* vl; ivol_sVolume *vp;
ivol_sVolume* vp;
errh_LogInfo(&cp->log, "Cardinality: %d, bodysize: %d\n", errh_LogInfo(&cp->log, "Cardinality: %d, bodysize: %d\n",
cp->node.cardinality, cp->node.bodySize); cp->node.cardinality, cp->node.bodySize);
for (vp = lst_Succ(NULL, &cp->vol_lh, &vl); vp != NULL; for (vp = lst_Succ(NULL, &cp->vol_lh, &vl); vp != NULL;
vp = lst_Succ(NULL, vl, &vl)) vp = lst_Succ(NULL, vl, &vl))
errh_LogInfo(&cp->log, errh_LogInfo(
"Volume: %s, id: %d, cardinality: %d, bodysize: %d\n", vp->volume.name, &cp->log, "Volume: %s, id: %d, cardinality: %d, bodysize: %d\n",
vp->vid, vp->volume.cardinality, vp->volume.rbodySize); vp->volume.name, vp->vid, vp->volume.cardinality, vp->volume.rbodySize);
} }
static pwr_tStatus events(ini_sContext* cp) static pwr_tStatus events(ini_sContext *cp) {
{ lst_sEntry *pl;
lst_sEntry* pl; ini_sProc *pp;
ini_sProc* pp;
pid_t pid; pid_t pid;
pid_t last_pid = 1; pid_t last_pid = 1;
pwr_tStatus sts = INI__SUCCESS; pwr_tStatus sts = INI__SUCCESS;
...@@ -913,7 +909,7 @@ static pwr_tStatus events(ini_sContext* cp) ...@@ -913,7 +909,7 @@ static pwr_tStatus events(ini_sContext* cp)
s += len + 1; s += len + 1;
totlen += len + 1; totlen += len + 1;
} }
argv = (char**)calloc(sizeof(void*), argc); argv = (char **)calloc(sizeof(void *), argc);
for (i = 0, s = get.data; i < argc; i++) { for (i = 0, s = get.data; i < argc; i++) {
len = strlen(s); len = strlen(s);
argv[i] = s; argv[i] = s;
...@@ -948,7 +944,7 @@ static pwr_tStatus events(ini_sContext* cp) ...@@ -948,7 +944,7 @@ static pwr_tStatus events(ini_sContext* cp)
pp = lst_Succ(NULL, pl, &pl)) { pp = lst_Succ(NULL, pl, &pl)) {
if (pp->proc.pid == pid) { if (pp->proc.pid == pid) {
errh_LogInfo(&cp->log, "Process %s exited with status %d", errh_LogInfo(&cp->log, "Process %s exited with status %d",
pp->proc.name, status); pp->proc.name, status);
break; break;
} }
} }
...@@ -958,8 +954,7 @@ static pwr_tStatus events(ini_sContext* cp) ...@@ -958,8 +954,7 @@ static pwr_tStatus events(ini_sContext* cp)
return INI__SUCCESS; return INI__SUCCESS;
} }
static void create_locks() static void create_locks() {
{
pwr_tStatus sts; pwr_tStatus sts;
lck_Create(&sts, lck_eLock_Time); lck_Create(&sts, lck_eLock_Time);
...@@ -973,8 +968,7 @@ static void create_locks() ...@@ -973,8 +968,7 @@ static void create_locks()
errh_Fatal("lock create NMps, %m", sts); errh_Fatal("lock create NMps, %m", sts);
} }
static void delete_locks() static void delete_locks() {
{
pwr_tStatus sts; pwr_tStatus sts;
lck_Delete(&sts, lck_eLock_Time); lck_Delete(&sts, lck_eLock_Time);
...@@ -988,24 +982,23 @@ static void delete_locks() ...@@ -988,24 +982,23 @@ static void delete_locks()
errh_Fatal("lock delete NMps, %m", sts); errh_Fatal("lock delete NMps, %m", sts);
} }
static void load_backup() static void load_backup() {
{
pwr_tObjid oid; pwr_tObjid oid;
pwr_sClass_AvArea* avp; pwr_sClass_AvArea *avp;
pwr_sClass_DvArea* dvp; pwr_sClass_DvArea *dvp;
pwr_sClass_IvArea* ivp; pwr_sClass_IvArea *ivp;
pwr_sClass_ATvArea* atvp; pwr_sClass_ATvArea *atvp;
pwr_sClass_DTvArea* dtvp; pwr_sClass_DTvArea *dtvp;
pwr_sClass_SvArea* svp; pwr_sClass_SvArea *svp;
pwr_sClass_InitArea* iavp; pwr_sClass_InitArea *iavp;
pwr_sClass_InitArea* idvp; pwr_sClass_InitArea *idvp;
pwr_sClass_InitArea* iivp; pwr_sClass_InitArea *iivp;
pwr_sClass_InitArea* iatvp; pwr_sClass_InitArea *iatvp;
pwr_sClass_InitArea* idtvp; pwr_sClass_InitArea *idtvp;
pwr_sClass_InitArea* isvp; pwr_sClass_InitArea *isvp;
pwr_tStatus sts; pwr_tStatus sts;
int i; int i;
pwr_sClass_IOHandler* iop; pwr_sClass_IOHandler *iop;
pwr_sAttrRef aref; pwr_sAttrRef aref;
sts = io_get_iohandler_object(&iop, NULL); sts = io_get_iohandler_object(&iop, NULL);
...@@ -1020,7 +1013,7 @@ static void load_backup() ...@@ -1020,7 +1013,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&avp); sts = gdh_ObjidToPointer(oid, (void *)&avp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &avp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &avp), %m", sts);
return; return;
...@@ -1032,7 +1025,7 @@ static void load_backup() ...@@ -1032,7 +1025,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&iavp); sts = gdh_ObjidToPointer(oid, (void *)&iavp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &iavp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &iavp), %m", sts);
return; return;
...@@ -1044,7 +1037,7 @@ static void load_backup() ...@@ -1044,7 +1037,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&dvp); sts = gdh_ObjidToPointer(oid, (void *)&dvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &dvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &dvp), %m", sts);
return; return;
...@@ -1056,7 +1049,7 @@ static void load_backup() ...@@ -1056,7 +1049,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&idvp); sts = gdh_ObjidToPointer(oid, (void *)&idvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &idvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &idvp), %m", sts);
return; return;
...@@ -1068,7 +1061,7 @@ static void load_backup() ...@@ -1068,7 +1061,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&ivp); sts = gdh_ObjidToPointer(oid, (void *)&ivp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &ivp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &ivp), %m", sts);
return; return;
...@@ -1080,7 +1073,7 @@ static void load_backup() ...@@ -1080,7 +1073,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&atvp); sts = gdh_ObjidToPointer(oid, (void *)&atvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &atvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &atvp), %m", sts);
return; return;
...@@ -1092,7 +1085,7 @@ static void load_backup() ...@@ -1092,7 +1085,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&dtvp); sts = gdh_ObjidToPointer(oid, (void *)&dtvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &dtvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &dtvp), %m", sts);
return; return;
...@@ -1104,7 +1097,7 @@ static void load_backup() ...@@ -1104,7 +1097,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&svp); sts = gdh_ObjidToPointer(oid, (void *)&svp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &svp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &svp), %m", sts);
return; return;
...@@ -1116,7 +1109,7 @@ static void load_backup() ...@@ -1116,7 +1109,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&iivp); sts = gdh_ObjidToPointer(oid, (void *)&iivp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &iivp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &iivp), %m", sts);
return; return;
...@@ -1128,7 +1121,7 @@ static void load_backup() ...@@ -1128,7 +1121,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&iatvp); sts = gdh_ObjidToPointer(oid, (void *)&iatvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &iatvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &iatvp), %m", sts);
return; return;
...@@ -1140,7 +1133,7 @@ static void load_backup() ...@@ -1140,7 +1133,7 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&idtvp); sts = gdh_ObjidToPointer(oid, (void *)&idtvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &idtvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &idtvp), %m", sts);
return; return;
...@@ -1152,14 +1145,14 @@ static void load_backup() ...@@ -1152,14 +1145,14 @@ static void load_backup()
return; return;
} }
sts = gdh_ObjidToPointer(oid, (void*)&isvp); sts = gdh_ObjidToPointer(oid, (void *)&isvp);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_ObjidToPointer(oid, (void *) &isvp), %m", sts); errh_Error("gdh_ObjidToPointer(oid, (void *) &isvp), %m", sts);
return; return;
} }
for (i = 0; i < iop->AvCount; i++) { for (i = 0; i < iop->AvCount; i++) {
pwr_tFloat32* ifp = gdh_TranslateRtdbPointer(iavp->Value[i]); pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]);
avp->Value[i] = *ifp; avp->Value[i] = *ifp;
} }
...@@ -1184,18 +1177,18 @@ static void load_backup() ...@@ -1184,18 +1177,18 @@ static void load_backup()
} }
for (i = 0; i < iop->SvCount; i++) { for (i = 0; i < iop->SvCount; i++) {
char* istrp = gdh_TranslateRtdbPointer(isvp->Value[i]); char *istrp = gdh_TranslateRtdbPointer(isvp->Value[i]);
strncpy(svp->Value[i], istrp, sizeof(svp->Value[0])); strncpy(svp->Value[i], istrp, sizeof(svp->Value[0]));
} }
typedef struct { typedef struct {
union { union {
pwr_tFloat32* f; pwr_tFloat32 *f;
pwr_tInt32* i; pwr_tInt32 *i;
pwr_tBoolean* b; pwr_tBoolean *b;
pwr_tTime* at; pwr_tTime *at;
pwr_tDeltaTime* dt; pwr_tDeltaTime *dt;
pwr_tString80* str; pwr_tString80 *str;
} actval_p; } actval_p;
pwr_tUInt32 validx; pwr_tUInt32 validx;
union { union {
...@@ -1216,14 +1209,14 @@ static void load_backup() ...@@ -1216,14 +1209,14 @@ static void load_backup()
} ini_sRestoreSig; } ini_sRestoreSig;
// Store ActualValue pointers // Store ActualValue pointers
ini_sRestoreSig* rsav = calloc(sizeof(ini_sRestoreSig), iop->AvCount); ini_sRestoreSig *rsav = calloc(sizeof(ini_sRestoreSig), iop->AvCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Av, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Av, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Av, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Av, &aref, &aref)) {
if (i >= iop->AvCount) if (i >= iop->AvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsav[i].op.av); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsav[i].op.av);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1234,14 +1227,14 @@ static void load_backup() ...@@ -1234,14 +1227,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsdv = calloc(sizeof(ini_sRestoreSig), iop->DvCount); ini_sRestoreSig *rsdv = calloc(sizeof(ini_sRestoreSig), iop->DvCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Dv, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Dv, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Dv, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Dv, &aref, &aref)) {
if (i >= iop->DvCount) if (i >= iop->DvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsdv[i].op.dv); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsdv[i].op.dv);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1252,14 +1245,14 @@ static void load_backup() ...@@ -1252,14 +1245,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsiv = calloc(sizeof(ini_sRestoreSig), iop->IvCount); ini_sRestoreSig *rsiv = calloc(sizeof(ini_sRestoreSig), iop->IvCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Iv, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Iv, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Iv, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Iv, &aref, &aref)) {
if (i >= iop->IvCount) if (i >= iop->IvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsiv[i].op.iv); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsiv[i].op.iv);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1270,14 +1263,14 @@ static void load_backup() ...@@ -1270,14 +1263,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsatv = calloc(sizeof(ini_sRestoreSig), iop->ATvCount); ini_sRestoreSig *rsatv = calloc(sizeof(ini_sRestoreSig), iop->ATvCount);
i = 1; i = 1;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_ATv, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_ATv, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_ATv, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_ATv, &aref, &aref)) {
if (i >= iop->ATvCount) if (i >= iop->ATvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsatv[i].op.atv); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsatv[i].op.atv);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer ATv, %m", sts); errh_Error("gdh_AttrRefToPointer ATv, %m", sts);
return; return;
...@@ -1288,14 +1281,14 @@ static void load_backup() ...@@ -1288,14 +1281,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsdtv = calloc(sizeof(ini_sRestoreSig), iop->DTvCount); ini_sRestoreSig *rsdtv = calloc(sizeof(ini_sRestoreSig), iop->DTvCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_DTv, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_DTv, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_DTv, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_DTv, &aref, &aref)) {
if (i >= iop->DTvCount) if (i >= iop->DTvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsdtv[i].op.dtv); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsdtv[i].op.dtv);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer DTv, %m", sts); errh_Error("gdh_AttrRefToPointer DTv, %m", sts);
return; return;
...@@ -1306,14 +1299,14 @@ static void load_backup() ...@@ -1306,14 +1299,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rssv = calloc(sizeof(ini_sRestoreSig), iop->SvCount); ini_sRestoreSig *rssv = calloc(sizeof(ini_sRestoreSig), iop->SvCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Sv, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Sv, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Sv, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Sv, &aref, &aref)) {
if (i >= iop->SvCount) if (i >= iop->SvCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rssv[i].op.sv); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rssv[i].op.sv);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Sv, %m", sts); errh_Error("gdh_AttrRefToPointer Sv, %m", sts);
return; return;
...@@ -1324,14 +1317,14 @@ static void load_backup() ...@@ -1324,14 +1317,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsai = calloc(sizeof(ini_sRestoreSig), iop->AiCount); ini_sRestoreSig *rsai = calloc(sizeof(ini_sRestoreSig), iop->AiCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ai, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ai, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Ai, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Ai, &aref, &aref)) {
if (i >= iop->AiCount) if (i >= iop->AiCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsai[i].op.ai); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsai[i].op.ai);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1342,14 +1335,14 @@ static void load_backup() ...@@ -1342,14 +1335,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsao = calloc(sizeof(ini_sRestoreSig), iop->AoCount); ini_sRestoreSig *rsao = calloc(sizeof(ini_sRestoreSig), iop->AoCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ao, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ao, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Ao, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Ao, &aref, &aref)) {
if (i >= iop->AoCount) if (i >= iop->AoCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsao[i].op.ao); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsao[i].op.ao);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1360,14 +1353,14 @@ static void load_backup() ...@@ -1360,14 +1353,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsii = calloc(sizeof(ini_sRestoreSig), iop->IiCount); ini_sRestoreSig *rsii = calloc(sizeof(ini_sRestoreSig), iop->IiCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ii, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Ii, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Ii, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Ii, &aref, &aref)) {
if (i >= iop->IiCount) if (i >= iop->IiCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsii[i].op.ii); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsii[i].op.ii);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1378,14 +1371,14 @@ static void load_backup() ...@@ -1378,14 +1371,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsio = calloc(sizeof(ini_sRestoreSig), iop->IoCount); ini_sRestoreSig *rsio = calloc(sizeof(ini_sRestoreSig), iop->IoCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Io, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Io, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Io, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Io, &aref, &aref)) {
if (i >= iop->IoCount) if (i >= iop->IoCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsio[i].op.io); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsio[i].op.io);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1396,14 +1389,14 @@ static void load_backup() ...@@ -1396,14 +1389,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsdi = calloc(sizeof(ini_sRestoreSig), iop->DiCount); ini_sRestoreSig *rsdi = calloc(sizeof(ini_sRestoreSig), iop->DiCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Di, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Di, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Di, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Di, &aref, &aref)) {
if (i >= iop->DiCount) if (i >= iop->DiCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsdi[i].op.di); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsdi[i].op.di);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1414,14 +1407,14 @@ static void load_backup() ...@@ -1414,14 +1407,14 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsdo = calloc(sizeof(ini_sRestoreSig), iop->DoCount); ini_sRestoreSig *rsdo = calloc(sizeof(ini_sRestoreSig), iop->DoCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Do, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Do, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Do, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Do, &aref, &aref)) {
if (i >= iop->DoCount) if (i >= iop->DoCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsdo[i].op.dox); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsdo[i].op.dox);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1432,15 +1425,15 @@ static void load_backup() ...@@ -1432,15 +1425,15 @@ static void load_backup()
i++; i++;
} }
ini_sRestoreSig* rsco = calloc(sizeof(ini_sRestoreSig), iop->CoCount); ini_sRestoreSig *rsco = calloc(sizeof(ini_sRestoreSig), iop->CoCount);
pwr_tInt32** rscoa = calloc(sizeof(pwr_tInt32*), iop->CoCount); pwr_tInt32 **rscoa = calloc(sizeof(pwr_tInt32 *), iop->CoCount);
i = 0; i = 0;
for (sts = gdh_GetClassListAttrRef(pwr_cClass_Co, &aref); ODD(sts); for (sts = gdh_GetClassListAttrRef(pwr_cClass_Co, &aref); ODD(sts);
sts = gdh_GetNextAttrRef(pwr_cClass_Co, &aref, &aref)) { sts = gdh_GetNextAttrRef(pwr_cClass_Co, &aref, &aref)) {
if (i >= iop->CoCount) if (i >= iop->CoCount)
break; break;
sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress*)&rsco[i].op.co); sts = gdh_AttrRefToPointer(&aref, (pwr_tAddress *)&rsco[i].op.co);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error("gdh_AttrRefToPointer Iv, %m", sts); errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
return; return;
...@@ -1565,15 +1558,14 @@ static void load_backup() ...@@ -1565,15 +1558,14 @@ static void load_backup()
} }
for (i = 0; i < iop->SvCount; i++) { for (i = 0; i < iop->SvCount; i++) {
char* istrp = gdh_TranslateRtdbPointer(isvp->Value[i]); char *istrp = gdh_TranslateRtdbPointer(isvp->Value[i]);
strncpy(istrp, svp->Value[i], 80); strncpy(istrp, svp->Value[i], 80);
} }
} }
static void ini_errl_cb(void* userdata, char* str, char severity, static void ini_errl_cb(void *userdata, char *str, char severity,
pwr_tStatus sts, int anix, int message_type) pwr_tStatus sts, int anix, int message_type) {
{ ini_sContext *cp = (ini_sContext *)userdata;
ini_sContext* cp = (ini_sContext*)userdata;
if (anix == 0 || !cp->np) if (anix == 0 || !cp->np)
return; return;
...@@ -1603,7 +1595,7 @@ static void ini_errl_cb(void* userdata, char* str, char severity, ...@@ -1603,7 +1595,7 @@ static void ini_errl_cb(void* userdata, char* str, char severity,
} }
cp->np->ProcMsgSeverity[anix - 1] = sts; cp->np->ProcMsgSeverity[anix - 1] = sts;
strncpy(cp->np->ProcMessage[anix - 1], &str[49], strncpy(cp->np->ProcMessage[anix - 1], &str[49],
sizeof(cp->np->ProcMessage[0])); sizeof(cp->np->ProcMessage[0]));
cp->np->ProcMessage[anix - 1][sizeof(cp->np->ProcMessage[0]) - 1] = 0; cp->np->ProcMessage[anix - 1][sizeof(cp->np->ProcMessage[0]) - 1] = 0;
break; break;
case errh_eMsgType_Status: case errh_eMsgType_Status:
...@@ -1616,8 +1608,7 @@ static void ini_errl_cb(void* userdata, char* str, char severity, ...@@ -1616,8 +1608,7 @@ static void ini_errl_cb(void* userdata, char* str, char severity,
* @brief create_pidfile Creates a pidfile for the process for things like * @brief create_pidfile Creates a pidfile for the process for things like
* systemd to keep track of. * systemd to keep track of.
*/ */
static void create_pidfile() static void create_pidfile() {
{
char str[256]; char str[256];
if (pid_filename == NULL) if (pid_filename == NULL)
...@@ -1673,7 +1664,7 @@ static void daemonize() ...@@ -1673,7 +1664,7 @@ static void daemonize()
chdir("/"); chdir("/");
// Close all file descriptors // Close all file descriptors
for (fd = sysconf(_SC_OPEN_MAX); fd > 0; fd--) for (int fd = sysconf(_SC_OPEN_MAX); fd > 0; fd--)
close(fd); close(fd);
// Reopen some fds // Reopen some fds
...@@ -1686,9 +1677,9 @@ static void daemonize() ...@@ -1686,9 +1677,9 @@ static void daemonize()
act.sa_sigaction = handle_signal; act.sa_sigaction = handle_signal;
act.sa_flags |= SA_SIGINFO; act.sa_flags |= SA_SIGINFO;
if ((sigemptyset(&act.sa_mask) == -1) if ((sigemptyset(&act.sa_mask) == -1) ||
|| (sigaction(SIGTERM, &act, NULL) == -1) (sigaction(SIGTERM, &act, NULL) == -1) ||
|| (sigaction(SIGHUP, &act, NULL) == -1)) { (sigaction(SIGHUP, &act, NULL) == -1)) {
perror("Could not set up signal handlers for rt_ini"); perror("Could not set up signal handlers for rt_ini");
} }
...@@ -1730,14 +1721,13 @@ static void daemonize() ...@@ -1730,14 +1721,13 @@ static void daemonize()
/** /**
* @brief handle_signal * @brief handle_signal
*/ */
void handle_signal(int sig, siginfo_t* si, void* ctx) void handle_signal(int sig, siginfo_t *si, void *ctx) {
{ ini_sContext *cp = (ini_sContext *)ctx;
ini_sContext* cp = (ini_sContext*)ctx;
switch (sig) { switch (sig) {
case SIGTERM: case SIGTERM:
errh_LogInfo( errh_LogInfo(&cp->log, "SIGNAL CAUGHT (%d). Exiting!\n", sig,
&cp->log, "SIGNAL CAUGHT (%d). Exiting!\n", sig, cp->node.bodySize); cp->node.bodySize);
stop(cp); stop(cp);
// running = 0; // running = 0;
if (cp->flags.b.daemonize) { if (cp->flags.b.daemonize) {
...@@ -1752,8 +1742,8 @@ void handle_signal(int sig, siginfo_t* si, void* ctx) ...@@ -1752,8 +1742,8 @@ void handle_signal(int sig, siginfo_t* si, void* ctx)
} }
break; break;
case SIGHUP: case SIGHUP:
errh_LogInfo( errh_LogInfo(&cp->log, "SIGNAL CAUGHT (%d). Restarting!\n", sig,
&cp->log, "SIGNAL CAUGHT (%d). Restarting!\n", sig, cp->node.bodySize); cp->node.bodySize);
// TODO restart :) // TODO restart :)
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment