コード例 #1
0
ファイル: procfs_status.c プロジェクト: coyizumi/cs111
int
procfs_doproccmdline(PFS_FILL_ARGS)
{

	/*
	 * If we are using the ps/cmdline caching, use that.  Otherwise
	 * read argv from the process space.
	 * Note that if the argv is no longer available, we deliberately
	 * don't fall back on p->p_comm or return an error: the authentic
	 * Linux behaviour is to return zero-length in this case.
	 */

	PROC_LOCK(p);
	if (p->p_args && p_cansee(td, p) == 0) {
		sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length);
		PROC_UNLOCK(p);
		return (0);
	}

	if ((p->p_flag & P_SYSTEM) != 0) {
		PROC_UNLOCK(p);
		return (0);
	}

	PROC_UNLOCK(p);

	return (proc_getargv(td, p, sb));
}
コード例 #2
0
ファイル: sbuf.c プロジェクト: eaas-framework/virtualbox
        /* re-use off */
        off = (sb->sb_data + sb->sb_datalen) - from;
        if (off > len)
            off = len;
        memcpy(to, from, off);
        len -= off;
        if (len)
            memcpy(to+off, sb->sb_data, len);
    }
}
#else /* VBOX_WITH_SLIRP_BSD_SBUF */
void
sbappend (PNATState pData, struct socket *so, struct mbuf *m)
{
    int ret = 0;
    int mlen = 0;
    caddr_t buf = NULL;

    STAM_PROFILE_START(&pData->StatIOSBAppend_pf, a);
    LogFlow(("sbappend: so = %R[natsock], m = %lx, m->m_len = %d\n", so, (long)m, m ? m->m_len : 0));

    STAM_COUNTER_INC(&pData->StatIOSBAppend);
    mlen = m_length(m, NULL);
    if (mlen <= 0)
    {
        STAM_COUNTER_INC(&pData->StatIOSBAppend_zm);
        goto done;
    }

    /*
     * We only write if there's nothing in the buffer,
     * ottherwise it'll arrive out of order, and hence corrupt
     */
    buf = RTMemAlloc(mlen);
    if (buf == NULL)
    {
        ret = 0;
        goto no_sent;
    }
    m_copydata(m, 0, mlen, buf);

    /*
     * If there is urgent data, call sosendoob
     * if not all was sent, sowrite will take care of the rest
     * (The rest of this function is just an optimisation)
     */
    if (so->so_urgc)
    {
        sbuf_bcpy(&so->so_rcv, buf, mlen);
        RTMemFree(buf);
        m_free(pData, m);
        sosendoob(so);
        return;
    }

    if(!sbuf_len(&so->so_rcv))
        ret = send(so->s, buf, mlen, 0);
no_sent:

    if (ret <= 0)
    {
        STAM_COUNTER_INC(&pData->StatIOSBAppend_wf);
        /*
         * Nothing was written
         * It's possible that the socket has closed, but
         * we don't need to check because if it has closed,
         * it will be detected in the normal way by soread()
         */
        sbuf_bcpy(&so->so_rcv, buf, mlen);
        STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wf, a);
        goto done;
    }
    else if (ret != mlen)
    {
        STAM_COUNTER_INC(&pData->StatIOSBAppend_wp);
        /*
         * Something was written, but not everything..
         * sbappendsb the rest
         */
        sbuf_bcpy(&so->so_rcv, &buf[ret + 1], mlen - ret);
        STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wp, a);
        goto done;
    } /* else */
    /* Whatever happened, we free the mbuf */
    STAM_COUNTER_INC(&pData->StatIOSBAppend_wa);
    STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wa, a);
done:
    RTMemFree(buf);
    m_freem(pData, m);
}