Commit graph

4184 commits

Author SHA1 Message Date
Patrick Ohly
f5af2bcc6a fork/exec: search for helper in libexec
Added code which checks for existence of the helper binary in the
libexec dir when it is given without any path component. Searching
inside the PATH env variable is still used as fallback when not
found in libexec (useful for testing without actually installing
in the final destination).
2012-01-17 13:22:11 +00:00
Patrick Ohly
e405d2b7ea fork/exec: catch error messages from child
Dead code, doesn't work. Merely committing as reminder. As before,
anything written by the child's logging code to stdout is printed
directly to the parent's stdout (no redirection anywhere).

The problems with this patch were:
- when SYNCEVOLUTION_DEBUG was set, the code still redirected
  the child's stdout to stderr
- the child prints INFO messages which are relevant for the user;
  with redirection, those do not reach the user
- the child's ERROR messages end up being printed as
  [ERROR] stderr output: [ERROR] ....
2012-01-17 13:22:10 +00:00
Patrick Ohly
616d51b34c GDBus GIO: no timeout for D-Bus method invocations
When calling a method, give the peer unlimited time to reply. Relevant
in particular for local sync, where the time for processing a message
is basically unpredictable.

Communication with the D-Bus daemon still uses the default timeout.
2012-01-17 13:22:10 +00:00
Patrick Ohly
b437a01f9e GDBus + libdbus/GIO: use dedicated class for plain buffers
Instead of overloading std::pair with additional meaning, use
GDBusCXX::DBusArray when we want to pass byte arrays. Allows defining
"normal" traits for std::pair.

API change, must be done in both D-Bus CXX layers and in the code using it.
2012-01-17 13:22:07 +00:00
Patrick Ohly
5f14f2a900 GDBus + GIO: improved D-Bus method calls
- moved common code into base class (prepare/send)
- add call operators with up to 10 parameters
2012-01-17 13:20:32 +00:00
Patrick Ohly
cb30dca6cc GDBus + libdbus: improved D-Bus method calls
- moved common code into base class (prepare/send) reps. .cpp file (CheckError())
- retrieve D-Bus error description from error message and use it as part of
  the C++ exception description, in addition to the error name (only error
  name was used before)
- add call operators with up to 10 parameters
2012-01-17 13:19:51 +00:00
Patrick Ohly
4222c5366b GDBus GIO: implemented client/server
This pretty much follows the example from:
http://developer.gnome.org/gio/2.28/GDBusServer.html#GDBusServer.description
2012-01-17 11:04:38 +01:00
Patrick Ohly
9a78c5e6bd D-Bus client/server: authentication
Checking authentication needs to be abstraced and cannot be done with
a libdbus-only method. At the moment the assumption is that the
connecting client is at least from the same user.
2012-01-17 11:04:38 +01:00
Patrick Ohly
e1b4a3f01b fork/exec: added state tracking
ForkExecParent is now keeping track of the current state:
        IDLE,           /**< instance constructed, but start() not called yet */
        STARTING,       /**< start() called */
        CONNECTED,      /**< child has connected, D-Bus connection established */
        TERMINATED      /**< child has quit */

Was needed for local sync and might be useful also elsewhere, thus
implemented in the core fork/exec code itself.
2012-01-17 11:04:37 +01:00
Patrick Ohly
00ab0bf025 fork/exec: implemented stop() and kill()
Sending the signals was missing.
2012-01-17 11:04:37 +01:00
Patrick Ohly
3fa4d9c528 fork/exec: added onFailure
Methods called from glib C code must not throw exceptions. If that
happens, the problem will be reported via onFailure.

