static void
la_handler_service_handle_register_finish (GObject      *object,
                                           GAsyncResult *res,
                                           gpointer      user_data)
{
  GDBusMethodInvocation *invocation = G_DBUS_METHOD_INVOCATION (user_data);
  LAHandlerService      *service;
  NSMConsumer           *nsm_consumer = NSM_CONSUMER (object);
  GError                *error = NULL;
  gint                   error_code;

  g_return_if_fail (IS_NSM_CONSUMER (nsm_consumer));
  g_return_if_fail (G_IS_ASYNC_RESULT (res));
  g_return_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation));

  /* finish registering the shutdown client */
  nsm_consumer_call_register_shutdown_client_finish (nsm_consumer, &error_code, res,
                                                     &error);
  if (error != NULL)
    {
      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
               DLT_STRING ("Failed to register a shutdown consumer:"),
               DLT_STRING (error->message));
      g_error_free (error);
    }

  /* retrieve the LAHandlerService from the invocation object */
  service = g_object_get_data (G_OBJECT (invocation), "la-handler-service");

  /* notify the caller that we have handled the registration request */
  la_handler_complete_register (service->interface, invocation);
}
Example #2
0
char *unique_name(char *src)
{
    DLT_LOG(dltsystem, DLT_LOG_DEBUG,
            DLT_STRING("dlt-system-filetransfer, creating unique temporary file name."));
    time_t t = time(NULL);
    int ok;
    unsigned long l = getFileSerialNumber(src, &ok) ^ t;
    if (!ok){
        return (char*) NULL;
    }

    char *basename_f = basename(src);
    // Length of ULONG_MAX + 1
    int len = 11+strlen(basename_f);
    if (len > NAME_MAX){
        DLT_LOG(dltsystem, DLT_LOG_WARN,
                DLT_STRING("dlt-system-filetransfer, unique name creation needs to shorten the filename:"),DLT_STRING(basename_f));
        len = NAME_MAX;
    }

    char *ret = malloc(len);

    MALLOC_ASSERT(ret);
    snprintf(ret, len, "%010lu%s", l,basename_f);
    return ret;
}
int readBlacklistConfigFile(const char* filename)
{
   int rval = 0;

   if(filename != NULL)
   {
      struct stat buffer;

      memset(&buffer, 0, sizeof(buffer));
      if(stat(filename, &buffer) != -1)
      {
         if(buffer.st_size > 0)     // check for empty file
         {
            char* configFileMap = 0;
            int fd = open(filename, O_RDONLY);

            if(fd == -1)
            {
              DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("blacklist - Err file open"), DLT_STRING(filename), DLT_STRING(strerror(errno)) );
              return EPERS_COMMON;
            }

            configFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0);  // map the configuration file into memory

            if(configFileMap == MAP_FAILED)
            {
              close(fd);
              DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("blacklist - Err mapping file:"), DLT_STRING(filename), DLT_STRING(strerror(errno)) );

              return EPERS_COMMON;
            }

            fillFileBackupCharTokenArray(buffer.st_size, configFileMap);

            createAndStoreFileNames();    // create filenames and store them in the tree

            (void)munmap(configFileMap, buffer.st_size);

            close(fd);
         }
         else
         {
            DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("blacklist - Err config file size is 0:"), DLT_STRING(filename));
            return EPERS_COMMON;
         }
      }
      else
      {
         DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("blacklist - failed to stat() conf file:"), DLT_STRING(filename));
         return EPERS_COMMON;
      }
   }
   else
   {
      DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("blacklist - config file name is NULL:"));
      rval = EPERS_COMMON;
   }

   return rval;
}
void* registerToPas(void* data)
{
   pthread_t thread;
   long* retval = NULL;

   // create send thread in order to wait until registration succeeded
   pthread_create(&thread, NULL, doSendPasRegister, NULL);

   // wait untill registration has finished
   pthread_join(thread, (void**)&retval);

   if((long)retval == -1)
   {
      //printf("==> PAS Appeared - register failed\n");
      DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("NameOwnerChanged - Failed reg to PAS dbus interface"));
   }
   else
   {
      //printf("==> PAS Appeared - register success\n");
      DLT_LOG(gPclDLTContext, DLT_LOG_INFO,  DLT_STRING("NameOwnerChanged - Successfully established IPC protocol for PCL."));
      gPasRegistered = 1;   // remember registration to PAS
   }

   return NULL;
}
static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data)
{
   (void)data;
   dbus_bool_t ret = FALSE;

   if(ARRAY_SIZE(gPollInfo.fds) > (unsigned int)(gPollInfo.nfds))
   {
      const int interval = dbus_timeout_get_interval(timeout);
      if ((0<interval)&&(TRUE==dbus_timeout_get_enabled(timeout)))
      {
         const int tfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
         if (-1!=tfd)
         {
            const struct itimerspec its = { .it_value= {interval/1000, interval%1000} };
            if (-1!=timerfd_settime(tfd, 0, &its, NULL))
            {
               tObjectEntry * const pEntry = &gPollInfo.objects[gPollInfo.nfds];
               pEntry->objtype = OT_TIMEOUT;
               pEntry->timeout = timeout;
               gPollInfo.fds[gPollInfo.nfds].fd = tfd;
               gPollInfo.fds[gPollInfo.nfds].events |= POLLIN;
               ++gPollInfo.nfds;
               ret = TRUE;
            }
            else
            {
               DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout - _settime() failed"), DLT_STRING(strerror(errno)) );
            }
         }
         else
         {
            DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout - _create() failed"), DLT_STRING(strerror(errno)) );
         }
      }
   }
bool_t Test_import_all_app(sint_t type, void* pv)
{
    bool_t 	bEverythingOK 	= true ;
    long 	impBytes		=-1;
    str_t  pchBackupFilePath [PATH_ABS_MAX_SIZE];

    bEverythingOK = ResetImportData(PersASSelectionType_Application);

    if(true == bEverythingOK)
	{
		(void)snprintf(pchBackupFilePath, sizeof(pchBackupFilePath), "%s%s", "all", BACKUP_FORMAT);

		/* Restore content */
		DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, DLT_STRING(LT_HDR), 	DLT_STRING("Import from:"),
																		DLT_STRING(pchBackupFilePath),
																		DLT_STRING("..."));

		impBytes = persAdminDataFolderImport(PersASSelectionType_Application, pchBackupFilePath);

		bEverythingOK = (impBytes >= 0)?true:false;
	}

    printf("\nTest_import_all - %s \n", bEverythingOK   ? "OK" : "FAILED") ;

    return bEverythingOK ;
}
Example #7
0
void start_logfile(DltSystemConfiguration *conf)
{
	DLT_LOG(dltsystem, DLT_LOG_DEBUG,
			DLT_STRING("dlt-system-logfile, starting."));
	DLT_LOG(dltsystem,DLT_LOG_DEBUG,DLT_STRING("Starting thread for logfile"));
	static pthread_attr_t t_attr;
	static pthread_t pt;
	pthread_create(&pt, &t_attr, (void *)logfile_thread, conf);
	threads.threads[threads.count++] = pt;
}
Example #8
0
/**
 * compress file, delete the source file
 * modification: compress into subdirectory
 * File whis is compress will be deleted afterwards
 *  @param src File to be sent
 *  @param dst destination where to compress the file
 * @param level of compression
**/
int compress_file_to(char *src, char *dst, int level)
{
    DLT_LOG(dltsystem, DLT_LOG_DEBUG,
            DLT_STRING("dlt-system-filetransfer, compressing file from:"),DLT_STRING(src),DLT_STRING("to:"),DLT_STRING(dst));
    char *buf;


    char dst_mode[8];
    snprintf(dst_mode,8, "wb%d", level);

    gzFile dst_file;
    FILE *src_file;

    dst_file = gzopen(dst, dst_mode);
    if(dst_file == Z_NULL)
    {

        return -1;
    }

    src_file = fopen(src, "r");

    if(src_file == NULL)
    {
        gzclose(dst_file);

        return -1;
    }

    buf = malloc(Z_CHUNK_SZ);
    MALLOC_ASSERT(buf);

    while(!feof(src_file))
    {
        int read = fread(buf, 1, Z_CHUNK_SZ, src_file);
        if(ferror(src_file))
        {
            free(buf);

            gzclose(dst_file);
            fclose(src_file);
            return -1;
        }
        gzwrite(dst_file, buf, read);
    }

    if(remove(src) < 0)
        DLT_LOG(dltsystem, DLT_LOG_WARN, DLT_STRING("Could not remove file"), DLT_STRING(src));
    free(buf);
    fclose(src_file);
    gzclose(dst_file);

    return 0;
}
Example #9
0
int flush_dir_compress(FiletransferOptions const *opts, int which, const char *compress_dir, const char *send_dir){

    //check for files in compress_dir. Assumption: a file which lies here, should have been compressed, but that action was interrupted.
    //As it can arrive here only by a rename, it is most likely to be a complete file
    struct dirent *dp;
    DIR *dir;
    dir = opendir(compress_dir);
    if(dir != NULL)
    {
        while((dp = readdir(dir)) != NULL)
        {
            if(dp->d_type != DT_REG)
                continue;
            DLT_LOG(dltsystem, DLT_LOG_DEBUG,
                    DLT_STRING("dlt-system-filetransfer, old file found in compress-directory."));


            //compress file into to_send dir
            int len = strlen(compress_dir)+strlen(dp->d_name)+2;
            char *cd_filename = malloc(len);
            MALLOC_ASSERT(cd_filename);
            snprintf(cd_filename,len,"%s/%s",compress_dir,dp->d_name);


            len = strlen(send_dir)+strlen(dp->d_name)+strlen(COMPRESS_EXTENSION)+2;
            char *dst_tosend = malloc(len);//the resulting filename in .tosend +2 for 1*"/", +1 for \0 + .gz
            MALLOC_ASSERT(dst_tosend);
            snprintf(dst_tosend,len,"%s/%s%s",send_dir,dp->d_name,COMPRESS_EXTENSION);

            if (compress_file_to(cd_filename,dst_tosend, opts->CompressionLevel[which]) != 0){
                free(dst_tosend);
                free(cd_filename);
                closedir(dir);
                return -1;
            }

            //send file
            send_dumped_file(opts,dst_tosend);
            free(dst_tosend);
            free(cd_filename);
        }
    }
    else
    {
        DLT_LOG(dltsystem, DLT_LOG_ERROR,
                DLT_STRING("Could not open directory"),
                DLT_STRING(compress_dir));
        return -1;
    }
    closedir(dir);//end: compress_dir

    return 0;
}
Example #10
0
void init_shell()
{
	DLT_LOG(dltsystem,DLT_LOG_DEBUG,
			DLT_STRING("dlt-system-shell, register callback"));
	DLT_REGISTER_CONTEXT(shellContext,"CMD","Execute Shell commands");
	DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback);
}
Example #11
0
void logfile_thread(void *v_conf)
{
	DLT_LOG(dltsystem, DLT_LOG_DEBUG,
			DLT_STRING("dlt-system-logfile, in thread."));
	DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;

	register_contexts(conf->LogFile);

	int logfile_delays[DLT_SYSTEM_LOG_FILE_MAX];
	int i;
	for(i = 0;i < conf->LogFile.Count;i++)
		logfile_delays[i] = conf->LogFile.TimeDelay[i];

	while(!threads.shutdown)
	{
		sleep(1);
		for(i = 0;i < conf->LogFile.Count;i++)
		{
			if(conf->LogFile.Mode[i] == SEND_MODE_OFF)
				continue;

			if(logfile_delays[i] <= 0)
			{
				send_file(conf->LogFile, i);
				logfile_delays[i] = conf->LogFile.TimeDelay[i];
				if(conf->LogFile.Mode[i] == SEND_MODE_ONCE)
					conf->LogFile.Mode[i] = SEND_MODE_OFF;
			}
			else
			{
				logfile_delays[i]--;
			}
		}
	}
}
Example #12
0
int wait_for_files(FiletransferOptions const *opts)
{
#ifdef linux
    DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files."));
    static char buf[INOTIFY_LEN];
    ssize_t len = read(ino.handle, buf, INOTIFY_LEN);
    if(len < 0)
    {
        DLT_LOG(filetransferContext, DLT_LOG_ERROR,
                DLT_STRING("Error while waiting for files in dlt-system file transfer."));
        return -1;
    }

    unsigned int i = 0;
    while(i < (len-INOTIFY_SZ))
    {
        struct inotify_event *ie = (struct inotify_event *)&buf[i];
        if(ie->len > 0)
        {
            if((ie->mask & IN_CLOSE_WRITE) || (ie->mask & IN_MOVED_TO))
            {
                int j;
                for(j = 0;j < opts->Count;j++)
                {
                    if(ie->wd == ino.fd[j])
                    {
                        DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, found new file."));
                        int length = strlen(opts->Directory[j])+ie->len+1;
                        if (length > PATH_MAX)
                        {
                            DLT_LOG(filetransferContext, DLT_LOG_ERROR,
                                    DLT_STRING("dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "),DLT_INT(length));
                            return -1;
                        }
                        char *tosend = malloc(length);
                        snprintf(tosend,length, "%s/%s", opts->Directory[j], ie->name);
                        send_one(tosend, opts, j);
                        free(tosend);
                    }
                }
            }
        }
        i += INOTIFY_SZ + ie->len;
    }
#endif
    return 0;
}
Example #13
0
void start_filetransfer(DltSystemConfiguration *conf)
{
    DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, start."));
    static pthread_attr_t t_attr;
    static pthread_t pt;
    pthread_create(&pt, &t_attr, (void *)filetransfer_thread, conf);
    threads.threads[threads.count++] = pt;
}
Example #14
0
static void doInitAppcheck(const char* appName)
{

   char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
   snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), appName, plugin_gResTableCfg);

   if(access(rctFilename, F_OK) == 0)
   {
      gAppCheckFlag = 1;   // "trusted" application
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("trusted app"));
   }
   else
   {
      gAppCheckFlag = 0;   // currently not a "trusted" application
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("NOT trusted app"));
   }
}
Example #15
0
void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...)
{
	char msg[1024];

	va_list args;
	va_start(args, fmt);
	vsprintf(msg, fmt, args);

#ifndef GENIVI_DLT
	std::chrono::system_clock::time_point cNow = std::chrono::system_clock::now();
	time_t tNow = std::chrono::system_clock::to_time_t(cNow);
	struct tm tmNow;
	PLAT_localtime(&tNow, &tmNow);
	std::chrono::system_clock::duration roundNow = cNow - std::chrono::system_clock::from_time_t(tNow);
	long int millis = (long int) std::chrono::duration_cast<std::chrono::milliseconds>(roundNow).count();

	if (path) {
		fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] [%s:%u] %s\n",
			   tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, path, line, msg);
	}
	else {
		fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] %s\n",
			   tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, msg);
	}
