Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yohann D'Anello
re6stnet
Commits
bf65bc45
Commit
bf65bc45
authored
Mar 18, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NetworkManager/ifupdown: stop using pid file to find daemon
parent
9dac60f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
38 deletions
+44
-38
daemon/network-manager
daemon/network-manager
+43
-37
debian/rules
debian/rules
+1
-1
No files found.
daemon/network-manager
View file @
bf65bc45
#!/usr/bin/python -S
#!/usr/bin/python -S
# Is there something standard like Debian's start-stop-daemon ?
import
errno
,
glob
,
os
,
signal
,
socket
,
subprocess
,
sys
,
time
import
errno
,
os
,
subprocess
,
signal
,
sys
,
time
DAEMON
=
"re6stnet"
DAEMON
=
"re6stnet"
CONFDIR
=
"/etc/re6stnet"
CONFDIR
=
"/etc/re6stnet"
...
@@ -9,47 +7,55 @@ CONFDIR = "/etc/re6stnet"
...
@@ -9,47 +7,55 @@ CONFDIR = "/etc/re6stnet"
os
.
environ
[
"PATH"
]
=
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
os
.
environ
[
"PATH"
]
=
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
iface
=
sys
.
argv
[
1
]
iface
=
sys
.
argv
[
1
]
action
=
sys
.
argv
[
2
]
action
=
sys
.
argv
[
2
]
pid_file
=
"/var/run/re6stnet-%s.pid"
%
iface
lock_name
=
DAEMON
+
':'
+
iface
if
action
in
(
"up"
,
"vpn-up"
):
if
action
in
(
"up"
,
"vpn-up"
):
os
.
chdir
(
CONFDIR
)
os
.
chdir
(
CONFDIR
)
if
os
.
path
.
exists
(
"re6stnet.conf"
)
and
not
subprocess
.
call
(
if
os
.
path
.
exists
(
"re6stnet.conf"
)
and
not
subprocess
.
call
(
(
DAEMON
,
"@re6stnet.conf"
,
"--test"
,
"main_interface != %r"
%
iface
)):
(
DAEMON
,
"@re6stnet.conf"
,
"--test"
,
"main_interface != %r"
%
iface
)):
pid_fd
=
os
.
open
(
pid_file
,
os
.
O_CREAT
|
os
.
O_WRONLY
|
os
.
O_EXCL
,
0666
)
s
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
try
:
try
:
pid
=
os
.
fork
()
s
.
bind
(
'
\
0
'
+
lock_name
)
if
not
pid
:
except
socket
.
error
,
e
:
os
.
setsid
()
if
e
[
0
]
!=
errno
.
EADDRINUSE
:
os
.
execlp
(
DAEMON
,
DAEMON
,
"@re6stnet.conf"
)
raise
os
.
write
(
pid_fd
,
str
(
pid
))
sys
.
stderr
.
write
(
"daemon already started
\
n
"
)
except
:
sys
.
exit
()
os
.
remove
(
pid_file
)
if
not
os
.
fork
():
raise
os
.
setsid
()
os
.
execlp
(
DAEMON
,
DAEMON
,
"@re6stnet.conf"
)
elif
action
in
(
"down"
,
"vpn-down"
):
elif
action
in
(
"down"
,
"vpn-down"
):
pattern
=
" @%s
\
n
"
%
lock_name
with
open
(
"/proc/net/unix"
)
as
f
:
for
line
in
f
:
if
line
.
endswith
(
pattern
):
sock_path
=
"socket:[%s]"
%
line
.
split
()[
-
2
]
break
else
:
sys
.
exit
()
pattern
=
"(%s)"
%
DAEMON
for
path
in
glob
.
glob
(
"/proc/*/stat"
):
try
:
pid
=
int
(
path
[
6
:
-
5
])
with
open
(
path
)
as
f
:
stat
=
f
.
read
().
split
()
if
stat
[
1
]
==
pattern
and
sock_path
in
(
os
.
readlink
(
path
)
for
path
in
glob
.
glob
(
path
[:
-
4
]
+
"fd/*"
)):
break
except
(
EnvironmentError
,
ValueError
):
pass
else
:
sys
.
exit
()
try
:
try
:
pid
=
open
(
pid_file
).
read
()
os
.
kill
(
pid
,
signal
.
SIGTERM
)
os
.
remove
(
pid_file
)
sleep
=
.
1
except
IOError
,
e
:
while
sleep
<
5
:
if
e
.
errno
!=
errno
.
ENOENT
:
time
.
sleep
(
sleep
)
os
.
kill
(
pid
,
0
)
sleep
*=
1.5
# we waited for about 11 seconds
os
.
kill
(
-
int
(
stat
[
4
]),
signal
.
SIGKILL
)
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
ESRCH
:
raise
raise
else
:
stat
=
open
(
'/proc/%s/stat'
%
pid
).
read
().
split
()
if
stat
[
0
]
==
pid
and
stat
[
1
]
==
"(re6stnet)"
:
pid
=
int
(
pid
)
def
kill
(
sig
):
try
:
os
.
kill
(
pid
,
sig
)
except
OSError
,
e
:
if
e
.
errno
==
errno
.
ESRCH
:
sys
.
exit
()
raise
kill
(
signal
.
SIGTERM
)
sleep
=
.
1
while
sleep
<
5
:
time
.
sleep
(
sleep
)
kill
(
0
)
sleep
*=
1.5
# we waited for about 11 seconds
pid
=
-
int
(
stat
[
4
])
kill
(
signal
.
SIGKILL
)
debian/rules
View file @
bf65bc45
...
@@ -37,7 +37,7 @@ override_dh_install:
...
@@ -37,7 +37,7 @@ override_dh_install:
for
a
in
up down
;
do
\
for
a
in
up down
;
do
\
set
debian/re6stnet/etc/network/if-
$$
a.d/re6stnet
;
\
set
debian/re6stnet/etc/network/if-
$$
a.d/re6stnet
;
\
install
-d
$
${
1
%/*
}
;
\
install
-d
$
${
1
%/*
}
;
\
printf
'#!/bin/sh -e\n[ "$$METHOD" = NetworkManager ] ||exec
$(NM)
"$$IFACE" %s\n'
$$
a
>
$$
1
;
\
printf
'#!/bin/sh -e\n[ "$$METHOD" = NetworkManager
-o "$$IFACE" = lo
] ||exec
$(NM)
"$$IFACE" %s\n'
$$
a
>
$$
1
;
\
chmod
+x
$$
1
;
\
chmod
+x
$$
1
;
\
done
done
...
...
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