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 ;
2015-02-01 23:04:35 +03:00
static usec_t arg_timeout = 120 * USEC_PER_SEC ;
2014-04-24 23:28:46 +04:00
static char * * arg_interfaces = NULL ;
2015-01-29 09:34:34 +03:00
static char * * arg_ignore = NULL ;
2014-04-24 23:28:46 +04:00
2014-08-02 19:12:21 +04:00
static void help ( void ) {
2014-04-24 23:28:46 +04:00
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 "
2014-08-02 19:12:21 +04:00
" -i --interface=INTERFACE Block until at least these interfaces have appeared \n "
2015-01-29 09:34:34 +03:00
" --ignore=INTERFACE Don't take these interfaces into account \n "
2015-02-01 23:04:35 +03:00
" --timeout=SECS Maximum time to wait for network connectivity \n "
2014-08-02 19:12:21 +04:00
, program_invocation_short_name ) ;
2014-04-24 23:28:46 +04:00
}
static int parse_argv ( int argc , char * argv [ ] ) {
enum {
ARG_VERSION = 0x100 ,
2015-01-29 09:34:34 +03:00
ARG_IGNORE ,
2015-02-01 23:04:35 +03:00
ARG_TIMEOUT ,
2014-04-24 23:28:46 +04:00
} ;
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 ' } ,
2015-01-29 09:34:34 +03:00
{ " ignore " , required_argument , NULL , ARG_IGNORE } ,
2015-02-01 23:04:35 +03:00
{ " timeout " , required_argument , NULL , ARG_TIMEOUT } ,
2014-04-24 23:28:46 +04:00
{ }
} ;
2015-02-01 23:04:35 +03:00
int c , r ;
2014-04-24 23:28:46 +04:00
assert ( argc > = 0 ) ;
assert ( argv ) ;
2014-08-26 14:28:28 +04:00
while ( ( c = getopt_long ( argc , argv , " +hiq " , options , NULL ) ) > = 0 )
2014-04-24 23:28:46 +04:00
switch ( c ) {
case ' h ' :
2014-08-02 19:12:21 +04:00
help ( ) ;
return 0 ;
2014-04-24 23:28:46 +04:00
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 ;
2015-01-29 09:34:34 +03:00
case ARG_IGNORE :
if ( strv_extend ( & arg_ignore , optarg ) < 0 )
return log_oom ( ) ;
break ;
2015-02-01 23:04:35 +03:00
case ARG_TIMEOUT :
r = parse_sec ( optarg , & arg_timeout ) ;
if ( r < 0 )
return r ;
break ;
2014-04-24 23:28:46 +04:00
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
2015-02-01 23:04:35 +03:00
r = manager_new ( & m , arg_interfaces , arg_ignore , arg_timeout ) ;
2014-02-28 04:02:01 +04:00
if ( r < 0 ) {
2014-11-28 15:19:16 +03:00
log_error_errno ( r , " Could not create manager: %m " ) ;
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
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 ) {
2014-11-28 15:19:16 +03:00
log_error_errno ( r , " Event loop failed: %m " ) ;
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 :
2015-01-29 09:34:34 +03:00
strv_free ( arg_interfaces ) ;
strv_free ( arg_ignore ) ;
2015-02-01 23:04:35 +03:00
if ( r > = 0 ) {
sd_notify ( false , " STATUS=All interfaces configured... " ) ;
return EXIT_SUCCESS ;
} else {
sd_notify ( false , " STATUS=Failed waiting for network connectivity... " ) ;
return EXIT_FAILURE ;
}
2014-02-28 04:02:01 +04:00
}