aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-25 16:09:11 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-04-25 16:09:11 +0300
commitac1d885f562d4c45069ef3f9460917153cad1344 (patch)
tree5584de198ec33ea947617826f46d49dd74316960 /src/main.c
parent55bb0a274095c4871e333e80d78873609bc39d3a (diff)
downloadtagr-ac1d885f562d4c45069ef3f9460917153cad1344.tar.gz
tagr-ac1d885f562d4c45069ef3f9460917153cad1344.tar.bz2
More bugfixes.
* Makefile.am (SUBDIRS): Add etc. * etc/Makefile.am: New file. * src/html.gram.y (create_html): Bugfixes. (add_value): Replace existing entry, if found. * src/log.c (log_facility, log_tag, log_print_severity): New variables. * src/main.c (sig_child): Collect all terminated subprocesses. (main): Redo syslog initialization. Use daemon. * src/output.c (add_stats): Exit immediately if the queue is empty. (update_output): Redefine some symbols unconditionally. * src/readconfig.c: Logging configuration. * src/tagr.h (log_facility, log_tag, log_print_severity): New variables.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c
index 1d1c9a3..55aefcb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -626,7 +626,8 @@ sig_child (int sig)
{
int status;
- waitpid ((pid_t) - 1, &status, WNOHANG);
+ while (waitpid ((pid_t)-1, &status, WNOHANG) > 0)
+ ;
signal (sig, sig_child);
}
@@ -755,11 +756,19 @@ main (int argc, char **argv)
argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
argp_program_version_hook = tagr_version;
- init_syslog (argv[0]);
+ if (!isatty (2))
+ log_to_stderr = 0;
+ init_syslog (argv[0]);
+
if (argp_parse (&argp, argc, argv, 0, &index, NULL))
exit (EX_USAGE);
+ if (log_to_stderr == -1)
+ log_to_stderr = foreground && isatty (0);
+ grecs_log_to_stderr = log_to_stderr;
+ init_syslog (program_invocation_short_name);
+
if (html_template_option)
html_template = html_template_option;
@@ -818,10 +827,6 @@ main (int argc, char **argv)
if (rebuild_option || import_option || list_option || read_option)
exit (0);
- if (log_to_stderr == -1)
- log_to_stderr = foreground && isatty (0);
- grecs_log_to_stderr = log_to_stderr;
-
if (listen_sockaddr.sa == NULL)
{
logmsg (L_CRIT, _("listener address is not configured"));
@@ -885,34 +890,21 @@ main (int argc, char **argv)
if (!foreground)
{
- int i;
- pid_t pid;
+ FILE *fp;
+
+ if (daemon (0, 0))
+ die (EX_OSERR, "cannot become daemon: %s", strerror (errno));
- pid = fork ();
- if (pid < 0)
- die (EX_OSERR, "cannot fork: %s", strerror (errno));
- if (pid > 0)
+ if ((fp = fopen (pidfile, "w")) != NULL)
{
- /* Parent branch */
- FILE *fp;
- /* write pid file */
- if ((fp = fopen (pidfile, "w")) != NULL)
- {
- fprintf (fp, "%d\n", pid);
- fclose (fp);
- }
- else
- {
- logmsg (L_ERR, "can't write pid file %s: %s",
- pidfile, strerror (errno));
- }
- exit (0);
+ fprintf (fp, "%lu\n", (unsigned long) getpid ());
+ fclose (fp);
+ }
+ else
+ {
+ logmsg (L_ERR, "can't write pid file %s: %s",
+ pidfile, strerror (errno));
}
- /* Child branch */
- chdir ("/");
- for (i = 0; i < 3; i++)
- close (i);
- setsid ();
}
logmsg (L_INFO, _("%s started"), program_version);

Return to:

Send suggestions and report system problems to the System administrator.