From 879838a0b5c395d7bef759b9d76eadefbe21d4c7 Mon Sep 17 00:00:00 2001 From: Nathan Straz Date: Thu, 19 Sep 2013 15:43:06 -0400 Subject: Add reasonable log priorities --- qarsh_packet.c | 47 ++++++++++++++++++++++++----------------------- sockutil.c | 8 ++++---- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/qarsh_packet.c b/qarsh_packet.c index 2ca3f13..84dc0c3 100644 --- a/qarsh_packet.c +++ b/qarsh_packet.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "qarsh_packet.h" @@ -208,7 +209,7 @@ fetch_uint8(char *buf, int *buflen, int *out) { uint8_t i; if (*buflen < sizeof i) { - lprintf(0, "Not enough data to unpack a uint8_t, %d\n", *buflen); + lprintf(LOG_ERR, "Not enough data to unpack a uint8_t, %d\n", *buflen); return buf; } memcpy(&i, buf, sizeof i); @@ -222,7 +223,7 @@ fetch_int(char *buf, int *buflen, int *out) { int i; if (*buflen < sizeof i) { - lprintf(0, "Not enough data to unpack a uint32_t, %d\n", *buflen); + lprintf(LOG_ERR, "Not enough data to unpack a uint32_t, %d\n", *buflen); return buf; } memcpy(&i, buf, sizeof i); @@ -236,13 +237,13 @@ fetch_string(char *buf, int *buflen, char **out) { int slen; if (*buflen < sizeof slen) { - lprintf(0, "Not enough data to unpack string length, %d\n", *buflen); + lprintf(LOG_ERR, "Not enough data to unpack string length, %d\n", *buflen); *out = NULL; return buf; } buf = fetch_int(buf, buflen, &slen); if (slen > *buflen) { - lprintf(0, "String is more than available data, %d > %d\n", slen, *buflen); + lprintf(LOG_ERR, "String is more than available data, %d > %d\n", slen, *buflen); *out = NULL; return buf; } @@ -259,7 +260,7 @@ fetch_off_t(char *buf, int *buflen, off_t *out) { off_t i; if (*buflen < sizeof i) { - lprintf(0, "Not enough data to unpack a off_t, %d\n", *buflen); + lprintf(LOG_ERR, "Not enough data to unpack a off_t, %d\n", *buflen); return buf; } memcpy(&i, buf, sizeof i); @@ -356,7 +357,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) { - lprintf(0, "Blob is larger than rest of packet, %d > %d\n", + lprintf(LOG_ERR, "Blob is larger than rest of packet, %d > %d\n", qp->qp_data.qp_count, *buflen); free(qp); } else { @@ -388,11 +389,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 { - lprintf(0, "Packet type %d not implemented yet\n", qp->qp_type); + lprintf(LOG_ERR, "Packet type %d not implemented yet\n", qp->qp_type); free(qp); qp = NULL; } - if (buflen) { lprintf(0, "%d remaining bytes of data in packet\n", buflen); } + if (buflen) { lprintf(LOG_INFO, "%d remaining bytes of data in packet\n", buflen); } return qp; } @@ -822,51 +823,51 @@ qpfree(struct qa_packet *qp) void dump_qp_ack(struct qa_packet *qp) { - lprintf(0, "%s #%d", QP_NAME(qp->qp_ack.qp_ack_type), + lprintf(LOG_DEBUG, "%s #%d", QP_NAME(qp->qp_ack.qp_ack_type), qp->qp_ack.qp_ack_seq); } void dump_qp_runcmd(struct qa_packet *qp) { - lprintf(0, "cmdline: %s", qp->qp_runcmd.qp_cmdline); + lprintf(LOG_DEBUG, "cmdline: %s", qp->qp_runcmd.qp_cmdline); } void dump_qp_returncode(struct qa_packet *qp) { - lprintf(0, "rc: %d", qp->qp_returncode.qp_rc); + lprintf(LOG_DEBUG, "rc: %d", qp->qp_returncode.qp_rc); } void dump_qp_cmdexit(struct qa_packet *qp) { if (WIFEXITED(qp->qp_cmdexit.qp_status)) { - lprintf(0, "exited: %d", WEXITSTATUS(qp->qp_cmdexit.qp_status)); + lprintf(LOG_DEBUG, "exited: %d", WEXITSTATUS(qp->qp_cmdexit.qp_status)); } else if (WIFSIGNALED(qp->qp_cmdexit.qp_status)) { - lprintf(0, "signaled: %d", WTERMSIG(qp->qp_cmdexit.qp_status)); + lprintf(LOG_DEBUG, "signaled: %d", WTERMSIG(qp->qp_cmdexit.qp_status)); } else { - lprintf(0, "status: %d", qp->qp_cmdexit.qp_status); + lprintf(LOG_DEBUG, "status: %d", qp->qp_cmdexit.qp_status); } } void dump_qp_setuser(struct qa_packet *qp) { - lprintf(0, "user: %s group: %s", + lprintf(LOG_DEBUG, "user: %s group: %s", qp->qp_setuser.qp_user, qp->qp_setuser.qp_group); } void dump_qp_kill(struct qa_packet *qp) { - lprintf(0, "sig: %d", qp->qp_kill.qp_sig); + lprintf(LOG_DEBUG, "sig: %d", qp->qp_kill.qp_sig); } void dump_qp_recvfile(struct qa_packet *qp) { - lprintf(0, "path: %s mode: %o count: %lld", + lprintf(LOG_DEBUG, "path: %s mode: %o count: %lld", qp->qp_recvfile.qp_path, qp->qp_recvfile.qp_mode, (long long int)qp->qp_recvfile.qp_count); } @@ -874,14 +875,14 @@ dump_qp_recvfile(struct qa_packet *qp) void dump_qp_sendfile(struct qa_packet *qp) { - lprintf(0, "path: %s", + lprintf(LOG_DEBUG, "path: %s", qp->qp_sendfile.qp_path); } void dump_qp_rstat(struct qa_packet *qp) { - lprintf(0, "path: %s st_mode: %o st_uid: %d st_gid: %d st_size: %lld", + lprintf(LOG_DEBUG, "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); @@ -890,24 +891,24 @@ dump_qp_rstat(struct qa_packet *qp) void dump_qp_data(struct qa_packet *qp) { - lprintf(0, "remfd: %d offset: %lld count: %d", + lprintf(LOG_DEBUG, "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) { - lprintf(0, "remfd: %d count: %d", + lprintf(LOG_DEBUG, "remfd: %d count: %d", qp->qp_dallow.qp_remfd, qp->qp_dallow.qp_count); } void dump_qp(struct qa_packet *qp) { - lprintf(0, "#%d %s ", qp->qp_seq, QP_NAME(qp->qp_type)); + lprintf(LOG_DEBUG, "#%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); } - lprintf(0, "\n"); + lprintf(LOG_DEBUG, "\n"); fflush(stderr); } diff --git a/sockutil.c b/sockutil.c index 9d2da1d..87a718b 100644 --- a/sockutil.c +++ b/sockutil.c @@ -56,7 +56,7 @@ connect_to_host(char *hostname, int port, unsigned short *ss_family) snprintf(portstr, NI_MAXSERV, "%d", port); if ((err = getaddrinfo(hostname, portstr, &hints, &ail)) != 0) { - lprintf(0, "Could not resolve hostname %s: %s\n", + lprintf(LOG_ERR, "Could not resolve hostname %s: %s\n", hostname, gai_strerror(err)); return -1; } @@ -115,7 +115,7 @@ recv_packet(int fd) do { if ((ret = read(fd, (char *)psbuf+bufused, sizeof packetsize - bufused)) < 0) { - lprintf(0, "Read error while reading packet size: %s\n", strerror(errno)); + lprintf(LOG_ERR, "Read error while reading packet size: %s\n", strerror(errno)); return NULL; } else if (ret == 0) { return NULL; @@ -125,14 +125,14 @@ recv_packet(int fd) packetsize = ntohl(packetsize); if (packetsize > QARSH_MAX_PACKET_SIZE) { - lprintf(0, "Packet size too large, %d > %d\n", packetsize, QARSH_MAX_PACKET_SIZE); + lprintf(LOG_ERR, "Packet size too large, %d > %d\n", packetsize, QARSH_MAX_PACKET_SIZE); return NULL; } /* Keep reading until we get the whole packet and nothing but the packet, so help me socket */ bufused = 0; do { if ((ret = read(fd, buf+bufused, packetsize-bufused)) < 0) { - lprintf(0, "Read error while reading packet data: %s\n", strerror(errno)); + lprintf(LOG_ERR, "Read error while reading packet data: %s\n", strerror(errno)); return NULL; } bufused += ret; -- cgit