Fossil SCM

Set the permissions of the unix socket of fossil server through the umask in effect for bind(), not with fchmod() on the unbound socket, which macOS refuses, so that --socket-mode and the default of 0660 work there. Remove the now unused file_set_mode().

dmestas 2026-11-21 11:51 UTC small-fixes
Commit 7ffce1d7b4ae7dd59314ff15d0297a2e96ae422ab1919d2940a99e1a2bfb04d4
2 files changed +13 -4 -15
+13 -4
--- src/cgi.c
+++ src/cgi.c
@@ -78,10 +78,11 @@
7878
# include <arpa/inet.h>
7979
# include <sys/times.h>
8080
# include <sys/time.h>
8181
# include <sys/wait.h>
8282
# include <sys/select.h>
83
+# include <sys/stat.h>
8384
# include <errno.h>
8485
#endif
8586
#ifdef __EMX__
8687
typedef int socklen_t;
8788
#endif
@@ -2642,10 +2643,12 @@
26422643
struct sockaddr_in6 inaddr6; /* Address for IPv6 */
26432644
struct sockaddr_in inaddr4; /* Address for IPv4 */
26442645
struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
26452646
int opt = 1; /* setsockopt flag */
26462647
int rc; /* Result code from system calls */
2648
+ mode_t mSock = 0660; /* Permissions for a unix-domain socket */
2649
+ mode_t mOld; /* Saved umask */
26472650
int iPort = mnPort; /* Port to try to use */
26482651
const char *zRequestType; /* Type of requests to listen for */
26492652
26502653
26512654
if( flags & HTTP_SERVER_SCGI ){
@@ -2685,17 +2688,23 @@
26852688
mxListen = listen4;
26862689
listen6 = -1;
26872690
26882691
/* Set the access permission for the new socket. Default to 0660.
26892692
** But use an alternative specified by --socket-mode if available.
2690
- ** Do this before bind() to avoid a race condition. */
2693
+ ** Set it through the umask that bind() uses to avoid a race
2694
+ ** condition. */
26912695
if( g.zSockMode ){
2692
- file_set_mode(g.zSockName, listen4, g.zSockMode, 0);
2693
- }else{
2694
- file_set_mode(g.zSockName, listen4, "0660", 1);
2696
+ char *zEnd = 0;
2697
+ mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0);
2698
+ if( zEnd[0] ){
2699
+ fossil_fatal("cannot change permissions on %s to \"%s\"",
2700
+ g.zSockName, g.zSockMode);
2701
+ }
26952702
}
2703
+ mOld = umask(~mSock & 0777);
26962704
rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr));
2705
+ umask(mOld);
26972706
/* Set the owner of the socket if requested by --socket-owner. This
26982707
** must wait until after bind(), after the filesystem object has been
26992708
** created. See https://lkml.org/lkml/2004/11/1/84 and
27002709
** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */
27012710
if( g.zSockOwner ){
27022711
--- src/cgi.c
+++ src/cgi.c
@@ -78,10 +78,11 @@
78 # include <arpa/inet.h>
79 # include <sys/times.h>
80 # include <sys/time.h>
81 # include <sys/wait.h>
82 # include <sys/select.h>
 
83 # include <errno.h>
84 #endif
85 #ifdef __EMX__
86 typedef int socklen_t;
87 #endif
@@ -2642,10 +2643,12 @@
2642 struct sockaddr_in6 inaddr6; /* Address for IPv6 */
2643 struct sockaddr_in inaddr4; /* Address for IPv4 */
2644 struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
2645 int opt = 1; /* setsockopt flag */
2646 int rc; /* Result code from system calls */
 
 
2647 int iPort = mnPort; /* Port to try to use */
2648 const char *zRequestType; /* Type of requests to listen for */
2649
2650
2651 if( flags & HTTP_SERVER_SCGI ){
@@ -2685,17 +2688,23 @@
2685 mxListen = listen4;
2686 listen6 = -1;
2687
2688 /* Set the access permission for the new socket. Default to 0660.
2689 ** But use an alternative specified by --socket-mode if available.
2690 ** Do this before bind() to avoid a race condition. */
 
2691 if( g.zSockMode ){
2692 file_set_mode(g.zSockName, listen4, g.zSockMode, 0);
2693 }else{
2694 file_set_mode(g.zSockName, listen4, "0660", 1);
 
 
 
2695 }
 
2696 rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr));
 
