Beispiel #1
0
static void logger_term(void *arg)
{
    char *lmsbuf = NULL;             /* xxx                       */
    int   lmsnum = -1;               /* xxx                       */
    int   lmscnt = -1;               /* xxx                       */
    char* term_msg = MSG(HHC02103, "I");

    UNREFERENCED(arg);

    log_wakeup(NULL);
    usleep(1000);

    /* Flush all pending logger o/p before redirecting?? */
    fflush(stdout);

    if(logger_active)
    {
        /* Redirect all output to stderr */
        dup2(STDERR_FILENO, STDOUT_FILENO);

        /* Tell logger thread we want it to exit */
        logger_active = 0;
        log_wakeup(NULL);
        usleep(1000);

        if ( logger_tid != 0 && !sysblk.shutdown )
        {
            sleep(2);
            /* Logger is now terminating */
            obtain_lock(&logger_lock);

            /* Wait for the logger to terminate */
            join_thread( logger_tid, NULL );
            detach_thread( logger_tid );

            release_lock(&logger_lock);

        }

        if ( fwrite("\n",1,1,stderr) ) {
            perror(QLINE "fwrite failure/HHC02102 ");
        }
        /* Read and display any msgs still remaining in the system log */
        lmsnum = log_line(-1);
        while((lmscnt = log_read(&lmsbuf, &lmsnum, LOG_BLOCK)))
        {
            char *p = NULL;
            char *strtok_str = NULL;

            lmsbuf[lmscnt-1] = '\0';

            p = strtok_r( lmsbuf, "\n", &strtok_str );
            while ( (p = strtok_r(NULL, "\n", &strtok_str ) ) != NULL )
            {
                char*   pLeft = p;
                int     nLeft = (int)strlen(p);

#if defined( OPTION_MSGCLR )
                /* Remove "<pnl,..." color string if it exists */
                if (1
                        && nLeft > 5
                        && strncasecmp( pLeft, "<pnl", 4 ) == 0
                        && (pLeft = memchr( pLeft+4, '>', nLeft-4 )) != NULL
                   )
                {
                    pLeft++;
                    nLeft -= (int)(pLeft - p);
                }
#endif // defined( OPTION_MSGCLR )
                if (nLeft)
                {
                    if ( fwrite(pLeft,nLeft,1,stderr) ) {
                        perror(QLINE "fwrite failure/HHC02102 ");
                    }
                    if ( fwrite("\n",1,1,stderr) ) {
                        perror(QLINE "fwrite failure/HHC02102 ");
                    }
                }
            }
        }
        if ( fwrite( term_msg, strlen(term_msg), 1, stderr ) ) {
            perror(QLINE "fwrite failure/HHC02102 ");
        }

        fflush(stderr);
    }
}
/* Blocks until one or more of the events registered with poll_fd_wait()
 * occurs, or until the minimum duration registered with poll_timer_wait()
 * elapses, or not at all if poll_immediate_wake() has been called.
 *
 * Also executes any autonomous subroutines registered with poll_fd_callback(),
 * if their file descriptors have become ready. */
