Commit Graph

41 Commits

Author SHA1 Message Date
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
ff527652c7 callouts: downgrade logging severity of messages to g_info() and g_debug()
In dispatcher, we install a log-handler which maps G_LOG_LEVEL_MESSAGE
to syslog priority LOG_NOTICE, which in turn causes journal to highlight
the message. We don't want that so instead use g_info() and g_debug()
which maps to lower syslog levels.

There is only one problem, in debug-mode, we don't use syslog but the
default logging handler from glib. In this case, we have to set
G_MESSAGES_DEBUG otherwise g_info()/g_debug() is suppressed.
2016-02-24 20:04:29 +01:00
Thomas Haller
6ee744f41d dispatcher: minor cleanup ignoring dispatcher scripts by filename 2016-02-21 18:31:39 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Lubomir Rintel
76cb1d4b72 dispatcher: drop a useless condition
The request->scripts are allocated in handle_action() and request_free() is
only called after that, so it never sees it NULL. Coverity knows:

CID 59385 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking request->scripts suggests that it may be null,
but it has already been dereferenced on all paths leading to the check.
2016-02-11 17:01:03 +01:00
Thomas Haller
ea112ed821 dispatcher: adjust logging output for dispatcher events
Previously, we would log messages like:
  #3 'pre-up' [tun0]: new request (1 scripts)