The more likely problem is that the child quits prematurely or with an
error code. Both is reported via onFailure now, so the user of
ForkExecParent no longer has to watch the child itself.
2012-01-17 11:04:37 +01:00
Patrick Ohly
3536b30c3b fork/exec: removed loop parameter
The parameter wasn't really needed for anything. Everything happens
inside the main context and the caller is responsible for creating and
running a loop.
2012-01-17 11:04:37 +01:00
Patrick Ohly
6b9d10a769 DBus client/server test: added usage of fork/exec
Run with --forkexec to let dbus-client-server restart itself as child.
2012-01-17 11:04:37 +01:00
Patrick Ohly
d6c87f80d8 fork/exec: generic utility class for fork/exec + D-Bus
This depends on glib and D-Bus support. There is no global switch for
D-Bus on/off, only one for syncevo-dbus-server on/off, so that is what
is getting checked for now. The utility class is inside
libsyncevolution.la, so that library now also depends on
libgdbussyncevo.la, if enabled.

The actual implementation uses the GDBus client/server utility classes
abnd g_spawn(). A child watch is used to detect premature exits of the
child.

The idea was to also have a failure signal. Except for "child quit
without establishing connection" there is no error which currently has
to be reported, and that problem is already reported via the onQuit
signal. Therefore there is no onFailure signal yet.
2012-01-17 11:04:37 +01:00
Patrick Ohly
c48ec0e803 GLibSupport: added alloc function for g_spawn() string arrays
AllocStringArray() allocates at least the array of plain string
pointers and optionally also copies the strings. Arbitrary alloc/free
functions can be used. Default is to not copy strings and use new []
for the array. That matches a usage where the strings are owned by
some collection and the array is in a boost::scoped_array.
2012-01-17 11:04:37 +01:00
Patrick Ohly
31e61c7200 GMainLoop smart pointer: moved to GLibSupport.h
Better use a shared pointer for GMainLoop. Avoids errors with ref
counting when coping an eptr and boost::intrusive_ptr has the same low
overhead.
2012-01-17 11:04:37 +01:00
Patrick Ohly
f88fe5acac GDBus: test program for client/server setup
Can run as both client and server. Linked against libsyncevolution
only because it needs some utility methods in it.

Logs authentication state when a new connection is created.  Currently
such connections are unauthenticated at first. If the client has the
same user ID as the server, it is allowed to proceed (tested
empirically). If not, authentication fails and handle_message() is
not called (but the connection remains open!?).

Disconnects are not properly detected because GDBus for libdbus
doesn't support reporting disconnects on a connection (not
implemented). Instead of relying on it, better watch child or parent
via some other means. In this example, the server side just keeps
the connection open until the next client connects. The client
lets GDBus exit() the process on disconnect.
2012-01-17 11:04:37 +01:00
Patrick Ohly
8f2c1d412a GDBus + libdbus: added direct client/server support
Added methods and classes for setting up direct D-Bus communication.
Only implemented for the non-GIO GDBus at the moment.

The callback must not throw exceptions because it is invoked from
plain C code.
2012-01-17 11:04:37 +01:00
Patrick Ohly
bf35e7e0d8 DBus (both): added the possibility to let DBusObjectHelper close the connection
Added closeConnection parameter to constructor, to be passed down to the
underlying DBusObject.
2012-01-17 11:04:37 +01:00
Patrick Ohly
ea3ed009ea autotools: moved definition of gdbus_dir
The definition is needed in various places, so putting it into the
top-level Makefile.am is cleaner.
2012-01-17 11:04:37 +01:00
Patrick Ohly
e4d6c154ad GDBus GIO: fixed asynchronous message replies
First, asynchronous method replies were not detected because their
dbus_traits still had "asynchronous = false". Second, the NULL reply
from an asynchrounous implementation was passed to
g_dbus_connection_send_message(), causing an error message to be
logged.
2012-01-17 11:04:37 +01:00
Patrick Ohly
ee9c9cff44 GDBus GIO: avoid segfault when activating object with no signals or no methods
array[len - 1] accesses an invalid element when the method or signal
array is empty. Need to check length first.
2012-01-17 11:04:37 +01:00
Patrick Ohly
ce59a217e2 GDBus + GIO: added exception for failure to add signal watch
When adding a signal watch failed, no error was reported and the
caller couldn't check for success. Now an exception is thrown.
2012-01-17 11:04:37 +01:00
Patrick Ohly
0fb196edce GDBus + libdbus: added exception for failure to add signal watch
When adding a signal watch failed, no error was reported and the
caller couldn't check for success. Now an exception is thrown.
2012-01-17 11:04:36 +01:00
Patrick Ohly
2c5f223458 GDBus + GIO: fixed error name
A hyphen is not allowed in a D-Bus error name. Creating such an error
failed and the error was never sent (?!).
2012-01-17 11:01:12 +01:00
Patrick Ohly
8c289f227a GDBus + libdbus: fixed error name
A hyphen is not allowed in a D-Bus error name. Creating such an error
failed and the error was never sent (?!).
2012-01-17 11:01:12 +01:00
Patrick Ohly
a2c5935920 D-Bus testing: need common '/' object for ConnMan and Bluez
Adding the always-on '/' object for ConnMan broke Bluez testing,
because adding a second '/' object for the Bluez calls fails with:
  KeyError: "Can't register the object-path handler for '/': there is already a handler"

