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

Generated by cgit