}
+bool
+vshTTYIsInterruptCharacter(vshControl *ctl,
+ const char chr)
+{
+ if (ctl->istty &&
+ ctl->termattr.c_cc[VINTR] == chr)
+ return true;
+
+ return false;
+}
+
+
+int
+vshTTYDisableInterrupt(vshControl *ctl)
+{
+ struct termios termset = ctl->termattr;
+
+ if (!ctl->istty)
+ return -1;
+
+ /* check if we need to set the terminal */
+ if (termset.c_cc[VINTR] == _POSIX_VDISABLE)
+ return 0;
+
+ termset.c_cc[VINTR] = _POSIX_VDISABLE;
+ termset.c_lflag &= ~ICANON;
+
+ if (tcsetattr(STDIN_FILENO, TCSANOW, &termset) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+int
+vshTTYRestore(vshControl *ctl)
+{
+ if (!ctl->istty)
+ return 0;
+
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &ctl->termattr) < 0)
+ return -1;
+
+ return 0;
+}
+
+
void
vshError(vshControl *ctl, const char *format, ...)
{
return EXIT_FAILURE;
}
+ if (isatty(STDIN_FILENO)) {
+ ctl->istty = true;
+
+ if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0)
+ ctl->istty = false;
+ }
+
if (virMutexInit(&ctl->lock) < 0) {
vshError(ctl, "%s", _("Failed to initialize mutex"));
return EXIT_FAILURE;
# include <unistd.h>
# include <sys/stat.h>
# include <inttypes.h>
+# include <termios.h>
# include "internal.h"
# include "virerror.h"
const char *escapeChar; /* String representation of
console escape character */
+
+ struct termios termattr; /* settings of the tty terminal */
+ bool istty; /* is the terminal a tty */
};
struct _vshCmdGrp {
void vshResetLibvirtError(void);
void vshSaveLibvirtError(void);
+/* terminal modifications */
+bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
+int vshTTYDisableInterrupt(vshControl *ctl);
+int vshTTYRestore(vshControl *ctl);
+
/* allocation wrappers */
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
# define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)