Skip to content

Commit

Permalink
Remove log rotation from the other apps too
Browse files Browse the repository at this point in the history
  • Loading branch information
Beirdo committed Apr 28, 2011
1 parent 062482b commit be5faf3
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 209 deletions.
2 changes: 1 addition & 1 deletion mythtv/programs/mythbackend/main.cpp
Expand Up @@ -107,7 +107,7 @@ int main(int argc, char **argv)

gContext = new MythContext(MYTH_BINARY_VERSION);

setupLogfile();
logStart(logfile);

if (cmdline.toBool("event") || cmdline.toBool("systemevent") ||
cmdline.toBool("setverbose") || cmdline.toBool("printsched") ||
Expand Down
51 changes: 0 additions & 51 deletions mythtv/programs/mythbackend/main_helpers.cpp
Expand Up @@ -274,43 +274,6 @@ void cleanup(void)
#endif
}

int log_rotate(int report_error)
{
#if 0
/* http://www.gossamer-threads.com/lists/mythtv/dev/110113 */

int new_logfd = open(logfile.toLocal8Bit().constData(),
O_WRONLY|O_CREAT|O_APPEND|O_SYNC, 0664);
if (new_logfd < 0)
{
// If we can't open the new log file, send data to /dev/null
if (report_error)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("Cannot open log file '%1'").arg(logfile));
return -1;
}
new_logfd = open("/dev/null", O_WRONLY);
if (new_logfd < 0)
{
// There's not much we can do, so punt.
return -1;
}
}
while (dup2(new_logfd, 1) < 0 && errno == EINTR) ;
while (dup2(new_logfd, 2) < 0 && errno == EINTR) ;
while (close(new_logfd) < 0 && errno == EINTR) ;
#endif

logStart(logfile);
return 0;
}

void log_rotate_handler(int)
{
log_rotate(0);
}

void showUsage(const MythBackendCommandLineParser &cmdlineparser, const QString &version)
{
QString help = cmdlineparser.GetHelpString(false);
Expand All @@ -322,20 +285,6 @@ void showUsage(const MythBackendCommandLineParser &cmdlineparser, const QString
<< endl << ahelp.constData() << endl;
}

void setupLogfile(void)
{
if (!logfile.isEmpty())
{
if (log_rotate(1) < 0)
{
VERBOSE(VB_IMPORTANT, LOC_WARN +
"Cannot open log file; using stdout/stderr instead");
}
else
signal(SIGHUP, &log_rotate_handler);
}
}

bool openPidfile(ofstream &pidfs, const QString &pidfile)
{
if (!pidfile.isEmpty())
Expand Down
3 changes: 0 additions & 3 deletions mythtv/programs/mythbackend/main_helpers.h
Expand Up @@ -10,11 +10,8 @@ class QSize;
bool setupTVs(bool ismaster, bool &error);
bool setup_context(MythBackendCommandLineParser &cmdline);
void cleanup(void);
int log_rotate(int report_error);
void log_rotate_handler(int);
void upnp_rebuild(int);
void showUsage(const MythBackendCommandLineParser &cmdlineparser, const QString &version);
void setupLogfile(void);
bool openPidfile(ofstream &pidfs, const QString &pidfilename);
bool setUser(const QString &username);
int handle_command(const MythBackendCommandLineParser &cmdline);
Expand Down
45 changes: 1 addition & 44 deletions mythtv/programs/mythjobqueue/main.cpp
Expand Up @@ -54,40 +54,6 @@ static void cleanup(void)
signal(SIGHUP, SIG_DFL);
}

static int log_rotate(int report_error)
{
#if 0
int new_logfd = open(logfile.toLocal8Bit().constData(),
O_WRONLY|O_CREAT|O_APPEND|O_SYNC, 0664);
if (new_logfd < 0)
{
// If we can't open the new log file, send data to /dev/null
if (report_error)
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("Cannot open log file '%1'").arg(logfile));
return -1;
}
new_logfd = open("/dev/null", O_WRONLY);
if (new_logfd < 0)
{
// There's not much we can do, so punt.
return -1;
}
}
while (dup2(new_logfd, 1) < 0 && errno == EINTR) ;
while (dup2(new_logfd, 2) < 0 && errno == EINTR) ;
while (close(new_logfd) < 0 && errno == EINTR) ;
#endif
logStart(logfile);
return 0;
}

static void log_rotate_handler(int)
{
log_rotate(0);
}