Journald interprets the "#" prefix as a severity level and
highlights them.
2016-01-26 14:10:56 +01:00
Thomas Haller
a841d40039 callouts: always print the environment even if no scripts are present
Commit ac6522bbf1 moved logging of the environment
after the check for @error_message to avoid a crash. However, in case of no
scripts (request->scripts->len == 0) we still want to log the environment,
so move it back to where it was, but avoid the crash.
2016-01-19 11:01:33 +01:00
Lubomir Rintel
ac6522bbf1 dispatcher: only dump environment when there's no error
(gdb) bt
  #0  0x00007f206bd1ec58 in handle_action (dbus_dispatcher=<optimized out>, context=0x7f2058003190, str_action=<optimized out>, connection_dict=0x7f205800bc40, connection_props=0x7f205800b900,
      device_props=0x7f205800b150, device_ip4_props=0x7f205800b120, device_ip6_props=0x7f205800b0f0, device_dhcp4_props=0x7f205800b0c0, device_dhcp6_props=0x7f205800b090, vpn_ip_iface=0x7f206c257990 "",
      vpn_ip4_props=0x7f205800b000, vpn_ip6_props=0x7f205800af90, request_debug=1, user_data=0x7f206c242980) at nm-dispatcher.c:722
  #1  0x00007f2068313dac in ffi_call_unix64 () at ../src/x86/unix64.S:76
  #2  0x00007f20683136d5 in ffi_call (cif=cif@entry=0x7ffdfde6d2f0, fn=<optimized out>, rvalue=0x7ffdfde6d260, avalue=avalue@entry=0x7ffdfde6d140) at ../src/x86/ffi64.c:522
  #3  0x00007f2069ba4678 in g_cclosure_marshal_generic (closure=0x7f206c23a9e0, return_gvalue=0x7ffdfde6d440, n_param_values=<optimized out>, param_values=<optimized out>, invocation_hint=<optimized out>,
      marshal_data=0x0) at gclosure.c:1454
  #4  0x00007f2069ba3e38 in g_closure_invoke (closure=0x7f206c23a9e0, return_value=return_value@entry=0x7ffdfde6d440, n_param_values=14, param_values=param_values@entry=0x7f206c256d10,
      invocation_hint=invocation_hint@entry=0x7ffdfde6d490) at gclosure.c:768
  #5  0x00007f2069bb575d in signal_emit_unlocked_R (node=node@entry=0x7f206c2505a0, detail=detail@entry=0, instance=instance@entry=0x7f206c2442a0, emission_return=emission_return@entry=0x7ffdfde6d5d0,
      instance_and_params=instance_and_params@entry=0x7f206c256d10) at gsignal.c:3553
  #6  0x00007f2069bbc641 in g_signal_emitv (instance_and_params=instance_and_params@entry=0x7f206c256d10, signal_id=signal_id@entry=6, detail=detail@entry=0, return_value=return_value@entry=0x7ffdfde6d5d0)
      at gsignal.c:3048
  #7  0x00007f206bd21aa1 in _nmdbus_dispatcher_skeleton_handle_method_call (connection=<optimized out>, sender=<optimized out>, object_path=<optimized out>,
      interface_name=0x7f2058010b20 "org.freedesktop.nm_dispatcher", method_name=0x7f205800ab00 "Action", parameters=<optimized out>, invocation=0x7f2058003190, user_data=0x7f206c2442a0)
      at nmdbus-dispatcher.c:1066
  #8  0x00007f2069ec8ba6 in g_dbus_interface_method_dispatch_helper (invocation=0x7f2058003190, method_call_func=0x7f206bd218d0 <_nmdbus_dispatcher_skeleton_handle_method_call>, interface=0x7f206c2442a0)
      at gdbusinterfaceskeleton.c:609
  #9  skeleton_intercept_handle_method_call (connection=<optimized out>, sender=sender@entry=0x7f205800ee50 ":1.1007", object_path=object_path@entry=0x7f20580108d0 "/org/freedesktop/nm_dispatcher",
      interface_name=interface_name@entry=0x7f2058010b20 "org.freedesktop.nm_dispatcher", method_name=method_name@entry=0x7f205800ab00 "Action", parameters=parameters@entry=0x7f205800af00,
      invocation=invocation@entry=0x7f2058003190, user_data=user_data@entry=0x7f206c2442a0) at gdbusinterfaceskeleton.c:650
  #10 0x00007f2069eb0bc1 in call_in_idle_cb (user_data=0x7f2058003190) at gdbusconnection.c:4873
  #11 0x00007f20696a279a in g_main_dispatch (context=0x7f206c23f9a0) at gmain.c:3109
  #12 g_main_context_dispatch (context=context@entry=0x7f206c23f9a0) at gmain.c:3708
  #13 0x00007f20696a2ae8 in g_main_context_iterate (context=0x7f206c23f9a0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3779
  #14 0x00007f20696a2dba in g_main_loop_run (loop=0x7f206c23fa80) at gmain.c:3973
  #15 0x00007f206bd1dcd4 in main (argc=1, argv=0x7ffdfde6da88) at nm-dispatcher.c:948
  (gdb) print error_message
  $4 = 0x7f206bd22980 "Missing or invalid required value path!"
  (gdb)
