Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
3c462ade
Commit
3c462ade
authored
Mar 10, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to daemonise.
parent
6c14652b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
1 deletion
+116
-1
babel.c
babel.c
+92
-1
util.c
util.c
+23
-0
util.h
util.h
+1
-0
No files found.
babel.c
View file @
3c462ade
...
...
@@ -65,6 +65,8 @@ int wireless_hello_interval = -1;
int
wired_hello_interval
=
-
1
;
int
idle_hello_interval
=
-
1
;
int
update_interval
=
-
1
;
int
do_daemonise
=
0
;
char
*
logfile
=
NULL
,
*
pidfile
=
NULL
;
unsigned
char
*
receive_buffer
=
NULL
;
int
receive_buffer_size
=
0
;
...
...
@@ -209,6 +211,14 @@ main(int argc, char **argv)
"Couldn't parse configuration from command line.
\n
"
);
exit
(
1
);
}
}
else
if
(
strcmp
(
*
arg
,
"-D"
)
==
0
)
{
do_daemonise
=
1
;
}
else
if
(
strcmp
(
*
arg
,
"-L"
)
==
0
)
{
SHIFTE
();
logfile
=
*
arg
;
}
else
if
(
strcmp
(
*
arg
,
"-I"
)
==
0
)
{
SHIFTE
();
pidfile
=
*
arg
;
}
else
{
goto
syntax
;
}
...
...
@@ -250,6 +260,80 @@ main(int argc, char **argv)
if
(
seqno_interval
<=
0
)
seqno_interval
=
MAX
(
wireless_hello_interval
-
1
,
2
);
if
(
do_daemonise
)
{
if
(
logfile
==
NULL
)
logfile
=
"/var/log/babel.log"
;
}
if
(
logfile
)
{
int
lfd
=
open
(
logfile
,
O_CREAT
|
O_WRONLY
|
O_APPEND
,
0644
);
if
(
lfd
<
0
)
{
perror
(
"open(logfile)"
);
goto
fail
;
}
fflush
(
stdout
);
fflush
(
stderr
);
rc
=
dup2
(
lfd
,
1
);
if
(
rc
<
0
)
{
perror
(
"dup2(logfile, 1)"
);
goto
fail
;
}
rc
=
dup2
(
lfd
,
2
);
if
(
rc
<
0
)
{
perror
(
"dup2(logfile, 2)"
);
goto
fail
;
}
close
(
lfd
);
}
fd
=
open
(
"/dev/null"
,
O_RDONLY
);
if
(
fd
<
0
)
{
perror
(
"open(null)"
);
goto
fail
;
}
rc
=
dup2
(
fd
,
0
);
if
(
rc
<
0
)
{
perror
(
"dup2(null, 0)"
);
goto
fail
;
}
close
(
fd
);
if
(
do_daemonise
)
{
rc
=
daemonise
();
if
(
rc
<
0
)
{
perror
(
"daemonise"
);
goto
fail_nopid
;
}
}
if
(
pidfile
)
{
int
pfd
,
len
;
char
buf
[
100
];
len
=
snprintf
(
buf
,
100
,
"%lu"
,
(
unsigned
long
)
getpid
());
if
(
len
<
0
||
len
>=
100
)
{
perror
(
"snprintf(getpid)"
);
goto
fail_nopid
;
}
pfd
=
open
(
pidfile
,
O_WRONLY
|
O_CREAT
|
O_EXCL
,
0644
);
if
(
pfd
<
0
)
{
perror
(
"creat(pidfile)"
);
goto
fail_nopid
;
}
rc
=
write
(
pfd
,
buf
,
len
);
if
(
rc
<
len
)
{
perror
(
"write(pidfile)"
);
goto
fail
;
}
close
(
pfd
);
}
rc
=
kernel_setup
(
1
);
if
(
rc
<
0
)
{
fprintf
(
stderr
,
"kernel_setup failed.
\n
"
);
...
...
@@ -658,6 +742,8 @@ main(int argc, char **argv)
}
close
(
fd
);
}
if
(
pidfile
)
unlink
(
pidfile
);
debugf
(
"Done.
\n
"
);
return
0
;
...
...
@@ -668,15 +754,20 @@ main(int argc, char **argv)
" "
"[-h hello] [-H wired_hello] [-i idle_hello] [-u update]
\n
"
" "
"[-k metric] [-s] [-
P
] [-l] [-w] [-d level]
\n
"
"[-k metric] [-s] [-
p
] [-l] [-w] [-d level]
\n
"
" "
"[-t table] [-T table] [-X net cost] [-c file] [-C statement]
\n
"
" "
"[-D] [-L logfile] [-I pidfile]
\n
"
" "
"id interface...
\n
"
,
argv
[
0
]);
exit
(
1
);
fail:
if
(
pidfile
)
unlink
(
pidfile
);
fail_nopid:
for
(
i
=
0
;
i
<
numnets
;
i
++
)
{
if
(
!
nets
[
i
].
up
)
continue
;
...
...
util.c
View file @
3c462ade
...
...
@@ -26,6 +26,7 @@ THE SOFTWARE.
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
...
...
@@ -353,3 +354,25 @@ parse_ifflags(unsigned int flags)
strcat
(
buf
,
"MULTICAST "
);
return
buf
;
}
int
daemonise
()
{
int
rc
;
fflush
(
stdout
);
fflush
(
stderr
);
rc
=
fork
();
if
(
rc
<
0
)
return
-
1
;
if
(
rc
>
0
)
exit
(
0
);
rc
=
setsid
();
if
(
rc
<
0
)
return
-
1
;
return
1
;
}
util.h
View file @
3c462ade
...
...
@@ -54,6 +54,7 @@ int martian_prefix(const unsigned char *prefix, int plen);
int
v4mapped
(
const
unsigned
char
*
address
);
void
v4tov6
(
unsigned
char
*
dst
,
const
unsigned
char
*
src
);
char
*
parse_ifflags
(
unsigned
int
flags
);
int
daemonise
(
void
);
/* If debugging is disabled, we want to avoid calling format_address
for every omitted debugging message. So debug is a macro. But
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment