Esempio n. 1
0
 os_int32
 os_reportRegisterPlugin(
    const char *library_file_name,
    const char *initialize_method_name,
    const char *argument,
    const char *report_method_name,
    const char *typedreport_method_name,
    const char *finalize_method_name,
    os_boolean suppressDefaultLogs,
    os_reportPlugin *plugin)
 {
#ifdef INCLUDE_PLUGGABLE_REPORTING
    os_library libraryHandle;
    os_libraryAttr attr;
    os_result osr;
    os_boolean error = OS_FALSE;
    os_int32 initResult;

    os_reportPlugin_initialize initFunction;
    os_reportPlugin_finalize finalizeFunction;
    os_reportPlugin_report reportFunction = NULL;
    os_reportPlugin_typedreport typedReportFunction = NULL;

    osr = os_libraryAttrInit(&attr);
    libraryHandle = NULL;

    if (library_file_name != NULL )
    {
       libraryHandle = os_libraryOpen (library_file_name, &attr);
    }

    if (libraryHandle == NULL)
    {
       OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                    "Unable to load library: %s", library_file_name);

       error = OS_TRUE;
    }

    if (!error && typedreport_method_name == NULL && report_method_name == NULL)
    {
       OS_REPORT (OS_ERROR, "os_reportRegisterPlugin", 0,
                    "At least one of TypedReport or Report symbole must be defined");

       error = OS_TRUE;
    }

    if (!error)
    {
        initFunction =  (os_reportPlugin_initialize)os_fptr(os_libraryGetSymbol (libraryHandle, initialize_method_name));

        if (initFunction == NULL)
        {
           OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                    "Unable to resolve report intialize function: %s", initialize_method_name);

           error = OS_TRUE;
        }
    }

    if (!error)
    {
        finalizeFunction = (os_reportPlugin_finalize)os_fptr(os_libraryGetSymbol (libraryHandle, finalize_method_name));

        if (finalizeFunction == NULL)
        {
            OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                    "Unable to resolve report finalize function: %s", finalize_method_name);

            error = OS_TRUE;
        }
    }

    if (!error )
    {
        if (report_method_name != NULL)
        {
            reportFunction = (os_reportPlugin_report)os_fptr(os_libraryGetSymbol (libraryHandle, report_method_name));

            if (reportFunction == NULL)
            {
                OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                            "Unable to resolve report Report function: %s", report_method_name);

                error = OS_TRUE;
            }
            else
            {
                ++xmlReportPluginsCount;
            }
        }

        if (typedreport_method_name != NULL)
        {
            typedReportFunction = (os_reportPlugin_typedreport)os_fptr(os_libraryGetSymbol (libraryHandle, typedreport_method_name));

            if (typedReportFunction == NULL)
            {
                OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                            "Unable to resolve report TypedReport function: %s", typedreport_method_name);

                error = OS_TRUE;
            }
        }
    }

    if (!error)
    {
        initResult = os_reportInitPlugin(argument,
                                       initFunction,
                                       finalizeFunction,
                                       reportFunction,
                                       typedReportFunction,
                                       suppressDefaultLogs,
                                       plugin);
        if (initResult)
        {
            OS_REPORT_1 (OS_ERROR, "os_reportRegisterPlugin", 0,
                            "Plug-in initialization method failed : %s", initialize_method_name);
        }
        else
        {
            return 0;
        }
    }

    OS_REPORT_1 (OS_WARNING, "os_reportRegisterPlugin", 0,
                 "Failed to register report plugin : %s", library_file_name);

    return -1;
