s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

ftrigw_fifodir_make.c (662B)


      1 /* ISC license. */
      2 
      3 #include <sys/stat.h>
      4 #include <unistd.h>
      5 #include <errno.h>
      6 #include <s6/ftrigw.h>
      7 
      8 int ftrigw_fifodir_make (char const *path, gid_t gid, int force)
      9 {
     10   mode_t m = umask(0) ;
     11   if (mkdir(path, 0700) < 0)
     12   {
     13     struct stat st ;
     14     umask(m) ;
     15     if (errno != EEXIST) return 0 ;
     16     if (stat(path, &st) == -1) return 0 ;
     17     if (st.st_uid != getuid()) return (errno = EACCES, 0) ;
     18     if (!S_ISDIR(st.st_mode)) return (errno = ENOTDIR, 0) ;
     19     if (!force) return 1 ;
     20   }
     21   else umask(m) ;
     22   if ((gid != (gid_t)-1) && (chown(path, -1, gid) < 0)) return 0 ;
     23   if (chmod(path, gid != (gid_t)-1 ? 03730 : 01733) < 0) return 0 ;
     24   return 1 ;
     25 }