예제 #1
0
//call error if gid/uid operation failed, so no return value needed
//@param uid user id to set to current process, 0 means keep current(daemon) value
//@param gid group id to set to current process, 0 means keep current(daemon) value
//@param id internal id of the app (nothing related to posix call)
//Note: this function also sets supplementary group(s) when uid is provided
static void set_uid_gids(uid_t uid, gid_t gid, uint32_t id)
{
    SWI_LOG("APPMON", DEBUG, "set_uid_gids: uid=%d, gid%d\n", uid, gid);
    if (gid && setgid(gid))
    {
        SWI_LOG("APPMON", ERROR, "Child: id= %d, setgid failed :%s\n", id, strerror(errno));
        exit(EXIT_FAILURE);
    }
    if (uid)
    {

        //supplementary groups
        const struct passwd *user = NULL;
        user = getpwuid(uid);
        if (NULL == user)
        {
            SWI_LOG("APPMON", ERROR, "Child: id= %d, getpwuid failed :%s\n", id, strerror(errno));
            exit(EXIT_FAILURE);
        }
        //initgroup second arg is one more group to add (in addition to all supplementary groups found):
        //use provided gid or user default group.
        if (-1 == initgroups(user->pw_name, gid ? gid : user->pw_gid))
        {
            SWI_LOG("APPMON", ERROR, "Child: initgroups failed: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }

        if (setuid(uid))
        {
            SWI_LOG("APPMON", ERROR, "Child: id= %d, setuid failed :%s\n", id, strerror(errno));
            exit(EXIT_FAILURE);
        }
    }
}
예제 #2
0
static char* fill_output_buf(char* fmt, ...)
{
    if (NULL == output_buf)
    {
        output_buf = malloc(output_bufsize);
        if (NULL == output_buf)
        {
            SWI_LOG("APPMON", ERROR, "fill_output_buf: malloc error\n");
            return NULL;
        }
    }
    va_list argp;
    va_start(argp, fmt);
    size_t towrite = vsnprintf(output_buf, output_bufsize, fmt, argp);
    va_end(argp);
    if (towrite > output_bufsize)
    {
        output_bufsize = towrite + 128;
        output_buf = realloc(output_buf, output_bufsize);
        if (NULL == output_buf)
        {
            SWI_LOG("APPMON", ERROR, "fill_output_buf: realloc error\n");
            return NULL;
        }
        va_start(argp, fmt);
        vsnprintf(output_buf, output_bufsize, fmt, argp);
        va_end(argp);
    }
    return output_buf;
}
예제 #3
0
/*
 * Simple Lua Signal command to send an event to an Lua VM using Lua Signal.
 *
 * Usage: luasignalcmd Lua_Signal_port_number signal_emitter signal_event [ event_param ]*
 *
 * Signal is sent to atoi(Lua_Signal_port_number), please refer to atoi() behavior.
 * All command params are mandatory except event params.
 * All signal parts (emitter, event, params) are sent as string only, see Lua Signal doc to get more details.
 */
int main(int argc, char** argv)
{
  int port = 0;
  //to use luaSignal API
  static LuaSignalCtx* luaSigCtx = NULL;
  const char* listen_emitters[] = { 0 };
  swi_status_t res;
  if (argc < 3)
  {
    SWI_LOG("LUASIGTRC", ERROR, "Param errors: need at least 2 params: EMITTER, EVENT\n");
    return 1;
  }

  port = atoi(argv[1]);
  if(port == 0){
    SWI_LOG("LUASIGTRC", ERROR, "Param error: first param must to be Lua signal port number\n");
    return 1;
  }

  res = LUASIGNAL_Init(&luaSigCtx, port, listen_emitters, NULL);
  if (SWI_STATUS_OK != res)
  {
    SWI_LOG("LUASIGTRC", ERROR, "LUASIGNAL_Init failed with error [%d], exiting\n", res);
    return 1;
  }

  res = LUASIGNAL_SignalT(luaSigCtx, argv[2], argv[3], (const char**)argv+4);
  if (SWI_STATUS_OK != res){
    SWI_LOG("LUASIGTRC", ERROR, "LUASIGNAL_SignalT failed with error [%d]\n", res);
  }

  LUASIGNAL_Destroy(luaSigCtx);
  return 0;
}
예제 #4
0
static app_t* add_app(char* wd, char* prog, int privileged)
{
  app_t* app = malloc(sizeof(app_t) + strlen(prog) + 1 + strlen(wd) + 1);
  if (NULL == app)
  {
    SWI_LOG("APPMON", ERROR, "add_app error: malloc error=[%s]\n", strerror(errno));
    return NULL;
  }

  app->pid = -1;
  app->wd = (char*) app + sizeof(app_t);
  app->prog = (char*) app + sizeof(app_t) + strlen(wd) + 1;
  strcpy(app->prog, prog);
  strcpy(app->wd, wd);
  app->status = KILLED; //application is not running and can be started by default
  app->last_exit_code = -1; //never died yet!
  app->last_exit_status = "App has never died yet"; //never died yet!
  app->start_count = 0; //never started yet!
  app->id = ++next_app_id;
  app->privileged = privileged;
  swi_status_t res = 0;
  if (SWI_STATUS_OK != (res = PointerList_PushLast(apps, app)))
  {
    SWI_LOG("APPMON", ERROR, "add_app error: PointerList_PushLast failed[AwtStatus=%d]\n", res);
    free(app);
    return NULL;
  }
  return app;
}
예제 #5
0
static void sms_handler(const char *sender, const char *message)
{
  SWI_LOG("SMS_TEST", DEBUG, "%s: sender=%s, message=%s\n", __FUNCTION__, sender, message);
  if (!strcmp(sender, PHONE_NUMBER) && !strcmp(message, MESSAGE))
    {
      SWI_LOG("SMS_TEST", DEBUG, "%s: sms matched !\n", __FUNCTION__);
      waiting_for_sms = 0;
    }
}
예제 #6
0
rc_ReturnCode_t swi_sms_Unregister(swi_sms_regId_t regId)
{
  rc_ReturnCode_t res;
  char *payload, *respPayload;
  size_t payloadLen;
  uint32_t respPayloadLen;
  cb_list_t *entry, *tmp;
  yajl_gen gen;

  for (entry = cb_list; entry; entry = entry->next)
    if (entry == regId)
      break;
  if (entry == NULL)
    return RC_BAD_PARAMETER;

  YAJL_GEN_ALLOC(gen);

  YAJL_GEN_INTEGER(entry->regId, "regId");

  YAJL_GEN_GET_BUF(payload, payloadLen);

  res = emp_send_and_wait_response(EMP_UNREGISTERSMSLISTENER, 0, payload, payloadLen, &respPayload, &respPayloadLen);
  yajl_gen_clear(gen);
  yajl_gen_free(gen);

  if (res != RC_OK)
  {
    SWI_LOG("SMS", ERROR, "Error while unregister sms, res=%d\n", res);
    SWI_LOG("SMS", ERROR, "got error msg=%s\n", respPayload);
    goto quit;
  }

  pthread_mutex_lock(&handler_lock);
  if (cb_list == regId)
  {
    free(cb_list);
    cb_list = NULL;
  }
  else
  {
    for (entry = cb_list; entry; entry = entry->next)
    {
      if (entry->next == regId)
      {
    break;
      }
    }
    tmp = entry->next;
    entry->next = tmp->next;
    free(tmp->payload);
    free(tmp);
  }
  pthread_mutex_unlock(&handler_lock);
quit:
  free(respPayload);
  return res;
}
예제 #7
0
static rc_ReturnCode_t newSmsHdlr(uint32_t payloadsize, char* payload)
{
  int regId;
  rc_ReturnCode_t res = RC_OK;
  cb_list_t *entry;
  char *sender, *message, *jsonPayload;
  yajl_val yval;

  jsonPayload = malloc(payloadsize + 1);
  memcpy(jsonPayload, payload, payloadsize);
  jsonPayload[payloadsize] = '\0';

  YAJL_TREE_PARSE(yval, jsonPayload);
  if (yval->u.array.values[0]->type != yajl_t_string)
  {
    SWI_LOG("SMS", ERROR, "%s: sender is not an string, got type=%d\n", __FUNCTION__, yval->u.array.values[0]->type);
    res = RC_BAD_PARAMETER;
    goto quit;
  }
  sender = YAJL_GET_STRING(yval->u.array.values[0]);

  if (yval->u.array.values[1]->type != yajl_t_string)
  {
    SWI_LOG("SMS", ERROR, "%s: message is not an string, got type=%d\n", __FUNCTION__, yval->u.array.values[1]->type);
    res = RC_BAD_PARAMETER;
    goto quit;
  }
  message = YAJL_GET_STRING(yval->u.array.values[1]);

  if (yval->u.array.values[2]->type != yajl_t_number)
  {
    SWI_LOG("SMS", ERROR, "%s: regId is not an number, got type=%d\n", __FUNCTION__, yval->u.array.values[2]->type);
    res = RC_BAD_PARAMETER;
    goto quit;
  }
  regId = YAJL_GET_INTEGER(yval->u.array.values[2]);

  pthread_mutex_lock(&handler_lock);
  for (entry = cb_list; entry; entry = entry->next)
  {
    if (entry->regId == regId)
    {
      entry->cb(sender, message);
      break;
    }
  }
  pthread_mutex_unlock(&handler_lock);
quit:
  free(jsonPayload);
  emp_freemessage(payload);
  yajl_tree_free(yval);

  return res;
}
예제 #8
0
rc_ReturnCode_t swi_sms_Send(const char *recipientPtr, const char* messagePtr, swi_sms_Format_t format)
{
  rc_ReturnCode_t res;
  char *payload, *respPayload;
  const char *smsFormat = "";
  size_t payloadLen;
  uint32_t respPayloadLen;
  yajl_gen gen;

  if (recipientPtr == NULL || messagePtr == NULL || format < SWI_SMS_7BITS || format > SWI_SMS_UCS2)
    return RC_BAD_PARAMETER;

  switch(format)
  {
    case SWI_SMS_7BITS:
      smsFormat = "7bits";
      break;
    case SWI_SMS_8BITS:
      smsFormat = "8bits";
      break;
    case SWI_SMS_UCS2:
      smsFormat = "ucs2";
      break;
    default:
      break;
  }

  YAJL_GEN_ALLOC(gen);

  yajl_gen_array_open(gen);

  YAJL_GEN_STRING(recipientPtr, "recipientPtr");
  YAJL_GEN_STRING(messagePtr, "messagePtr");
  YAJL_GEN_STRING(smsFormat, "smsFormat");

  yajl_gen_array_close(gen);

  YAJL_GEN_GET_BUF(payload, payloadLen);

  res = emp_send_and_wait_response(EMP_SENDSMS, 0, payload, payloadLen, &respPayload, &respPayloadLen);
  yajl_gen_clear(gen);
  yajl_gen_free(gen);

  if (res != RC_OK)
  {
    SWI_LOG("SMS", ERROR, "error while sending sms, res=%d\n", res);
    SWI_LOG("SMS", ERROR, "got error msg=%s\n", respPayload);
  }
  free(respPayload);
  return res;
}
예제 #9
0
static void send_result(char * res)
{
    SWI_LOG("APPMON", DEBUG, "send_result, res=%s\n", res);
    if (strlen(res) != write(client_skt, res, strlen(res)))
    {
        SWI_LOG("APPMON", ERROR, "cannot write res to socket\n");
    }
    char* ressep = "\n";
    if (strlen(ressep) != write(client_skt, ressep, strlen(ressep)))
    {
        SWI_LOG("APPMON", ERROR, "cannot write result separator to socket\n");
    }

}
예제 #10
0
static int test_8_UpdateNotification()
{
    swi_status_t res;
    swi_av_Asset_t* asset = NULL;
    waiting_notification = 1;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;
    res = swi_av_RegisterUpdateNotification(asset, (swi_av_updateNotificationCB) updateNotificationCb, "userData");
    if (res != SWI_STATUS_OK)
        return res;

    const char *cmd_SoftwareUpdate ="'SoftwareUpdate', { 'TOTO.my_pkg', 'my_version', '/toto/my_file', {foo='bar', num=42, float=0.23}})\n";
    exec_lua_code(cmd_SoftwareUpdate);
    SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SoftwareUpdate done\n");
    while (waiting_notification)
        ;

    swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    return result;
}
예제 #11
0
static int test_3_ConnectToServer()
{
    swi_status_t res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

//test using requesting SYNC connexion
    res = swi_av_ConnectToServer(SWI_AV_CX_SYNC);
    if (res != SWI_STATUS_OK)
        return res;

    SWI_LOG("AV_TEST", DEBUG, "sync done\n");

//test using 0 latency: async but "immediate" connection
    res = swi_av_ConnectToServer(0);
    if (res != SWI_STATUS_OK)
        return res;

//test using correct latency
    res = swi_av_ConnectToServer(10);
    if (res != SWI_STATUS_OK)
        return res;

//test using too big latency:
//expected behavior here: rejected
    res = swi_av_ConnectToServer((unsigned int) INT_MAX + 1);
    if (res != SWI_STATUS_WRONG_PARAMS)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    return 0;
}
예제 #12
0
static void err_exit(char* str)
{
    int err = errno;
    if (err)
    {
        SWI_LOG("APPMON", ERROR, "err_exit:  strerror(errno)=[%s], ctx=[%s]\n", strerror(errno), str);
    }
    else
    {
        err = APPMON_ERR_EXIT_CODE;
        SWI_LOG("APPMON", ERROR, "err_exit: ctx=[%s]\n", str);
    }
    SWI_LOG("APPMON", ERROR, "cleaning and exiting\n");
    clean_all();
    exit(err);
}
예제 #13
0
static int clean_all()
{
    app_t* tmp = NULL;
    rc_ReturnCode_t res = RC_OK;
    if (apps != NULL)
    {

        unsigned int size, i = 0;
        //first apps list traversal: stopping apps
        //(cannot free them now as stop_app and SIGCHLD_handler functions
        //will traverse apps list too.
        PointerList_GetSize(apps, &size, NULL);
        for (i = 0; i < size; i++)
        {
            PointerList_Peek(apps, i, (void**) &tmp);
            if (tmp->status == STARTED || tmp->status == TO_BE_KILLED)
            {
                stop_app(tmp);
                //collect zombies, non blocking
                waitpid(tmp->pid, NULL, 0);
            }
        }
        //last apps list traversal: free-ing apps
        PointerList_GetSize(apps, &size, NULL);
        for (i = 0; i < size; i++)
        {
            PointerList_Peek(apps, i, (void**) &tmp);
            free(tmp);
        }

        res = PointerList_Destroy(apps);
    }

    //close sockets
    if (srv_skt)
        close(srv_skt);
    if (client_skt)
        close(client_skt);

    //no more socket to write to, free buffers
    if (input_buf)
    {
        free(input_buf);
        input_buf = NULL;
    }

    if (output_buf)
    {
        free(output_buf);
        output_buf = NULL;
    }

    if (cwd)
    {
        free(cwd);
        cwd = NULL;
    }
    SWI_LOG("APPMON", DEBUG, "clean_all end\n");
    return res;
}
예제 #14
0
/* if an integer was found in str: returns 0, the integer value is put in res
 * if an integer was not found in str:
 *    - if errmsg is not nul, then call *error* with that message
 *    - if errmsg is null, then return 1
 */
static int parse_arg_integer(char* str, int* res, char* errmsg)
{
    //code from strtol man page
    char *endptr;
    long val = 0;

    errno = 0; /* To distinguish success/failure after call */
    val = strtol(str, &endptr, 0);

    /* Check for various possible errors */

    if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0))
    {
        err_exit("parse_arg_integer error, strtol failed");
    }

    if (endptr == str)
    {
        if (errmsg)
        {
            err_exit(errmsg);
        }
        else
            return 1; //not found
    }
    /* If we got here, strtol() successfully parsed a number */

    if (*endptr != '\0') /* Not necessarily an error... */
        SWI_LOG("APPMON", DEBUG, "Further characters after number arg: %s\n", endptr);

    *res = (int) val;
    return 0;
}
예제 #15
0
static rc_ReturnCode_t send_reg_payload(const char *payload, size_t payloadLen, int *regId)
{
  rc_ReturnCode_t res;
  char *rpayload = NULL, *respPayload = NULL;
  uint32_t respPayloadLen;
  yajl_val yval = NULL;

  res = emp_send_and_wait_response(EMP_REGISTERSMSLISTENER, 0, payload, payloadLen, &respPayload, &respPayloadLen);

  if (res != RC_OK)
    goto quit;

  rpayload = strndup(respPayload, respPayloadLen);
  if (rpayload == NULL)
  {
    res = RC_NO_MEMORY;
    goto quit;
  }

  YAJL_TREE_PARSE(yval, rpayload);
  if (yval->type != yajl_t_number)
  {
    SWI_LOG("SMS", ERROR, "Invalid regId type received from RA, got type=%u, expected %u\n", __FUNCTION__, yval->type, yajl_t_number);
    res = RC_BAD_PARAMETER;
    goto quit;
  }
  *regId = YAJL_GET_INTEGER(yval);
quit:
  yajl_tree_free(yval);
  free(respPayload);
  free(rpayload);
  return res;
}
예제 #16
0
/* Helper: retrieve a variable record from its id. */
static treehdlvar_t * get_treevar(ExtVars_id_t id)
{
    int i;
    for(i = 0; i < NVARS; i++)
        if(treehdlvars[i].id == id)
            return treehdlvars + i;
    SWI_LOG("TREEHDL", ERROR, "Variable %d not found\n", id);
    return NULL;
}
예제 #17
0
/* These functions are called when treemgr requires notifications for a specific node
   or for all existing nodes attached to the root node (treehdlsample) */