#else
   if (library_file_name != NULL ) {
       OS_REPORT_1(OS_ERROR, "os_reportRegisterPlugin", 0, "Unable to register report plugin: %s because \
                   product was not built with INCLUDE_PLUGGABLE_REPORTING enabled", library_file_name);
   } else {
Esempio n. 2
0
os_result
os_procCreate(
    const char *executable_file,
    const char *name,
    const char *arguments,
    os_procAttr *procAttr,
    os_procId *procId)
{
    int procTaskId;
    int sched_policy;
    os_result rv = os_resultSuccess;
    os_procContextData process_procContextData;
    os_int32 startRoutine = 0;
    os_int32 pOptions,privateSet;
    os_int32 len,i=0,n=0;
    char *converted = NULL;

    assert(executable_file != NULL);
    assert(name != NULL);
    assert(arguments != NULL);
    assert(procAttr != NULL);
    assert(procId != NULL);

    len = strlen(arguments);
    converted = (char*)os_malloc(len+1);
    for (; i < len ; i++)
    {
       if (arguments[i] != '\"')
       {
          converted[n] = arguments[i];
          n++;
       }
    }
    converted[n] = '\0';
    pOptions = 0;
    privateSet = 0;
    taskOptionsGet(taskIdSelf(),&pOptions);
    if ((pOptions & VX_PRIVATE_ENV) == 0)
    {
        envPrivateCreate(taskIdSelf(), 0);
        privateSet = 1;
    }
    putenv("SPLICE_NEW_PROCESS=no");

    if (procAttr->schedClass == OS_SCHED_REALTIME) {
        sched_policy = SCHED_FIFO;
    } else if (procAttr->schedClass == OS_SCHED_TIMESHARE) {
        return os_resultInvalid;
    } else if (procAttr->schedClass == OS_SCHED_DEFAULT) {
        sched_policy = SCHED_OTHER;
    } else {
        return os_resultInvalid;
    }

    if ((procAttr->schedPriority > VXWORKS_PRIORITY_MIN) ||
        (procAttr->schedPriority < VXWORKS_PRIORITY_MAX) ) {
        return os_resultInvalid;
    }


    {
      os_library binlib;
      os_libraryAttr attr;

      os_libraryAttrInit(&attr);
      /* Dynamic load of services is a special case, so try just static via
         os_libraryOpen */
      attr.staticLibOnly=1;
      binlib = os_libraryOpen( executable_file, &attr);
      /* FIXME existing use of os_int32 for pointer is CRAZY!! */
      if ( binlib != NULL )
      {
         startRoutine = (os_int32)os_libraryGetSymbol( binlib, executable_file );
      }

      if ( startRoutine == 0 && os_dynamicLibPlugin != NULL )
      {
         startRoutine = (os_uint32)os_dynamicLibPlugin->dlp_loadLib( executable_file );
      }

      if ( startRoutine == 0 )
      {
         OS_REPORT(OS_ERROR, "os_procCreate", 1,
                       "Unable to load %s (%s)",
                       executable_file, name);
     rv = os_resultInvalid;
      }
    }

    if (rv == os_resultSuccess)
    {
        process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData));
        if (process_procContextData == (os_procContextData) NULL) {
            OS_REPORT(OS_WARNING, "os_procCreate", 1,
                        "malloc failed with error %d (%s, %s)",
                        os_getErrno(), executable_file, name);
            rv = os_resultInvalid;
        }
        else
        {
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 ) || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 )
        /* the blockParent semaphore is used to prevent this task exiting before the spawned task
           has completed copying its environ. */
        os_sem_t blockParent;
        os_sem_init( &blockParent, 0);
#endif
            os_procInit(process_procContextData, name, executable_file, converted);
            process_procContextData->procAttrPrio = procAttr->schedPriority;
            procTaskId = taskSpawn((char *)name, procAttr->schedPriority,
                                   VX_FP_TASK
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
/* VX_PRIVATE_ENV flag is no longer functional in vxworks 6.9 */
                   | VX_PRIVATE_ENV
#endif
#if defined ( VXWORKS_55 ) || defined ( VXWORKS_54 )
                                   | VX_STDIO | VX_DEALLOC_STACK
#endif
                                   ,
                                   VXWORKS_PROC_DEFAULT_STACK,
                                   (FUNCPTR)os_procWrapper,
                                   (int)process_procContextData, (int)process_procContextData->executable,
                                   (int)startRoutine, (int)process_procContextData->arguments, taskIdSelf(),
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
                                   0,
#else
                                   &blockParent,
#endif
 0, 0, 0, 0);
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 ) )
            os_sem_wait(&blockParent);
            os_sem_destroy(&blockParent);
#endif
            if (procTaskId == ERROR)
            {
                os_free(process_procContextData);
                rv = os_resultInvalid;
            }
            else
            {
                *procId = *(os_procId *)&process_procContextData;
                rv = os_resultSuccess;
            }
        }
    }

    putenv("SPLICE_NEW_PROCESS=empty");
    if ( privateSet == 1)
    {
        envPrivateDestroy(taskIdSelf());
    }
    os_free(converted);
    return rv;
}