namespace
{
class CleanupGuard
Expand Down Expand Up @@ -150,16 +116,7 @@ int main(int argc, char *argv[])
if (cmdline.toBool("daemon"))
daemonize = true;

if (!logfile.isEmpty())
{
if (log_rotate(1) < 0)
{
VERBOSE(VB_IMPORTANT, LOC_WARN +
"Cannot open log file; using stdout/stderr instead");
}
else
signal(SIGHUP, &log_rotate_handler);
}
logStart(logfile);

CleanupGuard callCleanup(cleanup);

Expand Down
52 changes: 1 addition & 51 deletions mythtv/programs/mythtv-setup/main.cpp
Expand Up @@ -189,43 +189,6 @@ static int reloadTheme(void)
return 0;
}

static int log_rotate(int report_error)
{
#if 0
int new_logfd = open(logfile.toLocal8Bit().constData(),
O_WRONLY|O_CREAT|O_APPEND, 0664);

if (new_logfd < 0) {
/* If we can't open the new log file, send data to /dev/null */
if (report_error)
{
VERBOSE(VB_IMPORTANT, QString("Can not open log file '%1'")
.arg(logfile));
return -1;
}

new_logfd = open("/dev/null", O_WRONLY);

if (new_logfd < 0) {
/* There's not much we can do, so punt. */
return -1;
}
}

while (dup2(new_logfd, 1) < 0 && errno == EINTR);
while (dup2(new_logfd, 2) < 0 && errno == EINTR);
while (close(new_logfd) < 0 && errno == EINTR);

#endif
logStart(logfile);
return 0;
}

static void log_rotate_handler(int)
{
log_rotate(0);
}

int main(int argc, char *argv[])
{
QString geometry = QString::null;
Expand Down Expand Up @@ -335,20 +298,7 @@ int main(int argc, char *argv[])
if (cmdline.toBool("inputname"))
scanInputName = cmdline.toString("inputname");

if (logfile.size())
{
if (log_rotate(1) < 0)
cerr << "cannot open log file; using stdout/stderr" << endl;
else
{
VERBOSE(VB_IMPORTANT, QString("%1 version: %2 [%3] www.mythtv.org")
.arg(MYTH_APPNAME_MYTHTV_SETUP)
.arg(MYTH_SOURCE_PATH)
.arg(MYTH_SOURCE_VERSION));

signal(SIGHUP, &log_rotate_handler);
}
}
logStart(logfile);

if (!display.isEmpty())
{
Expand Down
60 changes: 1 addition & 59 deletions mythtv/programs/mythwelcome/main.cpp
Expand Up @@ -34,8 +34,6 @@

QString logfile = "";

static bool log_rotate(bool report_error);
static void log_rotate_handler(int);


static void initKeys(void)
Expand Down Expand Up @@ -84,7 +82,7 @@ int main(int argc, char **argv)
if (!cmdline.toString("logfile").isEmpty())
logfile = cmdline.toString("logfile");

logStart("");
logStart(logfile);

gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init())
Expand All @@ -101,14 +99,6 @@ int main(int argc, char **argv)
return -1;
}

if (!logfile.isEmpty())
{
if (!log_rotate(true))
cerr << "cannot open log file; using stdout/stderr" << endl;
else
signal(SIGHUP, &log_rotate_handler);
}

LCD::SetupLCD();

if (LCD *lcd = LCD::Get())
Expand Down Expand Up @@ -157,51 +147,3 @@ int main(int argc, char **argv)

return 0;
}


static bool log_rotate(bool report_error)
{
#if 0
int new_logfd = open(logfile.toLocal8Bit().constData(),
O_WRONLY|O_CREAT|O_APPEND, 0664);

if (new_logfd < 0)
{
/* If we can't open the new log file, send data to /dev/null */
if (report_error)
{
cerr << "cannot open log file " << logfile.toAscii().constData() << endl;
return false;
}

new_logfd = open("/dev/null", O_WRONLY);

if (new_logfd < 0)
{
/* There's not much we can do, so punt. */
return false;
}
}

#ifdef WINDOWS_CLOSE_CONSOLE
// pure Win32 GUI app does not have standard IO streams
// simply assign the file descriptors to the log file
*stdout = *(_fdopen(new_logfd, "w"));
*stderr = *stdout;
setvbuf(stdout, NULL, _IOLBF, 256);
#else
while (dup2(new_logfd, 1) < 0 && errno == EINTR);
while (dup2(new_logfd, 2) < 0 && errno == EINTR);
while (close(new_logfd) < 0 && errno == EINTR);
#endif
#endif

logStart(logfile);
return true;
}


static void log_rotate_handler(int)
{
log_rotate(false);
}

0 comments on commit be5faf3

Please sign in to comment.