svn commit: trunk/busybox: editors include libbb miscutils networki etc...

vda at busybox.net vda at busybox.net
Sun Feb 17 14:28:54 UTC 2008


Author: vda
Date: 2008-02-17 06:28:53 -0800 (Sun, 17 Feb 2008)
New Revision: 21044

Log:
libbb: introduce and use xrename and rename_or_warn.



Modified:
   trunk/busybox/editors/patch.c
   trunk/busybox/editors/sed.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/vfork_daemon_rexec.c
   trunk/busybox/libbb/xfuncs.c
   trunk/busybox/miscutils/crond.c
   trunk/busybox/networking/sendmail.c
   trunk/busybox/runit/runsv.c
   trunk/busybox/sysklogd/syslogd.c
   trunk/busybox/util-linux/mdev.c


Changeset:
Modified: trunk/busybox/editors/patch.c
===================================================================
--- trunk/busybox/editors/patch.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/editors/patch.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -150,10 +150,7 @@
 			backup_filename = xmalloc(strlen(new_filename) + 6);
 			strcpy(backup_filename, new_filename);
 			strcat(backup_filename, ".orig");
-			if (rename(new_filename, backup_filename) == -1) {
-				bb_perror_msg_and_die("cannot create file %s",
-						backup_filename);
-			}
+			xrename(new_filename, backup_filename);
 			dst_stream = xfopen(new_filename, "w");
 		}
 

Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/editors/sed.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -1340,8 +1340,7 @@
 
 			G.nonstdout = stdout;
 			/* unlink(argv[i]); */
-			// FIXME: error check / message?
-			rename(G.outname, argv[i]);
+			xrename(G.outname, argv[i]);
 			free(G.outname);
 			G.outname = NULL;
 		}

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/include/libbb.h	2008-02-17 14:28:53 UTC (rev 21044)
@@ -298,6 +298,8 @@
 int xopen3(const char *pathname, int flags, int mode);
 int open_or_warn(const char *pathname, int flags);
 int open3_or_warn(const char *pathname, int flags, int mode);
+void xrename(const char *oldpath, const char *newpath);
+int rename_or_warn(const char *oldpath, const char *newpath);
 off_t xlseek(int fd, off_t offset, int whence);
 off_t fdlength(int fd);
 

Modified: trunk/busybox/libbb/vfork_daemon_rexec.c
===================================================================
--- trunk/busybox/libbb/vfork_daemon_rexec.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/libbb/vfork_daemon_rexec.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -98,11 +98,6 @@
 	if (WIFSIGNALED(status))
 		return WTERMSIG(status) + 1000;
 	return 0;
-	if (WIFEXITED(status))
-		return WEXITSTATUS(status);
-	if (WIFSIGNALED(status))
-		return WTERMSIG(status) + 1000;
-	return 0;
 }
 
 #if ENABLE_FEATURE_PREFER_APPLETS

Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/libbb/xfuncs.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -146,18 +146,32 @@
 	return open3_or_warn(pathname, flags, 0666);
 }
 
+void xunlink(const char *pathname)
+{
+	if (unlink(pathname))
+		bb_perror_msg_and_die("can't remove file '%s'", pathname);
+}
+
+void xrename(const char *oldpath, const char *newpath)
+{
+	if (rename(oldpath, newpath))
+		bb_perror_msg_and_die("can't move '%s' to '%s'", oldpath, newpath);
+}
+
+int rename_or_warn(const char *oldpath, const char *newpath)
+{
+	int n = rename(oldpath, newpath);
+	if (n)
+		bb_perror_msg("can't move '%s' to '%s'", oldpath, newpath);
+	return n;
+}
+
 void xpipe(int filedes[2])
 {
 	if (pipe(filedes))
 		bb_perror_msg_and_die("can't create pipe");
 }
 
