*/
int recv_packet(int fd, char **buf, size_t *len)
{
- if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1;
+ if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) {
+ (*buf) = NULL;
+ *len = 0;
+ return -1;
+ }
+ if (len == 0) {
+ (*buf) = NULL;
+ return 0;
+ }
(*buf) = MALLOC(*len);
if (!*buf)
return -1;
if (read_all(fd, *buf, *len) != *len) {
FREE(*buf);
+ (*buf) = NULL;
+ *len = 0;
return -1;
}
return 0;
/*
* Original author : tridge@samba.org, January 2002
- *
+ *
* Copyright (c) 2005 Christophe Varoqui
* Copyright (c) 2005 Benjamin Marzinski, Redhat
*/
/* strip ANSI color markers */
while (*s != '\0') {
if ((*s == 0x1b) && (*(s+1) == '['))
- while ((*s++ != 'm') && (*s != '\0')) {};
+ while ((*s++ != 'm') && (*s != '\0')) {};
putchar(*s++);
}
}
/*
- * process the client
+ * process the client
*/
static void process(int fd)
{
char *reply;
size_t len;
- if (send_packet(fd, inbuf, strlen(inbuf) + 1) != 0)
+ if (send_packet(fd, inbuf, strlen(inbuf) + 1) != 0) {
+ printf("cannot send packet\n");
return;
- if (recv_packet(fd, &reply, &len) == 0) {
- print_reply(reply);
+ }
+ if (recv_packet(fd, &reply, &len) != 0)
+ printf("error receiving packet\n");
+ else {
+ printf("%s", reply);
FREE(reply);
}
}
-
+
/*
* entry point
*/
process_req(fd, inbuf);
else
process(fd);
-
+
return 0;
}
inbuf[len - 1] = 0;
condlog(4, "Got request [%s]", inbuf);
uxsock_trigger(inbuf, &reply, &rlen,
- trigger_data);
-
+ trigger_data);
if (reply) {
if (send_packet(c->fd, reply,
- rlen) != 0) {
+ rlen) != 0) {
dead_client(c);
}
+ condlog(4, "Reply [%d bytes]",
+ rlen);
FREE(reply);
reply = NULL;
}