Ejemplo n.º 1
0
int citp_do_init(int max_init_level)
{
  int rc = 0;
  int level;
  int saved_errno = errno;

  if( citp.init_level < max_init_level ) {
    /* If threads are launched very early in program startup, then there could be
     * a race here as multiple threads attempt to initialise on first access.
     * The guard must be recursive, since this function might be re-entered during
     * initialisation.
     */
    static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

    pthread_mutex_lock(&mutex);
    _citp_do_init_inprogress++;

    for (level = citp.init_level;
         level < CI_MIN(max_init_level, CITP_INIT_ALL);
         level++) {
      rc = cipt_init_funcs[level]();
      if (rc < 0)
        break;
      citp.init_level = level + 1;
    }

    --_citp_do_init_inprogress;
    pthread_mutex_unlock(&mutex);
  }
  Log_S(log("%s: reached level %d", __FUNCTION__, citp.init_level));
  if( rc == 0 )
    errno = saved_errno;
  return rc;
}
Ejemplo n.º 2
0
void _init(void)
{
  /* must not do any logging yet... */
  if( citp_do_init(CITP_INIT_ALL) < 0 )
    ci_fail(("EtherFabric transport library: failed to initialise (%d)",
             citp.init_level));

  Log_S(log("citp: initialisation done."));
}
Ejemplo n.º 3
0
void _init(void)
{
  if (getpagesize() != CI_PAGE_SIZE)
    ci_fail(("Page size mismatch, expected %u, "
             "but the current value is %u",
             CI_PAGE_SIZE, getpagesize()));
  /* must not do any logging yet... */
  if( citp_do_init(CITP_INIT_ALL) < 0 )
    ci_fail(("EtherFabric transport library: failed to initialise (%d)",
             citp.init_level));

  Log_S(log("citp: initialisation done."));
}
Ejemplo n.º 4
0
void citp_log_change_fd(void)
{
  int newfd, prev;
  /* We need to change logging fd, probably because someone wants to do a
  ** dup2() onto it.
  **
  ** No need to set 'close-on-exec' (FD_CLOEXEC) again for the newfd as
  ** it will be copied by the dup().
  */
  CITP_FDTABLE_LOCK();
  prev = citp.log_fd;
  newfd = oo_fcntl_dupfd_cloexec(prev, 3);
  if( newfd >= 0 ) {
    __citp_fdtable_reserve(newfd, 1);
    citp.log_fd = newfd;
  }
  Log_S(log("%s: old=%d new=%d", __FUNCTION__, prev, newfd));
  __citp_fdtable_reserve(prev, 0);
  ci_sys_close(prev);
  CITP_FDTABLE_UNLOCK();
}
Ejemplo n.º 5
0
int citp_do_init(int max_init_level)
{
  int rc = 0;
  int level;
  int saved_errno = errno;

  _citp_do_init_inprogress++;

  for (level = citp.init_level;
       level < CI_MIN(max_init_level, CITP_INIT_ALL);
       level++) {
    rc = cipt_init_funcs[level]();
    if (rc < 0)
      break;
    citp.init_level = level + 1;
  }

  --_citp_do_init_inprogress;
  Log_S(log("%s: reached level %d", __FUNCTION__, citp.init_level));
  if( rc == 0 )
    errno = saved_errno;
  return rc;
}
Ejemplo n.º 6
0
int citp_fdtable_ctor()
{
  struct rlimit rlim;
  int rc;

  Log_S(log("%s:", __FUNCTION__));

  /* How big should our fdtable be by default?  It's pretty arbitrary, but we have
   * seen a few apps that use setrlimit to set the fdtable to 4096 entries on
   * start-up (see bugs 3253 and 3373), so we choose that.  (Note: we can't grow
   * the table if the app later does setrlimit, and unused entries consume virtual
   * space only, so it's worth allocating a table of reasonable sized.)
   */
  citp_fdtable.size = 4096;

  if( getrlimit(RLIMIT_NOFILE, &rlim) == 0 ) {
    citp_fdtable.size = rlim.rlim_max;
    if( CITP_OPTS.fdtable_size != 0 &&
        CITP_OPTS.fdtable_size != rlim.rlim_max ) {
      Log_S(ci_log("Set the limits for the number of opened files "
                   "to EF_FDTABLE_SIZE=%u value.",
                   CITP_OPTS.fdtable_size));
      rlim.rlim_max = CITP_OPTS.fdtable_size;
      if( rlim.rlim_cur > rlim.rlim_max )
        rlim.rlim_cur = rlim.rlim_max;
      if( ci_sys_setrlimit(RLIMIT_NOFILE, &rlim) == 0 )
          citp_fdtable.size = rlim.rlim_max;
      else {
        /* Most probably, we've got EPERM */
        ci_assert_lt(citp_fdtable.size, CITP_OPTS.fdtable_size);
        ci_log("Can't set EF_FDTABLE_SIZE=%u; using %u",
               CITP_OPTS.fdtable_size, citp_fdtable.size);
        rlim.rlim_max = rlim.rlim_cur = citp_fdtable.size;
        CI_TRY(ci_sys_setrlimit(RLIMIT_NOFILE, &rlim));
      }
    }
  }
  else
    Log_S(ci_log("Assume EF_FDTABLE_SIZE=%u", citp_fdtable.size));

  citp_fdtable.inited_count = 0;

  citp_fdtable.table = ci_libc_malloc(sizeof (citp_fdtable_entry) *
                                      citp_fdtable.size);
  if( ! citp_fdtable.table ) {
    Log_U(log("%s: failed to allocate fdtable (0x%x)", __FUNCTION__,
              citp_fdtable.size));
    return -1;
  }

  /* The whole table is not initialised at start-of-day, but is initialised
  ** on demand.  citp_fdtable.inited_count counts the number of initialised
  ** entries.
  */

  if( (rc = oo_rwlock_ctor(&citp_ul_lock)) != 0 ) {
    Log_E(log("%s: oo_rwlock_ctor %d", __FUNCTION__, rc));
    return -1;
  }

  /* Install SIGONLOAD handler */
  {
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa)); /* sa_flags and sa_mask = 0 */
    sa.sa_handler = sighandler_do_nothing;
    sigaction(SIGONLOAD, &sa, NULL);
  }

  return 0;
}
Ejemplo n.º 7
0
void _fini(void)
{
  Log_S(log("citp: finishing up"));
}
Ejemplo n.º 8
0
void _fini(void)
{
  Log_S(log("citp: finishing up"));
  uncache_active_netifs();
}