summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2010-10-30 16:17:07 +0200
committerHans de Goede <hdegoede@redhat.com>2010-10-31 08:44:06 +0100
commit027959474724cc026b189598facbdc6b940c586e (patch)
treec74e7adc6a834a8b6707c9432a352b1e981765ca
parented5080ca4069fd99ebe71ba39bbdab2aeab58b03 (diff)
Switch to a sysv init script for starting spice-vdagentd
Starting from udev rules does not work well as we need /tmp and /var/log to be writable when spice-vdagentd *and* starting from udev gives selinux problems when trying to talk to console kit over dbus.
-rw-r--r--99-vdagent.rules2
-rw-r--r--Makefile6
-rw-r--r--spice-vdagentd.sh108
-rw-r--r--vdagentd.c10
4 files changed, 121 insertions, 5 deletions
diff --git a/99-vdagent.rules b/99-vdagent.rules
deleted file mode 100644
index 71b3604..0000000
--- a/99-vdagent.rules
+++ /dev/null
@@ -1,2 +0,0 @@
-KERNEL=="vport*", ATTR{name}=="com.redhat.spice.0" RUN+="/sbin/modprobe uinput"
-KERNEL=="vport*", ATTR{name}=="com.redhat.spice.0" RUN+="/sbin/spice-vdagentd"
diff --git a/Makefile b/Makefile
index 5a84cf6..afe6cb2 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VERSION = 0.6.3
DESTDIR ?=
sbindir ?= /sbin
bindir ?= /usr/bin
-udevdir ?= /lib/udev/rules.d
+initdir ?= /etc/rc.d/init.d
xdgautostartdir ?= /etc/xdg/autostart
gdmautostartdir ?= /usr/share/gdm/autostart/LoginWindow
@@ -21,8 +21,8 @@ install: build
install -d $(DESTDIR)$(sbindir)
install -p -m 755 spice-vdagent $(DESTDIR)$(bindir)
install -p -m 755 spice-vdagentd $(DESTDIR)$(sbindir)
- install -d $(DESTDIR)$(udevdir)
- install -p -m 644 *.rules $(DESTDIR)$(udevdir)
+ install -d $(DESTDIR)$(initdir)
+ install -p -m 755 spice-vdagentd.sh $(DESTDIR)$(initdir)/spice-vdagentd
install -d $(DESTDIR)$(xdgautostartdir)
install -d $(DESTDIR)$(gdmautostartdir)
desktop-file-install --dir=$(DESTDIR)$(xdgautostartdir) \
diff --git a/spice-vdagentd.sh b/spice-vdagentd.sh
new file mode 100644
index 0000000..e1ddcc4
--- /dev/null
+++ b/spice-vdagentd.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+#
+# spice-vdagentd Agent daemon for Spice guests
+#
+# chkconfig: 345 70 30
+# description: Together with a per X-session agent process the spice agent \
+# daemon enhances the spice guest user experience with client \
+# mouse mode, guest <-> client copy and paste support and more.
+
+### BEGIN INIT INFO
+# Provides: spice-vdagentd
+# Required-Start: $local_fs messagebus
+# Required-Stop: $local_fs messagebus
+# Should-Start: $local_fs messagebus
+# Should-Stop: $local_fs messagebus
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Agent daemon for Spice guests
+# Description: Together with a per X-session agent process the spice agent
+# daemon enhances the spice guest user experience with client
+# mouse mode, guest <-> client copy and paste support and more.
+### END INIT INFO
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+exec="/sbin/spice-vdagentd"
+prog="spice-vdagentd"
+port="/dev/virtio-ports/com.redhat.spice.0"
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+start() {
+ [ -x $exec ] || exit 5
+ [ -c $port ] || exit 6
+ echo -n $"Starting $prog: "
+ daemon $exec $SPICE_VDAGENTD_EXTRA_ARGS
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && touch $lockfile
+ return $retval
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc $prog
+ retval=$?
+ echo
+ [ $retval -eq 0 ] && rm -f $lockfile
+ return $retval
+}
+
+restart() {
+ stop
+ start
+}
+
+reload() {
+ restart
+}
+
+force_reload() {
+ restart
+}
+
+rh_status() {
+ # run checks to determine if the service is running or use generic status
+ status $prog
+}
+
+rh_status_q() {
+ rh_status >/dev/null 2>&1
+}
+
+
+case "$1" in
+ start)
+ rh_status_q && exit 0
+ $1
+ ;;
+ stop)
+ rh_status_q || exit 0
+ $1
+ ;;
+ restart)
+ $1
+ ;;
+ reload)
+ rh_status_q || exit 7
+ $1
+ ;;
+ force-reload)
+ force_reload
+ ;;
+ status)
+ rh_status
+ ;;
+ condrestart|try-restart)
+ rh_status_q || exit 0
+ restart
+ ;;
+ *)
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+ exit 2
+esac
+exit $?
diff --git a/vdagentd.c b/vdagentd.c
index 72801d1..bab21b6 100644
--- a/vdagentd.c
+++ b/vdagentd.c
@@ -46,6 +46,7 @@ struct agent_data {
/* variables */
static const char *logfilename = "/var/log/spice-vdagentd.log";
+static const char *pidfilename = "/var/run/spice-vdagentd.pid";
static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0";
static const char *uinput_device = "/dev/uinput";
static int debug = 0;
@@ -512,6 +513,7 @@ static void usage(FILE *fp)
void daemonize(void)
{
int x;
+ FILE *pidfile;
/* detach from terminal */
switch (fork()) {
@@ -519,6 +521,11 @@ void daemonize(void)
close(0); close(1); close(2);
setsid();
x = open("/dev/null", O_RDWR); x = dup(0); x = dup(0);
+ pidfile = fopen(pidfilename, "w");
+ if (pidfile) {
+ fprintf(pidfile, "%d\n", (int)getpid());
+ fclose(pidfile);
+ }
break;
case -1:
fprintf(logfile, "fork: %s\n", strerror(errno));
@@ -694,5 +701,8 @@ int main(int argc, char *argv[])
if (logfile != stderr)
fclose(logfile);
+ if (do_daemonize)
+ unlink(pidfilename);
+
return retval;
}