#include "readline.h"
#endif
-int recursion = 0;
+int recursion = 0, interactive;
extern int errno;
extern int sending_version_no;
-int count, quit=0;
+int count, quit=0, cancel=0;
char *whoami;
#ifdef POSIX
sigjmp_buf jb;
#endif
whoami = argv[0];
+ interactive = (isatty(0) && isatty(1));
initialize_sms_error_table();
initialize_krb_error_table();
discard_input()
{
putc('\n', stdout);
+
+ /* if we're inside a script, we have to clean up file descriptors,
+ so don't jump out yet */
+ if(recursion) {
+ cancel=1;
+ } else {
#ifdef POSIX
- siglongjmp(jb, 1);
+ siglongjmp(jb, 1);
#else
- longjmp(jb, 1);
+ longjmp(jb, 1);
#endif
+ }
}
char *mr_gets(prompt, buf, len)
{
char *in;
#ifdef USE_READLINE
- if(isatty(0) && isatty(1)) {
+ if(interactive) {
in=readline(prompt);
if (!in) return NULL;
recursion++;
- for(;;) {
+ while(!cancel) {
if (fgets(input, BUFSIZ, inp) == NULL)
break;
if ((cp = strchr(input, '\n')) != (char *)NULL)
}
recursion--;
+ if(!recursion) cancel=0;
fclose(inp);
if (argc == 3) {
char **argv;
{
int status;
+#ifdef POSIX
+ sigset_t sigs;
+#else
+ int mask;
+#endif
+
if (argc < 2) {
com_err("moira (query)", 0, "Usage: query handle [ args ... ]");
return;
}
count = 0;
+ /* Don't allow ^C during the query: it will confuse libmoira's
+ internal state. (Yay static variables) */
+#ifdef POSIX
+ sigemptyset(&sigs);
+ sigaddset(&sigs, SIGINT);
+ sigprocmask(SIG_BLOCK, &sigs, NULL);
+#else
+ mask = sigblock(SIGINT);
+#endif
status = mr_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
+#ifdef POSIX
+ sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+#else
+ sigsetmask(mask);
+#endif
printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
if (status) com_err("moira (query)", status, "");
}