Skip to content

Commit

Permalink
Fixed compilation for FreeBSD and Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
CurlyMoo committed Feb 24, 2014
1 parent 6661aef commit d0832e5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
10 changes: 3 additions & 7 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ short handshakes[MAX_CLIENTS];
unsigned short runmode = 1;
/* Socket identifier to the server if we are running as client */
int sockfd = 0;
int loopfd = 0;
/* In the client running in incognito mode */
unsigned short incognito_mode = 0;
/* Thread pointers */
Expand Down Expand Up @@ -255,9 +254,6 @@ void *broadcast(void *param) {

pthread_mutex_lock(&bcqueue_lock);
while(main_loop) {
#ifdef __FreeBSD__
pthread_mutex_lock(&bcqueue_lock);
#endif
if(bcqueue_number > 0) {
pthread_mutex_lock(&bcqueue_lock);

Expand Down Expand Up @@ -549,9 +545,6 @@ void *send_code(void *param) {
pthread_mutex_lock(&sendqueue_lock);

while(main_loop) {
#ifdef __FreeBSD__
pthread_mutex_lock(&sendqueue_lock);
#endif
if(sendqueue_number > 0) {
pthread_mutex_lock(&sendqueue_lock);
sending = 1;
Expand Down Expand Up @@ -1278,6 +1271,9 @@ void *clientize(void *param) {
break;
}
}
if(main_loop == 0) {
break;
}
switch(steps) {
case WELCOME:
socket_write(sockfd, "{\"message\":\"client node\",\"uuid\":\"%s\"}", pilight_uuid);
Expand Down
2 changes: 1 addition & 1 deletion libs/pilight/mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -3944,7 +3944,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {

if (select(max_fd + 1, &read_set, &write_set, NULL, &tv) > 0) {
if(mongoose_stop == 1) {
return;
return 0;
}
// Accept new connections
if (FD_ISSET(server->listening_sock, &read_set)) {
Expand Down
12 changes: 7 additions & 5 deletions libs/pilight/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ int socket_gc(void) {
}
}

send(socket_loopback, "1", 1, MSG_NOSIGNAL);
socket_close(socket_loopback);
if(socket_loopback > 0) {
send(socket_loopback, "1", 1, MSG_NOSIGNAL);
socket_close(socket_loopback);
}

logprintf(LOG_DEBUG, "garbage collected socket library");
return EXIT_SUCCESS;
Expand Down Expand Up @@ -336,7 +338,7 @@ int socket_write(int sockfd, const char *msg, ...) {
} else {
x = BUFFER_SIZE;
}
if((bytes = send(sockfd, &sendBuff[ptr], (size_t)x, MSG_NOSIGNAL)) == -1) {
if((bytes = (int)send(sockfd, &sendBuff[ptr], (size_t)x, MSG_NOSIGNAL)) == -1) {
/* Change the delimiter into regular newlines */
sendBuff[n-(len-1)] = '\0';
sendBuff[n-(len)] = '\n';
Expand Down Expand Up @@ -379,7 +381,7 @@ char *socket_read(int sockfd) {
int bytes = 0;
size_t msglen = 0;
int ptr = 0, n = 0, len = (int)strlen(EOSS);
fd_set fdsread, fdswrite;
fd_set fdsread;
char *message = NULL;
fcntl(sockfd, F_SETFL, O_NONBLOCK);

Expand All @@ -399,7 +401,7 @@ char *socket_read(int sockfd) {
return NULL;
} else if(n > 0) {
if(FD_ISSET(sockfd, &fdsread)) {
bytes = recv(sockfd, recvBuff, BUFFER_SIZE, 0);
bytes = (int)recv(sockfd, recvBuff, BUFFER_SIZE, 0);

if(bytes <= 0) {
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions libs/pilight/ssdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void ssdp_getethmac(void) {
memset(ssdp_mac, '\0', 13);
struct ifreq s;

memset(&s, '\0', sizeof(s));
strcpy(s.ifr_name, "re0");
if(ioctl(fd, SIOCGIFADDR, &s) == 0) {
int i;
Expand Down Expand Up @@ -264,6 +265,7 @@ int ssdp_seek(struct ssdp_list_t **ssdp_list) {
tv.tv_usec = 100000;

sock = socket(AF_INET, SOCK_DGRAM, 0);
memset((void *)&addr, '\0', sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(1900);
addr.sin_addr.s_addr = inet_addr("239.255.255.250");
Expand Down
3 changes: 0 additions & 3 deletions libs/pilight/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ void *threads_start(void *param) {

pthread_mutex_lock(&threadqueue_lock);
while(thread_loop) {
#ifdef __FreeBSD__
pthread_mutex_lock(&threadqueue_lock);
#endif
if(threadqueue_number > 0) {
pthread_mutex_lock(&threadqueue_lock);
tmp_threads = threadqueue;
Expand Down
9 changes: 4 additions & 5 deletions libs/pilight/webserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,10 @@ static int webserver_request_handler(struct mg_connection *conn) {
char name[11];
webserver_alpha_random(name, 10);
strcat(file, name);
int f = open(file, O_TRUNC | O_WRONLY | O_CREAT);
write(f, conn->content, conn->content_len);
int f = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if(write(f, conn->content, conn->content_len) != conn->content_len) {
logprintf(LOG_ERR, "php cache file truncated");
}
close(f);
raw = webserver_shell("cat %s | php-cgi %s 2>&1 | base64", conn, request, file, request);
unlink(file);
Expand Down Expand Up @@ -957,9 +959,6 @@ void *webserver_broadcast(void *param) {
pthread_mutex_lock(&webqueue_lock);

while(webserver_loop) {
#ifdef __FreeBSD__
pthread_mutex_lock(&webqueue_lock);
#endif
if(webqueue_number > 0) {
pthread_mutex_lock(&webqueue_lock);

Expand Down

0 comments on commit d0832e5

Please sign in to comment.