crux-musl

Unnamed repository; edit this file 'description' to name the repository.
git clone https://codeberg.org/emmett1/crux-musl
Log | Files | Refs | README | LICENSE

crux-patch.diff (7685B)


      1 diff --git a/start-stop-daemon.c b/start-stop-daemon.c
      2 index d16f0ed..1c3ff78 100644
      3 --- a/start-stop-daemon.c
      4 +++ b/start-stop-daemon.c
      5 @@ -20,10 +20,36 @@
      6   * Changes by Ian Jackson: added --retry (and associated rearrangements).
      7   */
      8  
      9 +#if 0
     10  #include <config.h>
     11  #include <compat.h>
     12  
     13  #include <dpkg/macros.h>
     14 +#else
     15 +# define VERSION "20221219"
     16 +# define CRUX "CRUX-Linux"
     17 +
     18 +# define WANT_SYSTEMD_NOTIFY 0 /* 1=yes */
     19 +
     20 +# define HAVE_SYS_PARAM_H
     21 +# define HAVE_SYS_SYSCALL_H
     22 +# define HAVE_SYS_USER_H
     23 +# define HAVE_STDDEF_H
     24 +# define HAVE_ERROR_H
     25 +# define HAVE_ERR_H
     26 +
     27 +# define HAVE_CLOCK_MONOTONIC
     28 +# define HAVE_GETDTABLESIZE
     29 +# define HAVE_IOPRIO_SET
     30 +# define HAVE_SETSID
     31 +
     32 +# define LIBCOMPAT_ATTR_NORET __attribute__((noreturn))
     33 +# define LIBCOMPAT_ATTR_PRINTF(X)
     34 +# define LIBCOMPAT_ATTR_VPRINTF(X)
     35 +
     36 +# define _GNU_SOURCE
     37 +# include <unistd.h>
     38 +#endif
     39  
     40  #if defined(__linux__)
     41  #  define OS_Linux
     42 @@ -135,6 +161,10 @@
     43  #define SCHED_RR -1
     44  #endif
     45  
     46 +#ifndef array_count
     47 +# define array_count(x) (sizeof(x) / sizeof((x)[0]))
     48 +#endif
     49 +
     50  #if defined(OS_Linux)
     51  /* This comes from TASK_COMM_LEN defined in Linux' include/linux/sched.h. */
     52  #define PROCESS_NAME_SIZE 15
     53 @@ -213,10 +243,12 @@ static int exitnodo = 1;
     54  static bool background = false;
     55  static bool close_io = true;
     56  static const char *output_io;
     57 +#if WANT_SYSTEMD_NOTIFY
     58  static bool notify_await = false;
     59  static int notify_timeout = 60;
     60  static char *notify_sockdir;
     61  static char *notify_socket;
     62 +#endif
     63  static bool mpidfile = false;
     64  static bool rpidfile = false;
     65  static int signal_nr = SIGTERM;
     66 @@ -406,8 +438,7 @@ xstrndup(const char *str, size_t n)
     67  static void
     68  timespec_gettime(struct timespec *ts)
     69  {
     70 -#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \
     71 -    defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
     72 +#ifdef HAVE_CLOCK_MONOTONIC
     73  	if (clock_gettime(CLOCK_MONOTONIC, ts) < 0)
     74  		fatale("clock_gettime failed");
     75  #else
     76 @@ -549,6 +580,7 @@ wait_for_child(pid_t pid)
     77  	}
     78  }
     79  
     80 +#if WANT_SYSTEMD_NOTIFY
     81  static void
     82  cleanup_socket_dir(void)
     83  {
     84 @@ -738,6 +770,7 @@ wait_for_notify(int fd)
     85  		}
     86  	}
     87  }
     88 +#endif /* WANT_SYSTEMD_NOTIFY */
     89  
     90  static void
     91  write_pidfile(const char *filename, pid_t pid)
     92 @@ -770,7 +803,9 @@ remove_pidfile(const char *filename)
     93  static void
     94  daemonize(void)
     95  {
     96 +#if WANT_SYSTEMD_NOTIFY
     97  	int notify_fd = -1;
     98 +#endif
     99  	pid_t pid;
    100  	sigset_t mask;
    101  	sigset_t oldmask;
    102 @@ -784,8 +819,10 @@ daemonize(void)
    103  	if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1)
    104  		fatale("cannot block SIGCHLD");
    105  
    106 +#if WANT_SYSTEMD_NOTIFY
    107  	if (notify_await)
    108  		notify_fd = create_notify_socket();
    109 +#endif
    110  
    111  	pid = fork();
    112  	if (pid < 0)
    113 @@ -796,6 +833,7 @@ daemonize(void)
    114  		 * not suffer from race conditions on return. */
    115  		wait_for_child(pid);
    116  
    117 +#if WANT_SYSTEMD_NOTIFY
    118  		if (notify_await) {
    119  			/* Wait for a readiness notification from the second
    120  			 * child, so that we can safely exit when the service
    121 @@ -804,13 +842,16 @@ daemonize(void)
    122  			close(notify_fd);
    123  			cleanup_socket_dir();
    124  		}
    125 +#endif
    126  
    127  		_exit(0);
    128  	}
    129  
    130  	/* Close the notification socket, even though it is close-on-exec. */
    131 +#if WANT_SYSTEMD_NOTIFY
    132  	if (notify_await)
    133  		close(notify_fd);
    134 +#endif
    135  
    136  	/* Create a new session. */
    137  	if (setsid() < 0)
    138 @@ -906,8 +947,10 @@ usage(void)
    139  "                                  scheduler (default prio is 4)\n"
    140  "  -k, --umask <mask>            change the umask to <mask> before starting\n"
    141  "  -b, --background              force the process to detach\n"
    142 +#if WANT_SYSTEMD_NOTIFY
    143  "      --notify-await            wait for a readiness notification\n"
    144  "      --notify-timeout <int>    timeout after <int> seconds of notify wait\n"
    145 +#endif
    146  "  -C, --no-close                do not close any file descriptor\n"
    147  "  -O, --output <filename>       send stdout and stderr to <filename>\n"
    148  "  -m, --make-pidfile            create the pidfile before starting\n"
    149 @@ -953,9 +996,9 @@ usage(void)
    150  static void
    151  do_version(void)
    152  {
    153 -	printf("start-stop-daemon %s for Debian\n\n", VERSION);
    154 -
    155 -	printf("Written by Marek Michalkiewicz, public domain.\n");
    156 +	printf("start-stop-daemon " VERSION " for " CRUX "\n\n"
    157 +		"Written by Marek Michalkiewicz, public domain.\n"
    158 +		"Adjusted for " CRUX ".\n");
    159  }
    160  
    161  static void DPKG_ATTR_NORET
    162 @@ -1280,8 +1323,10 @@ parse_options(int argc, char * const *argv)
    163  		{ "iosched",	  1, NULL, 'I'},
    164  		{ "umask",	  1, NULL, 'k'},
    165  		{ "background",	  0, NULL, 'b'},
    166 +#if WANT_SYSTEMD_NOTIFY
    167  		{ "notify-await", 0, NULL, OPT_NOTIFY_AWAIT},
    168  		{ "notify-timeout", 1, NULL, OPT_NOTIFY_TIMEOUT},
    169 +#endif
    170  		{ "no-close",	  0, NULL, 'C'},
    171  		{ "output",	  1, NULL, 'O'},
    172  		{ "make-pidfile", 0, NULL, 'm'},
    173 @@ -1297,7 +1342,9 @@ parse_options(int argc, char * const *argv)
    174  	const char *schedule_str = NULL;
    175  	const char *proc_schedule_str = NULL;
    176  	const char *io_schedule_str = NULL;
    177 +#if WANT_SYSTEMD_NOTIFY
    178  	const char *notify_timeout_str = NULL;
    179 +#endif
    180  	size_t changeuser_len;
    181  	int c;
    182  
    183 @@ -1398,12 +1445,14 @@ parse_options(int argc, char * const *argv)
    184  		case 'b':  /* --background */
    185  			background = true;
    186  			break;
    187 +#if WANT_SYSTEMD_NOTIFY
    188  		case OPT_NOTIFY_AWAIT:
    189  			notify_await = true;
    190  			break;
    191  		case OPT_NOTIFY_TIMEOUT:
    192  			notify_timeout_str = optarg;
    193  			break;
    194 +#endif
    195  		case 'C': /* --no-close */
    196  			close_io = false;
    197  			break;
    198 @@ -1462,9 +1511,11 @@ parse_options(int argc, char * const *argv)
    199  	if (output_io != NULL && output_io[0] != '/')
    200  		badusage("--output file needs to be an absolute filename");
    201  
    202 +#if WANT_SYSTEMD_NOTIFY
    203  	if (notify_timeout_str != NULL)
    204  		if (parse_unsigned(notify_timeout_str, 10, &notify_timeout) != 0)
    205  			badusage("invalid notify timeout value");
    206 +#endif
    207  
    208  	if (action == ACTION_NONE)
    209  		badusage("need one of --start or --stop or --status");
    210 @@ -2317,7 +2368,8 @@ do_pidfile(const char *name)
    211  
    212  			if (match_mode == MATCH_PIDFILE &&
    213  			    ((st.st_uid != getuid() && st.st_uid != 0) ||
    214 -			     (st.st_gid != getgid() && st.st_gid != 0)))
    215 +			     ((st.st_gid != getgid() && st.st_gid != 0) &&
    216 +			      (st.st_mode & 0020))))
    217  				fatal("matching only on non-root pidfile %s is insecure", name);
    218  			if (st.st_mode & 0002)
    219  				fatal("matching on world-writable pidfile %s is insecure", name);
    220 diff --git a/start-stop-daemon.pod b/start-stop-daemon.pod
    221 index 499e945..58cc083 100644
    222 --- a/start-stop-daemon.pod
    223 +++ b/start-stop-daemon.pod
    224 @@ -312,39 +312,6 @@ reason. This is a last resort, and is only meant for programs that either
    225  make no sense forking on their own, or where it's not feasible to add the
    226  code for them to do this themselves.
    227  
    228 -=item B<--notify-await>
    229 -
    230 -Wait for the background process to send a readiness notification before
    231 -considering the service started (since version 1.19.3).
    232 -This implements parts of the systemd readiness protocol, as specified
    233 -in the B<sd_notify>(3) man page.
    234 -The following variables are supported:
    235 -
    236 -=over
    237 -
    238 -=item B<READY=1>
    239 -
    240 -The program is ready to give service, so we can exit safely.
    241 -
    242 -=item B<EXTEND_TIMEOUT_USEC=>I<number>
    243 -
    244 -The program requests to extend the timeout by I<number> microseconds.
    245 -This will reset the current timeout to the specified value.
    246 -
    247 -=item B<ERRNO=>I<number>
    248 -
    249 -The program is exiting with an error.
    250 -Do the same and print the user-friendly string for the B<errno> value.
    251 -
    252 -=back
    253 -
    254 -=item B<--notify-timeout> I<timeout>
    255 -
    256 -Set a timeout for the B<--notify-await> option (since version 1.19.3).
    257 -When the timeout is reached, B<start-stop-daemon> will exit with an
    258 -error code, and no readiness notification will be awaited.
    259 -The default is B<60> seconds.
    260 -
    261  =item B<-C>, B<--no-close>
    262  
    263  Do not close any file descriptor when forcing the daemon into the background