Fix server not to create a journal on SIGHUP when !keep_journal:
(journal_reopen): New. (main): Use it. Fixes failure to obey !keep_journal. (journal_open): Internal linkage, changed semantics and return value. Callers changed. (journal_close): One caller left, inline and remove.
This commit is contained in:
parent
139086fd20
commit
befac7cf83
3 changed files with 30 additions and 21 deletions
|
@ -34,15 +34,12 @@
|
||||||
#ifndef JOURNAL_H
|
#ifndef JOURNAL_H
|
||||||
#define JOURNAL_H
|
#define JOURNAL_H
|
||||||
|
|
||||||
int journal_open(void);
|
|
||||||
int journal_close(void);
|
|
||||||
void journal_entry(char *fmt, ...);
|
|
||||||
|
|
||||||
int journal_startup(void);
|
int journal_startup(void);
|
||||||
void journal_shutdown(void);
|
void journal_shutdown(void);
|
||||||
|
int journal_reopen(void);
|
||||||
void journal_login(void);
|
void journal_login(void);
|
||||||
void journal_logout(void);
|
void journal_logout(void);
|
||||||
void journal_input(char *input);
|
void journal_input(char *);
|
||||||
void journal_update(int);
|
void journal_update(int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -63,22 +63,13 @@
|
||||||
static char journal_fname[] = "journal.log";
|
static char journal_fname[] = "journal.log";
|
||||||
static FILE *journal;
|
static FILE *journal;
|
||||||
|
|
||||||
int
|
static FILE *
|
||||||
journal_open(void)
|
journal_open(void)
|
||||||
{
|
{
|
||||||
journal = fopen(journal_fname, "a+");
|
return fopen(journal_fname, "a+");
|
||||||
return journal ? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
journal_close(void)
|
|
||||||
{
|
|
||||||
FILE *j = journal;
|
|
||||||
journal = NULL;
|
|
||||||
return j ? fclose(j) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
journal_entry(char *fmt, ...)
|
journal_entry(char *fmt, ...)
|
||||||
{
|
{
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
|
@ -109,7 +100,8 @@ journal_startup(void)
|
||||||
{
|
{
|
||||||
if (!keep_journal)
|
if (!keep_journal)
|
||||||
return 0;
|
return 0;
|
||||||
if (journal_open() < 0) {
|
journal = journal_open();
|
||||||
|
if (!journal) {
|
||||||
logerror("Can't open %s (%s)", journal_fname, strerror(errno));
|
logerror("Can't open %s (%s)", journal_fname, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +113,28 @@ void
|
||||||
journal_shutdown(void)
|
journal_shutdown(void)
|
||||||
{
|
{
|
||||||
journal_entry("shutdown");
|
journal_entry("shutdown");
|
||||||
journal_close();
|
if (journal) {
|
||||||
|
fclose(journal);
|
||||||
|
journal = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
journal_reopen(void)
|
||||||
|
{
|
||||||
|
FILE *j;
|
||||||
|
|
||||||
|
if (!keep_journal)
|
||||||
|
return 0;
|
||||||
|
j = journal_open();
|
||||||
|
if (!j) {
|
||||||
|
logerror("Can't open %s (%s)", journal_fname, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (journal)
|
||||||
|
fclose(journal);
|
||||||
|
journal = j;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -267,8 +267,7 @@ main(int argc, char **argv)
|
||||||
sig = empth_wait_for_signal();
|
sig = empth_wait_for_signal();
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
if (sig == SIGHUP) {
|
if (sig == SIGHUP) {
|
||||||
journal_close();
|
journal_reopen();
|
||||||
journal_open();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue