summaryrefslogtreecommitdiff
path: root/src/libpcp/src/logcontrol.c
blob: 2dc5c17a74a81efc9d69fdf91fdc4fde72276f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 * 
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * Thread-safe note
 *
 * This routine is not thread-safe as there is no serialization on the
 * use of the fd between the __pmSendLogControl() and the reading of
 * the reply PDU.  It is assumed that the caller is single-threaded,
 * which is true for the only current user of this routine, pmlc(1).
 */

#include "pmapi.h"
#include "impl.h"

int
__pmControlLog(int fd, const pmResult *request, int control, int state, int delta, pmResult **status)
{
    int         	n;
    __pmPDU     	*pb;

    if (request->numpmid < 1)
        return PM_ERR_TOOSMALL;

    /* send a PCP 2.0 log control request */
    n = __pmSendLogControl(fd, request, control, state, delta);
    if (n < 0)
	n = __pmMapErrno(n);
    else {
	int		pinpdu;
	/* get the reply */
	pinpdu = n = __pmGetPDU(fd, ANY_SIZE, __pmLoggerTimeout(), &pb);
	if (n == PDU_RESULT) {
	    n = __pmDecodeResult(pb, status);
	}
	else if (n == PDU_ERROR)
	    __pmDecodeError(pb, &n);
	else if (n != PM_ERR_TIMEOUT)
	    n = PM_ERR_IPC; /* unknown reply type */
	if (pinpdu > 0)
	    __pmUnpinPDUBuf(pb);
    }

    return n;
}