diff --git a/configure.ac b/configure.ac index 0918fe146..f60a49640 100644 --- a/configure.ac +++ b/configure.ac @@ -176,6 +176,25 @@ AC_CHECK_HEADERS([sys/statvfs.h \ xfs/xfs.h]) +dnl ---------------------------------------------------------------------------- +dnl +dnl file monitoring for the daemon + +# Check whether to enable systemd startup notification. +# This requires libsystemd-daemon. +AC_ARG_WITH([systemd-daemon], AS_HELP_STRING([--with-systemd-daemon], + [Add support for systemd startup notification (default is autodetected)]) + [USE_SYSTEMD_DAEMON=$withval], [USE_SYSTEMD_DAEMON=auto]) +AS_IF([test "x$USE_SYSTEMD_DAEMON" != "xno"], [ + PKG_CHECK_MODULES([SYSTEMD_DAEMON], [libsystemd-daemon], + [AC_DEFINE(USE_SYSTEMD_DAEMON,1,[Use systemd startup notification])], + [AS_IF([test "x$USE_SYSTEMD_DAEMON" = "xyes"], + [AC_MSG_ERROR([systemd startup notification support requested, but libsystemd-daemon not found.])] + )] + ) +]) + + dnl ---------------------------------------------------------------------------- dnl dnl dht diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 6ecd9cde3..12ab13b16 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -4,6 +4,7 @@ AM_CFLAGS = \ @LIBEVENT_CFLAGS@ \ @OPENSSL_CFLAGS@ \ @LIBCURL_CFLAGS@ \ + @SYSTEMD_DAEMON_CFLAGS@ \ @ZLIB_CFLAGS@ \ @PTHREAD_CFLAGS@ @@ -28,6 +29,7 @@ LDADD = \ @LIBCURL_LIBS@ \ @OPENSSL_LIBS@ \ @INTLLIBS@ \ + @SYSTEMD_DAEMON_LIBS@ \ @ZLIB_LIBS@ \ @PTHREAD_LIBS@ diff --git a/daemon/daemon.c b/daemon/daemon.c index abdb50ca3..b278510b0 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -30,6 +30,13 @@ #include #include +#ifdef USE_SYSTEMD_DAEMON + #include +#else + static void sd_notify (int status UNUSED, const char * str UNUSED) { } + static void sd_notifyf (int status UNUSED, const char * fmt UNUSED, ...) { } +#endif + #include "watch.h" #define MY_NAME "transmission-daemon" @@ -508,6 +515,8 @@ main (int argc, char ** argv) exit (1); } + sd_notifyf (0, "MAINPID=%d\n", (int)getpid()); + /* start the session */ tr_formatter_mem_init (MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR); tr_formatter_size_init (DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR); @@ -573,12 +582,27 @@ main (int argc, char ** argv) openlog (MY_NAME, LOG_CONS|LOG_PID, LOG_DAEMON); #endif - while (!closing) { - tr_wait_msec (1000); /* sleep one second */ - dtr_watchdir_update (watchdir); - pumpLogMessages (logfile); - } + sd_notify( 0, "READY=1\n" ); + while (!closing) + { + double up; + double dn; + + tr_wait_msec (1000); /* sleep one second */ + + dtr_watchdir_update (watchdir); + pumpLogMessages (logfile); + + up = tr_sessionGetRawSpeed_KBps (mySession, TR_UP); + dn = tr_sessionGetRawSpeed_KBps (mySession, TR_DOWN); + if (up>0 || dn>0) + sd_notifyf (0, "STATUS=Uploading %.2f KBps, Downloading %.2f KBps.\n", up, dn); + else + sd_notify (0, "STATUS=Idle.\n"); + } + + sd_notify( 0, "STATUS=Closing transmission session...\n" ); printf ("Closing transmission session..."); tr_sessionSaveSettings (mySession, configDir, &settings); dtr_watchdir_free (watchdir); @@ -599,5 +623,6 @@ main (int argc, char ** argv) if (pidfile_created) tr_remove (pid_filename); tr_variantFree (&settings); + sd_notify (0, "STATUS=\n"); return 0; }