modify socket file permissions by changing umask
This commit is contained in:
parent
aa32c75389
commit
17274b11b9
@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/un.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
@ -57,6 +58,10 @@ void* server_socket(void* param)
|
||||
address.sun_family = AF_UNIX;
|
||||
snprintf(address.sun_path, UNIX_PATH_MAX, sock_path);
|
||||
|
||||
// Set umask value for new socket file
|
||||
mode_t old_umask = umask(077);
|
||||
|
||||
// Create(bind) socket
|
||||
if(bind(socket_fd,
|
||||
(struct sockaddr *) &address,
|
||||
sizeof(struct sockaddr_un)) != 0)
|
||||
@ -65,6 +70,9 @@ void* server_socket(void* param)
|
||||
return (void*)1;
|
||||
}
|
||||
|
||||
// Return previous umask value
|
||||
umask(old_umask);
|
||||
|
||||
if(listen(socket_fd, 5) != 0)
|
||||
{
|
||||
log_event("listen() call failed");
|
||||
|
Loading…
Reference in New Issue
Block a user