summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Prakash Jana <engineerarun@gmail.com>2021-08-14 00:15:13 +0530
committerArun Prakash Jana <engineerarun@gmail.com>2021-08-14 00:22:37 +0530
commitab752bfe837eb86c079fd9062e665d54440938f5 (patch)
tree0035c9447e295cfb8a67d032925079fe64e3ade4
parent34f3e3ca34b26610fd6d27469680cd97bad330ba (diff)
Fix #36
-rw-r--r--src/bcal.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/bcal.c b/src/bcal.c
index e6f8927..41c2a22 100644
--- a/src/bcal.c
+++ b/src/bcal.c
@@ -23,6 +23,9 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
#include <readline/history.h>
#include <readline/readline.h>
#include "dslib.h"
@@ -267,6 +270,17 @@ static int try_bc(char *expr)
exit(-1);
}
+ if (write(pipe_pc[1], "quit\n", 5) != 5) {
+ log(ERROR, "write(7)! [%s]\n", strerror(errno));
+ exit(-1);
+ }
+
+ if (cfg.calc)
+ kill(pid, SIGTERM);
+
+ close(pipe_cp[0]);
+ close(pipe_pc[1]);
+
buffer[ret] = '\0';
if (buffer[0] != '(') {
@@ -275,6 +289,9 @@ static int try_bc(char *expr)
++ptr;
printf("%s", ptr);
+ if (cfg.calc && strstr(ptr, "is undefined"))
+ return -1;
+
len = bstrlcpy(lastres.p, ptr, NUM_LEN);
/* remove newline appended at the end of result by bc */