#else
	DltLogLevelType dlt_level; 

	switch (level) {
	case GPTP_LOG_LVL_CRITICAL:
		dlt_level = DLT_LOG_FATAL;
		break;
	case GPTP_LOG_LVL_ERROR:
		dlt_level = DLT_LOG_ERROR;
		break;
	case GPTP_LOG_LVL_EXCEPTION:
	case GPTP_LOG_LVL_WARNING:
		dlt_level = DLT_LOG_WARN;
		break;
	case GPTP_LOG_LVL_INFO:
	case GPTP_LOG_LVL_STATUS:
		dlt_level = DLT_LOG_INFO;
		break;
	case GPTP_LOG_LVL_DEBUG:
		dlt_level = DLT_LOG_DEBUG;
		break;
	case GPTP_LOG_LVL_VERBOSE:
		dlt_level = DLT_LOG_VERBOSE;
		break;
	default:
		dlt_level = DLT_LOG_INFO;
		break;
	}

	DLT_LOG(dlt_con_gptp, dlt_level, DLT_STRING(msg));
#endif

}
Example #16
0
static int private_pclDeinitLibrary(void)
{
   int rval = 1;
   int* retval;

   MainLoopData_u data;
   data.message.cmd = (uint32_t)CMD_QUIT;
   data.message.string[0] = '\0';  // no string parameter, set to 0

   if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)  // unregister for lifecycle dbus messages
   {
      rval = unregister_lifecycle(gShutdownMode);
   }

