aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--applets/applet_tables.c16
2 files changed, 15 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 03a57adf3..9d7a0a36c 100644
--- a/Makefile
+++ b/Makefile
@@ -368,7 +368,7 @@ gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c)
368# we depend on scripts_basic, since scripts/basic/fixdep 368# we depend on scripts_basic, since scripts/basic/fixdep
369# must be built before any other host prog 369# must be built before any other host prog
370PHONY += applets_dir 370PHONY += applets_dir
371applets_dir: scripts_basic gen_build_files 371applets_dir: scripts_basic gen_build_files include/config/MARKER
372 $(Q)$(MAKE) $(build)=applets 372 $(Q)$(MAKE) $(build)=applets
373 373
374applets/%: applets_dir ; 374applets/%: applets_dir ;
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index ef911a43b..e3d10c83f 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
@@ -10,6 +10,7 @@
10#include <sys/types.h> 10#include <sys/types.h>
11#include <sys/stat.h> 11#include <sys/stat.h>
12#include <fcntl.h> 12#include <fcntl.h>
13#include <limits.h>
13#include <stdlib.h> 14#include <stdlib.h>
14#include <string.h> 15#include <string.h>
15#include <stdio.h> 16#include <stdio.h>
@@ -61,6 +62,7 @@ static int str_isalnum_(const char *s)
61int main(int argc, char **argv) 62int main(int argc, char **argv)
62{ 63{
63 int i, j; 64 int i, j;
65 char tmp1[PATH_MAX], tmp2[PATH_MAX];
64 66
65 // In find_applet_by_name(), before linear search, narrow it down 67 // In find_applet_by_name(), before linear search, narrow it down
66 // by looking at N "equidistant" names. With ~350 applets: 68 // by looking at N "equidistant" names. With ~350 applets:
@@ -84,7 +86,8 @@ int main(int argc, char **argv)
84 86
85 if (!argv[1]) 87 if (!argv[1])
86 return 1; 88 return 1;
87 i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666); 89 snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
90 i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);
88 if (i < 0) 91 if (i < 0)
89 return 1; 92 return 1;
90 dup2(i, 1); 93 dup2(i, 1);
@@ -209,12 +212,21 @@ int main(int argc, char **argv)
209// fclose(fp); 212// fclose(fp);
210// } 213// }
211// if (strcmp(line_old, line_new) != 0) { 214// if (strcmp(line_old, line_new) != 0) {
212 fp = fopen(argv[2], "w"); 215 snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid());
216 fp = fopen(tmp2, "w");
213 if (!fp) 217 if (!fp)
214 return 1; 218 return 1;
215 fputs(line_new, fp); 219 fputs(line_new, fp);
220 if (fclose(fp))
221 return 1;
216// } 222// }
217 } 223 }
218 224
225 if (fclose(stdout))
226 return 1;
227 if (rename(tmp1, argv[1]))
228 return 1;
229 if (rename(tmp2, argv[2]))
230 return 1;
219 return 0; 231 return 0;
220} 232}