mirror of
https://github.com/sheumann/hush.git
synced 2024-12-25 18:33:06 +00:00
Patch from Jason Schoon to add optional SIGUSR1 support to dd.
This commit is contained in:
parent
67d5b8b5b1
commit
c5598177bc
@ -115,6 +115,18 @@ config CONFIG_DD
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
|
||||
config CONFIG_FEATURE_DD_SIGNAL_HANDLING
|
||||
bool "Enable DD signal handling for status reporting"
|
||||
default y
|
||||
depends on CONFIG_DD
|
||||
help
|
||||
sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null& pid=$! $ kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in 10899206+0 records out
|
||||
|
||||
config CONFIG_DF
|
||||
bool "df"
|
||||
default n
|
||||
|
@ -15,9 +15,9 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h> // For FEATURE_DD_SIGNAL_HANDLING
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
@ -31,12 +31,20 @@ static const struct suffix_mult dd_suffixes[] = {
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static size_t out_full;
|
||||
static size_t out_part;
|
||||
static size_t in_full;
|
||||
static size_t in_part;
|
||||
|
||||
static void dd_output_status(int cur_signal)
|
||||
{
|
||||
fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n",
|
||||
(long)in_full, (long)in_part,
|
||||
(long)out_full, (long)out_part);
|
||||
}
|
||||
|
||||
int dd_main(int argc, char **argv)
|
||||
{
|
||||
size_t out_full = 0;
|
||||
size_t out_part = 0;
|
||||
size_t in_full = 0;
|
||||
size_t in_part = 0;
|
||||
size_t count = -1;
|
||||
size_t bs = 512;
|
||||
ssize_t n;
|
||||
@ -53,6 +61,17 @@ int dd_main(int argc, char **argv)
|
||||
const char *outfile = NULL;
|
||||
char *buf;
|
||||
|
||||
if (ENABLE_FEATURE_DD_SIGNAL_HANDLING)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = dd_output_status;
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGUSR1, &sa, 0);
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strncmp("bs=", argv[i], 3) == 0)
|
||||
bs = bb_xparse_number(argv[i]+3, dd_suffixes);
|
||||
@ -180,9 +199,7 @@ int dd_main(int argc, char **argv)
|
||||
bb_perror_msg_and_die("%s", outfile);
|
||||
}
|
||||
|
||||
fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n",
|
||||
(long)in_full, (long)in_part,
|
||||
(long)out_full, (long)out_part);
|
||||
dd_output_status(0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user