-void xunlink(const char *pathname)
-{
-	if (unlink(pathname))
-		bb_perror_msg_and_die("can't remove file '%s'", pathname);
-}
-
 // Turn on nonblocking I/O on a fd
 int ndelay_on(int fd)
 {

Modified: trunk/busybox/miscutils/crond.c
===================================================================
--- trunk/busybox/miscutils/crond.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/miscutils/crond.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -548,7 +548,7 @@
 
 	fi = fopen(CRONUPDATE, "r");
 	if (fi != NULL) {
-		remove(CRONUPDATE);
+		unlink(CRONUPDATE);
 		while (fgets(buf, sizeof(buf), fi) != NULL) {
 			SynchronizeFile(strtok(buf, " \t\r\n"));
 		}
@@ -579,7 +579,7 @@
 	 * scan directory and add associated users
 	 */
 
-	remove(CRONUPDATE);
+	unlink(CRONUPDATE);
 	if (chdir(CDir) < 0) {
 		crondlog("\311cannot find %s\n", CDir);
 	}
@@ -814,7 +814,7 @@
 		crondlog("\024cannot fork\n");
 		line->cl_Pid = 0;
 		if (mail_filename) {
-			remove(mail_filename);
+			unlink(mail_filename);
 		}
 	} else if (mail_filename) {
 		/* PARENT, FORK SUCCESS
@@ -823,7 +823,7 @@
 		char mailFile2[128];
 
 		snprintf(mailFile2, sizeof(mailFile2), TMPDIR "/cron.%s.%d", user, pid);
-		rename(mail_filename, mailFile2);
+		rename(mail_filename, mailFile2); // TODO: xrename?
 	}
 	/*
 	 * Close the mail file descriptor.. we can't just leave it open in
@@ -896,7 +896,7 @@
 	 */
 
 	mailFd = open(mailFile, O_RDONLY);
-	remove(mailFile);
+	unlink(mailFile);
 	if (mailFd < 0) {
 		return;
 	}

Modified: trunk/busybox/networking/sendmail.c
===================================================================
--- trunk/busybox/networking/sendmail.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/networking/sendmail.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -512,10 +512,7 @@
 				if (fd < 0)
 					bb_perror_msg_and_die("cannot create unique file");
 				close(fd);
-				if (rename(tmp_name, new_name) < 0) {
-					// something is very wrong
-					bb_perror_msg_and_die("cannot move %s to %s", tmp_name, new_name);
-				}
+				xrename(tmp_name, new_name);
 			}
 
 			// delete message from server

Modified: trunk/busybox/runit/runsv.c
===================================================================
--- trunk/busybox/runit/runsv.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/runit/runsv.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -157,16 +157,6 @@
 	return fd;
 }
 
-static int rename_or_warn(const char *old, const char *new)
-{
-	if (rename(old, new) == -1) {
-		bb_perror_msg("%s: warning: cannot rename %s to %s",
-				dir, old, new);
-		return -1;
-	}
-	return 0;
-}
-
 static void update_status(struct svdir *s)
 {
 	ssize_t sz;

Modified: trunk/busybox/sysklogd/syslogd.c
===================================================================
--- trunk/busybox/sysklogd/syslogd.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/sysklogd/syslogd.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -344,10 +344,10 @@
 				sprintf(newFile, "%s.%d", G.logFilePath, i);
 				if (i == 0) break;
 				sprintf(oldFile, "%s.%d", G.logFilePath, --i);
-				rename(oldFile, newFile);
+				xrename(oldFile, newFile);
 			}
 			/* newFile == "f.0" now */
-			rename(G.logFilePath, newFile);
+			xrename(G.logFilePath, newFile);
 			fl.l_type = F_UNLCK;
 			fcntl(G.logFD, F_SETLKW, &fl);
 			close(G.logFD);

Modified: trunk/busybox/util-linux/mdev.c
===================================================================
--- trunk/busybox/util-linux/mdev.c	2008-02-16 23:40:47 UTC (rev 21043)
+++ trunk/busybox/util-linux/mdev.c	2008-02-17 14:28:53 UTC (rev 21044)
@@ -209,7 +209,7 @@
 				} else
 					dest = alias;
 
-				rename(device_name, dest);
+				rename(device_name, dest); // TODO: xrename?
 				symlink(dest, device_name);
 
 				if (alias != dest)




More information about the busybox-cvs mailing list