--- a/daemon.c
+++ b/daemon.c
@@ -16,6 +16,7 @@
#define MAXLEN 80
#define TIME_OUT 60
+
#define INPUT_FILE "/proc/meminfo"
#define OUTPUT_FILE "/tmp/meminfo.log"
#define LOCK_FILE "/tmp/.daemon.lock"
@@ -48,6 +49,11 @@
struct stat st;
int fd;
+ if (stat (INPUT_FILE, &st) != 0) {
+ perror (INPUT_FILE);
+ exit (EXIT_FAILURE);
+ }
+
if (argc == 2) {
if (!strcmp (argv[1], "-h")) {
printf ("Usage: %s [-f|-h]\n", argv[0]);
@@ -63,7 +69,10 @@
}
if (stat (LOCK_FILE, &st) < 0) {
- fd = open (LOCK_FILE, O_WRONLY | O_CREAT, 0);
+ if ((fd = open (LOCK_FILE, O_WRONLY | O_CREAT, 0)) < 0) {
+ perror (LOCK_FILE);
+ exit (EXIT_FAILURE);
+ }
close (fd);
} else {
fprintf (stderr, "%s is already running\n", argv[0]);