aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-18 22:36:27 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-18 22:36:27 +0300
commit84838fa69592cf37f97aaa918ad4e69b8bd4d62a (patch)
tree1f0395d1ff3f5ad391155bcd819ee77b972eb02f /src
parent5e93c56acf080ef006176076be4efab4aa0591c0 (diff)
downloadwydawca-84838fa69592cf37f97aaa918ad4e69b8bd4d62a.tar.gz
wydawca-84838fa69592cf37f97aaa918ad4e69b8bd4d62a.tar.bz2
Modify pidfile functions
Diffstat (limited to 'src')
-rw-r--r--src/pidfile.c20
-rw-r--r--src/wydawca.c5
-rw-r--r--src/wydawca.h5
3 files changed, 23 insertions, 7 deletions
diff --git a/src/pidfile.c b/src/pidfile.c
index edd8e09..efd2f80 100644
--- a/src/pidfile.c
+++ b/src/pidfile.c
@@ -20,13 +20,13 @@ char *pidfile = LOCALSTATEDIR "/run/wydawca.pid";
int force_startup;
void
-remove_pidfile(void)
+pidfile_remove(void)
{
unlink(pidfile);
}
void
-check_pidfile()
+pidfile_check(void)
{
FILE *fp = fopen(pidfile, "r+");
@@ -60,7 +60,7 @@ check_pidfile()
strerror(errno));
exit(EX_UNAVAILABLE);
} else {
- fp = fopen(pidfile, "w");
+ fp = fopen(pidfile, "w");
if (!fp) {
wy_log(LOG_ERR,
_("cannot open pidfile %s for writing: %s"),
@@ -71,3 +71,17 @@ check_pidfile()
fprintf(fp, "%lu\n", (unsigned long) getpid());
fclose(fp);
}
+
+void
+pidfile_update(void)
+{
+ FILE *fp = fopen(pidfile, "w");
+ if (!fp) {
+ wy_log(LOG_ERR,
+ _("cannot open pidfile %s for writing: %s"),
+ pidfile, strerror(errno));
+ exit(EX_UNAVAILABLE);
+ }
+ fprintf(fp, "%lu\n", (unsigned long) getpid());
+ fclose(fp);
+}
diff --git a/src/wydawca.c b/src/wydawca.c
index 09015c1..d07ebdf 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -325,6 +325,7 @@ wy_main(void)
}
wy_log(LOG_NOTICE, _("daemon launched"));
}
+ pidfile_update();
// Start cleaner thread
pthread_create(&tid, NULL, wy_thr_cleaner, NULL);
@@ -451,12 +452,12 @@ main(int argc, char **argv)
wy_log(LOG_NOTICE, _("wydawca (%s) started"), PACKAGE_STRING);
if (!wy_dry_run)
- check_pidfile();
+ pidfile_check();
wy_main();
dictionaries_close();
modules_close();
- remove_pidfile();
+ pidfile_remove();
wy_log(LOG_NOTICE, _("wydawca (%s) finished"), PACKAGE_STRING);
diff --git a/src/wydawca.h b/src/wydawca.h
index 2c1c3de..c48ea30 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -529,8 +529,9 @@ void report_finish(void);
extern char *report_string;
/* profile.c */
-void check_pidfile(void);
-void remove_pidfile(void);
+void pidfile_check(void);
+void pidfile_remove(void);
+void pidfile_update(void);
/* net.c */
void *wy_thr_listen(void *);

Return to:

Send suggestions and report system problems to the System administrator.