Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157769842
D38641.id117465.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D38641.id117465.diff
View Options
diff --git a/usr.sbin/config/main.cc b/usr.sbin/config/main.cc
--- a/usr.sbin/config/main.cc
+++ b/usr.sbin/config/main.cc
@@ -457,6 +457,8 @@
asprintf(&cp, "%s/%s", destdir, file);
else
cp = strdup(destdir);
+ if (cp == NULL)
+ err(EXIT_FAILURE, "malloc");
return (cp);
}
@@ -575,7 +577,7 @@
p += strlen(KERNCONFTAG);
fprintf(fo, "%s", p);
fclose(fo);
- moveifchanged(path("config.c.new"), path("config.c"));
+ moveifchanged("config.c.new", "config.c");
cfgfile_removeall();
}
@@ -587,6 +589,7 @@
moveifchanged(const char *from_name, const char *to_name)
{
char *p, *q;
+ char *from_path, *to_path;
int changed;
size_t tsize;
struct stat from_sb, to_sb;
@@ -594,17 +597,19 @@
changed = 0;
- if ((from_fd = open(from_name, O_RDONLY)) < 0)
+ from_path = path(from_name);
+ to_path = path(to_name);
+ if ((from_fd = open(from_path, O_RDONLY)) < 0)
err(EX_OSERR, "moveifchanged open(%s)", from_name);
- if ((to_fd = open(to_name, O_RDONLY)) < 0)
+ if ((to_fd = open(to_path, O_RDONLY)) < 0)
changed++;
if (!changed && fstat(from_fd, &from_sb) < 0)
- err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
+ err(EX_OSERR, "moveifchanged fstat(%s)", from_path);
if (!changed && fstat(to_fd, &to_sb) < 0)
- err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
+ err(EX_OSERR, "moveifchanged fstat(%s)", to_path);
if (!changed && from_sb.st_size != to_sb.st_size)
changed++;
@@ -615,23 +620,31 @@
p = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd,
(off_t)0);
if (p == MAP_FAILED)
- err(EX_OSERR, "mmap %s", from_name);
+ err(EX_OSERR, "mmap %s", from_path);
q = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd,
(off_t)0);
if (q == MAP_FAILED)
- err(EX_OSERR, "mmap %s", to_name);
+ err(EX_OSERR, "mmap %s", to_path);
changed = memcmp(p, q, tsize);
munmap(p, tsize);
munmap(q, tsize);
}
+
if (changed) {
- if (rename(from_name, to_name) < 0)
- err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
+ if (rename(from_path, to_path) < 0)
+ err(EX_OSERR, "rename(%s, %s)", from_path, to_path);
} else {
- if (unlink(from_name) < 0)
- err(EX_OSERR, "unlink(%s)", from_name);
+ if (unlink(from_path) < 0)
+ err(EX_OSERR, "unlink(%s)", from_path);
}
+
+ close(from_fd);
+ if (to_fd >= 0)
+ close(to_fd);
+
+ free(from_path);
+ free(to_path);
}
static void
diff --git a/usr.sbin/config/mkmakefile.cc b/usr.sbin/config/mkmakefile.cc
--- a/usr.sbin/config/mkmakefile.cc
+++ b/usr.sbin/config/mkmakefile.cc
@@ -184,7 +184,7 @@
}
(void) fclose(ifp);
(void) fclose(ofp);
- moveifchanged(path("Makefile.new"), path("Makefile"));
+ moveifchanged("Makefile.new", "Makefile");
}
static void
@@ -327,7 +327,7 @@
}
fprintf(ofp, "\"\\0\"\n};\n");
fclose(ofp);
- moveifchanged(path("hints.c.new"), path("hints.c"));
+ moveifchanged("hints.c.new", "hints.c");
}
/*
@@ -369,7 +369,7 @@
}
fprintf(ofp, "\"\\0\"\n};\n");
fclose(ofp);
- moveifchanged(path("env.c.new"), path("env.c"));
+ moveifchanged("env.c.new", "env.c");
}
static void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 26, 12:04 AM (9 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33519784
Default Alt Text
D38641.id117465.diff (3 KB)
Attached To
Mode
D38641: config: push path() into moveifchanged()
Attached
Detach File
Event Timeline
Log In to Comment