2697 /* Set the owner of the socket if requested by --socket-owner. This
2698 ** must wait until after bind(), after the filesystem object has been
2699 ** created. See https://lkml.org/lkml/2004/11/1/84 and
2700 ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */
2701 if( g.zSockOwner ){
2702
--- src/cgi.c
+++ src/cgi.c
@@ -78,10 +78,11 @@
78 # include <arpa/inet.h>
79 # include <sys/times.h>
80 # include <sys/time.h>
81 # include <sys/wait.h>
82 # include <sys/select.h>
83 # include <sys/stat.h>
84 # include <errno.h>
85 #endif
86 #ifdef __EMX__
87 typedef int socklen_t;
88 #endif
@@ -2642,10 +2643,12 @@
2643 struct sockaddr_in6 inaddr6; /* Address for IPv6 */
2644 struct sockaddr_in inaddr4; /* Address for IPv4 */
2645 struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
2646 int opt = 1; /* setsockopt flag */
2647 int rc; /* Result code from system calls */
2648 mode_t mSock = 0660; /* Permissions for a unix-domain socket */
2649 mode_t mOld; /* Saved umask */
2650 int iPort = mnPort; /* Port to try to use */
2651 const char *zRequestType; /* Type of requests to listen for */
2652
2653
2654 if( flags & HTTP_SERVER_SCGI ){
@@ -2685,17 +2688,23 @@
2688 mxListen = listen4;
2689 listen6 = -1;
2690
2691 /* Set the access permission for the new socket. Default to 0660.
2692 ** But use an alternative specified by --socket-mode if available.
2693 ** Set it through the umask that bind() uses to avoid a race
2694 ** condition. */
2695 if( g.zSockMode ){
2696 char *zEnd = 0;
2697 mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0);
2698 if( zEnd[0] ){
2699 fossil_fatal("cannot change permissions on %s to \"%s\"",
2700 g.zSockName, g.zSockMode);
2701 }
2702 }
2703 mOld = umask(~mSock & 0777);
2704 rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr));
2705 umask(mOld);
2706 /* Set the owner of the socket if requested by --socket-owner. This
2707 ** must wait until after bind(), after the filesystem object has been
2708 ** created. See https://lkml.org/lkml/2004/11/1/84 and
2709 ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */
2710 if( g.zSockOwner ){
2711
-15
--- src/file.c
+++ src/file.c
@@ -765,25 +765,10 @@
765765
iMTime = file_mtime(zFile, RepoFILE);
766766
zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
767767
fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
768768
}
769769
770
-/*
771
-** Change access permissions on a file.
772
-*/
773
-void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){
774
-#if !defined(_WIN32)
775
- mode_t m;
776
- char *zEnd = 0;
777
- m = strtol(zMode, &zEnd, 0);
778
- if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){
779
- fossil_fatal("cannot change permissions on %s to \"%s\"",
780
- zFN, zMode);
781
- }
782
-#endif
783
-}
784
-
785770
/* Change the owner of a file to zOwner. zOwner can be of the form
786771
** USER:GROUP.
787772
*/
788773
void file_set_owner(const char *zFN, int fd, const char *zOwner){
789774
#if !defined(_WIN32)
790775
--- src/file.c
+++ src/file.c
@@ -765,25 +765,10 @@
765 iMTime = file_mtime(zFile, RepoFILE);
766 zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
767 fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
768 }
769
770 /*
771 ** Change access permissions on a file.
772 */
773 void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){
774 #if !defined(_WIN32)
775 mode_t m;
776 char *zEnd = 0;
777 m = strtol(zMode, &zEnd, 0);
778 if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){
779 fossil_fatal("cannot change permissions on %s to \"%s\"",
780 zFN, zMode);
781 }
782 #endif
783 }
784
785 /* Change the owner of a file to zOwner. zOwner can be of the form
786 ** USER:GROUP.
787 */
788 void file_set_owner(const char *zFN, int fd, const char *zOwner){
789 #if !defined(_WIN32)
790
--- src/file.c
+++ src/file.c
@@ -765,25 +765,10 @@
765 iMTime = file_mtime(zFile, RepoFILE);
766 zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime);
767 fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime);
768 }
769
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770 /* Change the owner of a file to zOwner. zOwner can be of the form
771 ** USER:GROUP.
772 */
773 void file_set_owner(const char *zFN, int fd, const char *zOwner){
774 #if !defined(_WIN32)
775

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button