summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Alec Lanter <kintar1900@gmail.com>2017-04-28 08:17:40 -0500
committerGravatar Alec Lanter <kintar1900@gmail.com>2017-04-28 08:20:13 -0500
commitb5ad306ac967db3f3dace48952437b7729d31087 (patch)
tree98b86c7f12de4cfdcad20b83a65d222764e9e29c
parentff8bf9c30e6674a990e0efb99121c43ade7aff05 (diff)
downloadmkinitcpio-ykfde-b5ad306ac967db3f3dace48952437b7729d31087.tar.gz
mkinitcpio-ykfde-b5ad306ac967db3f3dace48952437b7729d31087.tar.zst
Updated ykfde.c to silently skip terminal updates when tcgetattr fails so that keys can be piped through from other commands.
-rw-r--r--bin/ykfde.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/bin/ykfde.c b/bin/ykfde.c
index 37e82a3..cc69636 100644
--- a/bin/ykfde.c
+++ b/bin/ykfde.c
@@ -64,32 +64,38 @@ char * ask_secret(const char * text) {
char * factor = NULL;
size_t len;
ssize_t readlen;
+ bool onTerminal = true;
/* get terminal properties */
if (tcgetattr(STDIN_FILENO, &tp) < 0) {
- fprintf(stderr, "Failed reading terminal attributes. Not on terminal?\n");
- return NULL;
+ onTerminal = false;
+ tp_save = tp;
}
- tp_save = tp;
/* disable echo on terminal */
- tp.c_lflag &= ~ECHO;
- if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) < 0) {
- fprintf(stderr, "Failed setting terminal attributes.\n");
- return NULL;
+ if (onTerminal) {
+ tp.c_lflag &= ~ECHO;
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) < 0) {
+ fprintf(stderr, "Failed setting terminal attributes.\n");
+ return NULL;
+ }
+
+ printf("Please give %s:", text);
}
- printf("Please give %s:", text);
readlen = getline(&factor, &len, stdin);
factor[readlen - 1] = '\0';
- putchar('\n');
- /* restore terminal */
- if (tcsetattr(STDIN_FILENO, TCSANOW, &tp_save) < 0) {
- fprintf(stderr, "Failed setting terminal attributes.\n");
- free(factor);
- return NULL;
+ if (onTerminal) {
+ putchar('\n');
+
+ /* restore terminal */
+ if (tcsetattr(STDIN_FILENO, TCSANOW, &tp_save) < 0) {
+ fprintf(stderr, "Failed setting terminal attributes.\n");
+ free(factor);
+ return NULL;
+ }
}
return factor;