fix crashes in server

This commit is contained in:
Thomas Schoebel-Theuer 2012-01-19 16:57:10 +01:00 committed by Thomas Schoebel-Theuer
parent 472da6628c
commit 74354dd9ff
2 changed files with 21 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/kthread.h>
#include "mars.h" #include "mars.h"
#include "mars_net.h" #include "mars_net.h"
@ -205,7 +206,7 @@ int mars_accept_socket(struct mars_socket *new_msock, struct mars_socket *old_ms
ok = mars_get_socket(old_msock); ok = mars_get_socket(old_msock);
if (likely(ok)) { if (likely(ok)) {
status = kernel_accept(old_msock->s_socket, &new_socket, 0); status = kernel_accept(old_msock->s_socket, &new_socket, O_NONBLOCK);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
goto err; goto err;
} }
@ -416,8 +417,14 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen)
if (status == -EAGAIN) { if (status == -EAGAIN) {
msleep(sleeptime); msleep(sleeptime);
// linearly increasing backoff // linearly increasing backoff
if (sleeptime < 100) if (sleeptime < 100) {
sleeptime += 1000 / HZ; sleeptime += 1000 / HZ;
} else if (kthread_should_stop()) {
MARS_WRN("interrupting, done = %d\n", done);
if (done > 0)
status = -EIDRM;
goto err;
}
continue; continue;
} }
if (!status) { // EOF if (!status) { // EOF

View File

@ -603,7 +603,7 @@ static int _server_thread(void *data)
/* TODO: check authorization. /* TODO: check authorization.
*/ */
if (!mars_global || !mars_global->global_power.button) { if (!mars_global || !mars_global->global_power.button || kthread_should_stop()) {
MARS_WRN("system is not alive\n"); MARS_WRN("system is not alive\n");
goto err; goto err;
} }
@ -626,12 +626,23 @@ static int _server_thread(void *data)
if (status < 0) { if (status < 0) {
BRICK_ERR("kill status = %d, giving up\n", status); BRICK_ERR("kill status = %d, giving up\n", status);
} }
brick = NULL;
} }
msleep(3000); msleep(3000);
} }
MARS_INF("-------- cleaning up ----------\n"); MARS_INF("-------- cleaning up ----------\n");
if (brick) {
//FIXME: this hangs up. Leaving a minor memleak for now.
//mars_put_socket(&brick->handler_socket);
//status = mars_kill_brick((void*)brick);
//if(status < 0) {
//BRICK_WRN("kill status = %d, giving up\n", status);
//}
brick = NULL;
}
spin_lock(&server_lock); spin_lock(&server_lock);
while (!list_empty(&server_list)) { while (!list_empty(&server_list)) {
struct list_head *tmp = server_list.next; struct list_head *tmp = server_list.next;