Пример #1
0
void notify_init(void)
{
	STAILQ_INIT(&clients);
	register_notifier(console_notifier);
}
Пример #2
0
void *network_thread (void *data)
{
    struct installer *instp = (struct installer *)data;
    int ctrllisten, ctrlconnfd;
    socklen_t clilen;
    struct sockaddr_un cliaddr;
    ipc_message msg;
    int nread;
    struct msg_elem *notification;
    int ret;

    if (!instp) {
        TRACE("Fatal error: Network thread aborting...");
        return (void *)0;
    }

    SIMPLEQ_INIT(&notifymsgs);
    register_notifier(network_notifier);

    /* Initialize and bind to UDS */
    ctrllisten = listener_create(SOCKET_CTRL_PATH, SOCK_STREAM);
    if (ctrllisten < 0 ) {
        TRACE("Error creating IPC sockets");
        exit(2);
    }

    do {
        clilen = sizeof(cliaddr);
        if ( (ctrlconnfd = accept(ctrllisten, (struct sockaddr *) &cliaddr, &clilen)) < 0) {
            if (errno == EINTR)
                continue;
            else {
                TRACE("Accept returns: %s", strerror(errno));
                continue;
            }
        }
        nread = read(ctrlconnfd, (void *)&msg, sizeof(msg));

        if (nread != sizeof(msg)) {
            TRACE("IPC message too short: fragmentation not supported");
            close(ctrlconnfd);
            continue;
        }
#ifdef DEBUG_IPC
        TRACE("request header: magic[0x%08X] type[0x%08X]", msg.magic, msg.type);
#endif

        pthread_mutex_lock(&stream_mutex);
        if (msg.magic == IPC_MAGIC)  {
            switch (msg.type) {
            case REQ_INSTALL:
                TRACE("Incoming network request: processing...");
                if (instp->status == IDLE) {
                    instp->fd = ctrlconnfd;
                    msg.type = ACK;

                    /* Drop all old notification from last run */
                    cleanum_msg_list();

                    /* Wake-up the installer */
                    pthread_cond_signal(&stream_wkup);
                } else {
                    msg.type = NACK;
                    sprintf(msg.data.msg, "Installation in progress");
                }
                break;
            case GET_STATUS:
                msg.type = GET_STATUS;
                memset(msg.data.msg, 0, sizeof(msg.data.msg));
                msg.data.status.current = instp->status;
                msg.data.status.last_result = instp->last_install;
                msg.data.status.error = instp->last_error;

                /* Get first notification from the queue */
                pthread_mutex_lock(&msglock);
                notification = SIMPLEQ_FIRST(&notifymsgs);
                if (notification) {
                    SIMPLEQ_REMOVE_HEAD(&notifymsgs, next);
                    nrmsgs--;
                    strncpy(msg.data.status.desc, notification->msg,
                            sizeof(msg.data.status.desc) - 1);
#ifdef DEBUG_IPC
                    printf("GET STATUS: %s\n", msg.data.status.desc);
#endif
                    msg.data.status.current = notification->status;
                    msg.data.status.error = notification->error;
                }
                pthread_mutex_unlock(&msglock);

                break;
            default:
                msg.type = NACK;
            }
        } else {
            /* Wrong request */
            msg.type = NACK;
            sprintf(msg.data.msg, "Wrong request: aborting");
        }
        ret = write(ctrlconnfd, &msg, sizeof(msg));
        if (ret < 0)
            printf("Error write on socket ctrl");

        if (msg.type != ACK)
            close(ctrlconnfd);
        pthread_mutex_unlock(&stream_mutex);
    } while (1);
    return (void *)0;
}
Пример #3
0
int syslog_init(void)
{
   setlogmask(LOG_UPTO(LOG_DEBUG));
   return register_notifier(syslog_notifier);
}