swi_status_t ExtVars_register_variable(ExtVars_id_t id, int enable)
{
    SWI_LOG("TREEHDL", DEBUG, "%s: id=%d, enable=%d\n", __FUNCTION__, id, enable);

    treehdlvar_t *var = get_treevar(id);
    if(!var)
        return SWI_STATUS_DA_NOT_FOUND;
    var->registered = enable;
    return SWI_STATUS_OK;
}
예제 #18
0
/* This function is called when treemgr get the value attached to a leaf */
swi_status_t ExtVars_get_variable (ExtVars_id_t id, void**value, ExtVars_type_t *type)
{
    SWI_LOG("TREEHDL", DEBUG, "%s(%d)\n", __FUNCTION__, id);

    treehdlvar_t *treehdlvar = get_treevar(id);

    if(treehdlvar == NULL) return SWI_STATUS_DA_NOT_FOUND;
    if(value) *value = (treehdlvar->type == EXTVARS_TYPE_STR) ? (void *)treehdlvar->value.s : &treehdlvar->value.d;
    if(type)  *type  = treehdlvar->type;
    return SWI_STATUS_OK;
}
예제 #19
0
rc_ReturnCode_t swi_sms_Destroy()
{
  rc_ReturnCode_t res;

  if (!module_initialized)
    return RC_OK;
  res = emp_parser_destroy(1, empCmds, empReregisterServices);
  if (res != RC_OK)
    SWI_LOG("SMS", ERROR, "error while destroy emp lib, res=%d\n", res);
  module_initialized = 0;
  return res;
}
예제 #20
0
static void empReregisterServices()
{
  cb_list_t *entry;
  rc_ReturnCode_t res;

  for (entry = cb_list; entry; entry = entry->next)
  {
    res = send_reg_payload(entry->payload, strlen(entry->payload), &entry->regId);
    if (res != RC_OK)
      SWI_LOG("SMS", WARNING, "Failed to register back callback %p with regId %p\n", entry->cb, entry);
  }
}
예제 #21
0
static char* readline(int fd)
{
    int i = 0;
    char c = 0;
    if (input_buf == NULL)
    {
        input_buf = malloc(input_bufsize);
        if (NULL == input_buf)
        {
            SWI_LOG("APPMON", ERROR, "readline: malloc error\n");
            return NULL;
        }
    }

    for (i = 0, c = 0; c != '\n'; i++)
    {
        if (i == input_bufsize)
        {
            input_bufsize += 128;
            input_buf = realloc(input_buf, input_bufsize);
            if (NULL == input_buf)
            {
                SWI_LOG("APPMON", ERROR, "readline: realloc error\n");
                return NULL;
            }
        }
        if (1 != read(fd, &c, 1))
        {
            //free(buf);
            return NULL;
        }
        input_buf[i] = c;
    }

    if (i > 1 && input_buf[i - 2] == '\r')
        i--;

    input_buf[i - 1] = '\0';
    return input_buf;
}
예제 #22
0
void SIGALRM_handler(int s)
{
    SWI_LOG("APPMON", DEBUG, "SIGALRM_handler: pid=%d ======>\n", getpid());
    app_t* app = NULL;
    unsigned int size = 0, i = 0;
    PointerList_GetSize(apps, &size, NULL);
    SWI_LOG("APPMON", DEBUG, "SIGALRM_handler: started_apps size = %d\n", size);
    for (i = 0; i < size; i++)
    {
        PointerList_Peek(apps, i, (void**) &app);
        if (NULL != app && app->status == TO_BE_RESTARTED)
        {
            SWI_LOG("APPMON", DEBUG, "SIGALRM_handler: needs to restart %s\n", app->prog);
            char * res = start_app(app);
            if (!strcmp(res, "ok"))
            {
                SWI_LOG("APPMON", DEBUG, "SIGALRM_handler: %s restarted, new pid=%d\n", app->prog, app->pid);
            }
            else
            {
                SWI_LOG("APPMON", ERROR, "SIGALRM_handler: Cannot restart app id=%d, prog=%s, err=%s\n", app->id, app->prog, res);
                PointerList_Remove(apps, i, (void**) &app);
            }
        }
    }
    SWI_LOG("APPMON", DEBUG, "SIGALRM_handler: pid=%d ======<\n", getpid());
    fflush(stdout);
}
예제 #23
0
static char* check_params(char *wd, char* prog)
{
    struct stat st;
    int res = stat(wd, &st);
    char *res_str;
    if (res)
    {
        perror("stat on wd folder error");
        res_str = fill_output_buf("wd (%s) cannot be stat!", wd);
        SWI_LOG("APPMON", ERROR, "%s\n", res_str);
        return res_str;
    }

    if (!S_ISDIR(st.st_mode))
    {
        res_str = fill_output_buf("wd (%s) is not a directory!", wd);
        SWI_LOG("APPMON", ERROR, "%s\n", res_str);
        return res_str;
    }

    res = stat(prog, &st);
    if (res)
    {
        perror("stat on prog file error");
        res_str = fill_output_buf("prog (%s) cannot be stat!", prog);
        SWI_LOG("APPMON", ERROR, "%s\n", res_str);
        return res_str;
    }

    if (!S_ISREG(st.st_mode) || access(prog, X_OK))
    {
        perror("access on prog");
        res_str = fill_output_buf("prog (%s) is not an executable file!", prog);
        SWI_LOG("APPMON", ERROR, "%s\n", res_str);
        return res_str;
    }

    return NULL;
}
예제 #24
0
static void getLeafCheckTypeValue(const char* getpath, swi_dset_Type_t gettype, union t_value tval)
{
  swi_dset_Iterator_t *set = NULL;
  bool isLeaf = true;
  swi_dset_Type_t t;
  SWI_LOG("DT_TEST", DEBUG, "get on %s\n", getpath);
  rc_ReturnCode_t res = swi_dt_Get(getpath, &set, &isLeaf);
  ASSERT_TESTCASE_IS_OK(res);
  if (isLeaf == false)
    ABORT("Leaf was expected here");

  res = swi_dset_Next(set);
  ASSERT_TESTCASE_IS_OK(res);
  t = swi_dset_GetType(set);
  if(gettype != t)
    ABORT("getLeafCheckTypeValue: unexpected type [%d] for path [%s], expected [%d]", t, getpath, gettype);
  int64_t ival = 0;
  double dval = 0;
  bool bval = false;
  const char* sval;
  switch(t){
    case SWI_DSET_STRING:
      sval = swi_dset_ToString(set);
      if(strcmp(sval, tval.sval) != 0)
        ABORT("getLeafCheckTypeValue: unexpected value [%s] for path [%s], expected [%s]", sval, getpath, tval.sval );
      break;
    case SWI_DSET_INTEGER:
      ival = swi_dset_ToInteger(set);
      if(ival != tval.ival)
        ABORT("getLeafCheckTypeValue: unexpected value [%d] for path [%s], expected [%d]", ival, getpath, tval.ival );
      break;
    case SWI_DSET_FLOAT:
      dval = swi_dset_ToFloat(set);
      if(dval != tval.dval )
        ABORT("getLeafCheckTypeValue: unexpected value [%f] for path [%s], expected [%f]", dval, getpath, tval.dval );
      break;
    case SWI_DSET_BOOL:
      bval = swi_dset_ToBool(set);
      if(bval != tval.bval)
        ABORT("getLeafCheckTypeValue: unexpected value [%d] for path [%s], expected [%d]", bval, getpath, tval.bval );
      break;
    case SWI_DSET_NIL:
      if(tval.sval != NULL)//not sure how to have a variable of NIL type as a result of a Get request.
        ABORT("getLeafCheckTypeValue: received type SWI_DSET_NIL, with expected value was not NULL");
      break;
    default:
      ABORT("Unexpected swi_dset_Type_t [%d] for path [%s]", t, getpath);
  }

  swi_dset_Destroy(set);
}
예제 #25
0
static void get_uid_option(uint32_t* uid)
{
    if (parse_arg_integer(optarg, (int*) uid, NULL))
    {
        //cannot get uid as the number, trying to use command arg a user name.
        struct passwd * user = NULL;
        user = getpwnam(optarg);
        if (NULL == user)
        {
            err_exit("Command line arguments parsing: invalid user given.");
        }
        else
            *uid = user->pw_uid;
    }
    SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: user uid=%d\n", *uid);
}
예제 #26
0
static void get_gid_option(uint32_t* gid)
{
    if (parse_arg_integer(optarg, (int*) gid, NULL))
        //cannot get gid as the number, trying to use command arg a group name.
    {
        struct group * grp = NULL;
        grp = getgrnam(optarg);
        if (NULL == grp)
        {
            err_exit("Command line arguments parsing: invalid group given");
        }
        else
            *gid = grp->gr_gid;
    }
    SWI_LOG("APPMON", DEBUG, "Command line arguments parsing: group gid=%d\n", *gid);
}
예제 #27
0
rc_ReturnCode_t swi_sms_Init()
{
  rc_ReturnCode_t res;

  if (module_initialized)
    return RC_OK;

  res = emp_parser_init(1, empCmds, empHldrs, empReregisterServices); // No async EMP cmd is managed by this lib
  if (res != RC_OK)
  {
    SWI_LOG("SMS", ERROR, "%s: Error while init emp lib, res=%d\n", __FUNCTION__, res);
    return res;
  }
  module_initialized = 1;
  return RC_OK;
}
예제 #28
0
static void dwcb_DataWritting(swi_av_Asset_t *asset, ///< [IN] the asset receiving the data
    const char *pathPtr, ///< [IN] the path targeted by the data sent by the server.
    swi_dset_Iterator_t* data, ///< [IN] the data iterator containing the received data.
                               ///<      The data contained in the iterator will be automatically released when the callback returns.
    int ack_id,                              ///< [IN] the id to be used to acknowledge the received data.
                                             ///<      If ack_id=0 then there is no need to acknowledge.
    void *userDataPtr)
{
  SWI_LOG("AV_TEST", DEBUG, "dwcb_DataWritting: pathPtr=%s, ack_id=%d\n", pathPtr, ack_id);

  if (strcmp(pathPtr, "sub.path"))
  {
    result = 102;
    waiting_notification = 0;
    return;
  }

  if (data == NULL )
  {
    result = 104;
    waiting_notification = 0;
    return;
  }
  char *val1 = NULL;

  if (RC_OK != swi_dset_GetStringByName(data, "foo", (const char**) &val1))
  {
    result = 105;
    waiting_notification = 0;
    return;
  }

  if (val1 == NULL || strcmp(val1, "bar"))
  {
    result = 106;
    waiting_notification = 0;
    return;
  }

  if (ack_id)
    swi_av_Acknowledge(ack_id, 42, "some error msg", "now", 0);

  swi_dset_Destroy(data);
  result = 0;
  waiting_notification = 0;
  return;
}
예제 #29
0
static int test_10_asset_receiveDataWriting()
{
    swi_status_t res = SWI_STATUS_OK;
    waiting_notification = 1;

    res = swi_av_Init();
    if (res != SWI_STATUS_OK)
        return res;

    swi_av_Asset_t* asset;

    res = swi_av_asset_Create(&asset, ASSET_ID);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_RegisterDataWrite(asset, dwcb_DataWritting, NULL );
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_asset_Start(asset);
    if (res != SWI_STATUS_OK)
        return res;

    /*command sends to TOTO asset*/
    const char* str = "'SendData', { Path = 'TOTO.sub.path', Body = { foo = 'bar' }, TicketId = %u, Type = 5, __class = 'AWT-DA::Message' })\n";
    char* cmd_SendDataWriting = addTicketId(str);

    exec_lua_code(cmd_SendDataWriting);
    SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataWriting done\n");
    while (waiting_notification)
        ;

    res = swi_av_asset_Destroy(asset);
    if (res != SWI_STATUS_OK)
        return res;

    res = swi_av_Destroy();
    if (res != SWI_STATUS_OK)
        return res;

    free(cmd_SendDataWriting);
    return result;
}
예제 #30
0
static int test_12_asset_receiveDataCommandList()
{
  rc_ReturnCode_t res = RC_OK;
  waiting_notification = 1;

  res = swi_av_Init();
  if (res != RC_OK)
    return res;

  swi_av_Asset_t* asset;

  res = swi_av_asset_Create(&asset, ASSET_ID);
  if (res != RC_OK)
    return res;

  res = swi_av_RegisterDataWrite(asset, dwcb_DataCommandList, NULL );
  if (res != RC_OK)
    return res;

  res = swi_av_asset_Start(asset);
  if (res != RC_OK)
    return res;

  const char* str = "'SendData', { Path = 'av_test_asset_id.sub.path', Body = { Command = 'plop',  Args = {42, 'bar'}, __class = 'AWT-DA::Command' },  TicketId = %u, Type = 2,  __class = 'AWT-DA::Message' })\n";
  char* cmd_SendDataCommandList = addTicketId(str);

  exec_lua_code(cmd_SendDataCommandList);
  SWI_LOG("AV_TEST", DEBUG, "exec_lua_code SendDataCommandList done\n");
  while (waiting_notification)
    ;

  res = swi_av_asset_Destroy(asset);
  if (res != RC_OK)
    return res;

  res = swi_av_Destroy();
  if (res != RC_OK)
    return res;

  free(cmd_SendDataCommandList);
  return result;
}