Page MenuHomeFreeBSD

D33671.1788185816.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D33671.1788185816.diff

Index: usr.sbin/kldxref/kldxref.c
===================================================================
--- usr.sbin/kldxref/kldxref.c
+++ usr.sbin/kldxref/kldxref.c
@@ -49,6 +49,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <stdbool.h>
#include <stdio.h>
@@ -134,7 +135,7 @@
int error;
size_t len;
u_char val;
-
+
if (dflag)
return (0);
val = len = strlen(str);
@@ -657,6 +658,32 @@
return (fdopen(fd, "w+"));
}
+static int
+copyfile(char *src, char *dst) {
+ int retval = 0;
+ int src_fd, dst_fd;
+
+ src_fd = open(src, O_RDONLY);
+ if (src_fd < 0) {
+ warn("can't open %s", src);
+ return 1;
+ }
+ dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC);
+ if (dst_fd < 0) {
+ warn("can't create %s", dst);
+ close(src_fd);
+ return 1;
+ }
+ if (copy_file_range(src_fd, NULL, dst_fd, NULL, SSIZE_MAX, 0) < 0) {
+ warn("can't copy %s to %s", src, dst);
+ retval = 1;
+ }
+
+ close(src_fd);
+ close(dst_fd);
+ return retval;
+}
+
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
static void
@@ -732,7 +759,17 @@
fclose(fxref);
fxref = NULL;
if (reccnt != 0) {
- rename(tempname, xrefname);
+ if (rename(tempname, xrefname) != 0) {
+ /* handle temp file being on a different filesystem */
+ if (errno == EXDEV) {
+ /* copyfile reports its own errors */
+ copyfile(tempname, xrefname);
+ unlink(tempname);
+ } else {
+ unlink(tempname);
+ warn("can't rename %s to %s", xrefname, tempname);
+ }
+ }
} else {
/* didn't find any entry, ignore this file */
unlink(tempname);

File Metadata

Mime Type
text/plain
Expires
Mon, Aug 31, 2:16 PM (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29491672
Default Alt Text
D33671.1788185816.diff (1 KB)

Event Timeline