Exemplo n.º 1
0
   void run(int argc, char* argv[], char* env[])
      {
      U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)

      UApplication::run(argc, argv, env);

      U_ASSERT( num_args == 2 )

      U_ASSERT( opt[(uint32_t)0U] == U_STRING_FROM_CONSTANT("1") )
      U_ASSERT( opt[(uint32_t)1U] == U_STRING_FROM_CONSTANT("pippo") )
      U_ASSERT( opt[(uint32_t)2U] == U_STRING_FROM_CONSTANT("Hello") )
      U_ASSERT( opt[(uint32_t)3U] == U_STRING_FROM_CONSTANT("1") )
      U_ASSERT( opt[(uint32_t)4U] == U_STRING_FROM_CONSTANT("Bucaiolo_a_te") )

      U_ASSERT( opt['a'] == U_STRING_FROM_CONSTANT("1") )
      U_ASSERT( opt['b'] == U_STRING_FROM_CONSTANT("pippo") )
      U_ASSERT( opt['c'] == U_STRING_FROM_CONSTANT("Hello") )

      U_ASSERT( opt[U_STRING_FROM_CONSTANT("option_with_no_short_1")] == U_STRING_FROM_CONSTANT("1") )
      U_ASSERT( opt[U_STRING_FROM_CONSTANT("option_with_no_short_2")] == U_STRING_FROM_CONSTANT("Bucaiolo_a_te") )

      U_ASSERT( strcmp(argv[optind], "argument_1") == 0 )
      ++optind;
      U_ASSERT( strcmp(argv[optind], "argument_2") == 0 )

      u_atexit(reset);

      (void) write(STDOUT_FILENO, U_CONSTANT_TO_PARAM("AutoSending SIGTERM...\n"));
      
#  ifndef DEBUG
      UInterrupt::act.sa_flags   = 0;
      UInterrupt::act.sa_handler = UInterrupt::handlerInterrupt;

      (void) U_SYSCALL(sigaction, "%d,%p,%p", SIGTERM, &UInterrupt::act, 0); // 15
#  endif

      UInterrupt::sendSignal(SIGTERM, u_pid);
      }
Exemplo n.º 2
0
bool ULog::open(uint32_t _size, mode_t mode)
{
   U_TRACE(0, "ULog::open(%u,%d)", _size, mode)

   // NB: we need to check because all instance try to close the log... (inherits from its parent)

   u_atexit(&ULog::close); // register function of close at exit()...

   if (UFile::getPath() == U_STRING_FROM_CONSTANT("syslog"))
      {
      prefix  = 0;
      pthis   = this;
      bsyslog = true;

#  ifndef __MINGW32__
      U_SYSCALL_VOID(openlog, "%S,%d,%d", u_progname, LOG_PID, LOG_LOCAL0);
#  endif

      U_RETURN(true);
      }

   if (UFile::creat(O_CREAT | O_RDWR | O_APPEND, mode))
      {
      uint32_t file_size = 0;

      if (_size)
         {
         file_size = UFile::size();

         if (UFile::ftruncate(_size)               == false ||
             UFile::memmap(PROT_READ | PROT_WRITE) == false)
            {
            goto end;
            }
         }

      pthis        = this;
      ptr_log_data = U_MALLOC_TYPE(log_data);

      LOG_ptr = LOG_page = (_size ? (UFile::map + file_size)      : 0); // append mode...
              file_limit = (_size ? (UFile::map + UFile::st_size) : 0);

      U_INTERNAL_ASSERT_EQUALS(lock,0)

      lock = U_NEW(ULock);

      U_INTERNAL_ASSERT_POINTER(lock)

#  ifdef USE_LIBZ
      backup_log_function = &ULog::backup;

      dir_log_gz = (const char*) U_SYSCALL(getenv, "%S", "DIR_LOG_GZ");

      UInterrupt::setHandlerForSignal(SIGUSR1, (sighandler_t)ULog::handlerSIGUSR1);
#  endif

      if (fmt) startup();

      U_RETURN(true);
      }

end:
   U_ERROR("cannot init log file %.*S...", U_FILE_TO_TRACE(*this));

   U_RETURN(false);
}