Commit 462f6a76 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix error handling during initialisation.

parent 95493899
...@@ -284,19 +284,19 @@ main(int argc, char **argv) ...@@ -284,19 +284,19 @@ main(int argc, char **argv)
rc = reopen_logfile(); rc = reopen_logfile();
if(rc < 0) { if(rc < 0) {
perror("reopen_logfile()"); perror("reopen_logfile()");
goto fail; exit(1);
} }
fd = open("/dev/null", O_RDONLY); fd = open("/dev/null", O_RDONLY);
if(fd < 0) { if(fd < 0) {
perror("open(null)"); perror("open(null)");
goto fail; exit(1);
} }
rc = dup2(fd, 0); rc = dup2(fd, 0);
if(rc < 0) { if(rc < 0) {
perror("dup2(null, 0)"); perror("dup2(null, 0)");
goto fail; exit(1);
} }
close(fd); close(fd);
...@@ -305,7 +305,7 @@ main(int argc, char **argv) ...@@ -305,7 +305,7 @@ main(int argc, char **argv)
rc = daemonise(); rc = daemonise();
if(rc < 0) { if(rc < 0) {
perror("daemonise"); perror("daemonise");
goto fail_nopid; exit(1);
} }
} }
...@@ -316,7 +316,7 @@ main(int argc, char **argv) ...@@ -316,7 +316,7 @@ main(int argc, char **argv)
len = snprintf(buf, 100, "%lu", (unsigned long)getpid()); len = snprintf(buf, 100, "%lu", (unsigned long)getpid());
if(len < 0 || len >= 100) { if(len < 0 || len >= 100) {
perror("snprintf(getpid)"); perror("snprintf(getpid)");
goto fail_nopid; exit(1);
} }
pfd = open(pidfile, O_WRONLY | O_CREAT | O_EXCL, 0644); pfd = open(pidfile, O_WRONLY | O_CREAT | O_EXCL, 0644);
...@@ -325,13 +325,13 @@ main(int argc, char **argv) ...@@ -325,13 +325,13 @@ main(int argc, char **argv)
snprintf(buf, 40, "creat(%s)", pidfile); snprintf(buf, 40, "creat(%s)", pidfile);
buf[39] = '\0'; buf[39] = '\0';
perror(buf); perror(buf);
goto fail_nopid; exit(1);
} }
rc = write(pfd, buf, len); rc = write(pfd, buf, len);
if(rc < len) { if(rc < len) {
perror("write(pidfile)"); perror("write(pidfile)");
goto fail; goto fail_pid;
} }
close(pfd); close(pfd);
...@@ -340,14 +340,14 @@ main(int argc, char **argv) ...@@ -340,14 +340,14 @@ main(int argc, char **argv)
rc = kernel_setup(1); rc = kernel_setup(1);
if(rc < 0) { if(rc < 0) {
fprintf(stderr, "kernel_setup failed.\n"); fprintf(stderr, "kernel_setup failed.\n");
exit(1); goto fail_pid;
} }
rc = kernel_setup_socket(1); rc = kernel_setup_socket(1);
if(rc < 0) { if(rc < 0) {
fprintf(stderr, "kernel_setup_socket failed.\n"); fprintf(stderr, "kernel_setup_socket failed.\n");
kernel_setup(0); kernel_setup(0);
exit(1); goto fail_pid;
} }
{ {
...@@ -801,9 +801,6 @@ main(int argc, char **argv) ...@@ -801,9 +801,6 @@ main(int argc, char **argv)
exit(1); exit(1);
fail: fail:
if(pidfile)
unlink(pidfile);
fail_nopid:
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net->up)
continue; continue;
...@@ -811,6 +808,9 @@ main(int argc, char **argv) ...@@ -811,6 +808,9 @@ main(int argc, char **argv)
} }
kernel_setup_socket(0); kernel_setup_socket(0);
kernel_setup(0); kernel_setup(0);
fail_pid:
if(pidfile)
unlink(pidfile);
exit(1); exit(1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment