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

Daemonize after certain possible errors #177

Merged
merged 2 commits into from Jan 22, 2018

Conversation

Projects
None yet
2 participants
@Hritik14
Copy link
Contributor

commented Jan 14, 2018

else abnormal exit is treated normal.

@@ -467,6 +459,16 @@ int main(int argc, char **argv)
if (!(args.flags & FLAG_NO_DAEMON)) {
create_PID_file();
}

if (!(args.flags & FLAG_NO_DAEMON)) {

This comment has been minimized.

Copy link
@kernc

kernc Jan 15, 2018

Owner

Are you sure daemonization comes after PID file creation above? Whose PID does the file then hold?

@Hritik14

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

Mind checking now ?

@kernc
Copy link
Owner

left a comment

I'll admit to opposing the messages-in-a-separate-file change. Given how they are simple error messages, any of them being used exactly once, I see no gain in having them defined so far away from where they're used.

Other than that and the few comments regarding style, this looks fine. 👍

error(EXIT_FAILURE, errno, LOGFILE_OPEN_ERROM);


if(access(PID_FILE, F_OK ) != -1) //PID file already exists

This comment has been minimized.

Copy link
@kernc

kernc Jan 18, 2018

Owner

I know the code is not pretty nor consistently adhered to any single style, but could you put a space after if and after //. And double-space before //. And remove the space after F_OK. Kind of like the rest of the code is.

This comment has been minimized.

Copy link
@Hritik14

Hritik14 Jan 18, 2018

Author Contributor

Done. I suppose this projects require a contributing.md that mentions these. Would make things a bit faster. Hmm... Maybe that can be automated. Can you list a consistent style you'd like the code to follow ?



if(access(PID_FILE, F_OK ) != -1) //PID file already exists
error(EXIT_FAILURE,errno, ANOTHER_RUNNING_ERROM);

This comment has been minimized.

Copy link
@kernc

kernc Jan 18, 2018

Owner

And a space after comma.

error(EXIT_FAILURE,errno, ANOTHER_RUNNING_ERROM);

if (!(args.flags & FLAG_NO_DAEMON)) {
int nochdir = 0;

This comment has been minimized.

Copy link
@kernc

kernc Jan 18, 2018

Owner

Please use space characters only. I know it's not overly consistent everywhere, but that's no justification to introduce further inconsistencies. For some peculiar legacy reason, the indentation level should be represented with two spaces, i.e. __.

This comment has been minimized.

Copy link
@Hritik14

Hritik14 Jan 18, 2018

Author Contributor

I wish this tab vs space war could end.

@Hritik14

This comment has been minimized.

Copy link
Contributor Author

commented Jan 18, 2018

Constant messages in a seperate file always seem good.
Translations become easy to contribute and messages are super easy to modify (if in case)

@Hritik14

This comment has been minimized.

Copy link
Contributor Author

commented Jan 21, 2018

Any update ?

@kernc
Copy link
Owner

left a comment

Thanks for the nudge. I understand your concerns re messages. But I'll disagree putting them in a single file is always good. Translations become easy to contribute once you have a template file to translate. Gettext, for one ubiquitous translation system, scans any source files you tell it for strings marked with gettext()/_() macro. I prefer stuff defined where they are used, especially when they are used exactly once. And these are error messages meant for advanced users as is the software in general — I don't foresee them being translated into multiple languages, really.

I'll much prefer to see that commit reverted, and let this PR be about what it says in the title? 😄

if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;

This comment has been minimized.

Copy link
@kernc

kernc Jan 21, 2018

Owner

if is missing an indent level under while. I guess don't fix (touch) indentation in this PR, other than on the lines you change. 👍

if (errno == EEXIST)
error(EXIT_FAILURE, errno, "Another process already running? Quitting. (" PID_FILE ")");
else error(EXIT_FAILURE, errno, "Error opening PID file '" PID_FILE "'");
if (errno == EEXIST) //This should never happen, ever, but error handling is nice.

This comment has been minimized.

Copy link
@kernc

kernc Jan 21, 2018

Owner

Two spaces before a comment start (//), one space before comment contents, like so:

if (errno == EEXIST)  // This should ...

I believe this is customary with other C-like imperative languages as well.


error(EXIT_FAILURE, errno, LOGFILE_OPEN_ERROM);


This comment has been minimized.

Copy link
@kernc

kernc Jan 21, 2018

Owner

If you want, can also remove one blank line here, so we're left with a total of one blank line between blocks.

@Hritik14 Hritik14 force-pushed the Hritik14:master branch from bd46d66 to 60828a8 Jan 22, 2018

@Hritik14 Hritik14 force-pushed the Hritik14:master branch from 60828a8 to 4d60a39 Jan 22, 2018

@Hritik14 Hritik14 changed the title Daemonize after creating PID files and other stuff Daemonize after certain possible errors Jan 22, 2018

@Hritik14

This comment has been minimized.

Copy link
Contributor Author

commented Jan 22, 2018

I think that's fixed now.

if (!(args.flags & FLAG_NO_DAEMON)) {
int nochdir = 0;
if (args.logfile[0] != '/')
nochdir = 1; // don't chdir (logfile specified with relative path)

This comment has been minimized.

Copy link
@kernc

kernc Jan 22, 2018

Owner

Just noticed. Since the already open logfile is now inherited by the daemon, nochdir can always be 0. Can remove the variable altogether.


if (!(args.flags & FLAG_NO_DAEMON)) {
int noclose = 1; // don't close streams (stderr used)
if (daemon(nochdir, noclose) == -1) // become daemon

This comment has been minimized.

Copy link
@kernc

kernc Jan 22, 2018

Owner

If we had CI, it would have caught this: nochdir is not defined.

This comment has been minimized.

Copy link
@Hritik14

Hritik14 Jan 22, 2018

Author Contributor

I blindly pushed it. Fixed it soon though. On my local machine it's not there and I force pushed it. Maybe I'd better commit again

@Hritik14 Hritik14 force-pushed the Hritik14:master branch from 98d4d23 to a20c49a Jan 22, 2018

@Hritik14 Hritik14 force-pushed the Hritik14:master branch from a20c49a to d7112c8 Jan 22, 2018

@Hritik14

This comment has been minimized.

Copy link
Contributor Author

commented Jan 22, 2018

Fixed

@kernc

kernc approved these changes Jan 22, 2018

@kernc

This comment has been minimized.

Copy link
Owner

commented Jan 22, 2018

Looks good! Thanks for the contribution, and patience. 👍

@kernc kernc merged commit 7a9f19f into kernc:master Jan 22, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.