summaryrefslogtreecommitdiff
path: root/start-stop-daemon/crux-patch.diff
blob: a6bc4293a4625246aa06d5bad015085900d668b6 (plain)
    1 --- start-stop-daemon.8.orig	2020-08-11 09:18:30.855173650 +0000
    2 +++ start-stop-daemon.8	2020-08-11 09:18:59.687682548 +0000
    3 @@ -20,7 +20,7 @@
    4  .\" You should have received a copy of the GNU General Public License
    5  .\" along with this program.  If not, see <https://www.gnu.org/licenses/>.
    6  .
    7 -.TH start\-stop\-daemon 8 "%RELEASE_DATE%" "%VERSION%" "dpkg suite"
    8 +.TH start\-stop\-daemon 8 "2019-03-10" "CRUX 3.5" "dpkg suite"
    9  .nh
   10  .SH NAME
   11  start\-stop\-daemon \- start and stop system daemon programs
   12 @@ -269,33 +269,6 @@
   13  make no sense forking on their own, or where it's not feasible to add the
   14  code for them to do this themselves.
   15  .TP
   16 -.BR \-\-notify\-await
   17 -Wait for the background process to send a readiness notification before
   18 -considering the service started (since version 1.19.3).
   19 -This implements parts of the systemd readiness procotol, as specified
   20 -in the \fBsd_notify\fP(3) man page.
   21 -The following variables are supported:
   22 -.RS
   23 -.TP
   24 -.B READY=1
   25 -The program is ready to give service, so we can exit safely.
   26 -.TP
   27 -.BI EXTEND_TIMEOUT_USEC= number
   28 -The program requests to extend the timeout by \fInumber\fP microseconds.
   29 -This will reset the current timeout to the specified value.
   30 -.TP
   31 -.BI ERRNO= number
   32 -The program is exiting with an error.
   33 -Do the same and print the user-friendly string for the \fBerrno\fP value.
   34 -.RE
   35 -.
   36 -.TP
   37 -.BI \-\-notify\-timeout timeout
   38 -Set a timeout for the \fB\-\-notify\-await\fP option (since version 1.19.3).
   39 -When the timeout is reached, \fBstart\-stop\-daemon\fP will exit with an
   40 -error code, and no readiness notification will be awaited.
   41 -The default is \fB60\fP seconds.
   42 -.TP
   43  .BR \-C ", " \-\-no\-close
   44  Do not close any file descriptor when forcing the daemon into the background
   45  (since version 1.16.5).
   46 --- start-stop-daemon.c.orig	2020-08-11 09:18:38.031635113 +0000
   47 +++ start-stop-daemon.c	2020-08-11 09:20:15.932117049 +0000
   48 @@ -20,10 +20,36 @@
   49   * Changes by Ian Jackson: added --retry (and associated rearrangements).
   50   */
   51  
   52 +#if 0
   53  #include <config.h>
   54  #include <compat.h>
   55  
   56  #include <dpkg/macros.h>
   57 +#else
   58 +# define VERSION 		"20190310"
   59 +# define CRUX 			"CRUX-Linux"
   60 +
   61 +# define WANT_SYSTEMD_NOTIFY	0 /* 1=yes */
   62 +
   63 +# define HAVE_SYS_PARAM_H
   64 +# define HAVE_SYS_SYSCALL_H
   65 +# define HAVE_SYS_USER_H
   66 +# define HAVE_STDDEF_H
   67 +# define HAVE_ERROR_H
   68 +# define HAVE_ERR_H
   69 +
   70 +# define HAVE_CLOCK_MONOTONIC
   71 +# define HAVE_GETDTABLESIZE
   72 +# define HAVE_IOPRIO_SET
   73 +# define HAVE_SETSID
   74 +
   75 +# define DPKG_ATTR_NORET	__attribute__((noreturn))
   76 +# define DPKG_ATTR_PRINTF(X)
   77 +# define DPKG_ATTR_VPRINTF(X)
   78 +
   79 +# define _GNU_SOURCE
   80 +# include <unistd.h>
   81 +#endif
   82  
   83  #if defined(__linux__)
   84  #  define OS_Linux
   85 @@ -160,6 +186,10 @@
   86  #define HAVE_IOPRIO_SET
   87  #endif
   88  
   89 +#ifndef array_count
   90 +# define array_count(x) 	(sizeof(x) / sizeof((x)[0]))
   91 +#endif
   92 +
   93  #define IOPRIO_CLASS_SHIFT 13
   94  #define IOPRIO_PRIO_VALUE(class, prio) (((class) << IOPRIO_CLASS_SHIFT) | (prio))
   95  #define IO_SCHED_PRIO_MIN 0
   96 @@ -212,10 +242,12 @@
   97  static int exitnodo = 1;
   98  static bool background = false;
   99  static bool close_io = true;
  100 +#if WANT_SYSTEMD_NOTIFY
  101  static bool notify_await = false;
  102  static int notify_timeout = 60;
  103  static char *notify_sockdir;
  104  static char *notify_socket;
  105 +#endif
  106  static bool mpidfile = false;
  107  static bool rpidfile = false;
  108  static int signal_nr = SIGTERM;
  109 @@ -405,8 +437,7 @@
  110  static void
  111  timespec_gettime(struct timespec *ts)
  112  {
  113 -#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \
  114 -    defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
  115 +#ifdef HAVE_CLOCK_MONOTONIC
  116  	if (clock_gettime(CLOCK_MONOTONIC, ts) < 0)
  117  		fatale("clock_gettime failed");
  118  #else
  119 @@ -548,6 +579,7 @@
  120  	}
  121  }
  122  
  123 +#if WANT_SYSTEMD_NOTIFY
  124  static void
  125  cleanup_socket_dir(void)
  126  {
  127 @@ -737,6 +769,7 @@
  128  		}
  129  	}
  130  }
  131 +#endif /* WANT_SYSTEMD_NOTIFY */
  132  
  133  static void
  134  write_pidfile(const char *filename, pid_t pid)
  135 @@ -769,7 +802,9 @@
  136  static void
  137  daemonize(void)
  138  {
  139 +#if WANT_SYSTEMD_NOTIFY
  140  	int notify_fd = -1;
  141 +#endif
  142  	pid_t pid;
  143  	sigset_t mask;
  144  	sigset_t oldmask;
  145 @@ -783,8 +818,10 @@
  146  	if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1)
  147  		fatale("cannot block SIGCHLD");
  148  
  149 +#if WANT_SYSTEMD_NOTIFY
  150  	if (notify_await)
  151  		notify_fd = create_notify_socket();
  152 +#endif
  153  
  154  	pid = fork();
  155  	if (pid < 0)
  156 @@ -795,6 +832,7 @@
  157  		 * not suffer from race conditions on return. */
  158  		wait_for_child(pid);
  159  
  160 +#if WANT_SYSTEMD_NOTIFY
  161  		if (notify_await) {
  162  			/* Wait for a readiness notification from the second
  163  			 * child, so that we can safely exit when the service
  164 @@ -803,6 +841,7 @@
  165  			close(notify_fd);
  166  			cleanup_socket_dir();
  167  		}
  168 +#endif
  169  
  170  		_exit(0);
  171  	}
  172 @@ -901,8 +940,10 @@
  173  "                                  scheduler (default prio is 4)\n"
  174  "  -k, --umask <mask>            change the umask to <mask> before starting\n"
  175  "  -b, --background              force the process to detach\n"
  176 +#if WANT_SYSTEMD_NOTIFY
  177  "      --notify-await            wait for a readiness notification\n"
  178  "      --notify-timeout <int>    timeout after <int> seconds of notify wait\n"
  179 +#endif
  180  "  -C, --no-close                do not close any file descriptor\n"
  181  "  -m, --make-pidfile            create the pidfile before starting\n"
  182  "      --remove-pidfile          delete the pidfile after stopping\n"
  183 @@ -947,9 +988,9 @@
  184  static void
  185  do_version(void)
  186  {
  187 -	printf("start-stop-daemon %s for Debian\n\n", VERSION);
  188 -
  189 -	printf("Written by Marek Michalkiewicz, public domain.\n");
  190 +	printf("start-stop-daemon " VERSION " for " CRUX "\n\n"
  191 +		"Written by Marek Michalkiewicz, public domain.\n"
  192 +		"Adjusted for " CRUX ".\n");
  193  }
  194  
  195  static void DPKG_ATTR_NORET
  196 @@ -1274,8 +1315,10 @@
  197  		{ "iosched",	  1, NULL, 'I'},
  198  		{ "umask",	  1, NULL, 'k'},
  199  		{ "background",	  0, NULL, 'b'},
  200 +#if WANT_SYSTEMD_NOTIFY
  201  		{ "notify-await", 0, NULL, OPT_NOTIFY_AWAIT},
  202  		{ "notify-timeout", 1, NULL, OPT_NOTIFY_TIMEOUT},
  203 +#endif
  204  		{ "no-close",	  0, NULL, 'C'},
  205  		{ "make-pidfile", 0, NULL, 'm'},
  206  		{ "remove-pidfile", 0, NULL, OPT_RM_PIDFILE},
  207 @@ -1290,7 +1333,9 @@
  208  	const char *schedule_str = NULL;
  209  	const char *proc_schedule_str = NULL;
  210  	const char *io_schedule_str = NULL;
  211 +#if WANT_SYSTEMD_NOTIFY
  212  	const char *notify_timeout_str = NULL;
  213 +#endif
  214  	size_t changeuser_len;
  215  	int c;
  216  
  217 @@ -1390,12 +1435,14 @@
  218  		case 'b':  /* --background */
  219  			background = true;
  220  			break;
  221 +#if WANT_SYSTEMD_NOTIFY
  222  		case OPT_NOTIFY_AWAIT:
  223  			notify_await = true;
  224  			break;
  225  		case OPT_NOTIFY_TIMEOUT:
  226  			notify_timeout_str = optarg;
  227  			break;
  228 +#endif
  229  		case 'C': /* --no-close */
  230  			close_io = false;
  231  			break;
  232 @@ -1448,9 +1495,11 @@
  233  			badusage("umask value must be a positive number");
  234  	}
  235  
  236 +#if WANT_SYSTEMD_NOTIFY
  237  	if (notify_timeout_str != NULL)
  238  		if (parse_unsigned(notify_timeout_str, 10, &notify_timeout) != 0)
  239  			badusage("invalid notify timeout value");
  240 +#endif
  241  
  242  	if (action == ACTION_NONE)
  243  		badusage("need one of --start or --stop or --status");
  244 @@ -2298,7 +2347,8 @@
  245  
  246  			if (match_mode == MATCH_PIDFILE &&
  247  			    ((st.st_uid != getuid() && st.st_uid != 0) ||
  248 -			     (st.st_gid != getgid() && st.st_gid != 0)))
  249 +			     ((st.st_gid != getgid() && st.st_gid != 0) &&
  250 +			      (st.st_mode & 0020))))
  251  				fatal("matching only on non-root pidfile %s is insecure", name);
  252  			if (st.st_mode & 0002)
  253  				fatal("matching on world-writable pidfile %s is insecure", name);

Generated by cgit