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

use err(3) functions #316

Closed
fluca1978 opened this issue Aug 24, 2022 · 0 comments
Closed

use err(3) functions #316

fluca1978 opened this issue Aug 24, 2022 · 0 comments

Comments

@fluca1978
Copy link
Collaborator

There is a lot of code that contains printf or fprintf(stderr) and exit (e.g., https://github.com/agroal/pgagroal/blob/master/src/main.c#L528).

I propose to change such bunch of code with the err(3) set of functions, like errx. Advantages:

  • it will bring coherency around the code
  • makes the code a little more readable
  • no need for the extra new line at the end of the string
  • provides automatically short application name in front of the message, as for example
$ pgagroal
pgagroal: Server section [a] duplicated at lines 15 and 19 of file </etc/pgagroal/pgagroal.conf>
pgagroal: 1 problematic or duplicated sections (file </etc/pgagroal/pgagroal.conf>)

$ /usr/local/bin/pgagroal
pgagroal: Server section [a] duplicated at lines 15 and 19 of file </etc/pgagroal/pgagroal.conf>
pgagroal: 1 problematic or duplicated sections (file </etc/pgagroal/pgagroal.conf>)

The pgagroal: part is automatically appended even if the application is invoked with a full path, so we can remove it (and forget about it) from every message.

fluca1978 added a commit to fluca1978/pgagroal that referenced this issue Aug 24, 2022
Whenever in the code there is a `printf` + `exit` or similar piece of
code, use `err(3)` functions instead.
This brings coherency, removes the need for the extra new line, the
program name and provides automatic expansion of errors when needed.

This also changes the `create_pidfile` sttic function so that it
terminates the current program (main) if the pid file cannot be
created. To emphasize this, the function has been renamed to
`create_pidfile_or_exit`. Also the `remove_pidfile` changed to emit a
warning if the pid file cannot be removed

Close agroal#316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant