diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-19 20:08:19 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-19 20:08:19 +0000 |
| commit | d257fb5763cce5da033d9378f7db02f3a0793230 (patch) | |
| tree | 1ff6d98e68b57bb1539321b992fb389652c3f98b | |
| parent | 0f02f900a2fb27f9627565a5f5ee9282a074fa53 (diff) | |
| download | busybox-w32-d257fb5763cce5da033d9378f7db02f3a0793230.tar.gz busybox-w32-d257fb5763cce5da033d9378f7db02f3a0793230.tar.bz2 busybox-w32-d257fb5763cce5da033d9378f7db02f3a0793230.zip | |
dd: fix skip= parse error (spotted by Dirk Clemens <develop@cle-mens.de>)
git-svn-id: svn://busybox.net/trunk/busybox@18500 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | coreutils/dd.c | 49 | ||||
| -rw-r--r-- | shell/README.job | 70 |
2 files changed, 92 insertions, 27 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 8b374aa8b..797aabdd9 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
| @@ -58,7 +58,7 @@ static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs, | |||
| 58 | return 1; | 58 | return 1; |
| 59 | if (n == obs) | 59 | if (n == obs) |
| 60 | G.out_full++; | 60 | G.out_full++; |
| 61 | else if (n > 0) | 61 | else if (n) /* > 0 */ |
| 62 | G.out_part++; | 62 | G.out_part++; |
| 63 | return 0; | 63 | return 0; |
| 64 | } | 64 | } |
| @@ -73,10 +73,10 @@ int dd_main(int argc, char **argv); | |||
| 73 | int dd_main(int argc, char **argv) | 73 | int dd_main(int argc, char **argv) |
| 74 | { | 74 | { |
| 75 | enum { | 75 | enum { |
| 76 | sync_flag = 1 << 0, | 76 | SYNC_FLAG = 1 << 0, |
| 77 | noerror = 1 << 1, | 77 | NOERROR = 1 << 1, |
| 78 | trunc_flag = 1 << 2, | 78 | TRUNC_FLAG = 1 << 2, |
| 79 | twobufs_flag = 1 << 3, | 79 | TWOBUFS_FLAG = 1 << 3, |
| 80 | }; | 80 | }; |
| 81 | static const char * const keywords[] = { | 81 | static const char * const keywords[] = { |
| 82 | "bs=", "count=", "seek=", "skip=", "if=", "of=", | 82 | "bs=", "count=", "seek=", "skip=", "if=", "of=", |
| @@ -98,10 +98,10 @@ int dd_main(int argc, char **argv) | |||
| 98 | OP_conv, | 98 | OP_conv, |
| 99 | OP_conv_notrunc, | 99 | OP_conv_notrunc, |
| 100 | OP_conv_sync, | 100 | OP_conv_sync, |
| 101 | OP_conv_noerror, | 101 | OP_conv_NOERROR, |
| 102 | #endif | 102 | #endif |
| 103 | }; | 103 | }; |
| 104 | int flags = trunc_flag; | 104 | int flags = TRUNC_FLAG; |
| 105 | size_t oc = 0, ibs = 512, obs = 512; | 105 | size_t oc = 0, ibs = 512, obs = 512; |
| 106 | ssize_t n, w; | 106 | ssize_t n, w; |
| 107 | off_t seek = 0, skip = 0, count = OFF_T_MAX; | 107 | off_t seek = 0, skip = 0, count = OFF_T_MAX; |
| @@ -152,23 +152,23 @@ int dd_main(int argc, char **argv) | |||
| 152 | while (1) { | 152 | while (1) { |
| 153 | /* find ',', replace them with nil so we can use arg for | 153 | /* find ',', replace them with nil so we can use arg for |
| 154 | * index_in_str_array without copying. | 154 | * index_in_str_array without copying. |
| 155 | * We rely on arg being non-null, else strstr would fault. | 155 | * We rely on arg being non-null, else strchr would fault. |
| 156 | */ | 156 | */ |
| 157 | key = strstr(arg, ","); | 157 | key = strchr(arg, ','); |
| 158 | if (key) | 158 | if (key) |
| 159 | *key = '\0'; | 159 | *key = '\0'; |
| 160 | what = index_in_str_array(keywords, arg) + 1; | 160 | what = index_in_str_array(keywords, arg) + 1; |
| 161 | if (what < OP_conv_notrunc) | 161 | if (what < OP_conv_notrunc) |
| 162 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); | 162 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); |
| 163 | if (what == OP_conv_notrunc) | 163 | if (what == OP_conv_notrunc) |
| 164 | flags &= ~trunc_flag; | 164 | flags &= ~TRUNC_FLAG; |
| 165 | if (what == OP_conv_sync) | 165 | if (what == OP_conv_sync) |
| 166 | flags |= sync_flag; | 166 | flags |= SYNC_FLAG; |
| 167 | if (what == OP_conv_noerror) | 167 | if (what == OP_conv_NOERROR) |
| 168 | flags |= noerror; | 168 | flags |= NOERROR; |
| 169 | if (!key) /* no ',' left, so this was the last specifier */ | 169 | if (!key) /* no ',' left, so this was the last specifier */ |
| 170 | break; | 170 | break; |
| 171 | arg += key - arg + 1; /* skip this keyword plus ',' */ | 171 | arg = key + 1; /* skip this keyword and ',' */ |
| 172 | } | 172 | } |
| 173 | continue; | 173 | continue; |
| 174 | } | 174 | } |
| @@ -186,7 +186,7 @@ int dd_main(int argc, char **argv) | |||
| 186 | seek = XATOU_SFX(arg, dd_suffixes); | 186 | seek = XATOU_SFX(arg, dd_suffixes); |
| 187 | continue; | 187 | continue; |
| 188 | } | 188 | } |
| 189 | if (what == skip) { | 189 | if (what == OP_skip) { |
| 190 | skip = XATOU_SFX(arg, dd_suffixes); | 190 | skip = XATOU_SFX(arg, dd_suffixes); |
| 191 | continue; | 191 | continue; |
| 192 | } | 192 | } |
| @@ -200,7 +200,7 @@ int dd_main(int argc, char **argv) | |||
| 200 | //XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever | 200 | //XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever |
| 201 | ibuf = obuf = xmalloc(ibs); | 201 | ibuf = obuf = xmalloc(ibs); |
| 202 | if (ibs != obs) { | 202 | if (ibs != obs) { |
| 203 | flags |= twobufs_flag; | 203 | flags |= TWOBUFS_FLAG; |
| 204 | obuf = xmalloc(obs); | 204 | obuf = xmalloc(obs); |
| 205 | } | 205 | } |
| 206 | if (infile != NULL) | 206 | if (infile != NULL) |
| @@ -212,12 +212,12 @@ int dd_main(int argc, char **argv) | |||
| 212 | if (outfile != NULL) { | 212 | if (outfile != NULL) { |
| 213 | int oflag = O_WRONLY | O_CREAT; | 213 | int oflag = O_WRONLY | O_CREAT; |
| 214 | 214 | ||
| 215 | if (!seek && (flags & trunc_flag)) | 215 | if (!seek && (flags & TRUNC_FLAG)) |
| 216 | oflag |= O_TRUNC; | 216 | oflag |= O_TRUNC; |
| 217 | 217 | ||
| 218 | ofd = xopen(outfile, oflag); | 218 | ofd = xopen(outfile, oflag); |
| 219 | 219 | ||
| 220 | if (seek && (flags & trunc_flag)) { | 220 | if (seek && (flags & TRUNC_FLAG)) { |
| 221 | if (ftruncate(ofd, seek * obs) < 0) { | 221 | if (ftruncate(ofd, seek * obs) < 0) { |
| 222 | struct stat st; | 222 | struct stat st; |
| 223 | 223 | ||
| @@ -247,13 +247,13 @@ int dd_main(int argc, char **argv) | |||
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | while (G.in_full + G.in_part != count) { | 249 | while (G.in_full + G.in_part != count) { |
| 250 | if (flags & noerror) /* Pre-zero the buffer when for noerror */ | 250 | if (flags & NOERROR) /* Pre-zero the buffer when for NOERROR */ |
| 251 | memset(ibuf, '\0', ibs); | 251 | memset(ibuf, '\0', ibs); |
| 252 | n = safe_read(ifd, ibuf, ibs); | 252 | n = safe_read(ifd, ibuf, ibs); |
| 253 | if (n == 0) | 253 | if (n == 0) |
| 254 | break; | 254 | break; |
| 255 | if (n < 0) { | 255 | if (n < 0) { |
| 256 | if (flags & noerror) { | 256 | if (flags & NOERROR) { |
| 257 | n = ibs; | 257 | n = ibs; |
| 258 | bb_perror_msg("%s", infile); | 258 | bb_perror_msg("%s", infile); |
| 259 | } else | 259 | } else |
| @@ -263,12 +263,12 @@ int dd_main(int argc, char **argv) | |||
| 263 | G.in_full++; | 263 | G.in_full++; |
| 264 | else { | 264 | else { |
| 265 | G.in_part++; | 265 | G.in_part++; |
| 266 | if (flags & sync_flag) { | 266 | if (flags & SYNC_FLAG) { |
| 267 | memset(ibuf + n, '\0', ibs - n); | 267 | memset(ibuf + n, '\0', ibs - n); |
| 268 | n = ibs; | 268 | n = ibs; |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
| 271 | if (flags & twobufs_flag) { | 271 | if (flags & TWOBUFS_FLAG) { |
| 272 | char *tmp = ibuf; | 272 | char *tmp = ibuf; |
| 273 | while (n) { | 273 | while (n) { |
| 274 | size_t d = obs - oc; | 274 | size_t d = obs - oc; |
| @@ -285,9 +285,8 @@ int dd_main(int argc, char **argv) | |||
| 285 | oc = 0; | 285 | oc = 0; |
| 286 | } | 286 | } |
| 287 | } | 287 | } |
| 288 | } else | 288 | } else if (write_and_stats(ofd, ibuf, n, obs, outfile)) |
| 289 | if (write_and_stats(ofd, ibuf, n, obs, outfile)) | 289 | goto out_status; |
| 290 | goto out_status; | ||
| 291 | } | 290 | } |
| 292 | 291 | ||
| 293 | if (ENABLE_FEATURE_DD_IBS_OBS && oc) { | 292 | if (ENABLE_FEATURE_DD_IBS_OBS && oc) { |
diff --git a/shell/README.job b/shell/README.job index b29d31588..7e262b489 100644 --- a/shell/README.job +++ b/shell/README.job | |||
| @@ -2,8 +2,12 @@ strace of "sleep 1 | sleep 2" being run from interactive bash 3.0 | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | Synopsis: | 4 | Synopsis: |
| 5 | open /dev/tty [, if fails, open ttyname(0)]; close /* helps re-establish ctty */ | ||
| 5 | get current signal mask | 6 | get current signal mask |
| 6 | install default handlers for GHLD QUIT TERM | 7 | TCGETS on fd# 0 |
| 8 | TCGETS on fd# 2 /* NB: if returns ENOTTY (2>/dev/null), sh seems to disable job control, | ||
| 9 | does not show prompt, but still executes cmds from fd# 0 */ | ||
| 10 | install default handlers for CHLD QUIT TERM | ||
| 7 | install common handler for HUP INT ILL TRAP ABRT FPE BUS SEGV SYS PIPE ALRM TERM XCPU XFSZ VTALRM USR1 USR2 | 11 | install common handler for HUP INT ILL TRAP ABRT FPE BUS SEGV SYS PIPE ALRM TERM XCPU XFSZ VTALRM USR1 USR2 |
| 8 | ignore QUIT | 12 | ignore QUIT |
| 9 | install handler for INT | 13 | install handler for INT |
| @@ -34,11 +38,73 @@ get our pprocess group | |||
| 34 | signal followed by a SIGCONT signal will be sent to each process | 38 | signal followed by a SIGCONT signal will be sent to each process |
| 35 | in the newly-orphaned process group. | 39 | in the newly-orphaned process group. |
| 36 | ... | 40 | ... |
| 37 | 41 | dup stderr to fd# 255 | |
| 42 | move ourself to our own process group | ||
| 43 | block CHLD TSTP TTIN TTOU | ||
| 44 | set tty's (255, stderr's) foreground process group to our group | ||
| 45 | allow all signals | ||
| 46 | mark 255 CLOEXEC | ||
| 47 | set CHLD handler | ||
| 48 | get signal mask | ||
| 49 | get fd#0 flags | ||
| 50 | get signal mask | ||
| 51 | set INT handler | ||
| 52 | block CHLD TSTP TTIN TTOU | ||
| 53 | set fd #255 foreground process group to our group | ||
| 54 | allow all signals | ||
| 55 | set INT handler | ||
| 56 | block all signals | ||
| 57 | allow all signals | ||
| 58 | block INT | ||
| 59 | allow all signals | ||
| 60 | lotsa sigactions: set INT,ALRM,WINCH handlers, ignore TERM,QUIT,TSTP,TTOU,TTIN | ||
| 61 | block all signals | ||
| 62 | allow all signals | ||
| 63 | block all signals | ||
| 64 | allow all signals | ||
| 65 | block all signals | ||
| 66 | allow all signals | ||
| 67 | read "sleep 1 | sleep 2\n" | ||
| 68 | block INT | ||
| 69 | TCSETSW on fd# 0 | ||
| 70 | allow all signals | ||
| 71 | lotsa sigactions: set INT,ALRM,WINCH handlers, ignore TERM,QUIT,TSTP,TTOU,TTIN | ||
| 72 | block CHLD | ||
| 73 | pipe([4, 5]) /* oops seems I lost another pipe() in editing... */ | ||
| 74 | fork child #1 | ||
| 75 | put child in it's own process group | ||
| 76 | block only CHLD | ||
| 77 | close(5) | ||
| 78 | block only INT CHLD | ||
| 79 | fork child #2 | ||
| 80 | put child in the same process group as first one | ||
| 81 | block only CHLD | ||
| 82 | close(4) | ||
| 83 | block only CHLD | ||
| 84 | block only CHLD TSTP TTIN TTOU | ||
| 85 | set fd# 255 foreground process group to first child's one | ||
| 86 | block only CHLD | ||
| 87 | block only CHLD | ||
| 88 | block only CHLD | ||
| 89 | wait4 for children to die or stop - first child exits | ||
| 90 | wait4 for children to die or stop - second child exits | ||
| 91 | block CHLD TSTP TTIN TTOU | ||
| 92 | set fd# 255 foreground process group to our own one | ||
| 93 | block only CHLD | ||
| 94 | block only CHLD | ||
| 95 | block nothing | ||
| 96 | --- SIGCHLD (Child exited) @ 0 (0) --- | ||
| 97 | wait for it - no child (already waited for) | ||
| 98 | sigreturn() | ||
| 99 | read signal mask | ||
| 100 | lotsa sigactions... | ||
| 101 | read next command | ||
| 38 | 102 | ||
| 39 | 103 | ||
| 40 | execve("/bin/sh", ["sh"], [/* 34 vars */]) = 0 | 104 | execve("/bin/sh", ["sh"], [/* 34 vars */]) = 0 |
| 41 | rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0 | 105 | rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0 |
| 106 | ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 | ||
| 107 | ioctl(2, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 | ||
| 42 | rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0 | 108 | rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0 |
| 43 | rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_DFL}, 8) = 0 | 109 | rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_DFL}, 8) = 0 |
| 44 | rt_sigaction(SIGTERM, {SIG_DFL}, {SIG_DFL}, 8) = 0 | 110 | rt_sigaction(SIGTERM, {SIG_DFL}, {SIG_DFL}, 8) = 0 |