#if USE_PASINTERFACE == 1
   rval = unregister_pers_admin_service();
   if(0 != rval)
 {
   DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclDeinitLibrary - Err to de-initialize IPC protocol for PCL."));
 }
   else
   {
     DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG,  DLT_STRING("pclDeinitLibrary - Succ de-initialized IPC protocol for PCL."));
   }
#endif

   process_prepare_shutdown(Shutdown_Full);           // close all db's and fd's and block access

   deliverToMainloop_NM(&data);                       // send quit command to dbus mainloop

   deleteHandleTrees();                               // delete allocated trees
   deleteBackupTree();
   deleteNotifyTree();

   pthread_join(gMainLoopThread, (void**)&retval);    // wait until the dbus mainloop has ended

   pthread_mutex_unlock(&gDbusPendingRegMtx);

#if USE_FILECACHE
   pfcDeinitCache();
#endif

   return rval;
}
static void watchToggled(DBusWatch *watch, void *data)
{
   (void)data;
   DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT64( (long)watch) );

   if(dbus_watch_get_enabled(watch))
      addWatch(watch, data);
   else
      removeWatch(watch, data);
}
Example #18
0
char *origin_name(char *src){
    if (strlen( (char*) basename(src)) > 10 ){
        return (char*)(basename(src)+10);
    }
    else{
        DLT_LOG(dltsystem, DLT_LOG_ERROR,
                DLT_STRING("dlt-system-filetransfer, error in recreating origin name!"));
        return NULL;
    }
}
static void
la_handler_service_constructed (GObject *object)
{
  LAHandlerService *service = LA_HANDLER_SERVICE (object);
  GError           *error = NULL;

  /* connect to the node state manager */
  service->nsm_consumer =
    nsm_consumer_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
                                         "org.genivi.NodeStateManager",
                                         "/org/genivi/NodeStateManager/Consumer",
                                          NULL, &error);
  if (error != NULL)
    {
      DLT_LOG (la_handler_context, DLT_LOG_ERROR,
               DLT_STRING ("Failed to connect to the NSM consumer:"),
               DLT_STRING (error->message));
      g_error_free (error);
    }
}
Example #20
0
void register_contexts(LogFileOptions fileopts)
{
	DLT_LOG(dltsystem, DLT_LOG_DEBUG,
			DLT_STRING("dlt-system-logfile, registering file contexts."));
	int i;
	for(i = 0;i < fileopts.Count;i++)
	{
		DLT_REGISTER_CONTEXT(logfileContext[i], fileopts.ContextId[i],
				fileopts.Filename[i]);
	}
}
Example #21
0
int pclDeinitLibrary(void)
{
   int rval = 1;

   pthread_mutex_lock(&gInitMutex);

   if(gPclInitCounter == 1)
   {
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - DEINIT  client lib - "), DLT_STRING(gAppId),
                                            DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter));
      rval = private_pclDeinitLibrary();

      gPclInitCounter--;   // decrement init counter
      DLT_UNREGISTER_CONTEXT(gPclDLTContext);
   }
   else if(gPclInitCounter > 1)
   {
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
                                           DLT_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitCounter));
      gPclInitCounter--;   // decrement init counter
   }
   else
   {
    DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
                                          DLT_STRING("- NOT INITIALIZED: "));
      rval = EPERS_NOT_INITIALIZED;
   }

   pthread_mutex_unlock(&gInitMutex);

   return rval;
}
int pclRecoverFromBackup(int backupFd, const char* original)
{
   int handle = open(original, O_TRUNC | O_RDWR);
   if(handle != -1)
   {
      if(pclBackupDoFileCopy(backupFd, handle) == -1)    // copy data from one file to another
      {
         DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("rBackup - couldn't write whole buffer"));
      }
   }

   return handle;
}
static void removeWatch(DBusWatch *watch, void *data)
{
   void* w_data = dbus_watch_get_data(watch);

   (void)data;

   DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT64( (long)watch) );

   if(w_data)
      free(w_data);

   dbus_watch_set_data(watch, NULL, NULL);
}
Example #24
0
void filetransfer_thread(void *v_conf)
{
    DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, in thread."));
    DltSystemConfiguration *conf = (DltSystemConfiguration *) v_conf;
    DLT_REGISTER_CONTEXT(filetransferContext, conf->Filetransfer.ContextId,
                         "File transfer manager.");

    sleep(conf->Filetransfer.TimeStartup);

    if(init_filetransfer_dirs(&(conf->Filetransfer)) < 0)
        return;

    while(!threads.shutdown)
    {
        if(wait_for_files(&(conf->Filetransfer)) < 0)
        {
            DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while waiting files. File transfer shutdown."));
            return;
        }
        sleep(conf->Filetransfer.TimeDelay);
    }
}
Example #25
0
void send_file(LogFileOptions fileopt, int n)
{
	DLT_LOG(dltsystem, DLT_LOG_DEBUG,
			DLT_STRING("dlt-system-logfile, sending file."));
	FILE * pFile;
	DltContext context = logfileContext[n];
	char buffer[1024];
	int bytes;
	int seq = 1;

	pFile = fopen(fileopt.Filename[n],"r");

	if(pFile != NULL)
	{
		while (!feof(pFile)) {
			bytes = fread(buffer,1,sizeof(buffer)-1,pFile);
			if(bytes>=0)
				buffer[bytes] = 0;
			else
				buffer[0] = 0;

			if(feof(pFile)) {
				DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq*-1), DLT_STRING(buffer));
				break;
			}
			else {
				DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq++), DLT_STRING(buffer));
			}
		}
		fclose(pFile);
	}
	else
	{
		DLT_LOG(dltsystem, DLT_LOG_ERROR,
				DLT_STRING("dlt-system-logfile, failed to open file."),
				DLT_STRING(fileopt.Filename[n]));
	}
}
Example #26
0
int flush_dir_original(FiletransferOptions const *opts, int which){
    struct dirent *dp;
    DIR *dir;
    const char *sdir = opts->Directory[which];
    dir = opendir(sdir);
    if(dir != NULL)
    {
        while((dp = readdir(dir)) != NULL)
        {
            if(dp->d_type != DT_REG){
                //we don't send directories
                continue;
            }
            DLT_LOG(dltsystem, DLT_LOG_DEBUG,
                    DLT_STRING("dlt-system-filetransfer, old file found in directory."));
            int len = strlen(sdir)+strlen(dp->d_name)+2;
            char *fn = malloc(len);
            MALLOC_ASSERT(fn);
            snprintf(fn,len, "%s/%s", sdir, dp->d_name);
            if(send_one(fn, opts, which) < 0)
            {
                closedir(dir);
                free(fn);
                return -1;
            }
            free(fn);
        }
    }
    else
    {
        DLT_LOG(dltsystem, DLT_LOG_ERROR,
                DLT_STRING("Could not open directory"),
                DLT_STRING(sdir));
        return -1;
    }
    closedir(dir);
    return 0;
}
Example #27
0
void send_dumped_file(FiletransferOptions const *opts,char *dst_tosend)
{

    char *fn = origin_name(dst_tosend);
    DLT_LOG(dltsystem, DLT_LOG_DEBUG,
            DLT_STRING("dlt-system-filetransfer, sending dumped file:"),DLT_STRING(fn));
    if(dlt_user_log_file_header_alias(&filetransferContext, dst_tosend, fn) == 0)
    {
        int pkgcount = dlt_user_log_file_packagesCount(&filetransferContext, dst_tosend);
        int lastpkg = 0;
        int success = 1;
        while(lastpkg < pkgcount)
        {
            int total = 2;
            int used = 2;
            dlt_user_check_buffer(&total, &used);
            while((total-used) < (total/2))
            {
                struct timespec t;
                t.tv_sec = 0;
                t.tv_nsec = 1000000ul*opts->TimeoutBetweenLogs;
                nanosleep(&t, NULL);
                dlt_user_check_buffer(&total, &used);
            }
            lastpkg++;
            if(dlt_user_log_file_data(&filetransferContext, dst_tosend, lastpkg, opts->TimeoutBetweenLogs) < 0)
            {
                success = 0;
                break;
            }
        }
        if (success)
            dlt_user_log_file_end(&filetransferContext, dst_tosend, 1);
    }
    DLT_LOG(dltsystem, DLT_LOG_DEBUG,
            DLT_STRING("dlt-system-filetransfer, sent dumped file"));
}
bool_t Test_Restore_Configurable_Default_User1(sint_t type, void* pv)
{
	bool_t 	bEverythingOK = true ;
	long	lRetVal;

	DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, 	DLT_STRING(LT_HDR),
												DLT_STRING("Restore configurable default for User1..."));

	lRetVal = persAdminDataRestore(	PersASSelectionType_User,
									PersASDefaultSource_Configurable,
									"",
									0x01,
									PERSIST_SELECT_ALL_SEATS);

	if(lRetVal < PAS_SUCCESS)
	{
		bEverythingOK = false;
	}

	DLT_LOG(persAdminSvcDLTCtx, DLT_LOG_INFO, 	DLT_STRING(LT_HDR),
												DLT_STRING("Test_Restore_Configurable_Default_User1: persAdminDataRestore() - "),
												DLT_STRING(bEverythingOK ? "OK" : "FAILED"));
	return bEverythingOK ;
} /* Test_Restore_Configurable_Default_User1 */
Example #29
0
int pclInitLibrary(const char* appName, int shutdownMode)
{
   int rval = 1;

   pthread_mutex_lock(&gInitMutex);
   if(gPclInitCounter == 0)
   {
      DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging");
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary => INIT  PCL - "), DLT_STRING(appName),
                              DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter) );

      rval = private_pclInitLibrary(appName, shutdownMode);
   }
   else
   {
      DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("pclInitLibrary - INIT  PCL - "), DLT_STRING(gAppId),
                                            DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitCounter) );
   }

   gPclInitCounter++;     // increment after private init, otherwise atomic access is too early
   pthread_mutex_unlock(&gInitMutex);

   return rval;
}
Example #30
0
int pclLifecycleSet(int shutdown)
{
   int rval = 0;

   if(gShutdownMode == PCL_SHUTDOWN_TYPE_NONE)
   {
      if(shutdown == PCL_SHUTDOWN)
      {
         DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId));
         process_prepare_shutdown(Shutdown_Partial);
         gCancelCounter++;
      }
      else if(shutdown == PCL_SHUTDOWN_CANCEL)
      {
         DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("lifecycleSet - PCL_SHUTDOWN_CANCEL -"), DLT_STRING(gAppId), DLT_STRING(" Cancel Counter - "), DLT_INT(gCancelCounter));
         if(gCancelCounter < Shutdown_MaxCount)
         {
           pers_unlock_access();
         }
         else
         {
           rval = EPERS_SHUTDOWN_MAX_CANCEL;
         }
      }
      else
      {
         rval = EPERS_COMMON;
      }
   }
   else
   {
      rval = EPERS_SHUTDOWN_NO_PERMIT;
   }

   return rval;
}