summaryrefslogtreecommitdiff
path: root/src/libpcp/src/logcontrol.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libpcp/src/logcontrol.c')
-rw-r--r--src/libpcp/src/logcontrol.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/libpcp/src/logcontrol.c b/src/libpcp/src/logcontrol.c
new file mode 100644
index 0000000..2dc5c17
--- /dev/null
+++ b/src/libpcp/src/logcontrol.c
@@ -0,0 +1,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;
+}