void
poll_block(void)
{
    static struct pollfd *pollfds;
    static size_t max_pollfds;

    struct poll_waiter *pw;
    struct list *node;
    int n_pollfds;
    int retval;

    assert(!running_cb);
    if (max_pollfds < n_waiters) {
        max_pollfds = n_waiters;
        pollfds = xrealloc(pollfds, max_pollfds * sizeof *pollfds);
    }

    n_pollfds = 0;
    LIST_FOR_EACH (pw, struct poll_waiter, node, &waiters) {
        pw->pollfd = &pollfds[n_pollfds];
        pollfds[n_pollfds].fd = pw->fd;
        pollfds[n_pollfds].events = pw->events;
        pollfds[n_pollfds].revents = 0;
        n_pollfds++;
    }

    retval = time_poll(pollfds, n_pollfds, timeout);
    if (retval < 0) {
        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
        VLOG_ERR_RL(&rl, "poll: %s", strerror(-retval));
    } else if (!retval && VLOG_IS_DBG_ENABLED()) {
        log_wakeup(&timeout_backtrace, "%d-ms timeout", timeout);
    }

    for (node = waiters.next; node != &waiters; ) {
        pw = CONTAINER_OF(node, struct poll_waiter, node);
        if (!pw->pollfd || !pw->pollfd->revents) {
            if (pw->function) {
                node = node->next;
                continue;
            }
        } else {
            if (VLOG_IS_DBG_ENABLED()) {
                log_wakeup(pw->backtrace, "%s%s%s%s%s on fd %d",
                           pw->pollfd->revents & POLLIN ? "[POLLIN]" : "",
                           pw->pollfd->revents & POLLOUT ? "[POLLOUT]" : "",
                           pw->pollfd->revents & POLLERR ? "[POLLERR]" : "",
                           pw->pollfd->revents & POLLHUP ? "[POLLHUP]" : "",
                           pw->pollfd->revents & POLLNVAL ? "[POLLNVAL]" : "",
                           pw->fd);
            }

            if (pw->function) {
#ifndef NDEBUG
                running_cb = pw;
#endif
                pw->function(pw->fd, pw->pollfd->revents, pw->aux);
#ifndef NDEBUG
                running_cb = NULL;
#endif
            }
        }
        node = node->next;
        poll_cancel(pw);
    }

    timeout = -1;
    timeout_backtrace.n_frames = 0;
}
Beispiel #3
0
DLL_EXPORT void writemsg(const char *srcfile, int line, const char* function,
                         int grp, int lvl, char *color, char *msg, ...)
{
    char   *bfr     =   NULL;
    char   *msgbuf  =   NULL;
    int     rc      =   1;
    int     errmsg  =   FALSE;
    int     siz     =   1024;
    char    file[FILENAME_MAX];
    char    prefix[64];
    va_list vl;

    bfr = strdup(srcfile);
    strlcpy(file, basename(bfr), sizeof(file));
    free(bfr);
    bfr = NULL;

    memset(prefix, 0, sizeof(prefix));

#ifdef OPTION_MSGLCK
    if(!sysblk.msggrp || (sysblk.msggrp && !grp))
        WRGMSG_ON;
#endif

  #ifdef NEED_LOGMSG_FFLUSH
    fflush(stdout);
  #endif

    BFR_VSNPRINTF();

    if (!bfr)
    {
#ifdef OPTION_MSGLCK
        if(!sysblk.msggrp || (sysblk.msggrp && !grp))
            WRGMSG_OFF;
#endif
        return;
    }

    if ( strlen(bfr) > 10 && SNCMP(bfr,"HHC",3) && (bfr[8] == 'S' || bfr[8] == 'E' || bfr[8] == 'W') )
        errmsg = TRUE;

#if defined( OPTION_MSGCLR )
    if ( !strlen(color) )
    {
        if ( errmsg )
            color = "<pnl,color(lightred,black),keep>";
        else
            color = "";
    }
#else
    color = "";
#endif // defined( OPTION_MSGCLR )

    if ( lvl & MLVL_DEBUG )
    {
#if defined( OPTION_MSGCLR )
        if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init && !sysblk.daemon_mode)
            MSGBUF(prefix, "%s" MLVL_DEBUG_PRINTF_PATTERN, color, file, line);
        else
#endif
            MSGBUF(prefix, MLVL_DEBUG_PRINTF_PATTERN, file, line);
    }
    else
    {
#if defined( OPTION_MSGCLR )
        if (strlen(color) > 0 && !sysblk.shutdown && sysblk.panel_init && !sysblk.daemon_mode)
        {
            MSGBUF(prefix, "%s", color );
        }
#endif // defined( OPTION_MSGCLR )
    }

    if(bfr)
    {
        size_t l = strlen(prefix)+strlen(bfr)+256;
        msgbuf = calloc(1,l);
        if (msgbuf)
        {
            if ( strlen(bfr) > 10 && SNCMP(bfr, "HHC", 3) )
                snprintf( msgbuf, l-1, "%s%s", prefix, ( sysblk.emsg & EMSG_TEXT ) ? &bfr[10] : bfr );
            else
                snprintf( msgbuf, l-1, "%s%s", prefix, bfr );
            log_write( 0, msgbuf );
            free(msgbuf);
        }
        free(bfr);
    }

    if ( errmsg && !MLVL(DEBUG) )
        logmsg("HHC00007" "I" " " HHC00007 "\n", function, file, line);

  #ifdef NEED_LOGMSG_FFLUSH
    fflush(stdout);
  #endif

#ifdef OPTION_MSGLCK
    if(!sysblk.msggrp || (sysblk.msggrp && !grp))
        WRGMSG_OFF;
#endif

    log_wakeup(NULL);
}