start-stop-daemon: sync with Debian

Hello,

you possibly want to integrate a change that can now be found on
Debian [master] with a very interesting change:

    start-stop-daemon: sync with Debian (CLOCK_MONOTONIC)..

    Using CLOCK_MONOTONIC instead of what was in use until today will
    ensure that running actions with configured time periods will run,
    and at correct times, even in the event of intermediate changes to
    the system clock.

--steffen

Author: Steffen Nurpmeso <sdaoden@users.sf.net>
Date:   2015-05-11 16:38:43 +0200

    start-stop-daemon: sync with Debian (CLOCK_MONOTONIC)..

    Using CLOCK_MONOTONIC instead of what was in use until today will
    ensure that running actions with configured time periods will run,
    and at correct times, even in the event of intermediate changes to
    the system clock.
This commit is contained in:
Steffen Nurpmeso 2015-05-11 16:51:34 +02:00 committed by Juergen Daubert
parent 0533b38e18
commit ef0b7dba60
4 changed files with 135 additions and 57 deletions

View File

@ -1,4 +1,4 @@
456389724ec3bdfcc0d28457eb0de459 crux-patch.diff
e3862e0d557d075a44b7b490eab16b63 crux-patch.diff
707efd334e4ba1d5f65f366a3c03c794 makefile
00a3895e85c98124737cf4354fbc9c84 start-stop-daemon.8
70b9c009a9b6c8e8507f1e6a9a64e230 start-stop-daemon.c
c021c418059b2afcb2f501927239beca start-stop-daemon.8
1e37b936e2981abd5dfdab08e5e4cc97 start-stop-daemon.c

View File

