@@ -189,6 +189,11 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
189
189
if ((* cur_block )-> output != NULL ) {
190
190
(* cur_block )-> output -> showrepeats = (* cur_block )-> showrepeats ;
191
191
}
192
+ } else if (strcasecmp (keyword , "perms" ) == 0 ) {
193
+ (* cur_block )-> perms = (mode_t ) strtoul (value , NULL , 8 );
194
+ if ((* cur_block )-> output != NULL ) {
195
+ (* cur_block )-> output -> perms = (* cur_block )-> perms ;
196
+ }
192
197
} else if (strcasecmp (keyword , "logdir" ) == 0 ) {
193
198
char * logdir = NULL ;
194
199
Output * outputs_scan = outputs ;
@@ -215,6 +220,7 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
215
220
else
216
221
free (logdir );
217
222
new_output -> fp = NULL ;
223
+ new_output -> perms = (* cur_block )-> perms ;
218
224
new_output -> size = (off_t ) 0 ;
219
225
new_output -> maxsize = (* cur_block )-> maxsize ;
220
226
new_output -> maxfiles = (* cur_block )-> maxfiles ;
@@ -353,6 +359,7 @@ static int configParser(const char * const file)
353
359
(off_t ) DEFAULT_MAXSIZE , /* maxsize */
354
360
DEFAULT_MAXFILES , /* maxfiles */
355
361
(time_t ) DEFAULT_MAXTIME , /* maxtime */
362
+ (mode_t ) DEFAULT_PERMS , /* perms */
356
363
NULL , /* output */
357
364
NULL , /* command */
358
365
NULL , /* program */
@@ -849,7 +856,7 @@ static int writeLogLine(Output * const output, const char * const date,
849
856
850
857
testdir :
851
858
if (stat (output -> directory , & st ) < 0 ) {
852
- if (mkdir (output -> directory , OUTPUT_DIR_PERMS ) < 0 ) {
859
+ if (mkdir (output -> directory , output -> perms ) < 0 ) {
853
860
warnp ("Can't create [%s]" , output -> directory );
854
861
return -1 ;
855
862
}
@@ -1638,6 +1645,21 @@ static void dodaemonize(void)
1638
1645
}
1639
1646
}
1640
1647
1648
+ static void setgroup (void )
1649
+ {
1650
+ if (group_name == NULL ) return ;
1651
+ struct group * g ;
1652
+ errno = 0 ;
1653
+ if ((g = getgrnam (group_name )) == NULL ) {
1654
+ if (errno == 0 )
1655
+ err ("Failed to set group: group '%s' not found" , group_name );
1656
+ else
1657
+ errp ("Failed to set group" );
1658
+ }
1659
+ if (setgid (g -> gr_gid ) == -1 )
1660
+ errp ("Failed to set group" );
1661
+ }
1662
+
1641
1663
__attribute__ ((noreturn ))
1642
1664
static void help (void )
1643
1665
{
@@ -1678,6 +1700,9 @@ static void parseOptions(int argc, char *argv[])
1678
1700
case 'C' :
1679
1701
config_file = xstrdup (optarg );
1680
1702
break ;
1703
+ case 'g' :
1704
+ group_name = xstrdup (optarg );
1705
+ break ;
1681
1706
case 'v' :
1682
1707
++ verbose ;
1683
1708
break ;
@@ -1722,6 +1747,7 @@ int main(int argc, char *argv[])
1722
1747
if (configParser (config_file ) < 0 )
1723
1748
err ("Bad configuration file" );
1724
1749
checkRoot ();
1750
+ setgroup ();
1725
1751
dodaemonize ();
1726
1752
setsignals ();
1727
1753
if (update_pid_file (pid_file ))
0 commit comments