summaryrefslogtreecommitdiffstats
path: root/qarsh_packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'qarsh_packet.c')
-rw-r--r--qarsh_packet.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/qarsh_packet.c b/qarsh_packet.c
index d6a45a1..24f4661 100644
--- a/qarsh_packet.c
+++ b/qarsh_packet.c
@@ -37,6 +37,9 @@
#include "qarsh_packet.h"
+/* Logging provided by qarshd, qarsh, or qacp */
+extern void lprintf(int priority, const char *format, ...);
+
/* Prototypes */
void parse_qp_hello(char *buf, int *buflen, struct qa_packet *qp);
void parse_qp_returncode(char *buf, int *buflen, struct qa_packet *qp);
@@ -205,7 +208,7 @@ fetch_int(char *buf, int *buflen, int *out)
{
int i;
if (*buflen < sizeof i) {
- fprintf(stderr, "Not enough data to unpack a uint32_t, %d\n", *buflen);
+ lprintf(0, "Not enough data to unpack a uint32_t, %d\n", *buflen);
return buf;
}
memcpy(&i, buf, sizeof i);
@@ -219,13 +222,13 @@ fetch_string(char *buf, int *buflen, char **out)
{
int slen;
if (*buflen < sizeof slen) {
- fprintf(stderr, "Not enough data to unpack string length, %d\n", *buflen);
+ lprintf(0, "Not enough data to unpack string length, %d\n", *buflen);
*out = NULL;
return buf;
}
buf = fetch_int(buf, buflen, &slen);
if (slen > *buflen) {
- fprintf(stderr, "String is more than available data, %d > %d\n", slen, *buflen);
+ lprintf(0, "String is more than available data, %d > %d\n", slen, *buflen);
*out = NULL;
return buf;
}
@@ -242,7 +245,7 @@ fetch_off_t(char *buf, int *buflen, off_t *out)
{
off_t i;
if (*buflen < sizeof i) {
- fprintf(stderr, "Not enough data to unpack a off_t, %d\n", *buflen);
+ lprintf(0, "Not enough data to unpack a off_t, %d\n", *buflen);
return buf;
}
memcpy(&i, buf, sizeof i);
@@ -339,7 +342,7 @@ parse_qp_data(char *buf, int *buflen, struct qa_packet *qp)
buf = fetch_off_t(buf, buflen, &(qp->qp_data.qp_offset));
buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_count));
if (qp->qp_data.qp_count > *buflen) {
- fprintf(stderr, "Blob is larger than rest of packet, %d > %d\n",
+ lprintf(0, "Blob is larger than rest of packet, %d > %d\n",
qp->qp_data.qp_count, *buflen);
free(qp);
} else {
@@ -371,11 +374,11 @@ parse_packet(char *buf, int buflen)
if (qa_pi[qp->qp_type].pi_parse)
qa_pi[qp->qp_type].pi_parse(buf, &buflen, qp);
else {
- fprintf(stderr, "Packet type %d not implemented yet\n", qp->qp_type);
+ lprintf(0, "Packet type %d not implemented yet\n", qp->qp_type);
free(qp);
qp = NULL;
}
- if (buflen) { fprintf(stderr, "%d remaining bytes of data in packet\n", buflen); }
+ if (buflen) { lprintf(0, "%d remaining bytes of data in packet\n", buflen); }
return qp;
}
@@ -797,51 +800,51 @@ qpfree(struct qa_packet *qp)
void
dump_qp_ack(struct qa_packet *qp)
{
- fprintf(stderr, "%s #%d", QP_NAME(qp->qp_ack.qp_ack_type),
+ lprintf(0, "%s #%d", QP_NAME(qp->qp_ack.qp_ack_type),
qp->qp_ack.qp_ack_seq);
}
void
dump_qp_runcmd(struct qa_packet *qp)
{
- fprintf(stderr, "cmdline: %s", qp->qp_runcmd.qp_cmdline);
+ lprintf(0, "cmdline: %s", qp->qp_runcmd.qp_cmdline);
}
void
dump_qp_returncode(struct qa_packet *qp)
{
- fprintf(stderr, "rc: %d", qp->qp_returncode.qp_rc);
+ lprintf(0, "rc: %d", qp->qp_returncode.qp_rc);
}
void
dump_qp_cmdexit(struct qa_packet *qp)
{
if (WIFEXITED(qp->qp_cmdexit.qp_status)) {
- fprintf(stderr, "exited: %d", WEXITSTATUS(qp->qp_cmdexit.qp_status));
+ lprintf(0, "exited: %d", WEXITSTATUS(qp->qp_cmdexit.qp_status));
} else if (WIFSIGNALED(qp->qp_cmdexit.qp_status)) {
- fprintf(stderr, "signaled: %d", WTERMSIG(qp->qp_cmdexit.qp_status));
+ lprintf(0, "signaled: %d", WTERMSIG(qp->qp_cmdexit.qp_status));
} else {
- fprintf(stderr, "status: %d", qp->qp_cmdexit.qp_status);
+ lprintf(0, "status: %d", qp->qp_cmdexit.qp_status);
}
}
void
dump_qp_setuser(struct qa_packet *qp)
{
- fprintf(stderr, "user: %s group: %s",
+ lprintf(0, "user: %s group: %s",
qp->qp_setuser.qp_user, qp->qp_setuser.qp_group);
}
void
dump_qp_kill(struct qa_packet *qp)
{
- fprintf(stderr, "sig: %d", qp->qp_kill.qp_sig);
+ lprintf(0, "sig: %d", qp->qp_kill.qp_sig);
}
void
dump_qp_recvfile(struct qa_packet *qp)
{
- fprintf(stderr, "path: %s mode: %o count: %lld",
+ lprintf(0, "path: %s mode: %o count: %lld",
qp->qp_recvfile.qp_path, qp->qp_recvfile.qp_mode,
(long long int)qp->qp_recvfile.qp_count);
}
@@ -849,14 +852,14 @@ dump_qp_recvfile(struct qa_packet *qp)
void
dump_qp_sendfile(struct qa_packet *qp)
{
- fprintf(stderr, "path: %s",
+ lprintf(0, "path: %s",
qp->qp_sendfile.qp_path);
}
void
dump_qp_rstat(struct qa_packet *qp)
{
- fprintf(stderr, "path: %s st_mode: %o st_uid: %d st_gid: %d st_size: %lld",
+ lprintf(0, "path: %s st_mode: %o st_uid: %d st_gid: %d st_size: %lld",
qp->qp_rstat.qp_path, qp->qp_rstat.qp_st_mode,
qp->qp_rstat.qp_st_uid, qp->qp_rstat.qp_st_gid,
(long long int)qp->qp_rstat.qp_st_size);
@@ -865,24 +868,24 @@ dump_qp_rstat(struct qa_packet *qp)
void
dump_qp_data(struct qa_packet *qp)
{
- fprintf(stderr, "remfd: %d offset: %lld count: %d",
+ lprintf(0, "remfd: %d offset: %lld count: %d",
qp->qp_data.qp_remfd, (long long int)qp->qp_data.qp_offset, qp->qp_data.qp_count);
}
void
dump_qp_data_allow(struct qa_packet *qp)
{
- fprintf(stderr, "remfd: %d count: %d",
+ lprintf(0, "remfd: %d count: %d",
qp->qp_dallow.qp_remfd, qp->qp_dallow.qp_count);
}
void
dump_qp(struct qa_packet *qp)
{
- fprintf(stderr, "#%d %s ", qp->qp_seq, QP_NAME(qp->qp_type));
+ lprintf(0, "#%d %s ", qp->qp_seq, QP_NAME(qp->qp_type));
if (qa_pi[qp->qp_type].pi_dump) {
qa_pi[qp->qp_type].pi_dump(qp);
}
- fprintf(stderr, "\n");
+ lprintf(0, "\n");
fflush(stderr);
}