diff options
Diffstat (limited to 'lib/libssl/src')
-rw-r--r-- | lib/libssl/src/crypto/engine/hw_cryptodev.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/libssl/src/crypto/engine/hw_cryptodev.c b/lib/libssl/src/crypto/engine/hw_cryptodev.c index 859af048ee5..b8217cdea1d 100644 --- a/lib/libssl/src/crypto/engine/hw_cryptodev.c +++ b/lib/libssl/src/crypto/engine/hw_cryptodev.c @@ -112,17 +112,32 @@ static struct { * Return a fd if /dev/crypto seems usable, 0 otherwise. */ static int +open_dev_crypto() +{ + static int fd = -1; + + if (fd == -1) { + if (fd = open("/dev/crypto", O_RDWR, 0) == -1) + return (-1); + /* close on exec */ + if (fcntl(fd, F_SETFD, 1) == -1) { + close(fd); + fd = -1; + return (-1); + } + } + return (fd); +} + +static int get_dev_crypto() { int fd, retfd; - if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) + if ((fd = open_dev_crypto()) == -1) return (-1); - if (ioctl(fd, CRIOGET, &retfd) == -1) { - close(fd); + if (ioctl(fd, CRIOGET, &retfd) == -1) return (-1); - } - close(fd); /* close on exec */ if (fcntl(retfd, F_SETFD, 1) == -1) { |