]> git.ipfire.org Git - thirdparty/fcron.git/commitdiff
added cl.c/cl.h to define the cl_t type with associated functions
authorThibault Godouet <yo8192@users.noreply.github.com>
Wed, 21 Nov 2012 22:45:23 +0000 (22:45 +0000)
committerThibault Godouet <yo8192@users.noreply.github.com>
Wed, 21 Nov 2012 22:45:23 +0000 (22:45 +0000)
Makefile.in
cl.c [new file with mode: 0644]
cl.h [new file with mode: 0644]
conf.c
fileconf.c
global.h

index 1f906ddbf701014a1a8002c973bc4479f1517237..d0b13f66aac7c454c4efac7d57bf1f783ed7ca19 100644 (file)
@@ -74,12 +74,12 @@ CFLAGS += $(OPTIM) $(OPTION) $(DEFS) $(CPPFLAGS)
 ifeq ($(FCRONDYN), 1)
 LIBOBJS := socket.o $(LIBOBJS)
 endif
-OBJSD := fcron.o subs.o mem.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o fcronconf.o $(LIBOBJS)
-OBJSTAB := fcrontab.o subs.o mem.o save.o temp_file.o  log.o fileconf.o allow.o read_string.o u_list.o env_list.o fcronconf.o
+OBJSD := fcron.o cl.o subs.o mem.o save.o temp_file.o log.o database.o job.o conf.o u_list.o exe_list.o lavg_list.o env_list.o fcronconf.o $(LIBOBJS)
+OBJSTAB := fcrontab.o cl.o subs.o mem.o save.o temp_file.o  log.o fileconf.o allow.o read_string.o u_list.o env_list.o fcronconf.o
 OBJSDYN := fcrondyn.o subs.o mem.o log.o allow.o read_string.o fcronconf.o
-OBJCONV := convert-fcrontab.o subs.o mem.o save.o log.o u_list.o env_list.o
+OBJCONV := convert-fcrontab.o cl.o subs.o mem.o save.o log.o u_list.o env_list.o
 OBJSIG := fcronsighup.o subs.o mem.o log.o allow.o fcronconf.o
-HEADERSALL := config.h $(SRCDIR)/global.h $(SRCDIR)/log.h $(SRCDIR)/subs.h $(SRCDIR)/mem.h $(SRCDIR)/save.h $(SRCDIR)/option.h $(SRCDIR)/dyncom.h
+HEADERSALL := config.h $(SRCDIR)/global.h $(SRCDIR)/cl.h $(SRCDIR)/log.h $(SRCDIR)/subs.h $(SRCDIR)/mem.h $(SRCDIR)/save.h $(SRCDIR)/option.h $(SRCDIR)/dyncom.h
 
 # this is a regular expression :
 # do not ci automaticaly generated files and doc (done by doc's Makefile)
