diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:28:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-17 14:28:53 +0000 |
commit | cb448fe01bbe75ef31c3190e8b63b0e1a320ffb4 (patch) | |
tree | 9757477193c1b8f3be9a772cabfb1ef92639240e | |
parent | ffae845cfd0a0b9872827d806984841d4cfee104 (diff) | |
download | busybox-w32-cb448fe01bbe75ef31c3190e8b63b0e1a320ffb4.tar.gz busybox-w32-cb448fe01bbe75ef31c3190e8b63b0e1a320ffb4.tar.bz2 busybox-w32-cb448fe01bbe75ef31c3190e8b63b0e1a320ffb4.zip |
libbb: introduce and use xrename and rename_or_warn.
-rw-r--r-- | editors/patch.c | 5 | ||||
-rw-r--r-- | editors/sed.c | 3 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 5 | ||||
-rw-r--r-- | libbb/xfuncs.c | 26 | ||||
-rw-r--r-- | miscutils/crond.c | 10 | ||||
-rw-r--r-- | networking/sendmail.c | 5 | ||||
-rw-r--r-- | runit/runsv.c | 10 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 4 | ||||
-rw-r--r-- | util-linux/mdev.c | 2 |
10 files changed, 33 insertions, 39 deletions
diff --git a/editors/patch.c b/editors/patch.c index 07fa5cfaf..1b283a133 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -150,10 +150,7 @@ int patch_main(int argc, char **argv) | |||
150 | backup_filename = xmalloc(strlen(new_filename) + 6); | 150 | backup_filename = xmalloc(strlen(new_filename) + 6); |
151 | strcpy(backup_filename, new_filename); | 151 | strcpy(backup_filename, new_filename); |
152 | strcat(backup_filename, ".orig"); | 152 | strcat(backup_filename, ".orig"); |
153 | if (rename(new_filename, backup_filename) == -1) { | 153 | xrename(new_filename, backup_filename); |
154 | bb_perror_msg_and_die("cannot create file %s", | ||
155 | backup_filename); | ||
156 | } | ||
157 | dst_stream = xfopen(new_filename, "w"); | 154 | dst_stream = xfopen(new_filename, "w"); |
158 | } | 155 | } |
159 | 156 | ||
diff --git a/editors/sed.c b/editors/sed.c index 433418253..e55bcafc4 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1340,8 +1340,7 @@ int sed_main(int argc, char **argv) | |||
1340 | 1340 | ||
1341 | G.nonstdout = stdout; | 1341 | G.nonstdout = stdout; |
1342 | /* unlink(argv[i]); */ | 1342 | /* unlink(argv[i]); */ |
1343 | // FIXME: error check / message? | 1343 | xrename(G.outname, argv[i]); |
1344 | rename(G.outname, argv[i]); | ||
1345 | free(G.outname); | 1344 | free(G.outname); |
1346 | G.outname = NULL; | 1345 | G.outname = NULL; |
1347 | } | 1346 | } |
diff --git a/include/libbb.h b/include/libbb.h index 67afcdf94..2af89df95 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -298,6 +298,8 @@ int xopen(const char *pathname, int flags); | |||
298 | int xopen3(const char *pathname, int flags, int mode); | 298 | int xopen3(const char *pathname, int flags, int mode); |
299 | int open_or_warn(const char *pathname, int flags); | 299 | int open_or_warn(const char *pathname, int flags); |
300 | int open3_or_warn(const char *pathname, int flags, int mode); | 300 | int open3_or_warn(const char *pathname, int flags, int mode); |
301 | void xrename(const char *oldpath, const char *newpath); | ||
302 | int rename_or_warn(const char *oldpath, const char *newpath); | ||
301 | off_t xlseek(int fd, off_t offset, int whence); | 303 | off_t xlseek(int fd, off_t offset, int whence); |
302 | off_t fdlength(int fd); | 304 | off_t fdlength(int fd); |
303 | 305 | ||
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 98339c930..1567d89be 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -98,11 +98,6 @@ int wait4pid(int pid) | |||
98 | if (WIFSIGNALED(status)) | 98 | if (WIFSIGNALED(status)) |
99 | return WTERMSIG(status) + 1000; | 99 | return WTERMSIG(status) + 1000; |
100 | return 0; | 100 | return 0; |
101 | if (WIFEXITED(status)) | ||
102 | return WEXITSTATUS(status); | ||
103 | if (WIFSIGNALED(status)) | ||
104 | return WTERMSIG(status) + 1000; | ||
105 | return 0; | ||
106 | } | 101 | } |
107 | 102 | ||
108 | #if ENABLE_FEATURE_PREFER_APPLETS | 103 | #if ENABLE_FEATURE_PREFER_APPLETS |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 8dd414d6a..b4c059f20 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -146,18 +146,32 @@ int open_or_warn(const char *pathname, int flags) | |||
146 | return open3_or_warn(pathname, flags, 0666); | 146 | return open3_or_warn(pathname, flags, 0666); |
147 | } | 147 | } |
148 | 148 | ||
149 | void xpipe(int filedes[2]) | ||
150 | { | ||
151 | if (pipe(filedes)) | ||
152 | bb_perror_msg_and_die("can't create pipe"); | ||
153 | } | ||
154 | |||
155 | void xunlink(const char *pathname) | 149 | void xunlink(const char *pathname) |
156 | { | 150 | { |
157 | if (unlink(pathname)) | 151 | if (unlink(pathname)) |
158 | bb_perror_msg_and_die("can't remove file '%s'", pathname); | 152 | bb_perror_msg_and_die("can't remove file '%s'", pathname); |
159 | } | 153 | } |
160 | 154 | ||
155 | void xrename(const char *oldpath, const char *newpath) | ||
156 | { | ||
157 | if (rename(oldpath, newpath)) | ||
158 | bb_perror_msg_and_die("can't move '%s' to '%s'", oldpath, newpath); | ||
159 | } | ||
160 | |||
161 | int rename_or_warn(const char *oldpath, const char *newpath) | ||
162 | { | ||
163 | int n = rename(oldpath, newpath); | ||
164 | if (n) | ||
165 | bb_perror_msg("can't move '%s' to '%s'", oldpath, newpath); | ||
166 | return n; | ||
167 | } | ||
168 | |||
169 | void xpipe(int filedes[2]) | ||
170 | { | ||
171 | if (pipe(filedes)) | ||
172 | bb_perror_msg_and_die("can't create pipe"); | ||
173 | } | ||
174 | |||
161 | // Turn on nonblocking I/O on a fd | 175 | // Turn on nonblocking I/O on a fd |
162 | int ndelay_on(int fd) | 176 | int ndelay_on(int fd) |
163 | { | 177 | { |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 0df143ae7..9721a8a9a 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -548,7 +548,7 @@ static void CheckUpdates(void) | |||
548 | 548 | ||
549 | fi = fopen(CRONUPDATE, "r"); | 549 | fi = fopen(CRONUPDATE, "r"); |
550 | if (fi != NULL) { | 550 | if (fi != NULL) { |
551 | remove(CRONUPDATE); | 551 | unlink(CRONUPDATE); |
552 | while (fgets(buf, sizeof(buf), fi) != NULL) { | 552 | while (fgets(buf, sizeof(buf), fi) != NULL) { |
553 | SynchronizeFile(strtok(buf, " \t\r\n")); | 553 | SynchronizeFile(strtok(buf, " \t\r\n")); |
554 | } | 554 | } |
@@ -579,7 +579,7 @@ static void SynchronizeDir(void) | |||
579 | * scan directory and add associated users | 579 | * scan directory and add associated users |
580 | */ | 580 | */ |
581 | 581 | ||
582 | remove(CRONUPDATE); | 582 | unlink(CRONUPDATE); |
583 | if (chdir(CDir) < 0) { | 583 | if (chdir(CDir) < 0) { |
584 | crondlog("\311cannot find %s\n", CDir); | 584 | crondlog("\311cannot find %s\n", CDir); |
585 | } | 585 | } |
@@ -814,7 +814,7 @@ ForkJob(const char *user, CronLine * line, int mailFd, | |||
814 | crondlog("\024cannot fork\n"); | 814 | crondlog("\024cannot fork\n"); |
815 | line->cl_Pid = 0; | 815 | line->cl_Pid = 0; |
816 | if (mail_filename) { | 816 | if (mail_filename) { |
817 | remove(mail_filename); | 817 | unlink(mail_filename); |
818 | } | 818 | } |
819 | } else if (mail_filename) { | 819 | } else if (mail_filename) { |
820 | /* PARENT, FORK SUCCESS | 820 | /* PARENT, FORK SUCCESS |
@@ -823,7 +823,7 @@ ForkJob(const char *user, CronLine * line, int mailFd, | |||
823 | char mailFile2[128]; | 823 | char mailFile2[128]; |
824 | 824 | ||
825 | snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid); | 825 | snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid); |
826 | rename(mail_filename, mailFile2); | 826 | rename(mail_filename, mailFile2); // TODO: xrename? |
827 | } | 827 | } |
828 | /* | 828 | /* |
829 | * Close the mail file descriptor.. we can't just leave it open in | 829 | * Close the mail file descriptor.. we can't just leave it open in |
@@ -896,7 +896,7 @@ static void EndJob(const char *user, CronLine * line) | |||
896 | */ | 896 | */ |
897 | 897 | ||
898 | mailFd = open(mailFile, O_RDONLY); | 898 | mailFd = open(mailFile, O_RDONLY); |
899 | remove(mailFile); | 899 | unlink(mailFile); |
900 | if (mailFd < 0) { | 900 | if (mailFd < 0) { |
901 | return; | 901 | return; |
902 | } | 902 | } |
diff --git a/networking/sendmail.c b/networking/sendmail.c index fa995abf4..b2fbc5a7a 100644 --- a/networking/sendmail.c +++ b/networking/sendmail.c | |||
@@ -512,10 +512,7 @@ int sendgetmail_main(int argc, char **argv) | |||
512 | if (fd < 0) | 512 | if (fd < 0) |
513 | bb_perror_msg_and_die("cannot create unique file"); | 513 | bb_perror_msg_and_die("cannot create unique file"); |
514 | close(fd); | 514 | close(fd); |
515 | if (rename(tmp_name, new_name) < 0) { | 515 | xrename(tmp_name, new_name); |
516 | // something is very wrong | ||
517 | bb_perror_msg_and_die("cannot move %s to %s", tmp_name, new_name); | ||
518 | } | ||
519 | } | 516 | } |
520 | 517 | ||
521 | // delete message from server | 518 | // delete message from server |
diff --git a/runit/runsv.c b/runit/runsv.c index 02271d68b..02dcf50ca 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -157,16 +157,6 @@ static int open_trunc_or_warn(const char *name) | |||
157 | return fd; | 157 | return fd; |
158 | } | 158 | } |
159 | 159 | ||
160 | static int rename_or_warn(const char *old, const char *new) | ||
161 | { | ||
162 | if (rename(old, new) == -1) { | ||
163 | bb_perror_msg("%s: warning: cannot rename %s to %s", | ||
164 | dir, old, new); | ||
165 | return -1; | ||
166 | } | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | static void update_status(struct svdir *s) | 160 | static void update_status(struct svdir *s) |
171 | { | 161 | { |
172 | ssize_t sz; | 162 | ssize_t sz; |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index c6e057138..dc5e6250a 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -344,10 +344,10 @@ static void log_locally(time_t now, char *msg) | |||
344 | sprintf(newFile, "%s.%d", G.logFilePath, i); | 344 | sprintf(newFile, "%s.%d", G.logFilePath, i); |
345 | if (i == 0) break; | 345 | if (i == 0) break; |
346 | sprintf(oldFile, "%s.%d", G.logFilePath, --i); | 346 | sprintf(oldFile, "%s.%d", G.logFilePath, --i); |
347 | rename(oldFile, newFile); | 347 | xrename(oldFile, newFile); |
348 | } | 348 | } |
349 | /* newFile == "f.0" now */ | 349 | /* newFile == "f.0" now */ |
350 | rename(G.logFilePath, newFile); | 350 | xrename(G.logFilePath, newFile); |
351 | fl.l_type = F_UNLCK; | 351 | fl.l_type = F_UNLCK; |
352 | fcntl(G.logFD, F_SETLKW, &fl); | 352 | fcntl(G.logFD, F_SETLKW, &fl); |
353 | close(G.logFD); | 353 | close(G.logFD); |
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index a18fc0916..2bb022476 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
@@ -209,7 +209,7 @@ static void make_device(char *path, int delete) | |||
209 | } else | 209 | } else |
210 | dest = alias; | 210 | dest = alias; |
211 | 211 | ||
212 | rename(device_name, dest); | 212 | rename(device_name, dest); // TODO: xrename? |
213 | symlink(dest, device_name); | 213 | symlink(dest, device_name); |
214 | 214 | ||
215 | if (alias != dest) | 215 | if (alias != dest) |