Skip to content

Commit

Permalink
Write a pidfile only when daemonized
Browse files Browse the repository at this point in the history
Newer systems running smarter init systems -such as systemd- do not need
a pidfile to track the process.

Do not write one unconditionally, but make it conditional to daemon-mode
instead, which feels more appropriate anyway as running into the
foreground with a pidfile doesn't make any sense.

Change-Id: Idf8c5c33fb8dff3dde20ccf995e0c21d4daf93e8
  • Loading branch information
paravoid committed Jun 19, 2015
1 parent d99974e commit f843ed2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions kafkatee.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ int main (int argc, char **argv) {
kt_log(LOG_ERR, "%s", errstr);
exit(1);
}
}

if (ezd_pidfile_open(conf.pid_file_path,
errstr, sizeof(errstr)) == -1) {
kt_log(LOG_ERR, "%s", errstr);
exit(1);
if (ezd_pidfile_open(conf.pid_file_path,
errstr, sizeof(errstr)) == -1) {
kt_log(LOG_ERR, "%s", errstr);
exit(1);
}
}


Expand All @@ -234,7 +234,8 @@ int main (int argc, char **argv) {
if (conf.fconf.encoding != ENC_STRING) {
kt_log(LOG_ERR, "Output formatting only supported for "
"output.encoding = string");
ezd_pidfile_close();
if (conf.daemonize)
ezd_pidfile_close();
exit(1);
}

Expand All @@ -243,7 +244,8 @@ int main (int argc, char **argv) {
kt_log(LOG_ERR,
"Failed to parse format string: %s\n%s",
conf.fconf.format, errstr);
ezd_pidfile_close();
if (conf.daemonize)
ezd_pidfile_close();
exit(1);
}
}
Expand All @@ -256,7 +258,8 @@ int main (int argc, char **argv) {
kt_log(LOG_ERR,
"Failed to open statistics log file %s: %s",
conf.stats_file, strerror(errno));
ezd_pidfile_close();
if (conf.daemonize)
ezd_pidfile_close();
exit(1);
}

Expand All @@ -272,7 +275,8 @@ int main (int argc, char **argv) {
errstr, sizeof(errstr)))) {
kt_log(LOG_ERR,
"Failed to create kafka handle: %s", errstr);
ezd_pidfile_close();
if (conf.daemonize)
ezd_pidfile_close();
exit(1);
}

Expand Down Expand Up @@ -340,7 +344,8 @@ int main (int argc, char **argv) {
"with exit code %i", conf.cmd_term, r);
}

ezd_pidfile_close();
if (conf.daemonize)
ezd_pidfile_close();

kt_log(LOG_INFO, "kafkatee exiting");
exit(conf.exit_code);
Expand Down

0 comments on commit f843ed2

Please sign in to comment.