diff --git a/cl.c b/cl.c
new file mode 100644 (file)
index 0000000..2711bc0
--- /dev/null
+++ b/cl.c
@@ -0,0 +1,75 @@
+/*
+ * FCRON - periodic command scheduler
+ *
+ *  Copyright 2000-2012 Thibault Godouet <fcron@free.fr>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  The GNU General Public License can also be found in the file
+ *  `LICENSE' that comes with the fcron source distribution.
+ */
+
+#include "global.h"
+#include "cl.h"
+#include "mem.h"
+
+cl_t*
+dups_cl(cl_t *orig)
+    /* Duplicate a line, including the strings it points to. */
+{
+    cl_t *cl = NULL;
+
+    Alloc(cl, cl_t);
+
+    /* copy the structure */
+    *cl = *orig;
+
+    /* don't assume any link to a file or belonging to a list */
+    cl->cl_file = NULL;
+    cl->cl_next = NULL;
+
+    /* we just copied the pointers of orig to cl, but we didn't
+     * make a copy of the strings yet.
+     * Reset the pointers, then copy the strings */
+    cl->cl_shell = NULL;
+    Set(cl->cl_shell, orig->cl_shell);
+
+    cl->cl_runas = NULL;
+    Set(cl->cl_runas, orig->cl_runas);
+    debug("%s: Set cl->cl_runas=%s", __func__, (cl->cl_runas == NULL) ? "null" : cl->cl_runas);
+
+    cl->cl_mailto = NULL;
+    Set(cl->cl_mailto, orig->cl_mailto);
+
+    cl->cl_tz = NULL;
+    Set(cl->cl_tz, orig->cl_tz);
+
+    return cl;
+}
+
+void
+free_line(cl_t *cl)
+    /* free a line, including its fields */
+{
+    if (cl != NULL) {
+        Free_safe(cl->cl_shell);
+        Free_safe(cl->cl_runas);
+        Free_safe(cl->cl_mailto);
+        Free_safe(cl->cl_tz);
+        Free_safe(cl);
+    }
+}
+
+
diff --git a/cl.h b/cl.h
new file mode 100644 (file)
index 0000000..8d6e373
--- /dev/null
+++ b/cl.h
@@ -0,0 +1,75 @@
+/*
+ * FCRON - periodic command scheduler
+ *
+ *  Copyright 2000-2012 Thibault Godouet <fcron@free.fr>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  The GNU General Public License can also be found in the file
+ *  `LICENSE' that comes with the fcron source distribution.
+ */
+
+/* cl: Cron Line type and associated functions */
+
+#ifndef __CL_H__
+#define __CL_H__
+
+/*
+ * TYPES
+ */
+
+#define OPTION_SIZE 4 /* number of bytes to hold the cl_option bit array */
+#define LAVG_SIZE 3
+/* warning : do not change the order of the members of this structure
+ *   because some tests made are dependent to that order */
+/* warning : if you change a field type, you may have to also make some changes
+ *   in the save/load binary fcrontab functions */
+typedef struct cl_t {
+    struct cl_t   *cl_next;
+    struct cf_t   *cl_file;       /* the file in which the line is           */
+    char          *cl_shell;      /* shell command                           */
+    char          *cl_runas;      /* determine permissions of the job        */
+    char          *cl_mailto;     /* mail output to cl_mailto                */
+    char          *cl_tz;         /* time zone of the line                   */
+    unsigned long  cl_id;         /* line's unique id number                 */
+    time_t         cl_until;      /* timeout of the wait for a lavg value    */
+    time_t         cl_first;      /* initial delay preserved for volatile entries */
+    time_t         cl_nextexe;    /* time and date of the next execution     */
+    long int       cl_timefreq;   /* Run every n seconds                     */
+    unsigned short cl_remain;     /* remaining until next execution          */
+    unsigned short cl_runfreq;    /* Run once every n matches(=1 for %-lines)*/
+    unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
+    unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
+    unsigned char  cl_numexe;     /* entries in queues & running processes   */
+    char           cl_nice;       /* nice value to control priority          */
+    unsigned char  cl_jitter;     /* run randomly late up to jitter seconds  */
+    /* see bitstring(3) man page for more details */
+    bitstr_t       bit_decl(cl_mins, 60); /* 0-59                            */
+    bitstr_t       bit_decl(cl_hrs, 24);  /* 0-23                            */
+    bitstr_t       bit_decl(cl_days, 32); /* 1-31                            */
+    bitstr_t       bit_decl(cl_mons, 12); /* 0-11                            */
+    bitstr_t       bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
+} cl_t;
+
+
+/*
+ * functions prototypes
+ */
+
+/* duplicate a line, including strings it points to */
+cl_t* dups_cl(cl_t *orig);
+void free_line(cl_t *cl);
+
+#endif /* __CL_H__ */
diff --git a/conf.c b/conf.c
index 019aa71ada6d803fbcde83c6f1b6a20687482720..8181cb737285e2540f650390e2b48770b3a9079b 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -35,7 +35,6 @@ int add_line_to_file(cl_t *cl, cf_t *cf, uid_t runas, char *runas_str,
 int read_strn(int fd, char **str, short int size);
 int read_type(int fd, short int *type, short int *size);
 void synchronize_file(char *file_name, int is_system_startup);
-void free_line(cl_t *cl);
 
 
 /* this is used to create a list of files to remove, to add */
@@ -991,19 +990,6 @@ add_line_to_file(cl_t *cl, cf_t *cf, uid_t runas, char *runas_str, time_t t_save
     return 0;
 }
 
-void
-free_line(cl_t *cl)
-    /* free a line, including its fields */
-{
-    if (cl != NULL) {
-        Free_safe(cl->cl_shell);
-        Free_safe(cl->cl_runas);
-        Free_safe(cl->cl_mailto);
-        Free_safe(cl->cl_tz);
-        Free_safe(cl);
-    }
-}
-
 void
 delete_file(const char *user_name)
     /* free a file if user_name is not null 
index b3c58603ef8aa588247afbc23e26d93374ead18a..19ad235adb054d2426cacb31367f4e971d15b0c0 100644 (file)
@@ -43,7 +43,6 @@ int read_shortcut(char *ptr, cf_t *cf);
 void read_env(char *ptr, cf_t *cf);
 char *read_opt(char *ptr, cl_t *cl);
 char *check_username(char *ptr, cf_t *cf, cl_t *cl);
-void free_line(cl_t *cl);
 
 
 char need_correction;
@@ -1857,19 +1856,6 @@ read_field(char *ptr, bitstr_t *ary, int max, const char **names)
     return ptr;
 }
 
-void
-free_line(cl_t *cl)
-    /* free a line, including its fields */
-{
-    if (cl != NULL) {
-        Free_safe(cl->cl_shell);
-        Free_safe(cl->cl_runas);
-        Free_safe(cl->cl_mailto);
-        Free_safe(cl->cl_tz);
-        Free_safe(cl);
-    }
-}
-
 void
 delete_file(const char *user_name)
     /* free a file if user_name is not null 
index c701a8fb5d7aa6cd428b5fa49132ae0eac774e05..49f5b2b6e36d329cbf750b9b657d48d05ab7f265 100644 (file)
--- a/global.h
+++ b/global.h
 #include "bitstring.h"     /* bit arrays */
 #include "option.h"        /* manage fcrontab's options */
 #include "env_list.h"      /* manage fcrontab's environment variable lists */
+#include "cl.h"            /* Cron Line cl_t type and associated functions */
 
 /* you should not change this (nor need to do it) */
 #define ERR     -1           
@@ -184,39 +185,6 @@ typedef struct cf_t {
 } cf_t;
 
 
-#define OPTION_SIZE 4 /* number of bytes to hold the cl_option bit array */
-#define LAVG_SIZE 3
-/* warning : do not change the order of the members of this structure
- *   because some tests made are dependent to that order */
-/* warning : if you change a field type, you may have to also make some changes
- *   in the save/load binary fcrontab functions */
-typedef struct cl_t {
-    struct cl_t   *cl_next;
-    struct cf_t   *cl_file;       /* the file in which the line is           */
-    char         *cl_shell;      /* shell command                           */
-    char          *cl_runas;      /* determine permissions of the job        */
-    char          *cl_mailto;     /* mail output to cl_mailto                */
-    char          *cl_tz;         /* time zone of the line                   */
-    unsigned long  cl_id;         /* line's unique id number                 */
-    time_t         cl_until;      /* timeout of the wait for a lavg value    */
-    time_t         cl_first;      /* initial delay preserved for volatile entries */
-    time_t         cl_nextexe;    /* time and date of the next execution     */
-    long int       cl_timefreq;   /* Run every n seconds                     */
-    unsigned short cl_remain;     /* remaining until next execution          */
-    unsigned short cl_runfreq;    /* Run once every n matches(=1 for %-lines)*/
-    unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
-    unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
-    unsigned char  cl_numexe;     /* entries in queues & running processes   */
-    char           cl_nice;       /* nice value to control priority          */
-    unsigned char  cl_jitter;     /* run randomly late up to jitter seconds  */
-    /* see bitstring(3) man page for more details */
-    bitstr_t      bit_decl(cl_mins, 60); /* 0-59                            */
-    bitstr_t      bit_decl(cl_hrs, 24);  /* 0-23                            */
-    bitstr_t      bit_decl(cl_days, 32); /* 1-31                            */
-    bitstr_t      bit_decl(cl_mons, 12); /* 0-11                            */
-    bitstr_t      bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
-} cl_t;
-
 typedef struct job_t {
     struct cl_t  *j_line;
     struct job_t   *j_next;