public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/hd-idle] epel10.2: feat: Add hd-idle-systemd-nodaemon patch which allow to writes logs into
@ 2026-06-06 22:58 Artem Polishchuk
  0 siblings, 0 replies; only message in thread
From: Artem Polishchuk @ 2026-06-06 22:58 UTC (permalink / raw)
  To: git-commits

          A new commit has been pushed.

          Repo   : rpms/hd-idle
          Branch : epel10.2
          Commit : fece9e82f3205a4bbba4ec728d3d1fc8a69d3cda
          Author : Artem Polishchuk <ego.cordatus@gmail.com>
          Date   : 2021-05-09T14:10:05+03:00
          Stats  : +153/-20 in 5 file(s)
          URL    : https://src.fedoraproject.org/rpms/hd-idle/c/fece9e82f3205a4bbba4ec728d3d1fc8a69d3cda?branch=epel10.2

          Log:
          feat: Add hd-idle-systemd-nodaemon patch which allow to writes logs into
journald instead of plain text file

---
diff --git a/hd-idle-systemd-nodaemon.diff b/hd-idle-systemd-nodaemon.diff
new file mode 100644
index 0000000..ad64584
--- /dev/null
+++ b/hd-idle-systemd-nodaemon.diff
@@ -0,0 +1,109 @@
+diff --git a/hd-idle.1 b/hd-idle.1
+index a77e863..f8828ee 100644
+--- a/hd-idle.1
++++ b/hd-idle.1
+@@ -68,6 +68,10 @@ Spin-down the specfified disk immediately and exit.
+ Debug mode. This will prevent hd-idle from becoming a daemon and print
+ debugging info to stdout/stderr
+ .TP
++.B \-n
++No-daemon mode. This will prevent hd-idle from becoming a daemon and print
++logging informatin to stdout. Most useful if hd-idle is started by systemd.
++.TP
+ .B \-h
+ Print usage information.
+ .SH "DISK SELECTION"
+diff --git a/hd-idle.c b/hd-idle.c
+index 82356f7..66abe48 100644
+--- a/hd-idle.c
++++ b/hd-idle.c
+@@ -125,6 +125,7 @@
+ #define DEFAULT_IDLE_TIME 600
+
+ #define dprintf if (debug) printf
++#define nprintf if (debug || nodaemon) printf
+
+ /* typedefs and structures */
+ typedef struct IDLE_TIME {
+@@ -159,6 +160,7 @@ IDLE_TIME *it_root;
+ DISKSTATS *ds_root;
+ char *logfile = "/dev/null";
+ int debug;
++int nodaemon = 0;
+
+ /* main function */
+ int main(int argc, char *argv[])
+@@ -180,7 +182,7 @@ int main(int argc, char *argv[])
+   it_root = it;
+
+   /* process command line options */
+-  while ((opt = getopt(argc, argv, "t:a:i:l:dh")) != -1) {
++  while ((opt = getopt(argc, argv, "t:a:i:l:dhn")) != -1) {
+     switch (opt) {
+
+     case 't':
+@@ -215,9 +217,15 @@ int main(int argc, char *argv[])
+       break;
+
+     case 'h':
+-      printf("usage: hd-idle [-t <disk>] [-a <name>] [-i <idle_time>] [-l <logfile>] [-d] [-h]\n");
++      printf("usage: hd-idle [-t <disk>] [-a <name>] [-i <idle_time>] [-l <logfile>] [-d] [-n] [-h]\n");
+       return(0);
+
++    case 'n':
++      nodaemon = 1;
++      /* unbuffered stdout, so it goes to systemd without delay */
++      setvbuf(stdout, NULL, _IOLBF, 0);
++      break;
++
+     case ':':
+       fprintf(stderr, "error: option -%c requires an argument\n", optopt);
+       return(1);
+@@ -228,19 +236,28 @@ int main(int argc, char *argv[])
+     }
+   }
+
++  if (nodaemon)
++    printf("hd-idle starting in nodaemon mode\n");
++
+   /* set sleep time to 1/10th of the shortest idle time */
+   min_idle_time = 1 << 30;
+   for (it = it_root; it != NULL; it = it->next) {
+     if (it->idle_time != 0 && it->idle_time < min_idle_time) {
+       min_idle_time = it->idle_time;
+     }
++    if (!nodaemon)
++      continue;
++    if (it->name)
++      printf("  disk: %s timeout: %d\n", it->name, it->idle_time);
++    else
++      printf("  default timeout: %d\n", it->idle_time);
+   }
+   if ((sleep_time = min_idle_time / 10) == 0) {
+     sleep_time = 1;
+   }
+
+   /* daemonize unless we're running in debug mode */
+-  if (!debug) {
++  if (!debug && !nodaemon) {
+     daemonize();
+   }
+
+@@ -317,6 +334,8 @@ int main(int argc, char *argv[])
+             if (have_logfile) {
+               log_spinup(ds);
+             }
++            if (nodaemon)
++              printf("spinup: %s\n", ds->name);
+             ds->spinup = now;
+           }
+           ds->reads = tmp.reads;
+@@ -393,7 +412,7 @@ static void spindown_disk(const char *name)
+   char dev_name[100];
+   int fd;
+
+-  dprintf("spindown: %s\n", name);
++  nprintf("spindown: %s\n", name);
+
+   /* fabricate SCSI IO request */
+   memset(&io_hdr, 0x00, sizeof(io_hdr));

diff --git a/hd-idle.default b/hd-idle.default
new file mode 100644
index 0000000..e9e3561
--- /dev/null
+++ b/hd-idle.default
@@ -0,0 +1,32 @@
+# hd-idle command line options
+# Options are:
+#  -a <name>               Set device name of disks for subsequent idle-time
+#                          parameters (-i). This parameter is optional in the
+#                          sense that there's a default entry for all disks
+#                          which are not named otherwise by using this
+#                          parameter. This can also be a symlink
+#                          (e.g. /dev/disk/by-uuid/...)
+#  -i <idle_time>          Idle time in seconds.
+#
+# Options not exactly useful here:
+#  -t <disk>               Spin-down the specfified disk immediately and exit.
+#  -d                      Debug mode. This will prevent hd-idle from
+#                          becoming a daemon and print debugging info to
+#                          stdout/stderr
+#  -n                      No daemon mode.
+#  -h                      Print usage information.
+#  -l <logfile>            Name of logfile (written only after a disk has spun
+#                          up). Please note that this option might cause the
+#                          disk which holds the logfile to spin up just because
+#                          another disk had some activity. This option should
+#                          not be used on systems with more than one disk
+#                          except for tuning purposes. On single-disk systems,
+#                          this option should not cause any additional spinups.
+#
+# spin down all disks after 180 seconds
+#HD_IDLE_OPTS="-i 180"
+#
+# only spin down /dev/sdb after 180 seconds
+#HD_IDLE_OPTS="-i 0 -a /dev/sdb -i 180"
+
+HD_IDLE_OPTS="-i 600"

diff --git a/hd-idle.logrotate b/hd-idle.logrotate
deleted file mode 100644
index a6efe14..0000000
--- a/hd-idle.logrotate
+++ /dev/null
@@ -1,6 +0,0 @@
-/var/log/hd-idle/*log {
-	missingok
-	notifempty
-	compress
-	delaycompress
-}

diff --git a/hd-idle.service b/hd-idle.service
index 1b252b4..af11952 100644
--- a/hd-idle.service
+++ b/hd-idle.service
@@ -3,9 +3,8 @@ Description=hd-idle - spin down idle hard disks
 Documentation=man:hd-idle(1)
 
 [Service]
-Type=forking
 EnvironmentFile=-/etc/sysconfig/hd-idle
-ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS
+ExecStart=/usr/sbin/hd-idle -n $HD_IDLE_OPTS
 
 [Install]
 WantedBy=multi-user.target

diff --git a/hd-idle.spec b/hd-idle.spec
index 0415ebf..73ba3a0 100644
--- a/hd-idle.spec
+++ b/hd-idle.spec
@@ -1,18 +1,19 @@
 Name:           hd-idle
 Version:        1.05
-Release:        12%{?dist}
+Release:        13%{?dist}
 Summary:        Spin down idle [USB] hard disks
 
 License:        GPLv2
 URL:            http://hd-idle.sourceforge.net
 Source0:        http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tgz
 Source1:        hd-idle.service
-Source2:        hd-idle.logrotate
+Source2:        %{name}.default
+
+Patch0:         %{name}-systemd-nodaemon.diff
 
 BuildRequires:  gcc
 BuildRequires:  systemd
 BuildRequires: make
-Requires:       logrotate
 %{?systemd_requires}
 
 %description
@@ -39,6 +40,7 @@ won't start again and you can as well pull the plug.
 
 %prep
 %setup -q -n %{name}
+%patch0 -p1
 sed -i 's/install -D -g root -o root/install -D/' Makefile
 
 
@@ -54,12 +56,7 @@ find "%{buildroot}%{_mandir}" -executable -type f -exec chmod -x {} \;
 
 install -d -m 755 %{buildroot}%{_unitdir}
 install -p -m 644 %{SOURCE1} %{buildroot}%{_unitdir}
-install -d %{buildroot}%{_sysconfdir}/sysconfig
-echo 'HD_IDLE_OPTS="-i 1200 -l /var/log/hd-idle/hd-idle.log"' > \
-     %{buildroot}%{_sysconfdir}/sysconfig/%{name}
-install -d -m 755 %{buildroot}%{_localstatedir}/log/%{name}
-install -d -m 755 %{buildroot}%{_sysconfdir}/logrotate.d
-install -p -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
+install -Dpm 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
 
 
 %post
@@ -76,15 +73,17 @@ install -p -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
 %{_sbindir}/*
 %{_mandir}/man1/%{name}.1*
 %{_unitdir}/*
-%config(noreplace) %{_sysconfdir}/logrotate.d/*
-%config(noreplace) %{_sysconfdir}/sysconfig/*
-%dir %{_localstatedir}/log/%{name}
+%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
 %license LICENSE
 %doc README
 
 
 
 %changelog
+* Sat May 08 2021 Artem Polishchuk <ego.cordatus@gmail.com> - 1.05-13
+- feat: Add hd-idle-systemd-nodaemon patch which allow to writes logs into
+  journald instead of plain text file
+
 * Tue Mar 02 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 1.05-12
 - Rebuilt for updated systemd-rpm-macros
   See https://pagure.io/fesco/issue/2583.

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-06 22:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-06 22:58 [rpms/hd-idle] epel10.2: feat: Add hd-idle-systemd-nodaemon patch which allow to writes logs into Artem Polishchuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox