diff options
author | Danny Kukawka <danny.kukawka@web.de> | 2010-08-23 14:47:41 +0200 |
---|---|---|
committer | Danny Kukawka <danny.kukawka@web.de> | 2010-08-23 14:47:41 +0200 |
commit | 6f1558bf77323d7649df0a4989000f484fbc9eb8 (patch) | |
tree | 91b708fb8131a39847df0c10cc1eda47d94fa963 | |
parent | ba8eac2971c99eb1c20d8beadd9c037b734d97b8 (diff) | |
parent | 7523710dde7479e6854e172b5810ffea84be58bf (diff) |
Merge branch 'master' of ssh://git.freedesktop.org/git/hal
-rwxr-xr-x | hald/haldaemon.in | 110 | ||||
-rw-r--r-- | tools/hal-storage-mount.c | 12 | ||||
-rw-r--r-- | tools/hal-storage-shared.c | 35 | ||||
-rw-r--r-- | tools/hal-storage-shared.h | 2 |
4 files changed, 118 insertions, 41 deletions
diff --git a/hald/haldaemon.in b/hald/haldaemon.in index 33ee31a5..34114c61 100755 --- a/hald/haldaemon.in +++ b/hald/haldaemon.in @@ -11,9 +11,6 @@ # pidfile: @HALD_PID_FILE@ # -# Sanity checks. -[ -x @sbindir@/hald ] || exit 1 - # Source function library. . @sysconfdir@/rc.d/init.d/functions @@ -23,52 +20,83 @@ servicename=haldaemon RETVAL=0 +# +# See how we were called. +# + +check() { + # Check that we're a privileged user + [ `id -u` = 0 ] || exit 4 + + # Check if hald is executable + test -x @sbindir@/hald || exit 5 +} + start() { - echo -n $"Starting HAL daemon: " - daemon --check $servicename $processname - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$servicename + + check + + # Check if it is already running + if [ ! -f @localstatedir@/lock/subsys/$servicename ]; then + echo -n $"Starting HAL daemon: " + daemon --check $servicename $processname + RETVAL=$? + [ $RETVAL -eq 0 ] && touch @localstatedir@/lock/subsys/$servicename + echo + fi + return $RETVAL } stop() { - echo -n $"Stopping HAL daemon: " - killproc $servicename -TERM - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - rm -f @localstatedir@/lock/subsys/$servicename - rm -f @HALD_PID_FILE@ - fi + check + + echo -n $"Stopping HAL daemon: " + killproc $servicename -TERM + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f @localstatedir@/lock/subsys/$servicename + echo + if [ $RETVAL -eq 0 ]; then + rm -f @localstatedir@/lock/subsys/$servicename + rm -f @HALD_PID_FILE@ + fi + return $RETVAL } -# See how we were called. case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status $processname - RETVAL=$? - ;; - restart) - stop +start) + start + ;; +stop) + stop + ;; +reload) + echo "$0: Unimplemented feature (hald does this automatically)." + RETVAL=3 + ;; +force-reload) + echo "$0: Unimplemented feature." + RETVAL=3 + ;; +status) + status -p @HALD_PID_FILE@ -l haldaemon $processname + RETVAL=$? + ;; +restart) + stop sleep 3 - start - ;; - condrestart) - if [ -f @localstatedir@/lock/subsys/$servicename ]; then - stop - sleep 3 - start - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - ;; + start + ;; +try-restart|condrestart) + if [ -f @localstatedir@/lock/subsys/$servicename ]; then + stop + sleep 3 + start + fi + ;; +*) + echo $"Usage: $0 {start|stop|status|restart|condrestart}" + RETVAL=2 esac + exit $RETVAL diff --git a/tools/hal-storage-mount.c b/tools/hal-storage-mount.c index 9471706c..3ecea02c 100644 --- a/tools/hal-storage-mount.c +++ b/tools/hal-storage-mount.c @@ -953,6 +953,16 @@ handle_mount (LibHalContext *hal_ctx, if (fwrite (hal_mtab_buf, 1, strlen (hal_mtab_buf), hal_mtab) != strlen (hal_mtab_buf)) { unknown_error ("Cannot write to /media/.hal-mtab~"); } + if (fflush (hal_mtab) < 0) { + unknown_error ("Cannot flush /media/.hal-mtab~"); + } + if (fsync (fileno (hal_mtab)) < 0) { + printf ("WARNING! syncing /media/.hal-mtab~ failed: %s\n", strerror (errno)); + } +#ifdef DEBUG + else + printf ("fsync /media/.hal-mtab~: success\n"); +#endif fclose (hal_mtab); g_free (hal_mtab_buf); #ifdef DEBUG @@ -1012,6 +1022,8 @@ handle_mount (LibHalContext *hal_ctx, #endif unknown_error ("Cannot rename /media/.hal-mtab~ to /media/.hal-mtab"); } + + fsync_dir("/media"); #ifdef DEBUG printf ("%d: XYA done renaming /media/.hal-mtab~ to /media/.hal-mtab\n", getpid ()); #endif diff --git a/tools/hal-storage-shared.c b/tools/hal-storage-shared.c index 422f00e7..e5373be2 100644 --- a/tools/hal-storage-shared.c +++ b/tools/hal-storage-shared.c @@ -47,6 +47,7 @@ #endif #include <sys/types.h> #include <unistd.h> +#include <dirent.h> #include <sys/file.h> #include <errno.h> #include <syslog.h> @@ -195,6 +196,28 @@ fstab_close (gpointer handle) #endif } +/* fsync() a directory */ +void +fsync_dir (char *path) +{ + DIR* d; + + d = opendir (path); + if (d == NULL) { + printf ("fsync_dir (%s): failed to opendir(): %s\n", path, strerror (errno)); + return; + } + + if (fsync (dirfd (d)) < 0) + printf ("fsync_dir (%s): failed to fsync(): %s\n", path, strerror (errno)); + + closedir (d); + +#ifdef DEBUG + printf ("fsync_dir (%s): success\n", path); +#endif +} + #ifdef __FreeBSD__ #define UMOUNT "/sbin/umount" #elif sun @@ -460,6 +483,17 @@ line_found: } } + if (fflush (hal_mtab_new) < 0) { + unknown_error ("Cannot flush /media/.hal-mtab~"); + } + if (fsync (fileno (hal_mtab_new)) < 0) { + printf ("WARNING! syncing /media/.hal-mtab~ failed: %s\n", strerror (errno)); + } +#ifdef DEBUG + else + printf ("fsync /media/.hal-mtab~: success\n"); +#endif + fclose (hal_mtab_new); g_strfreev (lines); @@ -521,6 +555,7 @@ line_found: unlink ("/media/.hal-mtab~"); unknown_error ("Cannot rename /media/.hal-mtab~ to /media/.hal-mtab"); } + fsync_dir("/media"); #ifdef DEBUG printf ("done unmounting\n"); diff --git a/tools/hal-storage-shared.h b/tools/hal-storage-shared.h index dcf7a0bc..fc7d63e9 100644 --- a/tools/hal-storage-shared.h +++ b/tools/hal-storage-shared.h @@ -41,6 +41,8 @@ void fstab_close (gpointer handle); gboolean lock_hal_mtab (void); void unlock_hal_mtab (void); +void fsync_dir (char *path); + void unknown_error (const char *detail); void bailout_if_drive_is_locked (LibHalContext *hal_ctx, LibHalDrive *drive, const char *invoked_by_syscon_name); |