Skip to contentSkip to conversation

Btrfs-prog/send: fix wrong dump_fd check in cmd_send_start()

PATCH In review Chen Yang 2 participants 4 messages Jan 31, 2013 – Feb 1, 2013 1 message not in the archive Btrfs file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Chen Yang

author
#1 lore raw

PATCH 1/1 Btrfs-prog/send: fix wrong dump_fd check in cmd_send_start()

In cmd_send_start(), there is a check to make sure dump_fd is not a tty before parsing command options. So if we use the option "-f file", it doesn't work for the dump_fd has not been created. So fix it.

---
 cmds-send.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
cmds-send.c +7 -5
index 2b9a610..aafa800 100644
@@ -429,11 +429,6 @@ int cmd_send_start(int argc, char **argv)
 	memset(&send, 0, sizeof(send));
 	send.dump_fd = fileno(stdout);
 
-	if (isatty(send.dump_fd)) {
-		fprintf(stderr, "ERROR: not dumping send stream into a terminal, redirect it into a file\n");
-		return 1;
-	}
-
 	while ((c = getopt(argc, argv, "vf:i:p:")) != -1) {
 		switch (c) {
 		case 'v':
@@ -497,6 +492,13 @@ int cmd_send_start(int argc, char **argv)
 		}
 	}
 
+	if (isatty(send.dump_fd)) {
+		fprintf(stderr, 
+			"ERROR: not dumping send stream into a terminal, "
+			"redirect it into a file\n");
+		return 1;
+	}
+
 	/* use first send subvol to determine mount_root */
 	subvol = argv[optind];
 
Signature · 1 line
1.7.7.6
#2 lore raw
Quoted 3 lines · Chen Yang

In cmd_send_start(), there is a check to make sure dump_fd is not a tty before parsing command options. So if we use the option "-f file", it doesn't work for the dump_fd has not been created. So fix it.

Good catch, thanks. I see that there's no special handling of the '-' filename that usually means stdout. We may want to add this as a common command line usage pattern.

david

author
#3 lore raw
Quoted 11 lines · Chen Yang
Quoted 3 lines

In cmd_send_start(), there is a check to make sure dump_fd is not a tty before parsing command options. So if we use the option "-f file", it doesn't work for the dump_fd has not been created. So fix it.

Good catch, thanks. I see that there's no special handling of the '-' filename that usually means stdout. We may want to add this as a common command line usage pattern.

david

We can touch a file name "-", so I think special handling of the '-' is unnecessary.

#4 lore raw
Quoted 5 lines · Chen Yang
Quoted 4 lines

Good catch, thanks. I see that there's no special handling of the '-' filename that usually means stdout. We may want to add this as a common command line usage pattern.

We can touch a file name "-", so I think special handling of the '-' is unnecessary.

I want to avoid creating a file named '-'. It would work the same way as 'cat -' etc.

david