This makes sense, because at the D-Bus message might be sent directly,
without including the well-known bus name, and thus finding the right
right object cannot be done by bus name.

Solved by registering a unified ConnMan/Bluez root object which provides
both interfaces.
2012-01-16 14:17:29 +01:00
Patrick Ohly
ef237ff52e D-Bus testing: ignore Network Manager when testing ConnMan
syncevo-dbus-server tried to connect to Network Manager on the system
bus when doing unit testing of the ConnMan code, which influenced the
outcome of the tests. Now test-dbus.py disables the usage of Network
Manager via the new DBUS_TEST_NETWORK_MANAGER env variable.
2012-01-16 12:29:30 +01:00
Patrick Ohly
f1bffbc1a4 Merge commit 'syncevolution-1-2-2'
Conflicts:
	Makefile.am
	configure-post.in
	configure.ac
	src/Makefile-gen.am
	src/dbus/qt/Makefile.am
	src/syncevo-dbus-server.cpp
	test/test-dbus.py

Conflicts caused by renaming of files on master. Manually applied the
relevant changes to the renamed files.
2012-01-16 11:47:10 +01:00
Patrick Ohly
09ce2bb579 autotools + NEWS: updated for 1.2.2 release 2012-01-13 16:53:30 +01:00
Patrick Ohly
8b7591e736 lcs: must include unistd.h for (s)size_t
ssize_t and size_t were taken for granted after including
some C++ header files. That's not guaranteed and breaks
on FC17 with g++ 4.7.

Probably the "pure C++" lcs code shouldn't use these types;
for now let's simply include unistd.h.
2012-01-13 16:42:08 +01:00
Patrick Ohly
5b170518cf WebDAV: fixed libneon compatibility mode when compiling against libneon-gnutls
When NEON_LIBS=-lneon-gnutls, the sed invocation didn't properly turn
that into -ldl. Instead it used -ldl-gnutls, which caused a link error.

Fixed with an extended regex.

