9
9
#define initgroups (x , y ) (0) /* nothing */
10
10
#endif
11
11
12
- static int log_syslog ;
12
+ static enum log_destination {
13
+ LOG_DESTINATION_UNSET = -1 ,
14
+ LOG_DESTINATION_NONE = 0 ,
15
+ LOG_DESTINATION_STDERR = 1 ,
16
+ LOG_DESTINATION_SYSLOG = 2 ,
17
+ } log_destination = LOG_DESTINATION_UNSET ;
13
18
static int verbose ;
14
19
static int reuseaddr ;
15
20
static int informative_errors ;
@@ -25,6 +30,7 @@ static const char daemon_usage[] =
25
30
" [--access-hook=<path>]\n"
26
31
" [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
27
32
" [--detach] [--user=<user> [--group=<group>]]\n"
33
+ " [--log-destination=(stderr|syslog|none)]\n"
28
34
" [<directory>...]" ;
29
35
30
36
/* List of acceptable pathname prefixes */
@@ -74,11 +80,14 @@ static const char *get_ip_address(struct hostinfo *hi)
74
80
75
81
static void logreport (int priority , const char * err , va_list params )
76
82
{
77
- if (log_syslog ) {
83
+ switch (log_destination ) {
84
+ case LOG_DESTINATION_SYSLOG : {
78
85
char buf [1024 ];
79
86
vsnprintf (buf , sizeof (buf ), err , params );
80
87
syslog (priority , "%s" , buf );
81
- } else {
88
+ break ;
89
+ }
90
+ case LOG_DESTINATION_STDERR :
82
91
/*
83
92
* Since stderr is set to buffered mode, the
84
93
* logging of different processes will not overlap
@@ -88,6 +97,11 @@ static void logreport(int priority, const char *err, va_list params)
88
97
vfprintf (stderr , err , params );
89
98
fputc ('\n' , stderr );
90
99
fflush (stderr );
100
+ break ;
101
+ case LOG_DESTINATION_NONE :
102
+ break ;
103
+ case LOG_DESTINATION_UNSET :
104
+ BUG ("log destination not initialized correctly" );
91
105
}
92
106
}
93
107
@@ -1286,17 +1300,29 @@ int cmd_main(int argc, const char **argv)
1286
1300
}
1287
1301
if (!strcmp (arg , "--inetd" )) {
1288
1302
inetd_mode = 1 ;
1289
- log_syslog = 1 ;
1290
1303
continue ;
1291
1304
}
1292
1305
if (!strcmp (arg , "--verbose" )) {
1293
1306
verbose = 1 ;
1294
1307
continue ;
1295
1308
}
1296
1309
if (!strcmp (arg , "--syslog" )) {
1297
- log_syslog = 1 ;
1310
+ log_destination = LOG_DESTINATION_SYSLOG ;
1298
1311
continue ;
1299
1312
}
1313
+ if (skip_prefix (arg , "--log-destination=" , & v )) {
1314
+ if (!strcmp (v , "syslog" )) {
1315
+ log_destination = LOG_DESTINATION_SYSLOG ;
1316
+ continue ;
1317
+ } else if (!strcmp (v , "stderr" )) {
1318
+ log_destination = LOG_DESTINATION_STDERR ;
1319
+ continue ;
1320
+ } else if (!strcmp (v , "none" )) {
1321
+ log_destination = LOG_DESTINATION_NONE ;
1322
+ continue ;
1323
+ } else
1324
+ die ("unknown log destination '%s'" , v );
1325
+ }
1300
1326
if (!strcmp (arg , "--export-all" )) {
1301
1327
export_all_trees = 1 ;
1302
1328
continue ;
@@ -1353,7 +1379,6 @@ int cmd_main(int argc, const char **argv)
1353
1379
}
1354
1380
if (!strcmp (arg , "--detach" )) {
1355
1381
detach = 1 ;
1356
- log_syslog = 1 ;
1357
1382
continue ;
1358
1383
}
1359
1384
if (skip_prefix (arg , "--user=" , & v )) {
@@ -1399,7 +1424,14 @@ int cmd_main(int argc, const char **argv)
1399
1424
usage (daemon_usage );
1400
1425
}
1401
1426
1402
- if (log_syslog ) {
1427
+ if (log_destination == LOG_DESTINATION_UNSET ) {
1428
+ if (inetd_mode || detach )
1429
+ log_destination = LOG_DESTINATION_SYSLOG ;
1430
+ else
1431
+ log_destination = LOG_DESTINATION_STDERR ;
1432
+ }
1433
+
1434
+ if (log_destination == LOG_DESTINATION_SYSLOG ) {
1403
1435
openlog ("git-daemon" , LOG_PID , LOG_DAEMON );
1404
1436
set_die_routine (daemon_die );
1405
1437
} else
0 commit comments