Changeset b94c5ec in rtems-libbsd


Ignore:
Timestamp:
11/03/14 14:21:06 (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
Children:
7ba9b7f
Parents:
f90fdf3
git-author:
Sebastian Huber <sebastian.huber@…> (11/03/14 14:21:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/04/14 12:02:55)
Message:

NSDISPATCH(3): Add rtems_nss_register_module()

Location:
freebsd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • freebsd/include/nsswitch.h

    rf90fdf3 rb94c5ec  
    216216        ns_mtab         *mtab;          /* method table */
    217217        unsigned int     mtabsize;      /* count of entries in method table */
     218#ifndef __rtems__
    218219        nss_module_unregister_fn unregister; /* called to unload module */
     220#endif /* __rtems__ */
    219221} ns_mod;
    220222
     
    239241#endif
    240242#endif /* _NS_PRIVATE */
     243#ifdef __rtems__
     244/**
     245 * @brief Registers a name service module.
     246 *
     247 * @param[in] source The source identifier.
     248 * @param[in] mtab The module table.  This table will be claimed by the name
     249 *   service dispatcher.
     250 * @param[in] mtabsize The module table entry count.
     251 *
     252 * @retval 0 Successful operation.
     253 * @retval -1 An error occurred.  The errno is set to indicate the error.
     254 */
     255int
     256rtems_nss_register_module(const char *source, ns_mtab *mtab,
     257    unsigned int mtabsize);
     258#endif /* __rtems__ */
    241259
    242260__END_DECLS
  • freebsd/lib/libc/net/nsdispatch.c

    rf90fdf3 rb94c5ec  
    133133static  ns_mod                  *_nsmod;
    134134
     135#ifndef __rtems__
    135136/* Placeholder for builtin modules' dlopen `handle'. */
    136137static  int                      __nss_builtin_handle;
    137138static  void                    *nss_builtin_handle = &__nss_builtin_handle;
     139#endif /* __rtems__ */
    138140
    139141#ifdef NS_CACHING
     
    190192static  int      nss_configure(void);
    191193static  void     ns_dbt_free(ns_dbt *);
     194#ifndef __rtems__
    192195static  void     ns_mod_free(ns_mod *);
     196#endif /* __rtems__ */
    193197static  void     ns_src_free(ns_src **, int);
     198#ifndef __rtems__
    194199static  void     nss_load_builtin_modules(void);
    195200static  void     nss_load_module(const char *, nss_module_register_fn);
    196201static  void     nss_atexit(void);
     202#endif /* __rtems__ */
    197203/* nsparser */
    198204extern  FILE    *_nsyyin;
     
    300306        modp = vector_search(&src->name, _nsmod, _nsmodsize, sizeof(*_nsmod),
    301307            string_compare);
     308#ifndef __rtems__
    302309        if (modp == NULL)
    303310                nss_load_module(src->name, NULL);
     311#else /* __rtems__ */
     312        (void)modp;
     313#endif /* __rtems__ */
    304314}
    305315
     
    380390        VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap),
    381391            (vector_free_elem)ns_dbt_free);
     392#ifndef __rtems__
    382393        VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod),
    383394            (vector_free_elem)ns_mod_free);
    384395        nss_load_builtin_modules();
     396#endif /* __rtems__ */
    385397        _nsyyparse();
    386398        (void)fclose(_nsyyin);
    387399        vector_sort(_nsmap, _nsmapsize, sizeof(*_nsmap), string_compare);
     400#ifndef __rtems__
    388401        if (confmod == 0)
    389402                (void)atexit(nss_atexit);
     403#endif /* __rtems__ */
    390404        confmod = statbuf.st_mtime;
    391405
     
    457471
    458472
     473#ifndef __rtems__
    459474/*
    460475 * NSS module management.
     
    500515        } else if (!is_dynamic())
    501516                goto fin;
    502 #ifndef __rtems__
    503517        else {
    504518                if (snprintf(buf, sizeof(buf), "nss_%s.so.%d", mod.name,
     
    524538                }
    525539        }
    526 #endif /* __rtems__ */
    527540        mod.mtab = fn(mod.name, &mod.mtabsize, &mod.unregister);
    528541        if (mod.mtab == NULL || mod.mtabsize == 0) {
    529 #ifndef __rtems__
    530542                if (mod.handle != nss_builtin_handle)
    531543                        (void)dlclose(mod.handle);
    532 #endif /* __rtems__ */
    533544                mod.handle = NULL;
    534545                nss_log(LOG_ERR, "%s, registration failed", mod.name);
     
    554565        if (mod->unregister != NULL)
    555566                mod->unregister(mod->mtab, mod->mtabsize);
    556 #ifndef __rtems__
    557567        if (mod->handle != nss_builtin_handle)
    558568                (void)dlclose(mod->handle);
    559 #endif /* __rtems__ */
    560569}
    561570
     
    580589                (void)_pthread_rwlock_unlock(&nss_lock);
    581590}
     591#else /* __rtems__ */
     592int
     593rtems_nss_register_module(const char *source, ns_mtab *mtab,
     594    unsigned int mtabsize)
     595{
     596        ns_mod mod;
     597        int result;
     598
     599        if (mtab == NULL || mtabsize == 0) {
     600                errno = EINVAL;
     601                return -1;
     602        }
     603
     604        memset(&mod, 0, sizeof(mod));
     605        mod.name = strdup(source);
     606        if (mod.name == NULL) {
     607                return -1;
     608        }
     609        mod.handle = (void *)1;
     610        mod.mtab = mtab;
     611        mod.mtabsize = mtabsize;
     612        qsort(mod.mtab, mod.mtabsize, sizeof(mod.mtab[0]), mtab_compare);
     613
     614        result = _pthread_rwlock_wrlock(&nss_lock);
     615        if (result != 0) {
     616                errno = result;
     617                return -1;
     618        }
     619
     620        _nsmod = vector_append(&mod, _nsmod, &_nsmodsize, sizeof(*_nsmod));
     621        vector_sort(_nsmod, _nsmodsize, sizeof(*_nsmod), string_compare);
     622
     623        (void)_pthread_rwlock_unlock(&nss_lock);
     624
     625        return 0;
     626}
     627#endif /* __rtems__ */
    582628
    583629
Note: See TracChangeset for help on using the changeset viewer.