Changeset 4338f97


Ignore:
Timestamp:
02/25/15 14:57:20 (6 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
2e22196d
Parents:
116f970
Message:

Check the environment variables for configuration of formats

We search for 3 environment variables and apply them to the config in the
following order. Such that the first has the lowest priority.

  1. LIBTRACE_CONF, The global environment configuration
  2. LIBTRACE_CONF_<FORMAT>, Applied to a given format
  3. LIBTRACE_CONF_<FORMAT_URI>, Applied the specified trace
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace_parallel.c

    r526d9d0 r4338f97  
    100100#include <signal.h>
    101101#include <unistd.h>
     102#include <ctype.h>
    102103
    103104static inline int delay_tracetime(libtrace_t *libtrace, libtrace_packet_t *packet, libtrace_thread_t *t);
     
    404405 */
    405406static inline int dispatch_packet(libtrace_t *trace,
    406                                                  libtrace_thread_t *t,
    407                                                  libtrace_packet_t **packet,
    408                                                  bool tracetime) {
     407                                  libtrace_thread_t *t,
     408                                  libtrace_packet_t **packet,
     409                                  bool tracetime) {
    409410        if ((*packet)->error > 0) {
    410411                if (tracetime) {
     
    902903 */
    903904inline static int trace_pread_packet_hasher_thread(libtrace_t *libtrace,
    904                                                       libtrace_thread_t *t,
    905                                                       libtrace_packet_t *packets[],
    906                                                       size_t nb_packets) {
     905                                                   libtrace_thread_t *t,
     906                                                   libtrace_packet_t *packets[],
     907                                                   size_t nb_packets) {
    907908        size_t i;
    908909
     
    15451546
    15461547        /* Figure out if we are using a dedicated hasher thread? */
    1547         if (require_hasher && libtrace->config.perpkt_threads > 1) {
     1548        if (require_hasher && libtrace->perpkt_thread_count > 1) {
    15481549                libtrace->hasher_thread.type = THREAD_HASHER;
    15491550        }
     
    15981599}
    15991600
     1601/** Parses the environment variable LIBTRACE_CONF into the supplied
     1602 * configuration structure.
     1603 *
     1604 * @param libtrace The trace from which we determine the URI
     1605 * @param uc A configuration structure to be configured.
     1606 *
     1607 * We search for 3 environment variables and apply them to the config in the
     1608 * following order. Such that the first has the lowest priority.
     1609 *
     1610 * 1. LIBTRACE_CONF, The global environment configuration
     1611 * 2. LIBTRACE_CONF_<FORMAT>, Applied to a given format
     1612 * 3. LIBTRACE_CONF_<FORMAT_URI>, Applied the specified trace
     1613 *
     1614 * E.g.
     1615 * - int:eth0 would match LIBTRACE_CONF, LIBTRACE_CONF_INT, LIBTRACE_CONF_INT_ETH0
     1616 * - dag:/dev/dag0,0 would match LIBTRACE_CONF, LIBTRACE_CONF_DAG, LIBTRACE_CONF_DAG__DEV_DAG0_0
     1617 * - test.erf would match LIBTRACE_CONF, LIBTRACE_CONF_ERF, LIBTRACE_CONF_ERF_TEST_ERF
     1618 *
     1619 * @note All enironment variables names MUST only contian
     1620 * [A-Z], [0-9] and [_] (underscore) and not start with a number. Any characters
     1621 * outside of this range should be captilised if possible or replaced with an
     1622 * underscore.
     1623 */
     1624static void parse_env_config (libtrace_t *libtrace, struct user_configuration* uc) {
     1625        char env_name[1024] = "LIBTRACE_CONF_";
     1626        size_t len = strlen(env_name);
     1627        size_t mark = 0;
     1628        size_t i;
     1629        char * env;
     1630
     1631        /* Make our compound string */
     1632        strncpy(&env_name[len], libtrace->format->name, sizeof(env_name) - len);
     1633        len += strlen(libtrace->format->name);
     1634        strncpy(&env_name[len], ":", sizeof(env_name) - len);
     1635        len += 1;
     1636        strncpy(&env_name[len], libtrace->uridata, sizeof(env_name) - len);
     1637
     1638        /* env names are allowed to be A-Z (CAPS) 0-9 and _ */
     1639        for (i = 0; env_name[i] != 0; ++i) {
     1640                env_name[i] = toupper(env_name[i]);
     1641                if(env_name[i] == ':') {
     1642                        mark = i;
     1643                }
     1644                if (!( (env_name[i] >= 'A' && env_name[i] <= 'Z') ||
     1645                       (env_name[i] >= '0' && env_name[i] <= '9') )) {
     1646                        env_name[i] = '_';
     1647                }
     1648        }
     1649
     1650        /* First apply global env settings LIBTRACE_CONF */
     1651        env = getenv("LIBTRACE_CONF");
     1652        if (env)
     1653        {
     1654                printf("Got env %s", env);
     1655                parse_user_config(uc, env);
     1656        }
     1657
     1658        /* Then format settings LIBTRACE_CONF_<FORMAT> */
     1659        if (mark != 0) {
     1660                env_name[mark] = 0;
     1661                env = getenv(env_name);
     1662                if (env) {
     1663                        printf("Got %s=%s", env_name, env);
     1664                        parse_user_config(uc, env);
     1665                }
     1666                env_name[mark] = '_';
     1667        }
     1668
     1669        /* Finally this specific trace LIBTRACE_CONF_<FORMAT_URI> */
     1670        env = getenv(env_name);
     1671        if (env) {
     1672                printf("Got %s=%s", env_name, env);
     1673                parse_user_config(uc, env);
     1674        }
     1675}
     1676
    16001677/* Start an input trace in the parallel libtrace framework.
    16011678 * This can also be used to restart an existing parallel.
     
    16501727        libtrace_parallel = 1;
    16511728
     1729        /* Parses configuration passed through environment variables */
     1730        parse_env_config(libtrace, &libtrace->config);
    16521731        verify_configuration(libtrace);
    16531732
Note: See TracChangeset for help on using the changeset viewer.