Ejemplo n.º 1
0
/** @This initializes an already allocated uprobe_pfx structure.
 *
 * @param uprobe_pfx pointer to the already allocated structure
 * @param next next probe to test if this one doesn't catch the event
 * @param min_level minimum level of passed-through messages
 * @param name name of the pipe (informative)
 * @return pointer to uprobe, or NULL in case of error
 */
struct uprobe *uprobe_pfx_init(struct uprobe_pfx *uprobe_pfx,
                               struct uprobe *next,
                               enum uprobe_log_level min_level,
                               const char *name)
{
    assert(uprobe_pfx != NULL);
    struct uprobe *uprobe = uprobe_pfx_to_uprobe(uprobe_pfx);
    if (likely(name != NULL)) {
        uprobe_pfx->name = strdup(name);
        if (unlikely(uprobe_pfx->name == NULL)) {
            uprobe_err(next, NULL, "allocation error in uprobe_pfx_init");
            uprobe_throw(next, NULL, UPROBE_FATAL, UBASE_ERR_ALLOC);
        }
    } else
        uprobe_pfx->name = NULL;
    uprobe_pfx->min_level = min_level;
    uprobe_init(uprobe, uprobe_pfx_throw, next);
    return uprobe;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    struct uprobe *uprobe1 = uprobe_stdio_alloc(NULL, stdout, UPROBE_LOG_DEBUG);
    assert(uprobe1 != NULL);

    uprobe_err(uprobe1, NULL, "This is an error");
    uprobe_warn_va(uprobe1, NULL, "This is a %s warning with %d", "composite",
                   0x42);
    uprobe_notice(uprobe1, NULL, "This is a notice");
    uprobe_dbg(uprobe1, NULL, "This is a debug");
    uprobe_stdio_free(uprobe1);

    struct uprobe *uprobe2 = uprobe_stdio_alloc(NULL, stdout, UPROBE_LOG_ERROR);
    assert(uprobe2 != NULL);
    uprobe_err_va(uprobe2, NULL, "This is another error with %d", 0x43);
    uprobe_warn(uprobe2, NULL, "This is a warning that you shouldn't see");
    uprobe_stdio_free(uprobe2);
    return 0;
}