[sheepdog] [PATCH v2 2/2] collie: restore snapshot only when stdin is pipe
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed Apr 10 06:01:57 CEST 2013
We don't expect that stdin is console when doing the 'vdi restore'
command.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/vdi.c | 6 ++++++
include/util.h | 5 +++++
2 files changed, 11 insertions(+)
diff --git a/collie/vdi.c b/collie/vdi.c
index 0a0814f..5603f97 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -1839,6 +1839,12 @@ static int vdi_restore(int argc, char **argv)
goto out;
}
+ if (is_stdin_console()) {
+ fprintf(stderr, "stdin must be pipe\n");
+ ret = EXIT_USAGE;
+ goto out;
+ }
+
ret = do_vdi_delete(vdiname, 0, NULL);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "Failed to delete the current state\n");
diff --git a/include/util.h b/include/util.h
index 192e3fd..8ba6710 100644
--- a/include/util.h
+++ b/include/util.h
@@ -148,6 +148,11 @@ static inline void uatomic_set_false(uatomic_bool *val)
#define TEXT_CYAN "\033[0;36m"
#define TEXT_BOLD_CYAN "\033[1;36m"
+static inline bool is_stdin_console(void)
+{
+ return isatty(STDIN_FILENO);
+}
+
static inline bool is_stdout_console(void)
{
return isatty(STDOUT_FILENO);
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list