Beispiel #1
0
/*
 * proc_wait --
 *	Wait for one of the processes.
 *
 * !!!
 * The pid_t type varies in size from a short to a long depending on the
 * system.  It has to be cast into something or the standard promotion
 * rules get you.  I'm using a long based on the belief that nobody is
 * going to make it unsigned and it's unlikely to be a quad.
 *
 * PUBLIC: int proc_wait __P((SCR *, long, const char *, int, int));
 */
int
proc_wait(SCR *sp, long int pid, const char *cmd, int silent, int okpipe)
{
    size_t len;
    int nf, pstat;
    char *p;

    /* Wait for the utility, ignoring interruptions. */
    for (;;) {
        errno = 0;
        if (waitpid((pid_t)pid, &pstat, 0) != -1)
            break;
        if (errno != EINTR) {
            msgq(sp, M_SYSERR, "waitpid");
            return (1);
        }
    }

    /*
     * Display the utility's exit status.  Ignore SIGPIPE from the
     * parent-writer, as that only means that the utility chose to
     * exit before reading all of its input.
     */
    if (WIFSIGNALED(pstat) && (!okpipe || WTERMSIG(pstat) != SIGPIPE)) {
        for (; isblank((unsigned char)*cmd); ++cmd);
        p = msg_print(sp, cmd, &nf);
        len = strlen(p);
        msgq(sp, M_ERR, "%.*s%s: received signal: %s%s",
             (int)MIN(len, 20), p, len > 20 ? " ..." : "",
             sigmsg(WTERMSIG(pstat)),
             WCOREDUMP(pstat) ? "; core dumped" : "");
        if (nf)
            FREE_SPACE(sp, p, 0);
        return (1);
    }

    if (WIFEXITED(pstat) && WEXITSTATUS(pstat)) {
        /*
         * Remain silent for "normal" errors when doing shell file
         * name expansions, they almost certainly indicate nothing
         * more than a failure to match.
         *
         * Remain silent for vi read filter errors.  It's historic
         * practice.
         */
        if (!silent) {
            for (; isblank((unsigned char)*cmd); ++cmd);
            p = msg_print(sp, cmd, &nf);
            len = strlen(p);
            msgq(sp, M_ERR, "%.*s%s: exited with status %d",
                 (int)MIN(len, 20), p, len > 20 ? " ..." : "",
                 WEXITSTATUS(pstat));
            if (nf)
                FREE_SPACE(sp, p, 0);
        }
        return (1);
    }
    return (0);
}
ControlClient::ControlClient(QHostAddress server, quint16 port, QObject *parent) :
    QObject(parent),
    _serveraddr(server),
    _port(port)
{
    // here not really keepalive because ctlserver just close socket
    _request = new TcpRequest(this, 1);
    connect(_request, SIGNAL(sigmsg(QString)), this, SLOT(servermsg(QString)));
    _raspcmd_prefix = "raspivid";
    _supportcmds << "start" << "stop" << "change" << "record" << "get_records"
                 << "rm_records" << "get_vodport" << "get_currparams";
    _dftwaitmsec = 100;
}