Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions canlogserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ int main(int argc, char **argv)
sigset_t sigset;
fd_set rdfs;
int s[MAXDEV];
int socki, accsocket;
int socki;
int accsocket = -1;
canid_t mask[MAXDEV] = {0};
canid_t value[MAXDEV] = {0};
int inv_filter[MAXDEV] = {0};
Expand Down Expand Up @@ -286,7 +287,7 @@ int main(int argc, char **argv)
inaddr.sin_addr.s_addr = htonl(INADDR_ANY);
inaddr.sin_port = htons(port);

while(bind(socki, (struct sockaddr*)&inaddr, sizeof(inaddr)) < 0) {
while(running && bind(socki, (struct sockaddr*)&inaddr, sizeof(inaddr)) < 0) {
struct timespec f = {
.tv_nsec = 100 * 1000 * 1000,
};
Expand All @@ -295,25 +296,38 @@ int main(int argc, char **argv)
nanosleep(&f, NULL);
}

if (!running) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The while() statement checks for running to be 1 so this check seems to be wrong inside the function.
I would suggest some comment here that running might be set to 0 due to an external signal.

close(socki);
return 128 + signal_num;
}

if (listen(socki, 3) != 0) {
perror("listen");
exit(1);
}

while(1) {
while(running) {
accsocket = accept(socki, (struct sockaddr*)&clientaddr, &sin_size);
if (accsocket > 0) {
//printf("accepted\n");
if (!fork())
break;
close(accsocket);
accsocket = -1;
}
else if (errno != EINTR) {
perror("accept");
exit(1);
}
}

if (!running) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

if (accsocket > 0)
close(accsocket);
close(socki);
return 128 + signal_num;
}

for (i=0; i<currmax; i++) {

pr_debug("open %d '%s' m%08X v%08X i%d e%d.\n",
Expand Down
Loading