more logging and fixed bug
used the wrong buffer when trying to read clients message
This commit is contained in:
15
src/hdbd.c
15
src/hdbd.c
@@ -61,30 +61,39 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_INFO, "Listening for connections...");
|
|
||||||
|
|
||||||
/* Actual program */
|
/* Actual program */
|
||||||
int client_sock;
|
int client_sock;
|
||||||
int data_length = 0;
|
int data_length = 0;
|
||||||
char receive_buf[1000];
|
char receive_buf[1000];
|
||||||
char send_buf[1000];
|
char send_buf[1000];
|
||||||
|
char log_line[10000];
|
||||||
memset(receive_buf, 0, sizeof receive_buf);
|
memset(receive_buf, 0, sizeof receive_buf);
|
||||||
memset(send_buf, 0, sizeof send_buf);
|
memset(send_buf, 0, sizeof send_buf);
|
||||||
|
memset(log_line, 0, sizeof log_line);
|
||||||
|
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "Listening for connections...");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
client_sock = accept(server_sock, NULL, NULL);
|
client_sock = accept(server_sock, NULL, NULL);
|
||||||
if (client_sock == -1) {
|
if (client_sock == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
syslog(LOG_INFO, "Accepted a connection");
|
||||||
data_length = recv(client_sock, receive_buf, sizeof receive_buf, 0);
|
data_length = recv(client_sock, receive_buf, sizeof receive_buf, 0);
|
||||||
if (data_length <= 0) {
|
if (data_length <= 0) {
|
||||||
|
syslog(LOG_WARNING, "Received no data from client");
|
||||||
strcpy(send_buf, "Failed to receive any data.");
|
strcpy(send_buf, "Failed to receive any data.");
|
||||||
send(client_sock, send_buf, strlen(send_buf), 0);
|
send(client_sock, send_buf, strlen(send_buf), 0);
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprintf(log_line, "Received from Client: %s", receive_buf);
|
||||||
|
syslog(LOG_DEBUG, log_line);
|
||||||
|
|
||||||
if (strstr(send_buf, "shutdown") != NULL) {
|
if (strstr(receive_buf, "shutdown") != NULL) {
|
||||||
|
syslog(LOG_NOTICE, "Shutting down");
|
||||||
strcpy(send_buf, "Shutting down.");
|
strcpy(send_buf, "Shutting down.");
|
||||||
send(client_sock, send_buf, strlen(send_buf), 0);
|
send(client_sock, send_buf, strlen(send_buf), 0);
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
|
|||||||
Reference in New Issue
Block a user