nghttpx: Android specific hack for special files for logging
Android lacks /dev/stderr, so directly use /proc/self/fd/2 as default errorlog-file. Android does not like O_APPEND for /proc/self/fd/1 and /proc/self/fd/2, so omit the flag for these paths.
This commit is contained in:
parent
a507fc80b6
commit
86dd1519b4
|
@ -746,7 +746,12 @@ void fill_default_config()
|
||||||
mod_config()->no_via = false;
|
mod_config()->no_via = false;
|
||||||
mod_config()->accesslog_file = nullptr;
|
mod_config()->accesslog_file = nullptr;
|
||||||
mod_config()->accesslog_syslog = false;
|
mod_config()->accesslog_syslog = false;
|
||||||
|
#if defined(__ANDROID__) || defined(ANDROID)
|
||||||
|
// Android does not have /dev/stderr. Use /proc/self/fd/2 instead.
|
||||||
|
mod_config()->errorlog_file = strcopy("/proc/self/fd/2");
|
||||||
|
#else // !__ANDROID__ && ANDROID
|
||||||
mod_config()->errorlog_file = strcopy("/dev/stderr");
|
mod_config()->errorlog_file = strcopy("/dev/stderr");
|
||||||
|
#endif // !__ANDROID__ && ANDROID
|
||||||
mod_config()->errorlog_syslog = false;
|
mod_config()->errorlog_syslog = false;
|
||||||
mod_config()->conf_path = strcopy("/etc/nghttpx/nghttpx.conf");
|
mod_config()->conf_path = strcopy("/etc/nghttpx/nghttpx.conf");
|
||||||
mod_config()->syslog_facility = LOG_DAEMON;
|
mod_config()->syslog_facility = LOG_DAEMON;
|
||||||
|
|
16
src/util.cc
16
src/util.cc
|
@ -589,8 +589,24 @@ bool numeric_host(const char *hostname)
|
||||||
|
|
||||||
int reopen_log_file(const char *path)
|
int reopen_log_file(const char *path)
|
||||||
{
|
{
|
||||||
|
#if defined(__ANDROID__) || defined(ANDROID)
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if(strcmp("/proc/self/fd/1", path) == 0 ||
|
||||||
|
strcmp("/proc/self/fd/2", path) == 0) {
|
||||||
|
|
||||||
|
// We will get permission denied error when O_APPEND is used for
|
||||||
|
// these paths.
|
||||||
|
fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC,
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
||||||
|
} else {
|
||||||
|
fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
||||||
|
}
|
||||||
|
#else // !__ANDROID__ && !ANDROID
|
||||||
auto fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
|
auto fd = open(path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC,
|
||||||
S_IRUSR | S_IWUSR | S_IRGRP);
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
||||||
|
#endif // !__ANDROID__ && !ANDROID
|
||||||
|
|
||||||
if(fd == -1) {
|
if(fd == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue