Compare commits

..

12 Commits

Author SHA1 Message Date
William Hubbs
f1e5510ccf version 0.50 2023-09-19 16:02:03 -05:00
William Hubbs
1b72c3a7ab update news 2023-09-19 15:59:31 -05:00
Natanael Copa
c4785f1b99 misc: add syscall fallback for close_range for musl libc
Add fallback for the close_range syscall wrapper. This is needed for
musl libc, which currently does not have a close_range wrapper.

Also set errno on errors.
2023-09-12 22:53:12 -05:00
Natanael Copa
e447562aaa start-stop-daemon: set fds to CLOEXEC instead of closing
Set file descriptors to CLOEXEC instead of closing them before exec,
similar to what we do in supervise-daemon.

Use the share cloexec_fds_from() helper for this.

closefrom() is no longer used so remove the test.
2023-09-12 22:53:12 -05:00
Natanael Copa
c199c5cf6e misc: add cloexec_fds_from() helper function
Move logic to set file descriptors to a cloexec_fds_from() function in
misc.c so it can be shared by both supervisor-daemon and
start-stop-daemon, and hide the details behind.
2023-09-12 22:53:12 -05:00
Natanael Copa
5bfb592d75 supervise-daemon: rename HAVE_CLOSE_RANGE_EXEC to HAVE_CLOSE_RANGE
Use HAVE_CLOSE_RANGE to tell if system provides a close_range(2)
wrapper, which better explains the purpose.

Add a compat inline which returns -1 if close_range is unavailable.
2023-09-12 22:53:12 -05:00
Timothy Kenno Handojo
b2c4eb97b5 remove /lib/rc/tmp creation from meson script
It is apparently for a piece of code that no longer exist.
There don't seem to be any part of the code referring to this directory (anymore, if there was).
2023-09-01 11:54:30 -05:00
William Hubbs
e740913fcb version 0.49 2023-08-31 14:13:19 -05:00
William Hubbs
1bc34a39cd update news 2023-08-31 14:12:26 -05:00
Sam James
c1cd3c9830 Don't re-define strlcpy/strlcat with >=glibc-2.38
`>=glibc-2.38` implements strlcpy, strlcat, etc so check for those functions
with Meson and don't provide conflicting prototypes.

Technically, it doesn't need _GNU_SOURCE, but it's easier because it's not
clear right now what glibc wants to guard it with. Note that these are in
POSIX next anyway.

Fixes: https://github.com/OpenRC/openrc/issues/643
Signed-off-by: Sam James <sam@gentoo.org>
2023-08-29 23:31:18 -04:00
Sven Wegener
86efc43d0e rc: fix automatic restart with runlevel-specific conf.d files
Commit fc4f15d6cd broke the automatic restart of
services having runlevel-specific conf.d files.

The double dirname() was not a mistake, but the way of getting from the
service script in init.d to the upper directory containing the conf.d
directory. dirname() modifies the argument in-place, so the second call
operated on a modified value. To make it more obvious what is going on,
have the second call operate on the returned value from the first call.

