Sat 10 Apr 2010 11:07:51 PM UTC, original submission:
As of version 2.2.2, with 'set backup' enabled, nano will try to chown() the newly created backup file to the owner of the original file being edited. The editing user is very likely not to be root, and it's not uncommon for a non-root user to be editing a file owned by a different user. If the chown() fails, it should not cause the entire backup to fail (which thus prevents saving the original file). The backup file is actually written successfully into the backupdir, the chmod() finishes successfully. The only reason the backup fails is because a non-root user cannot chown() a file to be owned by a different user.
Currently, the only way to successfully save the file in this situation is to disable backups via M-B keyboard shortcut.
Here is a relevant excerpt from strace, showing the error and the subsequent abort of the save operation.
# Press F3
write(1, "\33[88d\33(B\33[0;7mFile Name to Write"..., 423) = 423
# Enter for default
getcwd("/home/otheruser/file.txt", 4097)
stat("file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
getcwd("/home/otheruser/file.txt", 4097)
stat("file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
stat("/home/otheruser/file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
lstat("file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
stat("file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
open("file.txt", O_RDONLY) = 3
getcwd("/home/otheruser", 4097) = 65
stat("file.txt", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
stat("/home/myuser/.nanobak/!home!otheruser!file.txt~", {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
stat("/home/myuser/.nanobak/!home!otheruser!file.txt~.1", 0x7cc82f818860) = -1 ENOENT (No such file or directory)
open("/home/myuser/.nanobak/!home!otheruser!file.txt~.1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
chmod("/home/myuser/.nanobak/!home!otheruser!file.txt~.1", 0100664) = 0
fstat(3, {st_mode=S_IFREG|0664, st_size=3226, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x396a8ec91000
read(3, "contents of the file ..."..., 8192) = 3226
read(3, "", 4096) = 0
fstat(4, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x396a8ec92000
read(3, "", 8192) = 0
close(3) = 0
munmap(0x396a8ec91000, 4096) = 0
write(4, "contents of the file ..."..., 3226) = 3226
close(4) = 0
## At this point, the backup file was written successfully
munmap(0x396a8ec92000, 262144) = 0
chown("/home/myuser/.nanobak/!home!otheruser!file.txt~.1", 2011, 2011) = -1 EPERM (Operation not permitted)
## I cannot change ownership of my new backup file to match "otheruser" (uid 2011)
rt_sigprocmask(SIG_UNBLOCK, [WINCH], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [WINCH], NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [WINCH], NULL, 8) = 0
rt_sigaction(SIGTSTP, {SIG_IGN}, {SIG_IGN}, 8) = 0
poll([{fd=0, events=POLLIN}], 1, 0) = 0
poll([{fd=0, events=POLLIN}], 1, 0) = 0
write(1, "\r\33(B\33[0;7m[ Error writing backup"..., 518) = 518
## Thus backup is deemed failed, and saving the file is aborted.
|