From: thib Date: Mon, 25 Feb 2002 18:38:42 +0000 (+0000) Subject: Initial revision X-Git-Tag: ver1564~121 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93ab293984f7f788bbdab7463a50994b9cc265de;p=fcron Initial revision --- diff --git a/fcrondyn.c b/fcrondyn.c new file mode 100644 index 0000000..41d9d2f --- /dev/null +++ b/fcrondyn.c @@ -0,0 +1,100 @@ + +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: fcrondyn.c,v 1.1 2002-02-25 18:38:42 thib Exp $ */ + +/* fcrondyn : interact dynamically with running fcron process : + * - list jobs, with their status, next time of execution, etc + * - run, delay a job + * - send a signal to a job + * - etc ... + */ + +#include "fcrondyn.h" +#include "allow.h" + +char rcs_info[] = "$Id: fcrondyn.c,v 1.1 2002-02-25 18:38:42 thib Exp $"; + +void info(void); +void usage(void); + +#ifdef DEBUG +char debug_opt = 1; /* set to 1 if we are in debug mode */ +#else +char debug_opt = 0; /* set to 1 if we are in debug mode */ +#endif + +char *user = NULL; +uid_t uid = 0; +uid_t asuid = 0; + +/* needed by log part : */ +char *prog_name = NULL; +char foreground = 1; +char dosyslog = 1; +pid_t daemon_pid = 0; + + +void +info(void) + /* print some informations about this program : + * version, license */ +{ + fprintf(stderr, + "fcrondyn " VERSION_QUOTED " - interact dynamically with daemon fcron\n" + "Copyright 2000-2002 Thibault Godouet \n" + "This program is free software distributed WITHOUT ANY WARRANTY.\n" + "See the GNU General Public License for more details.\n" + ); + + exit(EXIT_OK); + +} + + +void +usage(void) + /* print a help message about command line options and exit */ +{ + fprintf(stderr, + "fcrondyn [-n] file [user|-u user]\n" + "fcrondyn { -l | -r | -e | -z } [-n] [user|-u user]\n" + "fcrondyn -h\n" + " -u user specify user name.\n" + " -l list user's current fcrontab.\n" + " -r remove user's current fcrontab.\n" + " -c f make fcrontab use config file f.\n" + " -d set up debug mode.\n" + " -h display this help message.\n" + "\n" + ); + + exit(EXIT_ERR); +} + +int +main(int argc, char **argv) +{ + +} diff --git a/fcrondyn.h b/fcrondyn.h new file mode 100644 index 0000000..ea336e8 --- /dev/null +++ b/fcrondyn.h @@ -0,0 +1,40 @@ +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: fcrondyn.h,v 1.1 2002-02-25 18:40:29 thib Exp $ */ + +#ifndef __FCRONDYN_H__ +#define __FCRONDYN_H__ + +#include "global.h" +#include "socket.h" + +/* global variables */ +extern char debug_opt; +extern char dosyslog; +extern char *user; +extern uid_t uid; +extern uid_t asuid; +extern uid_t fcrondyn_uid; + +#endif /* __FCRONDYN_H__ */ diff --git a/save.c b/save.c new file mode 100644 index 0000000..981d6bb --- /dev/null +++ b/save.c @@ -0,0 +1,97 @@ + +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: save.c,v 1.1 2002-02-25 18:45:18 thib Exp $ */ + +#include "global.h" +#include "save.h" + +extern char debug_opt; + +int +save_type(FILE *f, short int type) +/* save a single type (with no data attached) in a binary fcrontab file */ +{ + short int size = 0; + + if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; + if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; + + return OK; + + err: + return ERR; + +} + +int +save_str(FILE *f, short int type, char *str) +/* save a string of type "type" in a binary fcrontab file */ +{ + short int size = 0; + size = strlen(str); + + if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; + if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; + if ( write(fileno(f), str, size) < size ) goto err; + + return OK; + + err: + return ERR; + +} + +int +save_strn(FILE *f, short int type, char *str, short int size) +/* save a "size"-length string of type "type" in a binary fcrontab file */ +{ + + if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; + if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; + if ( write(fileno(f), str, size) < size ) goto err; + + return OK; + + err: + return ERR; + +} + +int +save_lint(FILE *f, short int type, long int value) +/* save an integer of type "type" in a binary fcrontab file */ +{ + short int size = sizeof(value); + + if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; + if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; + if ( write(fileno(f), &value, size) < size ) goto err; + + return OK; + + err: + return ERR; + +} diff --git a/socket.h b/socket.h new file mode 100644 index 0000000..60b1c97 --- /dev/null +++ b/socket.h @@ -0,0 +1,37 @@ +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: socket.h,v 1.1 2002-02-25 18:46:54 thib Exp $ */ + +#ifndef __SOCKET_H__ +#define __SOCKET_H__ + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#endif /* __SOCKET_H__ */ diff --git a/temp_file.c b/temp_file.c new file mode 100644 index 0000000..78666ba --- /dev/null +++ b/temp_file.c @@ -0,0 +1,80 @@ + +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: temp_file.c,v 1.1 2002-02-25 18:44:37 thib Exp $ */ + +#include "global.h" +#include "temp_file.h" + +extern char *tmp_path; +extern char debug_opt; + + +int +temp_file(char **name) + /* Open a temporary file and return its file descriptor */ +{ + int fd; +#ifdef HAVE_MKSTEMP + char name_local[PATH_LEN] = ""; + strcpy(name_local, tmp_path); + strcat(name_local, "fcr-XXXXXX"); + if ( (fd = mkstemp(name_local)) == -1 ) + die_e("Can't find a unique temporary filename"); + /* we must set the file mode to 600 (some version of mkstemp may set it + * incorrectly) */ + if ( fchmod(fd, S_IWUSR | S_IRUSR) != 0 ) + die_e("Can't fchmod temp file"); +#else + const int max_retries = 50; + char *name_local = NULL; + int i; + + i = 0; + do { + i++; + Set(name_local, tempnam(NULL, NULL)); + if ( name_local == NULL ) + die("Can't find a unique temporary filename"); + fd = open(name_local, O_RDWR|O_CREAT|O_EXCL|O_APPEND, S_IRUSR|S_IWUSR); + /* I'm not sure we actually need to be so persistent here */ + } while (fd == -1 && errno == EEXIST && i < max_retries); + if (fd == -1) + die_e("Can't open temporary file"); +#endif + if ( name == NULL && unlink(name_local) != 0 ) + die_e("Can't unlink temporary file %s", name_local); + + fcntl(fd, F_SETFD, 1); /* set close-on-exec flag */ + + /* give the name of the temp file if necessary */ + if (name != NULL) + *name = strdup2(name_local); +#ifndef HAVE_MKSTEMP + free(name_local); +#endif + + return fd; +} + diff --git a/temp_file.h b/temp_file.h new file mode 100644 index 0000000..325c0f3 --- /dev/null +++ b/temp_file.h @@ -0,0 +1,32 @@ +/* + * FCRON - periodic command scheduler + * + * Copyright 2000-2002 Thibault Godouet + * + * 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. + */ + + /* $Id: temp_file.h,v 1.1 2002-02-25 18:44:54 thib Exp $ */ + +#ifndef __TEMP_FILE_H__ +#define __TEMP_FILE_H__ + +/* functions prototypes */ +extern int temp_file(char **name); + +#endif /* __TEMP_FILE_H__ */