2014-02-28 04:02:01 +04:00
/***
This file is part of systemd .
Copyright 2013 Tom Gundersen < teg @ jklm . no >
systemd is free software ; you can redistribute it and / or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2014-04-24 23:28:46 +04:00
# include <getopt.h>
networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.
We will still block until all links we are aware of that are managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.
Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.
The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.
Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.
This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-23 19:42:55 +04:00
2014-02-28 04:02:01 +04:00
# include "sd-daemon.h"
2014-07-16 12:52:47 +04:00
networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.
We will still block until all links we are aware of that are managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.
Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.
The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.
Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.
This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-23 19:42:55 +04:00
# include "networkd-wait-online.h"
2014-02-28 04:02:01 +04:00
networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.
We will still block until all links we are aware of that are managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.
Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.
The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.
Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.
This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-23 19:42:55 +04:00
# include "strv.h"
2014-04-24 23:28:46 +04:00
# include "build.h"
static bool arg_quiet = false ;
static char * * arg_interfaces = NULL ;
static int help ( void ) {
printf ( " %s [OPTIONS...] \n \n "
" Block until network is configured. \n \n "
" -h --help Show this help \n "
" --version Print version string \n "
" -q --quiet Do not show status information \n "
" -i --interface=INTERFACE Block until at least these interfaces have appeared \n " ,
program_invocation_short_name ) ;
return 0 ;
}
static int parse_argv ( int argc , char * argv [ ] ) {
enum {
ARG_VERSION = 0x100 ,
} ;
static const struct option options [ ] = {
{ " help " , no_argument , NULL , ' h ' } ,
{ " version " , no_argument , NULL , ARG_VERSION } ,
{ " quiet " , no_argument , NULL , ' q ' } ,
{ " interface " , required_argument , NULL , ' i ' } ,
{ }
} ;
int c ;
assert ( argc > = 0 ) ;
assert ( argv ) ;
while ( ( c = getopt_long ( argc , argv , " +hq " , options , NULL ) ) > = 0 ) {
switch ( c ) {
case ' h ' :
return help ( ) ;
case ' q ' :
arg_quiet = true ;
break ;
case ARG_VERSION :
puts ( PACKAGE_STRING ) ;
puts ( SYSTEMD_FEATURES ) ;
return 0 ;
case ' i ' :
if ( strv_extend ( & arg_interfaces , optarg ) < 0 )
return log_oom ( ) ;
break ;
case ' ? ' :
return - EINVAL ;
default :
assert_not_reached ( " Unhandled option " ) ;
}
}
return 1 ;
}
2014-02-28 04:02:01 +04:00
int main ( int argc , char * argv [ ] ) {
2014-07-16 12:52:47 +04:00
_cleanup_ ( manager_freep ) Manager * m = NULL ;
int r ;
2014-04-24 23:28:46 +04:00
2014-07-16 12:52:47 +04:00
log_set_target ( LOG_TARGET_AUTO ) ;
2014-02-28 04:02:01 +04:00
log_parse_environment ( ) ;
log_open ( ) ;
2014-07-16 12:52:47 +04:00
umask ( 0022 ) ;
2014-04-24 23:28:46 +04:00
r = parse_argv ( argc , argv ) ;
if ( r < = 0 )
return r ;
2014-02-28 04:02:01 +04:00
2014-04-24 23:28:46 +04:00
if ( arg_quiet )
log_set_max_level ( LOG_WARNING ) ;
2014-02-28 04:02:01 +04:00
2014-07-16 12:52:47 +04:00
assert_se ( sigprocmask_many ( SIG_BLOCK , SIGTERM , SIGINT , - 1 ) = = 0 ) ;
networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.
We will still block until all links we are aware of that are managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.
Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.
The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.
Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.
This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-23 19:42:55 +04:00
2014-07-16 12:52:47 +04:00
r = manager_new ( & m , arg_interfaces ) ;
2014-02-28 04:02:01 +04:00
if ( r < 0 ) {
2014-07-16 12:52:47 +04:00
log_error ( " Could not create manager: %s " , strerror ( - r ) ) ;
goto finish ;
2014-02-28 04:02:01 +04:00
}
2014-07-16 12:52:47 +04:00
if ( manager_all_configured ( m ) ) {
2014-02-28 04:02:01 +04:00
r = 0 ;
2014-07-16 12:52:47 +04:00
goto finish ;
2014-02-28 04:02:01 +04:00
}
sd_notify ( false ,
" READY=1 \n "
2014-03-03 23:16:12 +04:00
" STATUS=Waiting for network connections... " ) ;
2014-02-28 04:02:01 +04:00
networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.
We will still block until all links we are aware of that are managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.
Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.
The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.
Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.
This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-23 19:42:55 +04:00
r = sd_event_loop ( m - > event ) ;
2014-02-28 04:02:01 +04:00
if ( r < 0 ) {
log_error ( " Event loop failed: %s " , strerror ( - r ) ) ;
2014-07-16 12:52:47 +04:00
goto finish ;
2014-02-28 04:02:01 +04:00
}
2014-07-16 12:52:47 +04:00
finish :
sd_notify ( false , " STATUS=All interfaces configured... " ) ;
2014-02-28 04:02:01 +04:00
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS ;
}