diff options
Diffstat (limited to 'applets')
-rw-r--r-- | applets/applet_tables.c | 16 | ||||
-rwxr-xr-x | applets/install.sh | 6 |
2 files changed, 18 insertions, 4 deletions
diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 858429ac2..b997194ad 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> |
@@ -62,6 +63,7 @@ int main(int argc, char **argv) | |||
62 | { | 63 | { |
63 | int i, j; | 64 | int i, j; |
64 | unsigned MAX_APPLET_NAME_LEN = 1; | 65 | unsigned MAX_APPLET_NAME_LEN = 1; |
66 | char tmp1[PATH_MAX], tmp2[PATH_MAX]; | ||
65 | 67 | ||
66 | // In find_applet_by_name(), before linear search, narrow it down | 68 | // In find_applet_by_name(), before linear search, narrow it down |
67 | // by looking at N "equidistant" names. With ~350 applets: | 69 | // by looking at N "equidistant" names. With ~350 applets: |
@@ -85,7 +87,8 @@ int main(int argc, char **argv) | |||
85 | 87 | ||
86 | if (!argv[1]) | 88 | if (!argv[1]) |
87 | return 1; | 89 | return 1; |
88 | i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666); | 90 | snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid()); |
91 | i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666); | ||
89 | if (i < 0) | 92 | if (i < 0) |
90 | return 1; | 93 | return 1; |
91 | dup2(i, 1); | 94 | dup2(i, 1); |
@@ -210,12 +213,21 @@ int main(int argc, char **argv) | |||
210 | // fclose(fp); | 213 | // fclose(fp); |
211 | // } | 214 | // } |
212 | // if (strcmp(line_old, line_new) != 0) { | 215 | // if (strcmp(line_old, line_new) != 0) { |
213 | fp = fopen(argv[2], "w"); | 216 | snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid()); |
217 | fp = fopen(tmp2, "w"); | ||
214 | if (!fp) | 218 | if (!fp) |
215 | return 1; | 219 | return 1; |
216 | fputs(line_new, fp); | 220 | fputs(line_new, fp); |
221 | if (fclose(fp)) | ||
222 | return 1; | ||
217 | // } | 223 | // } |
218 | } | 224 | } |
219 | 225 | ||
226 | if (fclose(stdout)) | ||
227 | return 1; | ||
228 | if (rename(tmp1, argv[1])) | ||
229 | return 1; | ||
230 | if (rename(tmp2, argv[2])) | ||
231 | return 1; | ||
220 | return 0; | 232 | return 0; |
221 | } | 233 | } |
diff --git a/applets/install.sh b/applets/install.sh index c75a78e9d..9aede0f53 100755 --- a/applets/install.sh +++ b/applets/install.sh | |||
@@ -5,7 +5,9 @@ export LC_CTYPE=POSIX | |||
5 | 5 | ||
6 | prefix=$1 | 6 | prefix=$1 |
7 | if [ -z "$prefix" ]; then | 7 | if [ -z "$prefix" ]; then |
8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]" | 8 | echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]" |
9 | echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none" | ||
10 | echo " OPTS is one or more of: --cleanup --noclobber" | ||
9 | exit 1 | 11 | exit 1 |
10 | fi | 12 | fi |
11 | shift # Keep only remaining options | 13 | shift # Keep only remaining options |
@@ -32,7 +34,7 @@ while [ ${#} -gt 0 ]; do | |||
32 | --sw-sh-sym) scriptwrapper="y"; linkopts="-fs";; | 34 | --sw-sh-sym) scriptwrapper="y"; linkopts="-fs";; |
33 | --cleanup) cleanup="1";; | 35 | --cleanup) cleanup="1";; |
34 | --noclobber) noclobber="1";; | 36 | --noclobber) noclobber="1";; |
35 | "") h="";; | 37 | --none) h="";; |
36 | *) echo "Unknown install option: $1"; exit 1;; | 38 | *) echo "Unknown install option: $1"; exit 1;; |
37 | esac | 39 | esac |
38 | shift | 40 | shift |