Improved signal handling, removed tmpnam()

This commit is contained in:
Nate Choe
2022-04-05 11:59:14 -05:00
parent 00bbd9c1d4
commit 8914e57eec
5 changed files with 64 additions and 8 deletions

View File

@@ -19,8 +19,10 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/shm.h>
#include <sys/socket.h>
@@ -165,3 +167,27 @@ int recvFd(int source) {
memcpy(&ret, CMSG_DATA(cmsg), sizeof(ret));
return ret;
}
int createTmpName(char *path) {
size_t len;
char possibleChars[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
len = strlen(path);
if (len < 5)
return 1;
for (;;) {
int i;
for (i = 0; i < 5; i++)
path[len - i - 1] =
possibleChars[rand() % sizeof(possibleChars)];
if (!faccessat(-1, path, F_OK, AT_EACCESS))
continue;
if (faccessat(-1, path, R_OK | W_OK, AT_EACCESS))
return 1;
return 0;
}
}