Partial cherry-pick from 856576df99 (without the install check).
2012-01-12 15:29:00 +01:00
Patrick Ohly
3d381aa0aa syncevo-dbus-server + ConnMan: fixed "online" detection (BMC #21541, BMD #24587)
SyncEvolution did not recognize any cellular connectivity as suitable
for syncing. The check for "connected technology" is unnecessary,
anything which makes the computer "online" should be good enough.
So now just use the ConnMan "State" property.

Additional benefit: will continue to work with ConnMan 1.0, which
won't have the "ConnectedTechnologies" property anymore.

The SyncEvolution code also (mis)used the "AvailableTechnologies"
property to determine whether OBEX over Bluetooth might work. As this
property is also going away, too, am changing the code so that
Bluetooth is always considered available (was already the case when
using Network Manager).

The Python D-Bus test for this functionality was overly complex (used
hidden state, code duplication) and didn't work (BMC #21541). Cleaned
up, which revealed some undesirable and broken behavior (BMC #24648).
That needs to be fixed separately. At the moment the test checks the
current behavior and works around the bug, so it passes.
2012-01-12 14:22:53 +00:00
Patrick Ohly
a1200aea47 sync logic: INFO message about writing backups
Point out that backups are created (user might be unaware otherwise
and wonder about the delay), explain why (so that users know how to
turn it off).
2012-01-11 16:10:08 +01:00
Patrick Ohly
545d4a5d1d sync logic: dumpData + printChanges logic was broken (BMC #24619)
The logic for dumpData and printChanges wasn't implemented correctly.
- run sync with dumpData=0 printChanges=0 => writes database dumps
  ("before/after" in logdir) although it shouldn't
- run status check (--status) with dumpData=1 printChanges=0 => dumps and
  prints changes although it should do neither
- same for --restore

The fix is to check the "print changes" setting in addition to (and
not instead of) m_doLogging. m_doLogging is merely an override used in
testing. If false, then the logdir handling and thus data dumps are
disabled.

For --status only check printChanges. This used to print changes and
thus dump data when either dumpData or printChanges were set. It makes
more sense to only produce the output when exactly that is asked for.
2012-01-11 16:10:08 +01:00
Patrick Ohly
ba96fca0ec EDS compatibility: bumped version check for EDS 3.2
SyncEvolution is known to work with EDS 3.2. Therefore use the
libebook/ecal/edataserver libs from 3.2 if available, without warnings
in the --version output. Also happens with inconsistent distro setups
where the old libs are available and would have been prefered by
SyncEvolution 1.2.1 even though the old libs no longer work with EDS
3.2.
2012-01-11 16:10:08 +01:00
Patrick Ohly
72a7f3d939 autotools: include missing src/dbus/qt/configure-sub.in
The file is necessary for running autogen.sh. Without it, the
src/dbus/qt directory was entered without having generated its
Makefile during configure, leading to a compile error.
2012-01-11 16:10:08 +01:00
Patrick Ohly
a2a3f8add5 autotools: exclude .gitignore from source .tar.gz
When bundling the libsynthesis source code, it's .gitignore file was
also bundled. The .gitignore caused problems when re-importing the
.tar.gz into git and normally isn't necessary, so don't ship it.
2012-01-11 16:10:08 +01:00
Patrick Ohly
209013a4d2 documentation: Fedora workaround
Fedora's build of SyncEvolution 1.2.1 failed because running the
uninstalled src/syncevolution didn't find the necessary shared
objects. Not sure why: on Debian Testing, src/syncevolution invokes
src/.libs/lt-syncevolution, which has the necessary paths set as
RPATH.

As a workaround, set LD_LIBRARY_PATH explicitly. This intentionally
includes a path which is only relevant on the master branch
(gdbuscxx), to simplify merging.
2012-01-11 16:10:08 +01:00
Patrick Ohly
98386d4e33 documentation: more readable --help, support cross-compilation better
The <<insert sync/source-property>> tags were visible in the --help
output. Now it says
   << see "syncevolution --sync/source-property ?" >>

These special tags still get expanded in README and man page.
That expansion is done by invoking the uninstalled syncevolution
binary. If that failed, compilation aborted. That's still the case
for native compilation (because we want to catch problems). For
cross-compilation such a failure is okay and keeps the tags in
the README/man page. That's done because running a binary compiled
for an entirely different architecture is not guaranteed to work.
2012-01-11 16:10:08 +01:00
Patrick Ohly
b240b6d4c4 testing: extended LD_LIBRARY_PATH
syncevo-dbus-server must be able to find it's D-Bus support
library, regardless whether it is in src/gdbus or src/gdbusxx.
2012-01-11 13:42:46 +00:00
Patrick Ohly
8c51d59111 GDBus GIO: fixed compile error
dbus_traits<bool> must derive from dbus_traits_base, otherwise compilation
fails because "asynchronous" is not defined.
2012-01-11 07:59:44 +00:00
Patrick Ohly
4f0254c801 Merge branch 'syncevolution-1-2-branch' 2012-01-10 11:49:43 +01:00
Patrick Ohly
6313c3a569 Cmdline: fixed a clang warning
Cmdline had one virtual method but no virtual destructor.
2011-12-21 14:54:56 +01:00
Patrick Ohly
846154d5ad D-Bus API: added documentation for Session.Attach/Detach()
These calls were available and referenced elsewhere in the
documentation without being documented themselves.
2011-12-20 09:09:28 +00:00
Patrick Ohly
b7b17159d9 GIO GDBus: fixed memory corruption
g_variant_get() does not work for C++ bool directly because at least
on x86_64, C++ bool uses 1 byte while gboolean uses 4. This caused
random stack corruption when unpacking four bytes into an address
which only had room for one. Caused "syncevolution --version" to segfault
when using a corrupted std::string later.
2011-12-19 18:00:01 +01:00
Patrick Ohly
b34591dd62 GDBus: API and usage cleanup
DBusCallObject and friends were not used anywhere. Removed.

DBusObject and DBusRemoteObject used pure virtual methods to let
derived classes provide information about interface, path,
destination, method and the connection. The idea behind that was that
most of these strings are static and thus do not need to be copied.

The downside is that one had to derive from these classes in order to
provide the required information. The same class could not own two
instances of the generic DBusObject to access two different
destinations. It also sprinkled the code for setting up D-Bus
operations into several different places (constructor, class definition).

Now the information is passed to the DBus[Remote]Object constructor
and stored in the classes, which are thus merely containers for the
information and thus easier to use. Users of the classes still derive
from them, to keep the change smaller, although that is no longer
necessary.

Removed plain DBusConnection pointers from the C++ interface, return
DBusConnectionPtr instead. The exception is DBusObject, which still
returns plain pointers owned by the instance (as before) to ease
integration with the underlying D-Bus library. DBUS_CONNECTION_TYPE
is not needed.

This revealed that quite some code incorrectly took another reference
to the connection when assigning to DBusConnectionPtr (assignment
always increases the refcount, only in the constructor is that
optional). As a result the private connections were never
destructed. Apparently there were some global pointers to active
connections, so that this (minor) resource leak didn't show up in
valgrind.

It also showed that the closing of the D-Bus connection never happened
properly, although libdbus requires it. The ref counting mechanism
cannot be used for this because it cannot be checked whether the last
reference is about to be dropped. The slightly hackish solution is to
designate one DBusObject as the "main owner" of the connection. When
that object destructs, it closes the connection. There might still be
some other references; they simply cannot (and shouldn't) send or
receive messages anymore.
2011-12-19 17:59:42 +01:00
Patrick Ohly
996a237b18 autotools: added missing dependency syncevolution -> libgdbussyncevo
Rebuilding the library did not trigger a relinking of syncevolution.
Adding .la files for LDADD is not enough, they also need to go into
DEPENDS.
2011-12-19 17:59:42 +01:00
Patrick Ohly
cb7ea565d3 autotools: added rule for libsynthesis.la
When compiling libsynthesis as part of the normal make invocation,
libsyncevolution.la had a dependency on libsynthesis.la, but no rule
to generate it. That worked for "make all" (because it entered the
subdir first), but not for "make <something>" where <something>
dependended on libsynthesis.

This commit adds such a rule. It is enough for initial builds, but not
complete yet because the outer make doesn't know the dependencies of
libsynthesis.la and thus won't trigger rebuilds. Add the complete file
list?
2011-12-19 17:59:42 +01:00
Patrick Ohly
6e18be3b8b GDBus: fixed invalid memory access
After removing a watch, destroying the glib source once more accessed
the now invalid "watch" pointer in finalize_watch(). Found in D-Bus
server mode after closing one connection.

The GSource was kept running and continued to use the freed
connection. Must use g_source_destroy() instead of g_source_unref() to
remove the source from the main loop in addition to decreasing its
ref count.

free_watch() is the right place to free WatchData, not
finalize_watch(), because the call sequence is free_watch() ->
g_source_destroy(source) -> finalize_watch().

Closing an unshared connection in free_connection() is too late,
because that is the destructor callback which is only called after
the last reference was already dropped. For the same reason the
dbus_connection_unref() there was wrong.

That code was never called in SyncEvolution because all connections
had their reference count increased one time to often when assigning
to DBusConnectionPtr. Fix will be committed separately. The problems
in this commit were found after fixing that problem and introducing
temporary connections in a D-Bus server, because then the faulty code
was called.
2011-12-19 17:59:42 +01:00