commit f20795ee496838171baa1ec26fd4c16c1729b22e
parent 5ad257ab769a3b22419087f1490c87b8a2d298d7
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Sat, 25 Dec 2021 22:53:46 -0600
mlock master buffer and clear it on exit
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/npm-agent.c b/npm-agent.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
@@ -226,9 +227,11 @@ main()
.sa_handler = alarm_handler,
};
- sigaction(SIGINT, &sa_term, NULL);
- sigaction(SIGTERM, &sa_term, NULL);
- sigaction(SIGALRM, &sa_alarm, NULL);
+
+ if (mlock(master, sizeof(master)) == -1) {
+ perror("failed to mlock master buffer");
+ goto error;
+ }
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1) {
@@ -319,5 +322,6 @@ error:
unlink(SOCKPATH);
error_socket:
close(sock);
+ clear_master();
return 1;
}