mirror of https://github.com/schoebel/mars
fix crashes in server
This commit is contained in:
parent
472da6628c
commit
74354dd9ff
11
mars_net.c
11
mars_net.c
|
@ -7,6 +7,7 @@
|
|||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/kthread.h>
|
||||
|
||||
#include "mars.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);
|
||||
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)) {
|
||||
goto err;
|
||||
}
|
||||
|
@ -416,8 +417,14 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen)
|
|||
if (status == -EAGAIN) {
|
||||
msleep(sleeptime);
|
||||
// linearly increasing backoff
|
||||
if (sleeptime < 100)
|
||||
if (sleeptime < 100) {
|
||||
sleeptime += 1000 / HZ;
|
||||
} else if (kthread_should_stop()) {
|
||||
MARS_WRN("interrupting, done = %d\n", done);
|
||||
if (done > 0)
|
||||
status = -EIDRM;
|
||||
goto err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!status) { // EOF
|
||||
|
|
|
@ -603,7 +603,7 @@ static int _server_thread(void *data)
|
|||
/* 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");
|
||||
goto err;
|
||||
}
|
||||
|
@ -626,12 +626,23 @@ static int _server_thread(void *data)
|
|||
if (status < 0) {
|
||||
BRICK_ERR("kill status = %d, giving up\n", status);
|
||||
}
|
||||
brick = NULL;
|
||||
}
|
||||
msleep(3000);
|
||||
}
|
||||
|
||||
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);
|
||||
while (!list_empty(&server_list)) {
|
||||
struct list_head *tmp = server_list.next;
|
||||
|
|
Loading…
Reference in New Issue