@ -1,5 +1,5 @@
diff --git a/start-stop-daemon/start-stop-daemon.8 b/start-stop-daemon/start-stop-daemon.8
index 9aad070..6d8275f 100644
index deae6c6..c17a3dd 100644
--- a/start-stop-daemon/start-stop-daemon.8
+++ b/start-stop-daemon/start-stop-daemon.8
@@ -20,7 +20,7 @@
@ -7,15 +7,15 @@ index 9aad070..6d8275f 100644
.\" along with this program. If not, see <https://www.gnu.org/licenses/>.
.
-.TH start\-stop\-daemon 8 "2014-03-26" "Debian Project" "dpkg utilities"
+.TH start\-stop\-daemon 8 "2015-02-25" "CRUX 3.1" "core services"
+.TH start\-stop\-daemon 8 "2015-05-11" "CRUX 3.1" "core services"
.SH NAME
start\-stop\-daemon \- start and stop system daemon programs
.
diff --git a/start-stop-daemon/start-stop-daemon.c b/start-stop-daemon/start-stop-daemon.c
index 6aebe9b..b3c1cb1 100644
index c35f448..eb5d4e6 100644
--- a/start-stop-daemon/start-stop-daemon.c
+++ b/start-stop-daemon/start-stop-daemon.c
@@ -20,10 +20,33 @@
@@ -20,10 +20,34 @@
* Changes by Ian Jackson: added --retry (and associated rearrangements).
*/
@ -25,7 +25,7 @@ index 6aebe9b..b3c1cb1 100644
#include <dpkg/macros.h>
+#else
+# define VERSION "20141020"
+# define VERSION "20140423"
+# define CRUX "CRUX 3.1"
+
+# define HAVE_SYS_PARAM_H
@ -36,6 +36,7 @@ index 6aebe9b..b3c1cb1 100644
+# define HAVE_ERROR_H
+# define HAVE_ERR_H
+
+# define HAVE_CLOCK_MONOTONIC
+# define HAVE_GETDTABLESIZE
+# define HAVE_IOPRIO_SET
+# define HAVE_SETSID
@ -49,7 +50,7 @@ index 6aebe9b..b3c1cb1 100644
#if defined(linux)
# define OSLinux
@@ -142,6 +165,10 @@
@@ -142,6 +166,10 @@
#define HAVE_IOPRIO_SET
#endif
@ -60,7 +61,17 @@ index 6aebe9b..b3c1cb1 100644
#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_PRIO_VALUE(class, prio) (((class) << IOPRIO_CLASS_SHIFT) | (prio))
#define IO_SCHED_PRIO_MIN 0
@@ -577,9 +604,9 @@ usage(void)
@@ -310,8 +338,7 @@ xstrdup(const char *str)
static void
timespec_gettime(struct timespec *ts)
{
-#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \
- defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
+#ifdef HAVE_CLOCK_MONOTONIC
if (clock_gettime(CLOCK_MONOTONIC, ts) < 0)
fatal("clock_gettime failed");
#else
@@ -615,9 +642,9 @@ usage(void)
static void
do_version(void)
{

View File

@ -5,7 +5,7 @@
.\" Copyright © 2000-2001 Wichert Akkerman <wakkerma@debian.org>
.\" Copyright © 2002-2003 Adam Heath <doogie@debian.org>
.\" Copyright © 2004 Scott James Remnant <keybuk@debian.org>
.\" Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
.\" Copyright © 2008-2015 Guillem Jover <guillem@debian.org>
.\"
.\" This is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
@ -94,7 +94,7 @@ will check that the process(es) have terminated.
.TP
.BR \-T ", " \-\-status
Check for the existence of a specified process, and returns an exit status
code, according to the LSB Init Script Actions.
code, according to the LSB Init Script Actions (since version 1.16.1).
.TP
.BR \-H ", " \-\-help
Show usage information and exit.
@ -106,11 +106,12 @@ Show the program version and exit.
.SS Matching options
.TP
.BR \-\-pid " \fIpid\fP"
Check for a process with the specified \fIpid\fP. The \fIpid\fP must be a
number greater than 0.
Check for a process with the specified \fIpid\fP (since version 1.17.6).
The \fIpid\fP must be a number greater than 0.
.TP
.BR \-\-ppid " \fIppid\fP"
Check for a process with the specified \fIppid\fP (parent pid).
Check for a process with the specified parent pid \fIppid\fP
(since version 1.17.7).
The \fIppid\fP must be a number greater than 0.
.TP
.BR \-p ", " \-\-pidfile " \fIpid-file\fP"
@ -217,7 +218,7 @@ Change to this username/uid before starting the process. You can also
specify a group by appending a
.BR : ,
then the group or gid in the same way
as you would for the `chown' command (\fIuser\fP\fB:\fP\fIgroup\fP).
as you would for the \fBchown\fP(1) command (\fIuser\fP\fB:\fP\fIgroup\fP).
If a user is specified without a group, the primary GID for that user is used.
When using this option
you must realize that the primary and supplemental groups are set as well,
@ -249,7 +250,7 @@ Typically used with programs that don't detach on their own. This option
will force
.B start\-stop\-daemon
to fork before starting the process, and force it into the background.
.B WARNING: start\-stop\-daemon
.B Warning: start\-stop\-daemon
cannot check the exit status if the process fails to execute for
.B any
reason. This is a last resort, and is only meant for programs that either
@ -257,7 +258,8 @@ make no sense forking on their own, or where it's not feasible to add the
code for them to do this themselves.
.TP
.BR \-C ", " \-\-no\-close
Do not close any file descriptor when forcing the daemon into the background.
Do not close any file descriptor when forcing the daemon into the background
(since version 1.16.5).
Used for debugging purposes to see the process output, or to redirect file
descriptors to log the process output.
Only relevant when using \fB\-\-background\fP.
@ -267,19 +269,21 @@ This alters the priority of the process before starting it.
.TP
.BR \-P ", " \-\-procsched " \fIpolicy\fP\fB:\fP\fIpriority\fP"
This alters the process scheduler policy and priority of the process before
starting it. The priority can be optionally specified by appending a \fB:\fP
starting it (since version 1.15.0).
The priority can be optionally specified by appending a \fB:\fP
followed by the value. The default \fIpriority\fP is 0. The currently
supported policy values are \fBother\fP, \fBfifo\fP and \fBrr\fP.
.TP
.BR \-I ", " \-\-iosched " \fIclass\fP\fB:\fP\fIpriority\fP"
This alters the IO scheduler class and priority of the process before starting
it. The priority can be optionally specified by appending a \fB:\fP followed
it (since version 1.15.0).
The priority can be optionally specified by appending a \fB:\fP followed
by the value. The default \fIpriority\fP is 4, unless \fIclass\fP is \fBidle\fP,
then \fIpriority\fP will always be 7. The currently supported values for
\fIclass\fP are \fBidle\fP, \fBbest-effort\fP and \fBreal-time\fP.
.TP
.BR \-k ", " \-\-umask " \fImask\fP"
This sets the umask of the process before starting it.
This sets the umask of the process before starting it (since version 1.13.22).
.TP
.BR \-m ", " \-\-make\-pidfile
Used when starting a program that does not create its own pid file. This
@ -290,7 +294,7 @@ create the file referenced with
and place the pid into it just before executing the process. Note, the
file will only be removed when stopping the program if
\fB\-\-remove\-pidfile\fP is used.
.B NOTE:
.B Note:
This feature may not work in all cases. Most notably when the program
being executed forks from its main process. Because of this, it is usually
only useful when combined with the
@ -298,8 +302,9 @@ only useful when combined with the
option.
.TP
.B \-\-remove\-pidfile
Used when stopping a program that does not remove its own pid file. This
option will make
Used when stopping a program that does not remove its own pid file
(since version 1.17.19).
This option will make
.B start\-stop\-daemon
remove the file referenced with
.B \-\-pidfile

View File

@ -67,11 +67,13 @@
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <fcntl.h>
#include <dirent.h>
#include <ctype.h>
@ -136,8 +138,6 @@
#define PROCESS_NAME_SIZE MAXCOMLEN
#endif
#define MIN_POLL_INTERVAL 20000 /* µs */
#if defined(SYS_ioprio_set) && defined(linux)
#define HAVE_IOPRIO_SET
#endif
@ -167,6 +167,16 @@ enum action_code {
ACTION_STATUS,
};
/* Time conversion constants. */
enum {
NANOSEC_IN_SEC = 1000000000L,
NANOSEC_IN_MILLISEC = 1000000L,
NANOSEC_IN_MICROSEC = 1000L,
};
/* The minimum polling interval, 20ms. */
static const long MIN_POLL_INTERVAL = 20 * NANOSEC_IN_MILLISEC;
static enum action_code action;
static bool testmode = false;
static int quietmode = 0;
@ -298,19 +308,47 @@ xstrdup(const char *str)
}
static void
xgettimeofday(struct timeval *tv)
timespec_gettime(struct timespec *ts)
{
if (gettimeofday(tv, NULL) != 0)
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \
defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
if (clock_gettime(CLOCK_MONOTONIC, ts) < 0)
fatal("clock_gettime failed");
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
fatal("gettimeofday failed");
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * NANOSEC_IN_MICROSEC;
#endif
}
#define timespec_cmp(a, b, OP) \
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_nsec OP (b)->tv_nsec) : \
((a)->tv_sec OP (b)->tv_sec))
static void
timespec_sub(struct timespec *a, struct timespec *b, struct timespec *res)
{
res->tv_sec = a->tv_sec - b->tv_sec;
res->tv_nsec = a->tv_nsec - b->tv_nsec;
if (res->tv_nsec < 0) {
res->tv_sec--;
res->tv_nsec += NANOSEC_IN_SEC;
}
}
static void
tmul(struct timeval *a, int b)
timespec_mul(struct timespec *a, int b)
{
long nsec = a->tv_nsec * b;
a->tv_sec *= b;
a->tv_usec *= b;
a->tv_sec = a->tv_sec + a->tv_usec / 1000000;
a->tv_usec %= 1000000;
a->tv_sec += nsec / NANOSEC_IN_SEC;
a->tv_nsec = nsec % NANOSEC_IN_SEC;
}
static char *
@ -1374,11 +1412,12 @@ pid_is_exec(pid_t pid, const struct stat *esb)
char buf[_POSIX2_LINE_MAX];
char **pid_argv_p;
char *start_argv_0_p, *end_argv_0_p;
bool res = false;
kd = ssd_kvm_open();
kp = ssd_kvm_get_procs(kd, KERN_PROC_PID, pid, NULL);
if (kp == NULL)
return false;
goto cleanup;
pid_argv_p = kvm_getargv(kd, kp, argv_len);
if (pid_argv_p == NULL)
@ -1403,9 +1442,14 @@ pid_is_exec(pid_t pid, const struct stat *esb)
}
if (stat(start_argv_0_p, &sb) != 0)
return false;
goto cleanup;
return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
res = (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
cleanup:
kvm_close(kd);
return res;
}
#endif
@ -1460,11 +1504,12 @@ pid_is_child(pid_t pid, pid_t ppid)
kvm_t *kd;
struct kinfo_proc *kp;
pid_t proc_ppid;
bool res = false;
kd = ssd_kvm_open();
kp = ssd_kvm_get_procs(kd, KERN_PROC_PID, pid, NULL);
if (kp == NULL)
return false;
goto cleanup;
#if defined(OSFreeBSD)
proc_ppid = kp->ki_ppid;
@ -1476,7 +1521,12 @@ pid_is_child(pid_t pid, pid_t ppid)
proc_ppid = kp->kp_proc.p_ppid;
#endif
return proc_ppid == ppid;
res = (proc_ppid == ppid);
cleanup:
kvm_close(kd);
return res;
}
#endif
@ -1518,11 +1568,12 @@ pid_is_user(pid_t pid, uid_t uid)
kvm_t *kd;
uid_t proc_uid;
struct kinfo_proc *kp;
bool res = false;
kd = ssd_kvm_open();
kp = ssd_kvm_get_procs(kd, KERN_PROC_PID, pid, NULL);
if (kp == NULL)
return false;
goto cleanup;
#if defined(OSFreeBSD)
proc_uid = kp->ki_ruid;
@ -1535,10 +1586,15 @@ pid_is_user(pid_t pid, uid_t uid)
kvm_read(kd, (u_long)&(kp->kp_proc.p_cred->p_ruid),
&proc_uid, sizeof(uid_t));
else
return false;
goto cleanup;
#endif
return (proc_uid == (uid_t)uid);
res = (proc_uid == (uid_t)uid);
cleanup:
kvm_close(kd);
return res;
}
#endif
@ -1602,11 +1658,12 @@ pid_is_cmd(pid_t pid, const char *name)
kvm_t *kd;
struct kinfo_proc *kp;
char *process_name;
bool res = false;
kd = ssd_kvm_open();
kp = ssd_kvm_get_procs(kd, KERN_PROC_PID, pid, NULL);
if (kp == NULL)
return false;
goto cleanup;
#if defined(OSFreeBSD)
process_name = kp->ki_comm;
@ -1618,7 +1675,12 @@ pid_is_cmd(pid_t pid, const char *name)
process_name = kp->kp_proc.p_comm;
#endif
return (strcmp(name, process_name) == 0);
res = (strcmp(name, process_name) == 0);
cleanup:
kvm_close(kd);
return res;
}
#endif
@ -2003,44 +2065,44 @@ set_what_stop(const char *str)
static bool
do_stop_timeout(int timeout, int *n_killed, int *n_notkilled)
{
struct timeval stopat, before, after, interval, maxinterval;
struct timespec stopat, before, after, interval, maxinterval;
int rc, ratio;
xgettimeofday(&stopat);
timespec_gettime(&stopat);
stopat.tv_sec += timeout;
ratio = 1;
for (;;) {
xgettimeofday(&before);
if (timercmp(&before, &stopat, >))
timespec_gettime(&before);
if (timespec_cmp(&before, &stopat, >))
return false;
do_stop(0, n_killed, n_notkilled);
if (!*n_killed)
return true;
xgettimeofday(&after);
timespec_gettime(&after);
if (!timercmp(&after, &stopat, <))
if (!timespec_cmp(&after, &stopat, <))
return false;
if (ratio < 10)
ratio++;
timersub(&stopat, &after, &maxinterval);
timersub(&after, &before, &interval);
tmul(&interval, ratio);
timespec_sub(&stopat, &after, &maxinterval);
timespec_sub(&after, &before, &interval);
timespec_mul(&interval, ratio);
if (interval.tv_sec < 0 || interval.tv_usec < 0)
interval.tv_sec = interval.tv_usec = 0;
if (interval.tv_sec < 0 || interval.tv_nsec < 0)
interval.tv_sec = interval.tv_nsec = 0;
if (timercmp(&interval, &maxinterval, >))
if (timespec_cmp(&interval, &maxinterval, >))
interval = maxinterval;
if (interval.tv_sec == 0 &&
interval.tv_usec <= MIN_POLL_INTERVAL)
interval.tv_usec = MIN_POLL_INTERVAL;
interval.tv_nsec <= MIN_POLL_INTERVAL)
interval.tv_nsec = MIN_POLL_INTERVAL;
rc = select(0, NULL, NULL, NULL, &interval);
rc = pselect(0, NULL, NULL, NULL, &interval, NULL);
if (rc < 0 && errno != EINTR)
fatal("select() failed for pause");
}