aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rwxr-xr-xhostname-post5
-rw-r--r--s2u.c113
-rwxr-xr-xs2u.sh24
-rw-r--r--s2u.spec7
5 files changed, 38 insertions, 116 deletions
diff --git a/Makefile b/Makefile
index d3d7c56..2b94cf5 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ RELEASE:=$(shell rpm -q --qf %{RELEASE} --specfile $(PACKAGE).spec)
TAG := $(shell echo "V$(VERSION)_$(RELEASE)" | tr -- '-.' '__')
FILES = Makefile README hostname-post s2u.c s2u.sh s2u.spec \
- AUTHORS LICENSE README ChangeLog
+ AUTHORS LICENSE README ChangeLog s2u.conf
DEFS = -DDBUS_API_SUBJECT_TO_CHANGE=1
CC = gcc
@@ -41,6 +41,9 @@ install:
install s2u $(DESTDIR)/usr/bin
install -d $(DESTDIR)/etc/sysconfig/network-scripts/hostname.d
install hostname-post $(DESTDIR)/etc/sysconfig/network-scripts/hostname.d/s2u
+ install -d $(DESTDIR)/etc/dbus-1/system.d
+ install s2u.conf $(DESTDIR)/etc/dbus-1/system.d
+
# rules to build a test rpm
localrpm: localdist buildrpm
diff --git a/hostname-post b/hostname-post
index 5c432e6..6a15f51 100755
--- a/hostname-post
+++ b/hostname-post
@@ -10,9 +10,6 @@
# running X11 dbus session.
#---------------------------------------------------------------
-for f in `ls /tmp/dbus-*-xsession* 2> /dev/null`; do
- . $f
- dbus-send --type=method_call --dest=com.mandrakesoft.user.message /com/mandrakesoft/user com.mandrakesoft.user.message string:"Hostname: $1" &
-done
+dbus-send --type=signal --dest=com.mandrakesoft.user.message /com/mandrakesoft/user com.mandrakesoft.user.message string:"Hostname: $1"
# hostname-post ends here
diff --git a/s2u.c b/s2u.c
index cbae7bb..82a0f6c 100644
--- a/s2u.c
+++ b/s2u.c
@@ -64,8 +64,8 @@ static gchar *cookie = NULL;
static void
usage ()
{
- fprintf (stderr, "\n" "usage : s2u [--daemon=yes|no] [--help]\n");
- fprintf (stderr,
+ g_printerr ("\n" "usage : s2u [--daemon=yes|no] [--help]\n");
+ g_printerr (
"\n"
" --daemon=yes|no Become a daemon\n"
" --help Show this information and exit\n"
@@ -84,61 +84,10 @@ static char *opt_run_as = NULL;
static void
die (const char *message)
{
- fprintf (stderr, "*** %s", message);
+ g_printerr ("*** %s", message);
exit (1);
}
-static int
-drak_echo_message (DBusConnection * connection,
- DBusMessage * message)
-{
- DBusError error;
- DBusMessage *reply;
- char *s;
-
- dbus_error_init (&error);
-
- if (!dbus_message_get_args (message,
- &error,
- DBUS_TYPE_STRING, &s,
- DBUS_TYPE_INVALID))
- {
- reply = dbus_message_new_error (message,
- error.name,
- error.message);
-
- if (reply == NULL)
- die ("No memory\n");
-
- if (!dbus_connection_send (connection, reply, NULL))
- die ("No memory\n");
-
- dbus_message_unref (reply);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- die ("No memory\n");
-
- if (!dbus_message_append_args (reply,
- DBUS_TYPE_STRING, s,
- DBUS_TYPE_INVALID))
- die ("No memory");
-
- if (!dbus_connection_send (connection, reply, NULL))
- die ("No memory\n");
-
- fprintf (stderr, "Mandrakesoft_user_message: %s\n", s);
-
- dbus_free (s);
-
- dbus_message_unref (reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
/** Message handler for method invocations. All invocations on any object
* or interface is routed through this function.
*
@@ -147,10 +96,12 @@ drak_echo_message (DBusConnection * connection,
* @param user_data User data
* @return What to do with the message
*/
+
static DBusHandlerResult
filter_function (DBusConnection * connection,
DBusMessage * message, void *user_data)
{
+
/*
INFO (("obj_path=%s interface=%s method=%s",
dbus_message_get_path(message),
@@ -159,7 +110,7 @@ filter_function (DBusConnection * connection,
*/
/* message, interface, method */
- if (dbus_message_is_method_call (message,
+ if (dbus_message_is_signal (message,
"com.mandrakesoft.user",
"message") &&
strcmp (dbus_message_get_path (message),
@@ -177,55 +128,41 @@ filter_function (DBusConnection * connection,
args[2] = getenv("DISPLAY");
args[4] = cookie;
- printf("setting cookie to %s\n", cookie);
+ g_print("setting cookie to %s\n", cookie);
g_spawn_async("/", args, NULL, 0, NULL, NULL, NULL, NULL);
- return drak_echo_message (connection, message);
+ return DBUS_HANDLER_RESULT_HANDLED;
} else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-DBusConnection *
+static void
service_dbus_init (void)
{
- DBusError dbus_error;
-
- dbus_connection_set_change_sigpipe (TRUE);
+ GError *error = NULL;
- dbus_error_init (&dbus_error);
- dbus_connection = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error);
+ dbus_connection = dbus_g_connection_get_connection (dbus_g_bus_get (DBUS_BUS_SYSTEM, &error));
if (dbus_connection == NULL) {
- printf("dbus_bus_get(): %s", dbus_error.message);
+ g_printerr ("dbus_bus_get(): %s", error->message);
exit (1);
}
- dbus_connection_setup_with_g_main (dbus_connection, NULL);
-
- /* service, object, interface, member */
- dbus_message_new_method_call ("com.mandrakesoft.user.message", "/com/mandrakesoft/user",
- "com.mandrakesoft.user",
- "message");
-
- dbus_bus_acquire_service (dbus_connection, "com.mandrakesoft.user.message",
- 0, &dbus_error);
- if (dbus_error_is_set (&dbus_error)) {
- printf("dbus_bus_acquire_service(): %s",
- dbus_error.message);
- exit (1);
- }
+ dbus_bus_add_match (dbus_connection,
+ "type='signal',"
+ "interface='com.mandrakesoft.user'",
+ NULL);
+
dbus_connection_add_filter (dbus_connection, filter_function, NULL,
NULL);
- return dbus_connection;
}
int
main (int argc, char *argv[])
{
- DBusConnection *dbus_connection;
GMainLoop *loop;
gchar* args[] =
{
@@ -300,14 +237,14 @@ main (int argc, char *argv[])
int dev_null_fd;
if (chdir ("/") < 0) {
- printf("Could not chdir to /, errno=%d", errno);
+ g_printerr ("Could not chdir to /, errno=%d", errno);
return 1;
}
child_pid = fork ();
switch (child_pid) {
case -1:
- printf("Cannot fork(), errno=%d", errno);
+ g_printerr ("Cannot fork(), errno=%d", errno);
break;
case 0:
@@ -342,7 +279,7 @@ main (int argc, char *argv[])
if ((pw = getpwnam (opt_run_as)) == NULL) {
- printf("Could not lookup user %s, errno=%d",
+ g_printerr ("Could not lookup user %s, errno=%d",
opt_run_as, errno);
exit (1);
}
@@ -351,12 +288,12 @@ main (int argc, char *argv[])
gid = pw->pw_gid;
if (setgid (gid) < 0) {
- printf("Failed to set GID to %d, errno=%d", gid, errno);
+ g_printerr("Failed to set GID to %d, errno=%d", gid, errno);
exit (1);
}
if (setuid (uid) < 0) {
- printf("Failed to set UID to %d, errno=%d", uid, errno);
+ g_printerr ("Failed to set UID to %d, errno=%d", uid, errno);
exit (1);
}
@@ -364,11 +301,11 @@ main (int argc, char *argv[])
g_type_init ();
- /* set up the dbus services */
- dbus_connection = service_dbus_init ();
-
loop = g_main_loop_new (NULL, FALSE);
+ /* set up the dbus services */
+ service_dbus_init ();
+
/* run the main loop and serve clients */
g_main_loop_run (loop);
diff --git a/s2u.sh b/s2u.sh
index c0e08d7..3f48b1f 100755
--- a/s2u.sh
+++ b/s2u.sh
@@ -6,32 +6,12 @@
# Version : $Id$
# Author : Frederic Lepied
# Created On : Sat Jul 31 01:03:37 2004
-# Purpose : launch the dbus client attaching it to an
-# exisiting dbus session or launching a new one to
-# attache itself to.
+# Purpose : launch the dbus client attaching it to
+# system bus
#---------------------------------------------------------------
CURR_DISPLAY=`LC_ALL=C xdpyinfo | grep 'display' | awk '{print $4}'`
-f="/tmp/dbus-$USER-xsession$CURR_DISPLAY"
-
-vars() {
- if [ -f "$f" -a -O "$f" ]; then
- . "$f"
- fi
-}
-
-vars
-
-if [ -z "$DBUS_SESSION_BUS_PID" -o ! -d "/proc/$DBUS_SESSION_BUS_PID" ]; then
- F=`mktemp /tmp/dbus.XXXXXX`
- chmod 600 $F
- dbus-launch --sh-syntax --exit-with-session > $F
- rm -f "$f"
- mv -f $F "$f"
- vars
-fi
-
exec s2u --daemon=yes
# s2u.sh ends here
diff --git a/s2u.spec b/s2u.spec
index 33ec158..8b082a2 100644
--- a/s2u.spec
+++ b/s2u.spec
@@ -1,6 +1,6 @@
Summary: System to user tools
Name: s2u
-Version: 0.4
+Version: 0.5
Release: 1mdk
URL: http://www.mandrakelinux.com/
Source0: %{name}-%{version}.tar.bz2
@@ -33,10 +33,15 @@ rm -rf $RPM_BUILD_ROOT
%_bindir/s2u
%_sysconfdir/X11/xinit.d/s2u.sh
%_sysconfdir/sysconfig/network-scripts/hostname.d/s2u
+%config(noreplace) %_sysconfdir/dbus-1/system.d/*.conf
# MAKE THE CHANGES IN CVS: NO PATCH OR SOURCE ALLOWED
%changelog
+* Mon Mar 07 2005 Frederic Crozat <fcrozat@mandrakesoft.com> 0.5-1mdk
+- Release 0.5 :
+ no longer use session bus, use system bus instead (fix Mdk bug #13166)
+
* Mon Oct 18 2004 Gwenole Beauchesne <gbeauchesne@mandrakesoft.com> 0.4-1mdk
- lib64 fixes