summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2009-07-23 18:33:20 +0000
committerFrederic Culot <calcurse@culot.org>2009-07-23 18:33:20 +0000
commitade0470197934fba87eb5113a7ecb2d542a6ed73 (patch)
tree3ec5a3f8b363c5ef84bdccbc761bb80edee57c9f /src
parentb55cad85dad5bd4bb81c92f6acaef7394b23d9b5 (diff)
downloadcalcurse-ade0470197934fba87eb5113a7ecb2d542a6ed73.tar.gz
calcurse-ade0470197934fba87eb5113a7ecb2d542a6ed73.zip
Functions added to implement a logging mechanism for calcurse daemon.
Diffstat (limited to 'src')
-rw-r--r--src/dmon.c9
-rwxr-xr-xsrc/io.c34
-rwxr-xr-xsrc/io.h3
-rwxr-xr-xsrc/utils.c14
-rwxr-xr-xsrc/utils.h3
-rwxr-xr-xsrc/vars.c3
-rwxr-xr-xsrc/vars.h6
7 files changed, 63 insertions, 9 deletions
diff --git a/src/dmon.c b/src/dmon.c
index 5845cda..9aae65f 100644
--- a/src/dmon.c
+++ b/src/dmon.c
@@ -1,4 +1,4 @@
-/* $calcurse: dmon.c,v 1.1 2009/07/20 19:44:04 culot Exp $ */
+/* $calcurse: dmon.c,v 1.2 2009/07/23 18:33:20 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -59,6 +59,8 @@ static void
dmon_sigs_hdlr (int sig)
{
notify_free_app ();
+ (void)io_fprintln (path_dmon_log, _("terminated at %s with signal %d\n"),
+ nowstr (), sig);
exit (EXIT_SUCCESS);
}
@@ -165,7 +167,10 @@ dmon_start (int parent_exit_status)
if (next.txt)
mem_free (next.txt);
-
+
+ (void)io_fprintln (path_dmon_log, _("sleeping at %s for %d seconds\n"),
+ nowstr (), DMON_SLEEP_TIME);
psleep (DMON_SLEEP_TIME);
+ (void)io_fprintln (path_dmon_log, _("awakened at %s\n"), nowstr ());
}
}
diff --git a/src/io.c b/src/io.c
index 8d51e81..3c0ffa9 100755
--- a/src/io.c
+++ b/src/io.c
@@ -1,4 +1,4 @@
-/* $calcurse: io.c,v 1.70 2009/07/19 08:20:00 culot Exp $ */
+/* $calcurse: io.c,v 1.71 2009/07/23 18:33:21 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -674,6 +674,34 @@ pcal_export_todo (FILE *stream)
(void)fprintf (stream, "\n");
}
+/* Append a line to a file. */
+unsigned
+io_fprintln (const char *fname, const char *fmt, ...)
+{
+ FILE *fp;
+ va_list ap;
+ char buf[BUFSIZ];
+ int ret;
+
+ fp = fopen (fname, "a");
+ RETVAL_IF (!fp, 0, _("Failed to open \"%s\", - %s\n"),
+ fname, strerror (errno));
+
+ va_start (ap, fmt);
+ ret = vsnprintf (buf, sizeof buf, fmt, ap);
+ RETVAL_IF (ret < 0, 0, _("Failed to build message\n"));
+ va_end (ap);
+
+ ret = fprintf (fp, "%s", buf);
+ RETVAL_IF (ret < 0, 0, _("Failed to print message \"%s\"\n"), buf);
+
+ ret = fclose (fp);
+ RETVAL_IF (ret != 0, 0, _("Failed to close \"%s\" - %s\n"),
+ fname, strerror (errno));
+
+ return 1;
+}
+
/*
* Initialization of data paths. The cfile argument is the variable
* which contains the calendar file. If none is given, then the default
@@ -699,6 +727,7 @@ io_init (char *cfile, char *datadir)
(void)snprintf (path_apts, BUFSIZ, "%s/" APTS_PATH_NAME, home);
(void)snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH_NAME, home);
(void)snprintf (path_lock, BUFSIZ, "%s/" LOCK_PATH_NAME, home);
+ (void)snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home);
}
else
{
@@ -711,7 +740,8 @@ io_init (char *cfile, char *datadir)
(void)snprintf (path_todo, BUFSIZ, "%s/" TODO_PATH, home);
(void)snprintf (path_conf, BUFSIZ, "%s/" CONF_PATH, home);
(void)snprintf (path_keys, BUFSIZ, "%s/" KEYS_PATH, home);
- (void)snprintf (path_lock, BUFSIZ, "%s/" LOCK_PATH, home);
+ (void)snprintf (path_lock, BUFSIZ, "%s/" LOCK_PATH, home);
+ (void)snprintf (path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home);
(void)snprintf (path_notes, BUFSIZ, "%s/" NOTES_DIR, home);
if (cfile == NULL)
{
diff --git a/src/io.h b/src/io.h
index a0b9d8f..c71cb13 100755
--- a/src/io.h
+++ b/src/io.h
@@ -1,4 +1,4 @@
-/* $calcurse: io.h,v 1.22 2009/07/12 16:22:01 culot Exp $ */
+/* $calcurse: io.h,v 1.23 2009/07/23 18:33:21 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -63,6 +63,7 @@ typedef struct {
char name[BUFSIZ];
} io_file_t;
+unsigned io_fprintln (const char *, const char *, ...);
void io_init (char *, char *);
void io_extract_data (char *, const char *, int);
unsigned io_save_conf (conf_t *);
diff --git a/src/utils.c b/src/utils.c
index 34cb142..9e4da1d 100755
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,4 @@
-/* $calcurse: utils.c,v 1.77 2009/07/20 19:45:27 culot Exp $ */
+/* $calcurse: utils.c,v 1.78 2009/07/23 18:33:21 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -764,6 +764,18 @@ now (void)
return (current_time);
}
+char *
+nowstr (void)
+{
+ static char buf[BUFSIZ];
+ time_t now;
+
+ (void)time (&now);
+ (void)strftime (buf, sizeof buf, "%a %b %d %T %Y", localtime (&now));
+
+ return buf;
+}
+
long
mystrtol (const char *str)
{
diff --git a/src/utils.h b/src/utils.h
index eae71a7..035f29a 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $calcurse: utils.h,v 1.47 2009/07/20 19:45:27 culot Exp $ */
+/* $calcurse: utils.h,v 1.48 2009/07/23 18:33:22 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -149,6 +149,7 @@ void draw_scrollbar (WINDOW *, int, int, int, int, int, unsigned);
void item_in_popup (char *, char *, char *, char *);
long get_today (void);
long now (void);
+char *nowstr (void);
long mystrtol (const char *);
void print_bool_option_incolor (WINDOW *, unsigned, int, int);
char *new_tempfile (const char *, int);
diff --git a/src/vars.c b/src/vars.c
index 7120ae1..0dc6a06 100755
--- a/src/vars.c
+++ b/src/vars.c
@@ -1,4 +1,4 @@
-/* $calcurse: vars.c,v 1.17 2009/07/12 16:22:02 culot Exp $ */
+/* $calcurse: vars.c,v 1.18 2009/07/23 18:33:22 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -103,6 +103,7 @@ char path_conf[] = "";
char path_notes[] = "";
char path_keys[] = "";
char path_lock[] = "";
+char path_dmon_log[] = "";
/* Variable to handle pads. */
struct pad_s apad;
diff --git a/src/vars.h b/src/vars.h
index 1f220e8..677c15a 100755
--- a/src/vars.h
+++ b/src/vars.h
@@ -1,4 +1,4 @@
-/* $calcurse: vars.h,v 1.34 2009/07/12 16:22:02 culot Exp $ */
+/* $calcurse: vars.h,v 1.35 2009/07/23 18:33:22 culot Exp $ */
/*
* Calcurse - text-based organizer
@@ -61,6 +61,7 @@
#define CONF_PATH_NAME "conf"
#define KEYS_PATH_NAME "keys"
#define LOCK_PATH_NAME ".calcurse.lock"
+#define DLOG_PATH_NAME "daemon.log"
#define NOTES_DIR_NAME "notes/"
#define TODO_PATH DIR_NAME TODO_PATH_NAME
@@ -68,6 +69,7 @@
#define CONF_PATH DIR_NAME CONF_PATH_NAME
#define KEYS_PATH DIR_NAME KEYS_PATH_NAME
#define LOCK_PATH DIR_NAME LOCK_PATH_NAME
+#define DLOG_PATH DIR_NAME DLOG_PATH_NAME
#define NOTES_DIR DIR_NAME NOTES_DIR_NAME
#define ATTR_FALSE 0
@@ -160,6 +162,8 @@ extern char path_conf[BUFSIZ];
extern char path_keys[BUFSIZ];
extern char path_notes[BUFSIZ];
extern char path_lock[BUFSIZ];
+extern char path_dmon_log[BUFSIZ];
+
extern struct pad_s apad;
extern struct nbar_s nbar;