Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write PID file after forking and before exiting. #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions zhm/zhm.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,13 @@ init_hm(void)
#ifndef DEBUG
if (!inetd && !nofork)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add { } to this statement? I don't like unblanaced if-else clauses where one has it and the other does not.

detach();

/* Write pid to file */
fp = fopen(PidFile, "w");
if (fp != NULL) {
else {
/* Write pid to file */
fp = fopen(PidFile, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", getpid());
fclose(fp);
}
}
#endif /* DEBUG */

Expand Down Expand Up @@ -469,11 +470,18 @@ detach(void)
/* detach from terminal and fork. */
register int i, x = ZGetFD();
register long size;
FILE *fp;

i = fork();
if (i) {
if (i < 0)
perror("fork");
perror("fork");
/* Write pid to file */
fp = fopen(PidFile, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", i);
fclose(fp);
}
exit(0);
}
#ifdef _POSIX_VERSION
Expand Down