Fixes: fc4f15d ("openrc: fix double-assignment to dir")
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
2023-07-26 22:41:42 -05:00
Jernej Jakob
cd53239701 bash-completion/rc-service: don't set or unset extglob
It breaks bash-completion.
It's not necessary to set extglob as patterns in '[[' after '=='
are always matched as if extglob were set.

Closes: #636
Signed-off-by: Jernej Jakob <jernej.jakob@gmail.com>
2023-07-26 22:41:19 -05:00
11 changed files with 64 additions and 33 deletions

12
NEWS.md
View File

@ -4,6 +4,18 @@ OpenRC NEWS
This file will contain a list of notable changes for each release. Note This file will contain a list of notable changes for each release. Note
the information in this file is in reverse order. the information in this file is in reverse order.
## OpenRC 0.50
This is a bug fix release which fixes a significant performance issue on
musl libc systems.
## OpenRC 0.49
This release adds support for glibc's builtin
strlcpy, strlcat etc functions, which will be in posix next.
Also, it fixes completions.
## OpenRC 0.48 ## OpenRC 0.48
This release is a maintenance release; it has no user-facing changes. This release is a maintenance release; it has no user-facing changes.

View File

@ -92,13 +92,11 @@ _rc_service()
return 0 return 0
elif [[ ${COMP_CWORD} -eq 2 ]] && [[ ${prev} != -* ]]; then # if second word typed and we didn't type in a function elif [[ ${COMP_CWORD} -eq 2 ]] && [[ ${prev} != -* ]]; then # if second word typed and we didn't type in a function
rc-service --exists "$prev" || return rc-service --exists "$prev" || return
shopt -s extglob
while read -r _ line; do while read -r _ line; do
if [[ $line == +([[:alnum:]_]):* ]]; then if [[ $line == +([[:alnum:]_]):* ]]; then
opts+="${line%%:*} " opts+="${line%%:*} "
fi fi
done < <(rc-service "$prev" describe 2>&1) done < <(rc-service "$prev" describe 2>&1)
shopt -u extglob
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0 return 0
fi fi

View File

@ -1,5 +1,5 @@
project('OpenRC', 'c', project('OpenRC', 'c',
version : '0.48', version : '0.50',
license: 'BSD-2', license: 'BSD-2',
default_options : [ default_options : [
'c_std=c99', 'c_std=c99',
@ -195,12 +195,14 @@ if cc.compiles(malloc_attribute_test, name : 'malloc attribute with arguments')
add_project_arguments('-DHAVE_MALLOC_EXTENDED_ATTRIBUTE', language: 'c') add_project_arguments('-DHAVE_MALLOC_EXTENDED_ATTRIBUTE', language: 'c')
endif endif
if cc.has_function('closefrom', prefix: '#define _GNU_SOURCE\n#include <unistd.h>') if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include <unistd.h>')
add_project_arguments('-DHAVE_CLOSEFROM', language: 'c') add_project_arguments('-DHAVE_CLOSE_RANGE', language: 'c')
elif cc.has_header('linux/close_range.h')
add_project_arguments('-DHAVE_LINUX_CLOSE_RANGE_H', language: 'c')
endif endif
if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include <unistd.h>') and \
cc.has_header_symbol('unistd.h', 'CLOSE_RANGE_CLOEXEC', prefix: '#define _GNU_SOURCE') if cc.has_function('strlcpy', prefix: '#define _GNU_SOURCE\n#include <string.h>')
add_project_arguments('-DHAVE_CLOSE_RANGE_CLOEXEC', language: 'c') add_project_arguments('-DHAVE_STRLCPY', language: 'c')
endif endif
incdir = include_directories('src/shared') incdir = include_directories('src/shared')

View File

@ -146,9 +146,7 @@ static const char *const color_terms[] = {
}; };
#endif #endif
/* strlcat and strlcpy are nice, shame glibc does not define them */ #ifndef HAVE_STRLCPY
#ifdef __GLIBC__
# if !defined (__UCLIBC__) && !defined (__dietlibc__)
static size_t static size_t
strlcat(char *dst, const char *src, size_t size) strlcat(char *dst, const char *src, size_t size)
{ {
@ -176,7 +174,6 @@ strlcat(char *dst, const char *src, size_t size)
return dst_n + (s - src); return dst_n + (s - src);
} }
# endif
#endif #endif
static bool static bool

View File

@ -527,7 +527,7 @@ runlevel_config(const char *service, const char *level)
char *conf, *dir; char *conf, *dir;
bool retval; bool retval;
dir = dirname(init); dir = dirname(dirname(init));
xasprintf(&conf, "%s/conf.d/%s.%s", dir, service, level); xasprintf(&conf, "%s/conf.d/%s.%s", dir, service, level);
retval = exists(conf); retval = exists(conf);
free(conf); free(conf);

View File

@ -37,10 +37,8 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#ifdef __GLIBC__ #ifndef HAVE_STRLCPY
# if !defined (__UCLIBC__) && !defined (__dietlibc__)
# define strlcpy(dst, src, size) snprintf(dst, size, "%s", src) # define strlcpy(dst, src, size) snprintf(dst, size, "%s", src)
# endif
#endif #endif
#ifndef timespecsub #ifndef timespecsub

View File

@ -15,10 +15,18 @@
* except according to the terms contained in the LICENSE file. * except according to the terms contained in the LICENSE file.
*/ */
#ifdef HAVE_CLOSE_RANGE
/* For close_range() */
# define _GNU_SOURCE
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_LINUX_CLOSE_RANGE_H
# include <linux/close_range.h>
#endif
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,6 +34,7 @@
#include <sys/file.h> #include <sys/file.h>
#include <sys/time.h> #include <sys/time.h>
#ifdef __linux__ #ifdef __linux__
# include <sys/syscall.h> /* for close_range */
# include <sys/sysinfo.h> # include <sys/sysinfo.h>
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -500,3 +509,30 @@ pid_t get_pid(const char *applet,const char *pidfile)
return pid; return pid;
} }
#ifndef HAVE_CLOSE_RANGE
static inline int close_range(int first RC_UNUSED,
int last RC_UNUSED,
unsigned int flags RC_UNUSED)
{
#ifdef SYS_close_range
return syscall(SYS_close_range, first, last, flags);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif
#ifndef CLOSE_RANGE_CLOEXEC
# define CLOSE_RANGE_CLOEXEC (1U << 2)
#endif
void
cloexec_fds_from(int first)
{
int i;
if (close_range(first, UINT_MAX, CLOSE_RANGE_CLOEXEC) < 0) {
for (i = getdtablesize() - 1; i >= first; --i)
fcntl(i, F_SETFD, FD_CLOEXEC);
}
}

View File

@ -73,4 +73,6 @@ void from_time_t(char *time_string, time_t tv);
time_t to_time_t(char *timestring); time_t to_time_t(char *timestring);
pid_t get_pid(const char *applet, const char *pidfile); pid_t get_pid(const char *applet, const char *pidfile);
void cloexec_fds_from(int);
#endif #endif

View File

@ -1098,12 +1098,7 @@ int main(int argc, char **argv)
|| rc_yesno(getenv("EINFO_QUIET"))) || rc_yesno(getenv("EINFO_QUIET")))
dup2(stderr_fd, STDERR_FILENO); dup2(stderr_fd, STDERR_FILENO);
#ifdef HAVE_CLOSEFROM cloexec_fds_from(3);
closefrom(3);
#else
for (i = getdtablesize() - 1; i >= 3; --i)
close(i);
#endif
if (scheduler != NULL) { if (scheduler != NULL) {
int scheduler_index; int scheduler_index;

View File

@ -22,11 +22,6 @@
#define ONE_SECOND 1000000000 #define ONE_SECOND 1000000000
#define ONE_MS 1000000 #define ONE_MS 1000000
#ifdef HAVE_CLOSE_RANGE_CLOEXEC
/* For close_range() */
# define _GNU_SOURCE
#endif
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
@ -570,11 +565,8 @@ RC_NORETURN static void child_process(char *exec, char **argv)
if (redirect_stderr || rc_yesno(getenv("EINFO_QUIET"))) if (redirect_stderr || rc_yesno(getenv("EINFO_QUIET")))
dup2(stderr_fd, STDERR_FILENO); dup2(stderr_fd, STDERR_FILENO);
#ifdef HAVE_CLOSE_RANGE_CLOEXEC cloexec_fds_from(3);
if (close_range(3, UINT_MAX, CLOSE_RANGE_CLOEXEC) < 0)
#endif
for (i = getdtablesize() - 1; i >= 3; --i)
fcntl(i, F_SETFD, FD_CLOEXEC);
cmdline = make_cmdline(argv); cmdline = make_cmdline(argv);
syslog(LOG_INFO, "Child command line: %s", cmdline); syslog(LOG_INFO, "Child command line: %s", cmdline);
free(cmdline); free(cmdline);

View File

@ -11,7 +11,6 @@ sysvinit="$4"
if [ "${os}" != Linux ]; then if [ "${os}" != Linux ]; then
install -d "${DESTDIR}/${rc_libexecdir}"/init.d install -d "${DESTDIR}/${rc_libexecdir}"/init.d
fi fi
install -d "${DESTDIR}/${rc_libexecdir}"/tmp
install -m 644 "${MESON_BUILD_ROOT}/src/shared/version" "${DESTDIR}/${rc_libexecdir}" install -m 644 "${MESON_BUILD_ROOT}/src/shared/version" "${DESTDIR}/${rc_libexecdir}"
if [ "${os}" = Linux ] && [ "${sysvinit}" = yes ]; then if [ "${os}" = Linux ] && [ "${sysvinit}" = yes ]; then
ln -s openrc-init "${DESTDIR}/${sbindir}"/init ln -s openrc-init "${DESTDIR}/${sbindir}"/init