bin/125680: atacontrol(8): atacontrol depends on executable in
/usr
Antoine Brodin
antoine at FreeBSD.org
Mon Jul 21 08:33:40 UTC 2008
On Mon, Jul 21, 2008 at 10:04 AM, Garrett Cooper <yanefbsd at gmail.com> wrote:
> Antoine,
> You're right. I flip-flopped parent and child there in my
> original statement.
> I also saw the async ('&') terminal command.
> But what is ultimately gained by forking another process to read
> a device other than just resuming control for the terminal to the
> user? It seems like all this does is create potential for additional
> zombie processes on the system...
> Just as an experiment, could you insert another printf or some
> statement to ensure that the read is deterministically completed every
> time?
I have attached a patch with an extra printf.
I guess that the dd/read is done in the background because it can take
hours, so the user doesn't have to wait hours to have his terminal
back.
Cheers,
Antoine
-------------- next part --------------
Index: sbin/atacontrol/atacontrol.c
===================================================================
RCS file: /home/ncvs/src/sbin/atacontrol/atacontrol.c,v
retrieving revision 1.48
diff -u -p -r1.48 atacontrol.c
--- sbin/atacontrol/atacontrol.c 15 May 2008 01:25:29 -0000 1.48
+++ sbin/atacontrol/atacontrol.c 21 Jul 2008 08:19:46 -0000
@@ -37,6 +37,7 @@
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <unistd.h>
static const char *
mode2str(int mode)
@@ -517,12 +518,31 @@ main(int argc, char **argv)
if (ioctl(fd, IOCATARAIDREBUILD, &array) < 0)
warn("ioctl(IOCATARAIDREBUILD)");
else {
- char buffer[128];
- sprintf(buffer, "/usr/bin/nice -n 20 /bin/dd "
- "if=/dev/ar%d of=/dev/null bs=1m &",
- array);
- if (system(buffer))
- warn("background dd");
+ char device[64];
+ char *buffer;
+ int arfd;
+
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ nice(20);
+ snprintf(device, sizeof(device), "/dev/ar%d",
+ array);
+ if ((arfd = open(device, O_RDONLY)) == -1)
+ err(1, "open %s", device);
+ if ((buffer = malloc(1024 * 1024)) == NULL)
+ err(1, "malloc");
+ while (read(arfd, buffer, 1024 * 1024) > 0)
+ ;
+ printf("atacontrol: ar%d rebuild completed\n",
+ array);
+ free(buffer);
+ close(arfd);
+ break;
+ default:
+ break;
+ }
}
exit(EX_OK);
}
More information about the freebsd-bugs
mailing list