From dzfkct.busyboxml at pacien.net Mon Jan 1 23:37:23 2024 From: dzfkct.busyboxml at pacien.net (pacien) Date: Tue, 2 Jan 2024 00:37:23 +0100 Subject: [PATCH v3 RESEND] udhcpc(6): add -K option to set kernel packet priority Message-ID: <20240101233723.3075557-1-dzfkct.busyboxml@pacien.net> From: pacien This adds a command line option (-K) to set the (kernel) packet priority. The option is part of "FEATURE_UDHCPC_SK_PRIO". This makes it straightforward to set some VLAN priority for DHCP requests through an egress QoS map. Packet matching for firewall or scheduler marking is otherwise broken due to the use of raw packets. (Such priority tag is a hard requirement for some ISPs, such as Orange in France). Enabling this feature costs 264 octets according to bloatcheck. Co-authored-by: Cl?ment P?ron Signed-off-by: Pacien TRAN-GIRARD --- networking/udhcp/Config.src | 10 ++++++++++ networking/udhcp/common.h | 6 ++++-- networking/udhcp/d6_common.h | 2 ++ networking/udhcp/d6_dhcpc.c | 26 +++++++++++++++++++------- networking/udhcp/d6_packet.c | 21 +++++++++++++++++++-- networking/udhcp/dhcpc.c | 29 ++++++++++++++++++++--------- networking/udhcp/dhcpc.h | 1 + networking/udhcp/dhcpd.c | 6 ++++-- networking/udhcp/packet.c | 21 +++++++++++++++++++-- 9 files changed, 98 insertions(+), 24 deletions(-) diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index 7ba7f48fc..731cf12fa 100644 --- a/networking/udhcp/Config.src +++ b/networking/udhcp/Config.src @@ -176,3 +176,13 @@ config FEATURE_UDHCP_8021Q help If selected, both client and server will support passing of VLAN ID and priority via options 132 and 133 as per 802.1Q. + +config FEATURE_UDHCPC_SK_PRIO + bool "Enable '-K' option for udhcpc" + default y + depends on UDHCPC || UDHCPC6 + help + If selected, enables -K option to set the kernel priority of DHCP + packets. Useful together with some egress QoS mapping to send + requests with a specific VLAN priority tag, as required by some + ISPs. diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 49a0b593d..30ee68375 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -359,12 +359,14 @@ int udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) FAST_FUNC; int udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, const uint8_t *dest_arp, - int ifindex) FAST_FUNC; + int ifindex + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) FAST_FUNC; int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, - const char *ifname) FAST_FUNC; + const char *ifname + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) FAST_FUNC; void udhcp_sp_setup(void) FAST_FUNC; void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC; diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h index 3cbfbb89e..05a5dc2b4 100644 --- a/networking/udhcp/d6_common.h +++ b/networking/udhcp/d6_common.h @@ -180,12 +180,14 @@ int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct in6_addr *src_ipv6, int source_port, struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio) ); int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex( struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct in6_addr *src_ipv6, int source_port, struct in6_addr *dst_ipv6, int dest_port + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio) ); #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index cdd06188e..173aa2914 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -127,6 +127,7 @@ static const char udhcpc6_longopts[] ALIGN1 = USE_FOR_MMU( "background\0" No_argument "b" ) + IF_FEATURE_UDHCPC_SK_PRIO("sk-priority\0" Required_argument "K") /// IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a") IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") ; @@ -152,12 +153,14 @@ enum { OPT_d = 1 << 16, /* The rest has variable bit positions, need to be clever */ OPTBIT_d = 16, - USE_FOR_MMU( OPTBIT_b,) - ///IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPTBIT_P,) - USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) - ///IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) + USE_FOR_MMU( OPTBIT_b,) + IF_FEATURE_UDHCPC_SK_PRIO(OPTBIT_K,) + ///IF_FEATURE_UDHCPC_ARPING( OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPTBIT_P,) + USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) + IF_FEATURE_UDHCPC_SK_PRIO(OPT_K = 1 << OPTBIT_K,) + ///IF_FEATURE_UDHCPC_ARPING( OPT_a = 1 << OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) }; #if ENABLE_FEATURE_UDHCPC6_RFC4704 @@ -561,6 +564,7 @@ static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t * packet, (end - (uint8_t*) packet), /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_DHCP6MCAST_ADDR + IF_FEATURE_UDHCPC_SK_PRIO(, client_data.sk_prio) ); } @@ -866,6 +870,7 @@ static NOINLINE int send_d6_renew(struct in6_addr *server_ipv6, struct in6_addr &packet, (opt_ptr - (uint8_t*) &packet), our_cur_ipv6, CLIENT_PORT6, server_ipv6, SERVER_PORT6 + IF_FEATURE_UDHCPC_SK_PRIO(, client_data.sk_prio) ); return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); } @@ -899,6 +904,7 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) &packet, (opt_ptr - (uint8_t*) &packet), our_cur_ipv6, CLIENT_PORT6, server_ipv6, SERVER_PORT6 + IF_FEATURE_UDHCPC_SK_PRIO(, client_data.sk_prio) ); } @@ -1129,7 +1135,7 @@ static void client_background(void) //usage:# define IF_UDHCP_VERBOSE(...) //usage:#endif //usage:#define udhcpc6_trivial_usage -//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"R] [-t N] [-T SEC] [-A SEC|-n] [-i IFACE] [-s PROG]\n" +//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"R]"IF_FEATURE_UDHCPC_SK_PRIO(" [-K PRIO]")" [-t N] [-T SEC] [-A SEC|-n] [-i IFACE] [-s PROG]\n" //usage: " [-p PIDFILE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-ldo] [-r IPv6] [-x OPT:VAL]... [-O OPT]..." //usage:#define udhcpc6_full_usage "\n" //usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")" @@ -1150,6 +1156,9 @@ static void client_background(void) //usage: IF_FEATURE_UDHCP_PORT( //usage: "\n -P PORT Use PORT (default 546)" //usage: ) +//usage: IF_FEATURE_UDHCPC_SK_PRIO( +//usage: "\n -K PRIO Set kernel packet priority (default 0)" +//usage: ) ////usage: IF_FEATURE_UDHCPC_ARPING( ////usage: "\n -a Use arping to validate offered address" ////usage: ) @@ -1199,6 +1208,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) /* Default options */ IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) + IF_FEATURE_UDHCPC_SK_PRIO(client_data.sk_prio = 0;) client_data.interface = CONFIG_UDHCPC_DEFAULT_INTERFACE; client_data.script = CONFIG_UDHCPC6_DEFAULT_SCRIPT; client_data.sockfd = -1; @@ -1212,6 +1222,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) /* O,x: list; -T,-t,-A take numeric param */ "i:np:qRr:s:T:+t:+SA:+O:*ox:*fld" USE_FOR_MMU("b") + IF_FEATURE_UDHCPC_SK_PRIO("K:+") ///IF_FEATURE_UDHCPC_ARPING("a") IF_FEATURE_UDHCP_PORT("P:") "v" @@ -1222,6 +1233,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ , &list_O , &list_x + IF_FEATURE_UDHCPC_SK_PRIO(, &client_data.sk_prio) IF_FEATURE_UDHCP_PORT(, &str_P) IF_UDHCP_VERBOSE(, &dhcp_verbose) ); diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 142de9b43..501497154 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c @@ -54,7 +54,8 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6 UNUSED_PARAM, int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct in6_addr *src_ipv6, int source_port, - struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp) + struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) { struct sockaddr_ll dest_sll; struct ip6_udp_d6_packet packet; @@ -68,6 +69,13 @@ int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( goto ret_msg; } +#if ENABLE_FEATURE_UDHCPC_SK_PRIO + if (setsockopt_SOL_SOCKET_int(fd, SO_PRIORITY, sk_prio) < 0) { + msg = "setsockopt(%s)"; + goto ret_close; + } +#endif + memset(&dest_sll, 0, sizeof(dest_sll)); memset(&packet, 0, offsetof(struct ip6_udp_d6_packet, data)); packet.data = *d6_pkt; /* struct copy */ @@ -139,7 +147,8 @@ int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex( int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex( struct d6_packet *d6_pkt, unsigned d6_pkt_size, struct in6_addr *src_ipv6, int source_port, - struct in6_addr *dst_ipv6, int dest_port) + struct in6_addr *dst_ipv6, int dest_port + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) { struct sockaddr_in6 sa; int fd; @@ -151,6 +160,14 @@ int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex( msg = "socket(%s)"; goto ret_msg; } + +#if ENABLE_FEATURE_UDHCPC_SK_PRIO + if (setsockopt_SOL_SOCKET_int(fd, SO_PRIORITY, sk_prio) < 0) { + msg = "setsockopt(%s)"; + goto ret_close; + } +#endif + setsockopt_reuseaddr(fd); memset(&sa, 0, sizeof(sa)); diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index c757fb37c..8108f6856 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -75,6 +75,7 @@ static const char udhcpc_longopts[] ALIGN1 = "background\0" No_argument "b" ) "broadcast\0" No_argument "B" + IF_FEATURE_UDHCPC_SK_PRIO("sk-priority\0" Required_argument "K") IF_FEATURE_UDHCPC_ARPING("arping\0" Optional_argument "a") IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P") ; @@ -102,12 +103,14 @@ enum { OPT_B = 1 << 18, /* The rest has variable bit positions, need to be clever */ OPTBIT_B = 18, - USE_FOR_MMU( OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPTBIT_P,) - USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) - IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) - IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) + USE_FOR_MMU( OPTBIT_b,) + IF_FEATURE_UDHCPC_SK_PRIO(OPTBIT_K,) + IF_FEATURE_UDHCPC_ARPING( OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPTBIT_P,) + USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) + IF_FEATURE_UDHCPC_SK_PRIO(OPT_K = 1 << OPTBIT_K,) + IF_FEATURE_UDHCPC_ARPING( OPT_a = 1 << OPTBIT_a,) + IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) }; @@ -704,7 +707,8 @@ static int raw_bcast_from_client_data_ifindex(struct dhcp_packet *packet, uint32 return udhcp_send_raw_packet(packet, /*src*/ src_nip, CLIENT_PORT, /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, - client_data.ifindex); + client_data.ifindex + IF_FEATURE_UDHCPC_SK_PRIO(, client_data.sk_prio)); } static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) @@ -713,7 +717,8 @@ static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t return udhcp_send_kernel_packet(packet, ciaddr, CLIENT_PORT, server, SERVER_PORT, - client_data.interface); + client_data.interface + IF_FEATURE_UDHCPC_SK_PRIO(, client_data.sk_prio)); return raw_bcast_from_client_data_ifindex(packet, ciaddr); } @@ -1161,7 +1166,7 @@ static void client_background(void) //usage:# define IF_UDHCP_VERBOSE(...) //usage:#endif //usage:#define udhcpc_trivial_usage -//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"RB]"IF_FEATURE_UDHCPC_ARPING(" [-a[MSEC]]")" [-t N] [-T SEC] [-A SEC|-n]\n" +//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"RB]"IF_FEATURE_UDHCPC_SK_PRIO(" [-K PRIO]")IF_FEATURE_UDHCPC_ARPING(" [-a[MSEC]]")" [-t N] [-T SEC] [-A SEC|-n]\n" //usage: " [-i IFACE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-s PROG] [-p PIDFILE]\n" //usage: " [-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]..." //usage:#define udhcpc_full_usage "\n" @@ -1183,6 +1188,9 @@ static void client_background(void) //usage: "\n -R Release IP on exit" //usage: "\n -f Run in foreground" //usage: "\n -S Log to syslog too" +//usage: IF_FEATURE_UDHCPC_SK_PRIO( +//usage: "\n -K PRIO Set kernel packet priority (default 0)" +//usage: ) //usage: IF_FEATURE_UDHCPC_ARPING( //usage: "\n -a[MSEC] Validate offered address with ARP ping" //usage: ) @@ -1232,6 +1240,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) /* Default options */ IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) + IF_FEATURE_UDHCPC_SK_PRIO(client_data.sk_prio = 0;) client_data.interface = CONFIG_UDHCPC_DEFAULT_INTERFACE; client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; client_data.sockfd = -1; @@ -1246,6 +1255,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) /* O,x: list; -T,-t,-A take numeric param */ "CV:F:i:np:qRr:s:T:+t:+SA:+O:*ox:*fB" USE_FOR_MMU("b") + IF_FEATURE_UDHCPC_SK_PRIO("K:+") IF_FEATURE_UDHCPC_ARPING("a::") IF_FEATURE_UDHCP_PORT("P:") "v" @@ -1258,6 +1268,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ , &list_O , &list_x + IF_FEATURE_UDHCPC_SK_PRIO(, &client_data.sk_prio) IF_FEATURE_UDHCPC_ARPING(, &str_a) IF_FEATURE_UDHCP_PORT(, &str_P) IF_UDHCP_VERBOSE(, &dhcp_verbose) diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 19b054b32..733491953 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h @@ -9,6 +9,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN struct client_data_t { uint8_t client_mac[6]; /* Our mac address */ + IF_FEATURE_UDHCPC_SK_PRIO(int sk_prio;) IF_FEATURE_UDHCP_PORT(uint16_t port;) int ifindex; /* Index number of the interface to use */ uint32_t xid; diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 66750e2e6..814b791b0 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -603,7 +603,8 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc udhcp_send_raw_packet(dhcp_pkt, /*src*/ server_data.server_nip, SERVER_PORT, /*dst*/ ciaddr, CLIENT_PORT, chaddr, - server_data.ifindex); + server_data.ifindex + IF_FEATURE_UDHCPC_SK_PRIO(, 0)); } /* Send a packet to gateway_nip using the kernel ip stack */ @@ -618,7 +619,8 @@ static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) * even those which are clients' requests and would normally * (i.e. without relay) use CLIENT_PORT. See RFC 1542. */ - server_data.interface); + server_data.interface + IF_FEATURE_UDHCPC_SK_PRIO(, 0)); } static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast) diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 529978189..9cd2beafe 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -106,7 +106,8 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, const uint8_t *dest_arp, - int ifindex) + int ifindex + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) { struct sockaddr_ll dest_sll; struct ip_udp_dhcp_packet packet; @@ -121,6 +122,13 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, goto ret_msg; } +#if ENABLE_FEATURE_UDHCPC_SK_PRIO + if (setsockopt_SOL_SOCKET_int(fd, SO_PRIORITY, sk_prio) < 0) { + msg = "setsockopt(%s)"; + goto ret_close; + } +#endif + memset(&dest_sll, 0, sizeof(dest_sll)); memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data)); packet.data = *dhcp_pkt; /* struct copy */ @@ -192,7 +200,8 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, uint32_t dest_nip, int dest_port, - const char *ifname) + const char *ifname + IF_FEATURE_UDHCPC_SK_PRIO(, int sk_prio)) { struct sockaddr_in sa; unsigned padding; @@ -205,6 +214,14 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, msg = "socket(%s)"; goto ret_msg; } + +#if ENABLE_FEATURE_UDHCPC_SK_PRIO + if (setsockopt_SOL_SOCKET_int(fd, SO_PRIORITY, sk_prio) < 0) { + msg = "setsockopt(%s)"; + goto ret_close; + } +#endif + setsockopt_reuseaddr(fd); /* If interface carrier goes down, unless we -- 2.42.0 From vda.linux at googlemail.com Mon Jan 1 23:56:58 2024 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 2 Jan 2024 00:56:58 +0100 Subject: [PATCH] xvfork: override die_func to _exit on child processes In-Reply-To: References: <20231108025757.1924934-1-asmadeus@codewreck.org> Message-ID: On Fri, Dec 15, 2023 at 6:57?AM Dominique Martinet wrote: > > > > For this particular problem die_func could just be overriden in > > > > time.c's run_command after vfork, but this problem actually came up > > > > before in shell/hush.c as per the fflush_and__exit comment so it seems > > > > more appropriate to do this globally in the xvfork macro and get rid of > > > > this whole class of bugs forever. > > > > > > Maybe we can always use _exit(), > > > or fflush_all(); _exit() in xfunc_die()? > > > > hmm, exit does a bunch of stuff: > > - we apparently use atexit() in a few applets, so these would need the > > real exit() to get invoked > > - any lib destructor would also be called, I'm not sure we rely on any > > so that's probably fine. Same with on_exit(), not used directly. > > - The man page for exit(3) on my system also says files created by > > tmpfile(3) are removed; we don't seem to use it either. > > - flushing and closinig all FILEs; I agree close itself isn't needed, > > fflush_all() as you've suggested is probably enough... And hush.c has > > been calling it after vfork so it's probably fine? because while the > > address space is shared, that takes and releases locks when it's done, > > so while it's not explicitely safe it's probably ok. And fflush is > > definitely needed in the normal case. > > > > I'm not sure there's anything else that needs to be done on exit? > > > > > > So that leaves atexit hooks which we need in some applets (mount, sed -- > > the one in libpwdgrp is just a free "to make valgrind happy" so can be > > skipped); if we update these two to override die_func instead (don't > > even need to use exit there, they can just register their hook as > > die_func instead of atexit), then I guess it would be ok to do > > `fflush_all(); _exit()` in xfunc_die(), but I'm not 100% comfortable > > with that so that'll require a bunch of testing. > > > > I can update the patch if you really prefer this, but I won't be able to > > test much more than running the test suite on x86_64/debian and alpines > > (I guess it's a good excuse to add a new test item for 'time > > notavalidcommand' at the same time), it'll probably require a bit more > > validiation. > > What would you like me to do with this, should I send a v2 that tries to > default to `flush_all(); exit()` in xfunc_die()? Yes, I think we should try it. Conditional on musl. Something like this in libbb/xfunc_die.c: +//musl has no __MUSL__ or similar define to check for, +//but its has these lines: +// #define __NEED_fsblkcnt_t +// #define __NEED_fsfilcnt_t +#if defined(__linux__) && defined(__NEED_fsblkcnt_t) && defined(__NEED_fsfilcnt_t) +# define LIBC_IS_MUSL 1 +# include +#else +# define LIBC_IS_MUSL 0 +#endif void FAST_FUNC xfunc_die(void) { if (die_func) die_func(); +#if LIBC_IS_MUSL +// We may be in the child after vfork(). +// On musl, sometime between 1.1.20 and 1.1.22, exit() after vfork() +// stopped working properly: it takes init_fini_lock but does not release it +// before dying, which makes subsequent exit in parent process hang +// trying to take the same lock again. Thus, use _exit instead: fflush_all(); _exit(xfunc_error_retval); +#else exit(xfunc_error_retval); +#endif } From vda.linux at googlemail.com Tue Jan 2 00:00:05 2024 From: vda.linux at googlemail.com (Denys Vlasenko) Date: Tue, 2 Jan 2024 01:00:05 +0100 Subject: [PATCH resend] sed: check errors writing file with sed -i In-Reply-To: <20230919081102.3136547-1-asmadeus@codewreck.org> References: <20230919081102.3136547-1-asmadeus@codewreck.org> Message-ID: Applied, thank you! On Tue, Sep 19, 2023 at 10:11?AM Dominique Martinet wrote: > > From: Dominique Martinet > > sed would currently not error if write failed when modifying a file. > > This can be reproduced with the following 'script': > $ sudo mount -t tmpfs tmpfs -o size=1M /tmp/m > $ sudo chmod 777 /tmp/m > $ echo foo > /tmp/m/foo > $ dd if=/dev/zero of=/tmp/m/fill bs=4k > dd: error writing '/tmp/m/fill': No space left on device > 256+0 records in > 255+0 records out > 1044480 bytes (1.0 MB, 1020 KiB) copied, 0.00234567 s, 445 MB/s > $ busybox sed -i -e 's/.*/bar/' /tmp/m/foo > $ echo $? > 0 > $ cat /tmp/m/foo > > > new behaviour: > $ echo foo > /tmp/m/foo > $ ./busybox sed -i -e 's/.*/bar/' /tmp/m/foo > sed: write error > $ echo $? > 4 > $ cat /tmp/m/foo > foo > > function old new delta > sed_main 754 801 +47 > ------------------------------------------------------------------------------ > (add/remove: 0/0 grow/shrink: 1/0 up/down: 47/0) Total: 47 bytes > text data bss dec hex filename > 75727 2510 1552 79789 137ad busybox_old > 75774 2510 1552 79836 137dc busybox_unstripped > > Signed-off-by: Dominique Martinet > --- > Resending this patch again as it doesn't seem to have been applied. > > FWIW it's still applied on alpine builds (since Nov last year); would be > great to see this merged so I can forget about it :) > > editors/sed.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/editors/sed.c b/editors/sed.c > index 00dde60be329..6179c5e80958 100644 > --- a/editors/sed.c > +++ b/editors/sed.c > @@ -1648,6 +1648,11 @@ int sed_main(int argc UNUSED_PARAM, char **argv) > fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid); > > process_files(); > + fflush(G.nonstdout); > + if (ferror(G.nonstdout)) { > + xfunc_error_retval = 4; /* It's what gnu sed exits with... */ > + bb_simple_error_msg_and_die(bb_msg_write_error); > + } > fclose(G.nonstdout); > G.nonstdout = stdout; > > -- > 2.39.2 > From rmy at pobox.com Tue Jan 2 09:01:32 2024 From: rmy at pobox.com (Ron Yorston) Date: Tue, 02 Jan 2024 09:01:32 +0000 Subject: [PATCH] Makefile.flags: suppress clang warnings when cross-compiling Message-ID: <6593d0ec.sqgRag22g6hbgOXh%rmy@pobox.com> Extend the changes introduced by commit b4ef2e3467 (Makefile.flags: suppress some clang-9 warnings) so they also cover the case where clang is used as a cross-compiler. Signed-off-by: Ron Yorston --- Makefile.flags | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.flags b/Makefile.flags index e4cd658fd..97cb4dca2 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -48,7 +48,7 @@ endif # gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action() CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition) -ifneq ($(CC),clang) +ifneq ($(lastword $(subst -, ,$(CC))),clang) # "clang-9: warning: optimization flag '-finline-limit=0' is not supported CFLAGS += $(call cc-option,-finline-limit=0,) endif @@ -66,7 +66,7 @@ CFLAGS += $(call cc-option,-static-libgcc,) endif CFLAGS += $(call cc-option,-falign-functions=1,) -ifneq ($(CC),clang) +ifneq ($(lastword $(subst -, ,$(CC))),clang) # "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two) CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,) endif @@ -79,7 +79,7 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,) CFLAGS += $(call cc-option,-fno-builtin-printf,) # clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs -ifeq ($(CC),clang) +ifeq ($(lastword $(subst -, ,$(CC))),clang) CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand) endif -- 2.43.0 From rmy at pobox.com Tue Jan 2 09:49:40 2024 From: rmy at pobox.com (Ron Yorston) Date: Tue, 02 Jan 2024 09:49:40 +0000 Subject: [PATCH] Remove FAST_FUNC from variadic functions Message-ID: <6593dc34.cykHOswCzlDYbWjH%rmy@pobox.com> The GCC documentation points out that the stdcall attribute doesn't apply to functions which take a variable number of arguments. GCC is silent about this during compilation but clang complains noisily. Remove FAST_FUNC from all variadic functions. This has no effect whatsoever on the binary resulting from a default 32-bit build. Signed-off-by: Ron Yorston --- include/libbb.h | 24 ++++++++++++------------ libbb/getopt32.c | 4 ++-- libbb/herror_msg.c | 4 ++-- libbb/perror_msg.c | 4 ++-- libbb/verror_msg.c | 6 +++--- libbb/xfuncs_printf.c | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index ef5d04713..6ef090a0e 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -926,7 +926,7 @@ int bb_putchar(int ch) FAST_FUNC; /* Note: does not use stdio, writes to fd 2 directly */ int bb_putchar_stderr(char ch) FAST_FUNC; int fputs_stdout(const char *s) FAST_FUNC; -char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC; +char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) RETURNS_MALLOC; char *auto_string(char *str) FAST_FUNC; // gcc-4.1.1 still isn't good enough at optimizing it // (+200 bytes compared to macro) @@ -1350,12 +1350,12 @@ char* single_argv(char **argv) FAST_FUNC; char **skip_dash_dash(char **argv) FAST_FUNC; extern const char *const bb_argv_dash[]; /* { "-", NULL } */ extern uint32_t option_mask32; -uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; +uint32_t getopt32(char **argv, const char *applet_opts, ...); # define No_argument "\0" # define Required_argument "\001" # define Optional_argument "\002" #if ENABLE_LONG_OPTS -uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...) FAST_FUNC; +uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...); #else #define getopt32long(argv,optstring,longopts,...) \ getopt32(argv,optstring,##__VA_ARGS__) @@ -1430,17 +1430,17 @@ extern uint8_t xfunc_error_retval; extern void (*die_func)(void); void xfunc_die(void) NORETURN FAST_FUNC; void bb_show_usage(void) NORETURN FAST_FUNC; -void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; +void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); void bb_simple_error_msg(const char *s) FAST_FUNC; -void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; +void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; -void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; +void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); void bb_simple_perror_msg(const char *s) FAST_FUNC; -void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; +void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; -void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; +void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); void bb_simple_herror_msg(const char *s) FAST_FUNC; -void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; +void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; void bb_perror_nomsg(void) FAST_FUNC; @@ -1456,7 +1456,7 @@ void bb_logenv_override(void) FAST_FUNC; typedef smalluint exitcode_t; #if ENABLE_FEATURE_SYSLOG_INFO -void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; +void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); void bb_simple_info_msg(const char *s) FAST_FUNC; void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; #else @@ -1832,8 +1832,8 @@ int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *ol int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; /* NB: "unsigned request" is crucial! "int request" will break some arches! */ -int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; -int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; +int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); +int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); #if ENABLE_IOCTL_HEX2STR_ERROR int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; diff --git a/libbb/getopt32.c b/libbb/getopt32.c index e861d0567..56040e150 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -595,7 +595,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, return (int32_t)-1; } -uint32_t FAST_FUNC +uint32_t getopt32(char **argv, const char *applet_opts, ...) { uint32_t opt; @@ -608,7 +608,7 @@ getopt32(char **argv, const char *applet_opts, ...) } #if ENABLE_LONG_OPTS -uint32_t FAST_FUNC +uint32_t getopt32long(char **argv, const char *applet_opts, const char *longopts, ...) { uint32_t opt; diff --git a/libbb/herror_msg.c b/libbb/herror_msg.c index a7dd98679..09537ae92 100644 --- a/libbb/herror_msg.c +++ b/libbb/herror_msg.c @@ -8,7 +8,7 @@ */ #include "libbb.h" -void FAST_FUNC bb_herror_msg(const char *s, ...) +void bb_herror_msg(const char *s, ...) { va_list p; @@ -17,7 +17,7 @@ void FAST_FUNC bb_herror_msg(const char *s, ...) va_end(p); } -void FAST_FUNC bb_herror_msg_and_die(const char *s, ...) +void bb_herror_msg_and_die(const char *s, ...) { va_list p; diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c index fa1f0d339..32adb8c38 100644 --- a/libbb/perror_msg.c +++ b/libbb/perror_msg.c @@ -8,7 +8,7 @@ */ #include "libbb.h" -void FAST_FUNC bb_perror_msg(const char *s, ...) +void bb_perror_msg(const char *s, ...) { va_list p; @@ -18,7 +18,7 @@ void FAST_FUNC bb_perror_msg(const char *s, ...) va_end(p); } -void FAST_FUNC bb_perror_msg_and_die(const char *s, ...) +void bb_perror_msg_and_die(const char *s, ...) { va_list p; diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c index 74b608f4c..7c167d912 100644 --- a/libbb/verror_msg.c +++ b/libbb/verror_msg.c @@ -156,7 +156,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) #endif -void FAST_FUNC bb_error_msg_and_die(const char *s, ...) +void bb_error_msg_and_die(const char *s, ...) { va_list p; @@ -166,7 +166,7 @@ void FAST_FUNC bb_error_msg_and_die(const char *s, ...) xfunc_die(); } -void FAST_FUNC bb_error_msg(const char *s, ...) +void bb_error_msg(const char *s, ...) { va_list p; @@ -183,7 +183,7 @@ void FAST_FUNC bb_vinfo_msg(const char *s, va_list p) syslog_level = LOG_ERR; } -void FAST_FUNC bb_info_msg(const char *s, ...) +void bb_info_msg(const char *s, ...) { va_list p; diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 842d10cd2..e7b3fde98 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -334,7 +334,7 @@ void FAST_FUNC xprint_and_close_file(FILE *file) // Die with an error message if we can't malloc() enough space and do an // sprintf() into that space. -char* FAST_FUNC xasprintf(const char *format, ...) +char* xasprintf(const char *format, ...) { va_list p; int r; @@ -547,7 +547,7 @@ void FAST_FUNC selinux_or_die(void) /* not defined, other code must have no calls to it */ #endif -int FAST_FUNC ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) +int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) { int ret; va_list p; @@ -563,7 +563,7 @@ int FAST_FUNC ioctl_or_perror_and_die(int fd, unsigned request, void *argp, cons return ret; } -int FAST_FUNC ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) +int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) { va_list p; int ret = ioctl(fd, request, argp); -- 2.43.0 From jonessyue at qnap.com Thu Jan 4 10:20:16 2024 From: jonessyue at qnap.com (=?iso-2022-jp?B?Sm9uZXMgU3l1ZSAbJEJpLVhnPSEbKEI=?=) Date: Thu, 4 Jan 2024 10:20:16 +0000 Subject: [PATCH] crond: add LOG_NDELAY to openlog In-Reply-To: References: <4b2b4b6e5f814e3b804b263fd5001493@AcuMS.aculab.com> Message-ID: > I'd actually suggest using fork() - much safer. > While slightly slower no one is going to notice the difference > when cron is running programs. Yes. No doubt about it! :) Replace vfork() with fork()[1] could way around this issue[2], since fork() is copy-on-write so each children process has its own address space and its own copy of 'static var LogFile' in data segment, it is not shared any more among all processes including parent and children, and any modification from children is not visible to parent. Per my environment we did have some entry-level embedded systems with much less memory and very limited computation power, so vfork() implementation is preferred than fork() since vfork() is more effective on memory footprint and process creation speed. Really a BIG FAN of how busybox explains vfork(): https://busybox.net/FAQ.html#tips_vfork So it looks like simply adds LOG_NDELAY might be a feasible approach to address this issue :) [1] Replace vfork() with fork() --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -713,7 +713,7 @@ fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail) set_env_vars(pas, shell, NULL); /* don't use crontab's PATH for sendmail */ sv_logmode = logmode; - pid = vfork(); + pid = fork(); if (pid == 0) { /* CHILD */ /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */ [2] Use strace to understand how fork() looks like. The crond parent cloned two children pid is 25660 and 25661. parent has its own consistent 'LogFile = 5' and DGRAM socket fd = 5. # grep -rE "^clone|^vfork|^sock.*UNIX.*DGRAM|connect.*log|sendto.*75|can\'|parse error|change directory" 20231213_01.log.20290 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f65ac34a9d0) = 25660 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f65ac34a9d0) = 25661 socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5 connect(5, {sa_family=AF_UNIX, sun_path="/dev/log"}, 110) = 0 sendto(5, "<75>Dec 13 14:11:00 crond[20290]: user admin: parse error at <\n", 63, MSG_NOSIGNAL, NULL, 0) = 63 The children pid=25660 and 25661 both has its own consistent 'LogFile = 4' and DGRAM socket fd = 4. # grep -rE "^vfork|^sock.*UNIX.*DGRAM|connect.*log|sendto.*75|can\'|parse error|change directory" 20231213_01.log.25660 socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 4 connect(4, {sa_family=AF_UNIX, sun_path="/dev/log"}, 110) = 0 sendto(4, "<75>Dec 13 14:10:02 crond[25660]: can't change directory to '/share/homes/admin'\n", 81, MSG_NOSIGNAL, NULL, 0) = 81 # grep -rE "^vfork|^sock.*UNIX.*DGRAM|connect.*log|sendto.*75|can\'|parse error|change directory" 20231213_01.log.25661 socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 4 connect(4, {sa_family=AF_UNIX, sun_path="/dev/log"}, 110) = 0 sendto(4, "<75>Dec 13 14:10:02 crond[25661]: can't change directory to '/share/homes/admin'\n", 81, MSG_NOSIGNAL, NULL, 0) = 81 -- Regards, Jones Syue | ??? QNAP Systems, Inc. From jonessyue at qnap.com Fri Jan 5 10:18:31 2024 From: jonessyue at qnap.com (=?iso-2022-jp?B?Sm9uZXMgU3l1ZSAbJEJpLVhnPSEbKEI=?=) Date: Fri, 5 Jan 2024 10:18:31 +0000 Subject: [PATCH] crond: add LOG_NDELAY to openlog In-Reply-To: References: <4b2b4b6e5f814e3b804b263fd5001493@AcuMS.aculab.com> Message-ID: Hello List, > So it looks like simply adds LOG_NDELAY might be a feasible approach to > address this issue :) Attached is a proposed v2 patch, code is the same, leverage comments from inetd_main() at inetd.c and rewrite git logs, any feedback is much appreciated, thank you :) -- Regards, Jones Syue | ??? QNAP Systems, Inc. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: 0001-crond-add-LOG_NDELAY-to-openlog-v2.txt URL: From dstumph at gmail.com Wed Jan 10 02:32:27 2024 From: dstumph at gmail.com (David Stumph) Date: Tue, 9 Jan 2024 21:32:27 -0500 Subject: [PATCH] - vi: Append a newline to opened files that don't already end in one Message-ID: <8fcb5cdc-dcd0-4466-aab4-89638d7b8141@gmail.com> Package: busybox Version: master Severity: bug Hello all, I found a bit of broken behavior when `busybox vi` is used on a file that doesn't end in a newline. If you go to the last line of the file and type "o", the new line that opens below it contains the last character of the previous line. This shouldn't happen, and I attached a demo text file that you can reproduce it on. The "A" command on that line is also broken, as it desynchronizes the cursor from where text appears. I made a patch to fix it by adding a newline to the end of files that don't already have one. This comes with the caveat that opening a file, not making any edits, and saving it can append a newline. Vi, vim, nano, and gedit already add this newline though, so this is expected behavior. Output of `make bloatcheck`: function old new delta init_text_buffer 161 193 +32 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 32/0) Total: 32 bytes text data bss dec hex filename 1026178 16515 1808 1044501 ff015 busybox_old 1026210 16515 1808 1044533 ff035 busybox_unstripped Thanks, David -------------- next part -------------- A non-text attachment was scrubbed... Name: vi-newline.patch Type: text/x-patch Size: 522 bytes Desc: not available URL: -------------- next part -------------- Go to the beginning of the last line with your cursor, and press 'o'. It will move the 1 onto its own line, which is improper behavior. You can also type "A" to append to the line, and the cursor ends up getting desynchronized from where characters appear. If it doesn't show the problem, you might need to truncate the ending newline character if one got added. This line: 1 From rmy at pobox.com Wed Jan 10 11:38:17 2024 From: rmy at pobox.com (Ron Yorston) Date: Wed, 10 Jan 2024 11:38:17 +0000 Subject: [PATCH] - vi: Append a newline to opened files that don't already end in one In-Reply-To: <8fcb5cdc-dcd0-4466-aab4-89638d7b8141@gmail.com> References: <8fcb5cdc-dcd0-4466-aab4-89638d7b8141@gmail.com> Message-ID: <659e81a9.vv7/u0tdwU9R6Njj%rmy@pobox.com> There was another, similar patch for this issue last year: http://lists.busybox.net/pipermail/busybox/2023-April/090272.html Ron From thomas at devoogdt.com Fri Jan 19 13:30:21 2024 From: thomas at devoogdt.com (Thomas Devoogdt) Date: Fri, 19 Jan 2024 14:30:21 +0100 Subject: [PATCH v1] seedrng.c: fix clock_gettime support for older kernels and glibc combinations Message-ID: <20240119133021.2274318-1-thomas.devoogdt@barco.com> CLOCK_BOOTTIME has been added in Linux >= 2.6.39, so fallback to CLOCK_MONOTONIC on older kernels. Also, ensure proper compilation with older glibc versions. https://www.man7.org/linux/man-pages/man3/clock_settime.3.html Signed-off-by: Thomas Devoogdt --- miscutils/seedrng.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c index 3bf6e2ea7..07ecc8a82 100644 --- a/miscutils/seedrng.c +++ b/miscutils/seedrng.c @@ -69,6 +69,21 @@ static ssize_t getrandom(void *buffer, size_t length, unsigned flags) #define GRND_INSECURE 0x0004 #endif +/* fix for glibc < 2.3.4 */ +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +/* fix for glibc < 2.3.4 */ +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 1 +#endif + +/* fix for glibc < 2.14 */ +#ifndef CLOCK_BOOTTIME +#define CLOCK_BOOTTIME 7 +#endif + #define DEFAULT_SEED_DIR "/var/lib/seedrng" #define CREDITABLE_SEED_NAME "seed.credit" #define NON_CREDITABLE_SEED_NAME "seed.no-credit" @@ -228,7 +243,9 @@ int seedrng_main(int argc UNUSED_PARAM, char **argv) //Hashing in a constant string doesn't add any entropy // sha256_hash(&hash, "SeedRNG v1 Old+New Prefix", 25); clock_gettime(CLOCK_REALTIME, ×tamp[0]); - clock_gettime(CLOCK_BOOTTIME, ×tamp[1]); + if (clock_gettime(CLOCK_BOOTTIME, ×tamp[1]) < 0 && errno == EINVAL) + clock_gettime(CLOCK_MONOTONIC, ×tamp[1]); /* fallback for Linux < 2.6.39 */ + sha256_hash(&hash, timestamp, sizeof(timestamp)); for (i = 0; i <= 1; i++) { -- 2.43.0 From mjt at tls.msk.ru Sat Jan 20 10:12:41 2024 From: mjt at tls.msk.ru (Michael Tokarev) Date: Sat, 20 Jan 2024 13:12:41 +0300 Subject: [PATCH v1] seedrng.c: fix clock_gettime support for older kernels and glibc combinations In-Reply-To: <20240119133021.2274318-1-thomas.devoogdt@barco.com> References: <20240119133021.2274318-1-thomas.devoogdt@barco.com> Message-ID: <38e3c84d-4bea-4c7f-802d-00a52396e398@tls.msk.ru> 19.01.2024 16:30, Thomas Devoogdt : > CLOCK_BOOTTIME has been added in Linux >= 2.6.39, > so fallback to CLOCK_MONOTONIC on older kernels. > > Also, ensure proper compilation with older glibc versions. Why do you care about such old kernels? To me, it would be better to clean up such old fallbacks, remove support for, say, kernels <3.x or <4.x (like, for example, modutils compatibility can be removed entirely), instead of adding new fallbacks.. /mjt From thomas at devoogdt.com Sat Jan 20 12:55:09 2024 From: thomas at devoogdt.com (Thomas Devoogdt) Date: Sat, 20 Jan 2024 13:55:09 +0100 Subject: [PATCH v1] seedrng.c: fix clock_gettime support for older kernels and glibc combinations In-Reply-To: <38e3c84d-4bea-4c7f-802d-00a52396e398@tls.msk.ru> References: <20240119133021.2274318-1-thomas.devoogdt@barco.com> <38e3c84d-4bea-4c7f-802d-00a52396e398@tls.msk.ru> Message-ID: Op za 20 jan 2024 om 11:12 schreef Michael Tokarev : > > 19.01.2024 16:30, Thomas Devoogdt : > > CLOCK_BOOTTIME has been added in Linux >= 2.6.39, > > so fallback to CLOCK_MONOTONIC on older kernels. > > > > Also, ensure proper compilation with older glibc versions. > > Why do you care about such old kernels? > To me, it would be better to clean up such old fallbacks, remove > support for, say, kernels <3.x or <4.x (like, for example, > modutils compatibility can be removed entirely), instead of > adding new fallbacks.. Sometimes people do have this kind of old hardware and kernels, that is mainly the reason why I came across this problem. That said, the FAQ mentioned the supported versions (https://www.busybox.net/FAQ.html#kernel) which are now Linux >= 2.4.x and glibc >= 2.2, so for that reason, I thought that this patch would have a chance to get accepted. Raising the minimally supported versions would be somewhat contradictory to what this commit tries to resolve, but it's also not on me to decide on where the line is drawn of what is supported. > /mjt > Kind Regards, Thomas Devoogdt From rob at landley.net Thu Jan 25 11:22:13 2024 From: rob at landley.net (Rob Landley) Date: Thu, 25 Jan 2024 05:22:13 -0600 Subject: [PATCH] awk: fix segfault when compiled by clang In-Reply-To: <65aa981d.5TChNMNXWAYI/wWg%rmy@pobox.com> References: <65aa981d.5TChNMNXWAYI/wWg%rmy@pobox.com> Message-ID: On 1/19/24 09:41, Ron Yorston wrote: > A 32-bit build of BusyBox using clang segfaulted in the test > "awk assign while assign". Specifically, on line 7 of the test > input where the adjustment of the L.v pointer when the Fields > array was reallocated > > L.v += Fields - old_Fields_ptr; > > was out by 4 bytes. > > Rearrange to code so both gcc and clang generate code that works. Out of morbid curiosity, why did this message a week ago wind up delivered to me through the mailing list (I confirmed I was not personally cc'd on it), but not wind up in the mailing list web archive? http://lists.busybox.net/pipermail/busybox/2024-January/date.html Rob From rmy at pobox.com Thu Jan 25 11:40:40 2024 From: rmy at pobox.com (Ron Yorston) Date: Thu, 25 Jan 2024 11:40:40 +0000 Subject: [PATCH] awk: fix segfault when compiled by clang In-Reply-To: References: <65aa981d.5TChNMNXWAYI/wWg%rmy@pobox.com> Message-ID: <65b248b8.L5ZwELWDUUD4D3h2%rmy@pobox.com> Rob Landley wrote: >Out of morbid curiosity, why did this message a week ago wind up delivered to me >through the mailing list (I confirmed I was not personally cc'd on it), but not >wind up in the mailing list web archive? Dunno. I did notice the mailing list archive was unavailable at the time I sent the message. Presumably it was encountering difficulties which resulted in it becoming forgetful. It is archived elsewhere: https://marc.info/?l=busybox&r=1&b=202401&w=2 Ron From john.hossbach at taillight.com Thu Jan 25 21:53:22 2024 From: john.hossbach at taillight.com (John Hossbach) Date: Thu, 25 Jan 2024 15:53:22 -0600 Subject: BusyBox crond format help Message-ID: I'm seeking documentation on the format that BusyBox's crond supports under BB 1.35.0. I could not find anything, so I took to reading source, but quickly got confused and started to not believe what I was reading. Originally, I was hoping to find that crond supported "H" (the random value in cron). As I began reading crond.c, I started to think that it didn't even support ranges like 1-10. I base this off of lines 234 and 270 where skip is set to 0 and if the field is not *, a digit, or one of the pre-defined 3-character strings, it seems to throw a parsing error even though comments seem to imply that it handles an optional range. https://git.busybox.net/busybox/tree/miscutils/crond.c?h=1_35_stable#n234 So, maybe less about the interpretation of the C code and more about documentation on the scheduling formats BB crond supports. Thank you, *John Greg Hossbach* VCP6.5-DCV, VCP6-DCV Sr. Engineer, DevOps @ Tail Light ? https://calendly.com/john-hossbach -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonessyue at qnap.com Fri Jan 26 03:58:18 2024 From: jonessyue at qnap.com (=?iso-2022-jp?B?Sm9uZXMgU3l1ZSAbJEJpLVhnPSEbKEI=?=) Date: Fri, 26 Jan 2024 03:58:18 +0000 Subject: BusyBox crond format help In-Reply-To: References: Message-ID: > Originally, I was hoping to find that crond supported "H" (the random value in cron). It looks like 'H' token for random/hashed time is a special extension and only supported in Jenkins cron by far: https://www.jenkins.io/doc/book/pipeline/syntax/#cron-syntax https://github.com/jenkinsci/jenkins/commit/a31a186b https://issues.jenkins.io/browse/JENKINS-17311 https://en.wikipedia.org/wiki/Cron#Non-standard_characters After poking around man pages and source code, busybox cron and other alternatives looks like do not support 'H' yet: Vixie cron: https://man7.org/linux/man-pages/man5/crontab.5.html cronie: https://linux.die.net/man/5/crontab GNU mcron: https://www.gnu.org/software/mcron/manual/mcron.html -- Regards, Jones Syue | ??? QNAP Systems, Inc. From jonessyue at qnap.com Fri Jan 26 07:33:56 2024 From: jonessyue at qnap.com (=?iso-2022-jp?B?Sm9uZXMgU3l1ZSAbJEJpLVhnPSEbKEI=?=) Date: Fri, 26 Jan 2024 07:33:56 +0000 Subject: BusyBox crond format help In-Reply-To: References: Message-ID: Found a link has alternative examples might help, prepend a sleep with random intervals before starting a job: https://stackoverflow.com/questions/9049460/cron-jobs-and-random-times-within-given-hours -- Regards, Jones Syue | ??? QNAP Systems, Inc. From john.hossbach at taillight.com Fri Jan 26 14:58:54 2024 From: john.hossbach at taillight.com (John Hossbach) Date: Fri, 26 Jan 2024 08:58:54 -0600 Subject: BusyBox crond format help In-Reply-To: References: Message-ID: Thank you so much! Also finally remembered my C char * from being mothballed and now the code makes sense. ha. I like the idea of sleep random! On Fri, Jan 26, 2024, 1:34?AM Jones Syue ??? wrote: > Found a link has alternative examples might help, > prepend a sleep with random intervals before starting a job: > > https://stackoverflow.com/questions/9049460/cron-jobs-and-random-times-within-given-hours > > -- > > Regards, > Jones Syue | ??? > QNAP Systems, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonessyue at qnap.com Mon Jan 29 03:27:48 2024 From: jonessyue at qnap.com (=?iso-2022-jp?B?Sm9uZXMgU3l1ZSAbJEJpLVhnPSEbKEI=?=) Date: Mon, 29 Jan 2024 03:27:48 +0000 Subject: [PATCH] crond: log5 fix typo, replace log level '4' with '5' Message-ID: Hello list, Attached is a patch to fix a typo in crond.c log5(), please take a look and review, thank you :) -- Regards, Jones Syue | ??? QNAP Systems, Inc. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: 0001-crond-log5-fix-typo-replace-log-level-4-with-5.txt URL: