Skip to content

Commit 66dff2c

Browse files
committed
Merge branch 'github-pull-47' into for-master
These patches help build make-initrd on musl-based systems (tested on Gentoo). However, support is not yet complete because musl's `ldconfig` does not support the `-p` argument: ``` $ ldconfig -p Unimplemented option: -p ``` As a result, all code that relies on `ldconfig -p` (and likely `ldconfig -vNX` too) is currently broken. This PR contains the first commit from the #46 as both patchsets modify the same areas of the code, even though they are not directly related. Signed-off-by: Alexey Gladkov <[email protected]>
2 parents 861f9c1 + a24eae4 commit 66dff2c

File tree

15 files changed

+81
-12
lines changed

15 files changed

+81
-12
lines changed

Makefile.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ dest_data_sbindir := $(dest_runtimedir)/sbin
5757
dest_data_libdir := $(dest_runtimedir)/$(libcdir)
5858
dest_featuredir := $(dest_execdir)/$(FEATURESDIR)
5959

60+
fts_LIBS := @fts_LIBS@
61+
6062
HAVE_GZIP := @HAVE_GZIP@
6163
HAVE_GZIP_LIBS := @HAVE_GZIP_LIBS@
6264
HAVE_GZIP_CFLAGS := @HAVE_GZIP_CFLAGS@
@@ -132,7 +134,7 @@ CFLAGS = @CFLAGS@ \
132134
-Wno-pointer-arith \
133135
-Werror=shadow -Werror=missing-prototypes -Werror=implicit-function-declaration
134136

135-
CPPFLAGS += @CPPFLAGS@ @DEFS@ -I$(CURDIR)
137+
CPPFLAGS += @CPPFLAGS@ @DEFS@ -I$(CURDIR) -I$(CURDIR)/include
136138

137139
UDEVD = @UDEVD@
138140
UDEVADM = @UDEVADM@

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ AC_CHECK_FUNCS([ \
6060
strpbrk strrchr strstr strtol strtoul strtoull uname \
6161
twalk_r tdestroy updwtmp])
6262

63+
saved_LIBS="$LIBS"
64+
AC_SEARCH_LIBS([fts_close], [fts])
65+
LIBS="$saved_LIBS"
66+
case "$ac_cv_search_fts_close" in
67+
no) AC_MSG_FAILURE([failed to find fts_close]) ;;
68+
-l*) fts_LIBS="$ac_cv_search_fts_close" ;;
69+
*) fts_LIBS= ;;
70+
esac
71+
AC_SUBST([fts_LIBS])
72+
6373
AC_MSG_CHECKING([if in-tree build is required])
6474
AC_ARG_ENABLE(local-build,
6575
[AS_HELP_STRING(--enable-local-build,

include/temp_failure_retry.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
// Copyright (C) 1991-2025 Free Software Foundation, Inc.
3+
4+
#ifndef _TEMP_FAILURE_RETRY_H
5+
# define _TEMP_FAILURE_RETRY_H 1
6+
7+
# include <unistd.h>
8+
9+
# ifndef TEMP_FAILURE_RETRY
10+
/* This implementation of TEMP_FAILURE_RETRY is taken from the glibc code. */
11+
# define TEMP_FAILURE_RETRY(expression) \
12+
(__extension__ \
13+
({ long int __result; \
14+
do __result = (long int) (expression); \
15+
while (__result == -1L && errno == EINTR); \
16+
__result; }))
17+
18+
# endif
19+
#endif

runtime/src/libinitramfs/logging.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <errno.h>
1111
#include <time.h>
1212

13+
#include "temp_failure_retry.h"
1314
#include "rd/logging.h"
1415

1516
int log_priority = LOG_INFO;

runtime/src/nfsmount/mount.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ int nfs_mount(const char *pathname, const char *hostname,
305305
goto bail;
306306
}
307307

308-
if (bindresvport(sock, 0) == -1) {
309-
perror("bindresvport");
308+
if (bindanyprivport(sock) == -1) {
309+
perror("bindanyprivport");
310310
goto bail;
311311
}
312312

runtime/src/nfsmount/sunrpc.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sys/types.h>
44
#include <sys/socket.h>
55
#include <netinet/in.h>
6+
#include <errno.h>
67
#include <poll.h>
78
#include <unistd.h>
89
#include <stdio.h>
@@ -141,6 +142,29 @@ static int rpc_call_udp(struct client *clnt, struct rpc *rpc)
141142
return (int) ret;
142143
}
143144

145+
int bindanyprivport(int sd)
146+
{
147+
struct sockaddr_in addr;
148+
memset(&addr, 0, sizeof(addr));
149+
addr.sin_family = AF_INET;
150+
151+
#define LOWPORT 512
152+
#define ENDPORT (IPPORT_RESERVED - 1)
153+
154+
for (short port = LOWPORT; port <= ENDPORT; ++port) {
155+
addr.sin_port = htons(port);
156+
if (bind(sd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
157+
return 0;
158+
}
159+
160+
if (errno != EADDRINUSE) {
161+
return -1;
162+
}
163+
}
164+
165+
return -1;
166+
}
167+
144168
struct client *tcp_client(uint32_t server, uint16_t port, uint32_t flags)
145169
{
146170
struct client *clnt = malloc(sizeof(*clnt));
@@ -159,8 +183,8 @@ struct client *tcp_client(uint32_t server, uint16_t port, uint32_t flags)
159183
goto bail;
160184
}
161185

162-
if ((flags & CLI_RESVPORT) && bindresvport(sock, 0) == -1) {
163-
perror("bindresvport");
186+
if ((flags & CLI_RESVPORT) && bindanyprivport(sock) == -1) {
187+
perror("bindanyprivport");
164188
goto bail;
165189
}
166190

@@ -204,8 +228,8 @@ struct client *udp_client(uint32_t server, uint16_t port, uint32_t flags)
204228
goto bail;
205229
}
206230

207-
if ((flags & CLI_RESVPORT) && bindresvport(sock, 0) == -1) {
208-
perror("bindresvport");
231+
if ((flags & CLI_RESVPORT) && bindanyprivport(sock) == -1) {
232+
perror("bindanyprivport");
209233
goto bail;
210234
} else {
211235
struct sockaddr_in me;

runtime/src/nfsmount/sunrpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct client {
9999

100100
#define CLI_RESVPORT 00000001
101101

102+
int bindanyprivport(int sd);
102103
struct client *tcp_client(uint32_t server, uint16_t port, uint32_t flags);
103104
struct client *udp_client(uint32_t server, uint16_t port, uint32_t flags);
104105
void client_free(struct client *client);

runtime/src/ueventd/path.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <fcntl.h>
88
#include <errno.h>
99

10+
#include "temp_failure_retry.h"
1011
#include "rd/logging.h"
1112
#include "ueventd.h"
1213

runtime/src/ueventd/process.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <unistd.h>
1313
#include <errno.h>
1414

15+
#include "temp_failure_retry.h"
1516
#include "ueventd.h"
1617

1718
pid_t waitpid_retry(pid_t pid, int *wstatus, int options)

tools/get-libc-dir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ libc="$(
55
ldd "$BASH" |
66
sed -n -e 's|[[:space:]]*libc\.so.*[[:space:]]=>[[:space:]]\(/.*\)[[:space:]](0x.*$|\1|p'
77
)"
8-
printf '%s\n' "${libc%/libc.so*}"
8+
printf '%s\n' "${libc%/*}"

0 commit comments

Comments
 (0)