summaryrefslogtreecommitdiff
path: root/source4/lib/replace/getpass.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-09-06 05:27:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:17:37 -0500
commitcdd352bfcb5aab71558961ee46068f7b89c1ba80 (patch)
tree280e1e5869e40de4cbf11821b6ea562bb2640525 /source4/lib/replace/getpass.c
parent886d020dbfa7e69ed780dfba579ad52ebd37e277 (diff)
downloadsamba-cdd352bfcb5aab71558961ee46068f7b89c1ba80.tar.gz
samba-cdd352bfcb5aab71558961ee46068f7b89c1ba80.tar.bz2
samba-cdd352bfcb5aab71558961ee46068f7b89c1ba80.zip
r18132: getpass can't depend on fns in lib/util/
(This used to be commit b346ab2f0573177e0a4654fd7c77a071225fc785)
Diffstat (limited to 'source4/lib/replace/getpass.c')
-rw-r--r--source4/lib/replace/getpass.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/source4/lib/replace/getpass.c b/source4/lib/replace/getpass.c
index 1aac7c61ab..05fb7976b9 100644
--- a/source4/lib/replace/getpass.c
+++ b/source4/lib/replace/getpass.c
@@ -114,6 +114,32 @@ static int tcsetattr(int fd, int flags, struct sgttyb *_t)
static struct termios t;
#endif /* SYSV_TERMIO */
+static void catch_signal(int signum,void (*handler)(int ))
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction act;
+ struct sigaction oldact;
+
+ memset(&act, 0, sizeof(act));
+
+ act.sa_handler = handler;
+#ifdef SA_RESTART
+ /*
+ * We *want* SIGALRM to interrupt a system call.
+ */
+ if(signum != SIGALRM)
+ act.sa_flags = SA_RESTART;
+#endif
+ sigemptyset(&act.sa_mask);
+ sigaddset(&act.sa_mask,signum);
+ sigaction(signum,&act,&oldact);
+ return oldact.sa_handler;
+#else /* !HAVE_SIGACTION */
+ /* FIXME: need to handle sigvec and systems with broken signal() */
+ return signal(signum, handler);
+#endif
+}
+
char *getsmbpass(const char *prompt)
{
FILE *in, *out;
@@ -123,7 +149,7 @@ char *getsmbpass(const char *prompt)
size_t nread;
/* Catch problematic signals */
- CatchSignal(SIGINT, SIGNAL_CAST SIG_IGN);
+ catch_signal(SIGINT, SIGNAL_CAST SIG_IGN);
/* Try to write to and read from the terminal if we can.
If we can't open the terminal, use stderr and stdin. */
@@ -175,7 +201,7 @@ char *getsmbpass(const char *prompt)
fclose (in);
/* Catch problematic signals */
- CatchSignal(SIGINT, SIGNAL_CAST SIG_DFL);
+ catch_signal(SIGINT, SIGNAL_CAST SIG_DFL);
printf("\n");
return buf;