2016-01-18 19:12:17 +01:00
Thomas Haller
466a081c0f dispatcher: add assertion and code comment to complete_script() 2016-01-12 16:24:38 +01:00
Thomas Haller
2b54bd6a53 dispatcher: fix use-after-free in complete_script()
complete_request() possibly frees the request, making the @script and @request
a dangling pointer. We must not use those pointers, except a plain pointer-
comparison.
2016-01-12 16:24:38 +01:00
Lubomir Rintel
ddc6d97f00 dispatcher: only evaluate the number of the scripts if the request is still there
The request could have been completed by the call to complete_request() just above.
In that case we should just return instead of looking for nowait scripts to run.

  Core was generated by `/usr/libexec/nm-dispatcher'.
  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0x00007f6c916ad0fb in complete_script (script=<error reading variable: value has been optimized out>, script=<error reading variable: value has been optimized out>) at nm-dispatcher.c:349
  349                     if (   script->request->num_scripts_nowait == 0
  (gdb) bt
  #0  0x00007f6c916ad0fb in complete_script (script=<error reading variable: value has been optimized out>, script=<error reading variable: value has been optimized out>) at nm-dispatcher.c:349
  #1  0x00007f6c8f02d484 in g_child_watch_dispatch (source=<optimized out>, callback=<optimized out>, user_data=<optimized out>) at gmain.c:5148
  #2  0x00007f6c8f03079a in g_main_context_dispatch (context=0x7f6c9358d9a0) at gmain.c:3109
  #3  0x00007f6c8f03079a in g_main_context_dispatch (context=context@entry=0x7f6c9358d9a0) at gmain.c:3708
  #4  0x00007f6c8f030ae8 in g_main_context_iterate (context=0x7f6c9358d9a0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3779
  #5  0x00007f6c8f030dba in g_main_loop_run (loop=0x7f6c9358da80) at gmain.c:3973
  #6  0x00007f6c916abcd4 in main (argc=1, argv=0x7ffee4326768) at nm-dispatcher.c:935
  (gdb)

Fixes: e97a334e37

https://bugzilla.redhat.com/show_bug.cgi?id=1297826
2016-01-12 15:48:03 +01:00
Jiří Klimeš
6cd5cc595f dispatcher: fix abort in case of an error (rh #1275813)
request_free() can be called on an error.

Oct 27 20:27:46 localhost.localdomain nm-dispatcher[2328]: #1 'pre-up': completed: invalid request: Missing or invalid required value path!
Oct 27 20:27:46 localhost.localdomain nm-dispatcher[2328]: **
Oct 27 20:27:46 localhost.localdomain nm-dispatcher[2328]: ERROR:nm-dispatcher.c:203:request_free: assertion failed (request->num_scripts_done == request->scripts->len): (0 == 1)

Fixes: 1999723241

https://bugzilla.redhat.com/show_bug.cgi?id=1275813
2015-10-30 14:00:15 +01:00
Thomas Haller
e7685f4304 dispatcher: refactor logging of nm-dispatcher
Refactor logging so that all logging lines for a request/script
have the same prefix, indicating the event to which they belong.

Previously, we only scheduled one script at a time so it was always
clear for which request a script belongs. Now we schedule scripts
in parallel, so we must know the event (request) for which we log
a message.
2015-08-25 15:27:19 +02:00
Thomas Haller
e81ba75949 dispatcher: return error reason from nm_dispatcher_utils_construct_envp()
Also, error out in handle_action() when nm_dispatcher_utils_construct_envp()
indicates a failure.
2015-08-25 15:27:19 +02:00
Thomas Haller
199754a845 dispatcher: remove local @iface variable from handle_action() 2015-08-25 15:27:18 +02:00
Thomas Haller
38fa197bab dispatcher: move clearing @quit_id in handle_action()
First create and initialize @request, and then start it.
2015-08-25 15:27:18 +02:00
Thomas Haller
8143d895ca dispatcher: use slice allocator for Request and ScriptInfo 2015-08-25 15:27:18 +02:00
Thomas Haller
e97a334e37 dispatcher: run "wait" scripts only after "no-wait" scripts complete
Previously, dispatcher would start all "no-wait" script right away,
but it would also start the first "wait" script while the "no-wait"
script are still running (unless, there are other "wait" scripts that
delay the execution).

Now, do not start processing the "wait" scripts, as long as there are
any "no-wait" scripts from the same request running.
2015-08-25 15:27:18 +02:00
Beniamino Galvani
1999723241 nm-dispatcher: allow scripts to be marked as no-wait
When a script is a symbolic link to the 'no-wait.d' subdirectory, the
dispatcher now schedules it immediately and in parallel with other
no-wait scripts.

https://bugzilla.gnome.org/show_bug.cgi?id=746703
2015-08-25 15:27:18 +02:00
Beniamino Galvani
2e2e588cd5 nm-dispatcher: fix memory leaks 2015-08-25 15:27:18 +02:00
Thomas Haller
4c80e322ae dispatcher: explicitly set missing interface argument for device actions
The first argument for dispatcher actions is the interface name, except
for the "hostname" action, where no interface is available.

For "hostname" actions continue to pass "none", as there is no interface
available. But for device actions, it may happen that the interface name
is missing too. In this case, don't pass "none" but instead an empty
name.
2015-08-19 23:36:36 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
8fdf198632 dispatcher: don't exit with failure in case D-Bus service stops
The initsystem should stop nm-dispatcher before stopping D-Bus
service. However, on some systems that is not implemented, so
nm-dispatcher should not exit with a failure message when the
system bus disappears.
Instead just assume that D-Bus service was stopped during shutdown
and exit gracefully.

Based-on-patch-by: Jacob <jacobgodserv@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=751017
2015-07-01 17:13:52 +02:00
Thomas Haller
22bfe2feb2 dispatcher: repeat waitpid() call on EINTR
Also, no use of first trying to kill() with signal zero. Just
send SIGKILL right away.
2015-05-05 16:39:18 +02:00
Dan Winship
c22e3f327a core, dispatcher: drop unnecessary setpgid() calls
There's no point in calling setpgid() on short-lived processes, so
remove the setpgid() calls when spawning dispatcher scripts, iptables,
iscsiadmin, and netconf.
2015-01-19 11:29:13 -05:00
Jiří Klimeš
28599331e3 callout: ignore waitpid() return value
Coverity:
Defect type: CHECKED_RETURN
2014-12-05 09:38:40 +01:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Jiří Klimeš
4ad7cda7a4 dispatcher: fix crash on missing scripts (bgo #738654)
GLib-CRITICAL **: g_variant_type_checked_: assertion `g_variant_type_string_is_valid (type_string)' failed
GLib-CRITICAL **: g_variant_new_array: assertion `n_children > 0 || child_type != NULL' failed

https://bugzilla.gnome.org/show_bug.cgi?id=738654
2014-10-21 08:57:02 +02:00
Dan Winship
1a5cfc1f45 dispatcher: port to GDBus
Port nm-dispatcher to GDBus, mostly, using dbus-glib's GVariant
utilities to translate the return value of nm_connection_to_dbus().
2014-09-18 11:26:59 -04:00
Thomas Haller
02747203c6 dispatcher: silence warning about sub-directories in dispatcher directory
Especially now that we have the 'pre-up.d/' and 'pre-down.d/' directories,
silently skip over any sub directories inside the dispatcher directory.

Fixes warning:
  nm-dispatcher: Cannot execute '/etc/NetworkManager/dispatcher.d/pre-up.d': not a regular file.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-17 19:15:31 +02:00
Thomas Haller
589272facf dispatcher: fix leak in callouts/nm-dispatcher
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-17 19:09:56 +02:00
Thomas Haller
c8e7953333 dispatcher/trivial: rename variables for script directory to NMD_SCRIPT_DIR_* 2014-06-16 19:18:57 +02:00
Dan Williams
33e5e1c500 dispatcher: don't warn on non-critical missing directory error 2014-06-06 18:28:03 -05:00
Dan Williams
02252224e2 dispatcher: bump overall timeout to 10 minutes (rh #982734) (rh #1048345)
Since NM now handles long-running dispatcher scripts better, allow them
to run for really long times.
2014-06-06 13:43:47 -05:00
Dan Williams
fd5761ecb2 dispatcher: don't use NULL error domains
glib doesn't like it, plus we don't use the error anyway, so just
return the constant error string.
2014-06-06 13:43:47 -05:00
Dan Williams
1383f4bc14 dispatcher: use separate directories for pre-up/pre-down events
To ensure that NetworkManager does not block needlessly for events
which have no scripts, require scripts that respond to blocking
events to opt into the action.
2014-06-06 13:43:46 -05:00
Dan Williams
5150cb88c2 dispatcher: only dispatch if scripts exist
If there are no dispatcher scripts, don't bother dispatching any
events.  This saves some time configuring networking if the event
would have no effect anyway.
2014-06-06 13:43:45 -05:00
Dan Williams
4cc13befd3 dispatcher: rename executable to 'nm-dispatcher' 2014-06-06 13:43:45 -05:00