diff options
author | antoine <antoine@FreeBSD.org> | 2008-08-06 18:08:02 +0000 |
---|---|---|
committer | antoine <antoine@FreeBSD.org> | 2008-08-06 18:08:02 +0000 |
commit | 58dd6e51d2ea129c3affb5a395688f47506812fc (patch) | |
tree | 6c5c4cf73a00bc0db119729e2629bac37138aae8 /sbin | |
parent | e3e7adc95f1aaf8d34da7dabded2d3af55e5daf5 (diff) | |
download | FreeBSD-src-58dd6e51d2ea129c3affb5a395688f47506812fc.zip FreeBSD-src-58dd6e51d2ea129c3affb5a395688f47506812fc.tar.gz |
Make atacontrol(8) rebuild work when /usr is not mounted or from /rescue
PR: bin/125680
MFC after: 1 month
Tested by: Stef Walter
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/atacontrol/atacontrol.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/sbin/atacontrol/atacontrol.c b/sbin/atacontrol/atacontrol.c index 030f825..cf4a0ff 100644 --- a/sbin/atacontrol/atacontrol.c +++ b/sbin/atacontrol/atacontrol.c @@ -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,30 @@ 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; + ssize_t len; + int arfd; + + if (daemon(0, 1) == -1) + err(1, "daemon"); + 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 ((len = read(arfd, buffer, 1024 * 1024)) > 0) + ; + if (len == -1) + err(1, "read"); + else + fprintf(stderr, + "atacontrol: ar%d rebuild completed\n", + array); + free(buffer); + close(arfd); } exit(EX_OK); } |