char *argv[64];
};
+static void user_cancel (int);
static void set_up_terminal (void);
static void prepare_drives (struct drv *drv);
static int launch (void);
static struct parsed_command parse_command_line (char *buf, int *exit_on_error_rtn);
static int parse_quoted_string (char *p);
static int execute_and_inline (const char *cmd, int exit_on_error);
+static void error_cb (guestfs_h *g, void *data, const char *msg);
static void initialize_readline (void);
static void cleanup_readline (void);
#ifdef HAVE_LIBREADLINE
static int override_progress_bars = -1;
/* Currently open libguestfs handle. */
-guestfs_h *g;
+guestfs_h *g = NULL;
int read_only = 0;
int live = 0;
int have_terminfo = 0;
int progress_bars = 0;
int is_interactive = 0;
+const char *input_file = NULL;
+int input_lineno = 0;
static void __attribute__((noreturn))
usage (int status)
*/
is_interactive = !file && isatty (0);
+ /* Register a ^C handler. We have to do this before launch could
+ * possibly be called below.
+ */
+ if (is_interactive) {
+ memset (&sa, 0, sizeof sa);
+ sa.sa_handler = user_cancel;
+ sa.sa_flags = SA_RESTART;
+ sigaction (SIGINT, &sa, NULL);
+
+ guestfs_set_pgroup (g, 1);
+ }
+
/* Old-style -i syntax? Since -a/-d/-N and -i was disallowed
* previously, if we have -i without any drives but with something
* on the command line, it must be old-style syntax.
}
}
+ /* Get the name of the input file, for error messages, and replace
+ * the default error handler.
+ */
+ if (!is_interactive) {
+ if (file)
+ input_file = file;
+ else
+ input_file = "*stdin*";
+ guestfs_set_error_handler (g, error_cb, NULL);
+ }
+ input_lineno = 0;
+
/* Decide if we display progress bars. */
progress_bars =
override_progress_bars >= 0
exit (EXIT_SUCCESS);
}
+static void
+user_cancel (int sig)
+{
+ if (g)
+ guestfs_user_cancel (g);
+}
+
/* The <term.h> header file which defines this has "issues". */
extern int tgetent (char *, const char *);
break;
}
+ input_lineno++;
+
pcmd = parse_command_line (buf, &exit_on_error);
if (pcmd.status == -1 && exit_on_error)
exit (EXIT_FAILURE);
"For complete documentation: man guestfish\n"));
}
+/* Error callback. This replaces the standard libguestfs error handler. */
+static void
+error_cb (guestfs_h *g, void *data, const char *msg)
+{
+ fprintf (stderr, _("%s:%d: libguestfs: error: %s\n"),
+ input_file, input_lineno, msg);
+}
+
void
free_strings (char **argv)
{