diff options
author | Nathan Straz <nstraz@redhat.com> | 2013-09-19 10:10:16 -0400 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2013-09-19 10:26:32 -0400 |
commit | 8bc29add2abf434390b3e6696ff7b364d658f028 (patch) | |
tree | faa927113db114a7d1ed4c03f9196def61692a95 /sockutil.c | |
parent | 486049502c9156e1309a81651f014f2d4fd4450e (diff) | |
download | qarsh-8bc29add2abf434390b3e6696ff7b364d658f028.tar.gz qarsh-8bc29add2abf434390b3e6696ff7b364d658f028.tar.xz qarsh-8bc29add2abf434390b3e6696ff7b364d658f028.zip |
Creat a thin logging layer
When qarshd is run via xinetd, stderr still goes out the socket
and messages from sockutil.c or qarsh_packet.c can interfere
with the protocol. Create a thin wrapper which qacp and qarsh can
send to stderr and qarshd can send to syslog.
Diffstat (limited to 'sockutil.c')
-rw-r--r-- | sockutil.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -32,6 +32,9 @@ #include "qarsh_packet.h" +/* Logging provided by qarshd, qarsh, or qacp */ +extern void lprintf(int priority, const char *format, ...); + static int packet_seq = 1; /* Some generic socket related functions to make things easier */ @@ -53,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) { - fprintf(stderr, "Could not resolve hostname %s: %s\n", + lprintf(0, "Could not resolve hostname %s: %s\n", hostname, gai_strerror(err)); return -1; } @@ -112,7 +115,7 @@ recv_packet(int fd) do { if ((ret = read(fd, (char *)psbuf+bufused, sizeof packetsize - bufused)) < 0) { - fprintf(stderr, "Read error while reading packet size: %s\n", strerror(errno)); + lprintf(0, "Read error while reading packet size: %s\n", strerror(errno)); return NULL; } else if (ret == 0) { return NULL; @@ -122,14 +125,14 @@ recv_packet(int fd) packetsize = ntohl(packetsize); if (packetsize > QARSH_MAX_PACKET_SIZE) { - fprintf(stderr, "Packet size too large, %d > %d\n", packetsize, QARSH_MAX_PACKET_SIZE); + lprintf(0, "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) { - fprintf(stderr, "Read error while reading packet data: %s\n", strerror(errno)); + lprintf(0, "Read error while reading packet data: %s\n", strerror(errno)); return NULL; } bufused += ret; |