From 6ef841ff48e776ae8702279cb95510285d1a4ea8 Mon Sep 17 00:00:00 2001 From: Thibault Godouet Date: Tue, 1 Jan 2013 18:14:10 +0000 Subject: [PATCH] Applied indentation --- convert-fcrontab.c | 20 +++-- fcron.c | 211 +++++++++++++++++++++++---------------------- job.c | 2 +- log.c | 78 +++++++++-------- log.h | 4 +- subs.c | 15 ++-- 6 files changed, 173 insertions(+), 157 deletions(-) diff --git a/convert-fcrontab.c b/convert-fcrontab.c index d22daaf..7d846e1 100644 --- a/convert-fcrontab.c +++ b/convert-fcrontab.c @@ -241,10 +241,11 @@ main(int argc, char *argv[]) /* constants and variables defined by command line */ - while(1) { - c = getopt(argc, argv, "chV"); - if (c == EOF) break; - switch (c) { + while (1) { + c = getopt(argc, argv, "chV"); + if (c == EOF) + break; + switch (c) { case 'V': info(); @@ -254,12 +255,13 @@ main(int argc, char *argv[]) usage(); break; - case 'c': - Set(fcronconf, optarg); break; + case 'c': + Set(fcronconf, optarg); + break; - case ':': - fprintf(stderr, "(setopt) Missing parameter"); - usage(); + case ':': + fprintf(stderr, "(setopt) Missing parameter"); + usage(); case '?': usage(); diff --git a/fcron.c b/fcron.c index 842980b..59fbab6 100644 --- a/fcron.c +++ b/fcron.c @@ -59,8 +59,8 @@ char foreground = 0; /* set to 1 when we are on foreground, else 0 */ time_t first_sleep = FIRST_SLEEP; time_t save_time = SAVE; -char once = 0; /* set to 1 if fcron shall return immediately after running - * all jobs that are due at the time when fcron is started */ +char once = 0; /* set to 1 if fcron shall return immediately after running + * all jobs that are due at the time when fcron is started */ /* Get the default locale character set for the mail * "Content-Type: ...; charset=" header */ @@ -136,27 +136,26 @@ usage(void) /* print a help message about command line options and exit */ { fprintf(stderr, "\nfcron " VERSION_QUOTED "\n\n" - "fcron [-d] [-f] [-b]\n" - "fcron -h\n" - " -s t --savetime t Save fcrontabs on disk every t sec.\n" - " -l t --firstsleep t Sets the initial delay before any job is executed" - ",\n default to %d seconds.\n" - " -m n --maxserial n Set to n the max number of running serial jobs.\n" - " -c f --configfile f Make fcron use config file f.\n" - " -n d --newspooldir d Create d as a new spool directory.\n" - " -f --foreground Stay in foreground.\n" - " -b --background Go to background.\n" - " -y --nosyslog Don't log to syslog at all.\n" - " -p --logfilepath If set, log to the file given as argument.\n" - " -o --once Execute all jobs that need to be run, wait for " - "them,\n then return. Sets firstsleep to 0.\n" - " Especially useful with -f and -y.\n" - " -d --debug Set Debug mode.\n" - " -h --help Show this help message.\n" - " -V --version Display version & infos about fcron.\n", - FIRST_SLEEP - ); - + "fcron [-d] [-f] [-b]\n" + "fcron -h\n" + " -s t --savetime t Save fcrontabs on disk every t sec.\n" + " -l t --firstsleep t Sets the initial delay before any job is executed" + ",\n default to %d seconds.\n" + " -m n --maxserial n Set to n the max number of running serial jobs.\n" + " -c f --configfile f Make fcron use config file f.\n" + " -n d --newspooldir d Create d as a new spool directory.\n" + " -f --foreground Stay in foreground.\n" + " -b --background Go to background.\n" + " -y --nosyslog Don't log to syslog at all.\n" + " -p --logfilepath If set, log to the file given as argument.\n" + " -o --once Execute all jobs that need to be run, wait for " + "them,\n then return. Sets firstsleep to 0.\n" + " Especially useful with -f and -y.\n" + " -d --debug Set Debug mode.\n" + " -h --help Show this help message.\n" + " -V --version Display version & infos about fcron.\n", + FIRST_SLEEP); + exit(EXIT_ERR); } @@ -306,23 +305,22 @@ parseopt(int argc, char *argv[]) int i; #ifdef HAVE_GETOPT_LONG - static struct option opt[] = - { - {"debug", 0, NULL, 'd'}, - {"foreground", 0, NULL, 'f'}, - {"background", 0, NULL, 'b'}, - {"nosyslog", 0, NULL, 'y'}, - {"logfilepath", 1, NULL, 'p'}, - {"help", 0, NULL, 'h'}, - {"version", 0, NULL, 'V'}, - {"once", 0, NULL, 'o'}, - {"savetime", 1, NULL, 's'}, - {"firstsleep", 1, NULL, 'l'}, - {"maxserial", 1, NULL, 'm'}, - {"configfile", 1, NULL, 'c'}, - {"newspooldir", 1, NULL, 'n'}, - {"queuelen", 1, NULL, 'q'}, - {0,0,0,0} + static struct option opt[] = { + {"debug", 0, NULL, 'd'}, + {"foreground", 0, NULL, 'f'}, + {"background", 0, NULL, 'b'}, + {"nosyslog", 0, NULL, 'y'}, + {"logfilepath", 1, NULL, 'p'}, + {"help", 0, NULL, 'h'}, + {"version", 0, NULL, 'V'}, + {"once", 0, NULL, 'o'}, + {"savetime", 1, NULL, 's'}, + {"firstsleep", 1, NULL, 'l'}, + {"maxserial", 1, NULL, 'm'}, + {"configfile", 1, NULL, 'c'}, + {"newspooldir", 1, NULL, 'n'}, + {"queuelen", 1, NULL, 'q'}, + {0, 0, 0, 0} }; #endif /* HAVE_GETOPT_LONG */ @@ -333,78 +331,89 @@ parseopt(int argc, char *argv[]) while (1) { #ifdef HAVE_GETOPT_LONG - c = getopt_long(argc, argv, "dfbyp:hVos:l:m:c:n:q:", opt, NULL); + c = getopt_long(argc, argv, "dfbyp:hVos:l:m:c:n:q:", opt, NULL); #else - c = getopt(argc, argv, "dfbyp:hVos:l:m:c:n:q:"); -#endif /* HAVE_GETOPT_LONG */ - if ( c == EOF ) break; - switch ( (char)c ) { + c = getopt(argc, argv, "dfbyp:hVos:l:m:c:n:q:"); +#endif /* HAVE_GETOPT_LONG */ + if (c == EOF) + break; + switch ((char)c) { - case 'V': - info(); break; + case 'V': + info(); + break; - case 'h': - usage(); break; + case 'h': + usage(); + break; - case 'd': - debug_opt = 1; break; + case 'd': + debug_opt = 1; + break; - case 'f': - foreground = 1; break; + case 'f': + foreground = 1; + break; - case 'b': - foreground = 0; break; + case 'b': + foreground = 0; + break; - case 'y': - dosyslog = 0; break; + case 'y': + dosyslog = 0; + break; case 'p': logfile_path = strdup2(optarg); break; - - case 'o': - once = 1; first_sleep = 0; break; - - case 's': - if ( (save_time = strtol(optarg, NULL, 10)) < 60 || save_time >= LONG_MAX ) - die("Save time can only be set between 60 and %d.", LONG_MAX); - break; - - case 'l': - if ( (first_sleep = strtol(optarg, NULL, 10)) < 0 || first_sleep >= LONG_MAX) - die("First sleep can only be set between 0 and %d.", LONG_MAX); - break; - - case 'm': - if ( (serial_max_running = strtol(optarg, NULL, 10)) <= 0 - || serial_max_running >= SHRT_MAX ) - die("Max running can only be set between 1 and %d.",SHRT_MAX); - break; - - case 'c': - Set(fcronconf, optarg); - break; - - case 'n': - create_spooldir(optarg); - break; - - case 'q': - if ( (lavg_queue_max = serial_queue_max = strtol(optarg, NULL, 10)) < 5 - || serial_queue_max >= SHRT_MAX ) - die("Queue length can only be set between 5 and %d.", SHRT_MAX); - break; - - case ':': - error("(parseopt) Missing parameter"); - usage(); - - case '?': - usage(); - - default: - warn("(parseopt) Warning: getopt returned %c", c); - } + + case 'o': + once = 1; + first_sleep = 0; + break; + + case 's': + if ((save_time = strtol(optarg, NULL, 10)) < 60 + || save_time >= LONG_MAX) + die("Save time can only be set between 60 and %d.", LONG_MAX); + break; + + case 'l': + if ((first_sleep = strtol(optarg, NULL, 10)) < 0 + || first_sleep >= LONG_MAX) + die("First sleep can only be set between 0 and %d.", LONG_MAX); + break; + + case 'm': + if ((serial_max_running = strtol(optarg, NULL, 10)) <= 0 + || serial_max_running >= SHRT_MAX) + die("Max running can only be set between 1 and %d.", SHRT_MAX); + break; + + case 'c': + Set(fcronconf, optarg); + break; + + case 'n': + create_spooldir(optarg); + break; + + case 'q': + if ((lavg_queue_max = serial_queue_max = + strtol(optarg, NULL, 10)) < 5 || serial_queue_max >= SHRT_MAX) + die("Queue length can only be set between 5 and %d.", SHRT_MAX); + break; + + case ':': + error("(parseopt) Missing parameter"); + usage(); + + case '?': + usage(); + + default: + warn("(parseopt) Warning: getopt returned %c", c); + } } if (optind < argc) { diff --git a/job.c b/job.c index 23df4c6..7a5b6b8 100644 --- a/job.c +++ b/job.c @@ -261,7 +261,7 @@ change_user_setup_env(struct cl_t *cl, setup_user_and_env(cl, pas, sendmailenv, jobenv, curshell, curhome, content_type, encoding); - become_user(cl, pas, (curhome!=NULL)? *curhome : "/"); + become_user(cl, pas, (curhome != NULL) ? *curhome : "/"); } void diff --git a/log.c b/log.c index 25565e5..a2f0b2e 100644 --- a/log.c +++ b/log.c @@ -42,12 +42,12 @@ int dosyslog = 1; char *logfile_path = NULL; -char* make_msg(const char *append, char *fmt, va_list args); +char *make_msg(const char *append, char *fmt, va_list args); void log_syslog_str(int priority, char *msg); -void log_file_str(FILE *logfile, int priority, char *msg); +void log_file_str(FILE * logfile, int priority, char *msg); void log_console_str(int priority, char *msg); void log_fd_str(int fd, char *msg); -static void print_line_prefix(FILE *logfile, int priority); +static void print_line_prefix(FILE * logfile, int priority); static void xlog(int priority, int fd, char *fmt, va_list args); static void xlog_e(int priority, int fd, char *fmt, va_list args); #ifdef HAVE_LIBPAM @@ -69,8 +69,8 @@ static FILE *logfile = NULL; void xopenlog(void) { - if (log_open) - return; + if (log_open) + return; /* we MUST set log_open to 1 before doing anything else. That way, * if we call a function that logs something, which calls xopenlog, @@ -89,11 +89,13 @@ xopenlog(void) if (dosyslog) { /* we have already called openlog() which cannot fail */ - syslog(COMPLAIN_LEVEL, "Could not fopen log file '%s': %s", logfile_path, strerror(saved_errno)); + syslog(COMPLAIN_LEVEL, "Could not fopen log file '%s': %s", + logfile_path, strerror(saved_errno)); } print_line_prefix(stderr, COMPLAIN_LEVEL); - fprintf(stderr, "Could not fopen log file '%s': %s\n", logfile_path, strerror(saved_errno)); + fprintf(stderr, "Could not fopen log file '%s': %s\n", logfile_path, + strerror(saved_errno)); } } @@ -104,24 +106,26 @@ void xcloselog() { if (!log_open) - return; + return; // check whether we need to close syslog, or a file. if (logfile != NULL) { - if (fclose(logfile)!= 0) { + if (fclose(logfile) != 0) { int saved_errno = errno; - syslog(COMPLAIN_LEVEL, "Error while closing log file '%s': %s", logfile_path, strerror(saved_errno)); + syslog(COMPLAIN_LEVEL, "Error while closing log file '%s': %s", + logfile_path, strerror(saved_errno)); if (foreground == 1) { print_line_prefix(stderr, COMPLAIN_LEVEL); - fprintf(stderr, "Error while closing log file '%s': %s\n", logfile_path, strerror(saved_errno)); + fprintf(stderr, "Error while closing log file '%s': %s\n", + logfile_path, strerror(saved_errno)); } } } if (dosyslog) { - closelog(); + closelog(); } log_open = 0; @@ -159,20 +163,20 @@ log_syslog_str(int priority, char *msg) { if (dosyslog) { xopenlog(); - syslog(priority, "%s", msg); + syslog(priority, "%s", msg); } } /* log a simple string to a log file if needed */ void -log_file_str(FILE *logfile, int priority, char *msg) +log_file_str(FILE * logfile, int priority, char *msg) { xopenlog(); /* we may have failed to open the logfile - check if * it does exist *after* xopenlog() */ if (logfile != NULL) { - print_line_prefix(logfile, priority); + print_line_prefix(logfile, priority); fprintf(logfile, "%s\n", msg); fflush(logfile); } @@ -184,8 +188,8 @@ void log_console_str(int priority, char *msg) { if (foreground == 1) { - print_line_prefix(stderr, priority); - fprintf(stderr, "%s\n", msg); + print_line_prefix(stderr, priority); + fprintf(stderr, "%s\n", msg); } } @@ -241,7 +245,7 @@ xlog_e(int priority, int fd, char *fmt, va_list args) /* write a message to the file specified by logfile. */ static void -print_line_prefix(FILE *logfile, int priority) +print_line_prefix(FILE * logfile, int priority) { time_t t = time(NULL); struct tm *ft; @@ -254,21 +258,21 @@ print_line_prefix(FILE *logfile, int priority) strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", ft); // is it an info/warning/error/debug message? - switch(priority) { - case EXPLAIN_LEVEL: - type = " INFO"; - break; - case WARNING_LEVEL: - type = " WARN"; - break; - case COMPLAIN_LEVEL: - type = "ERROR"; - break; - case DEBUG_LEVEL: - type = "DEBUG"; - break; - default: - type = "UNKNOWN_SEVERITY"; + switch (priority) { + case EXPLAIN_LEVEL: + type = " INFO"; + break; + case WARNING_LEVEL: + type = " WARN"; + break; + case COMPLAIN_LEVEL: + type = "ERROR"; + break; + case DEBUG_LEVEL: + type = "DEBUG"; + break; + default: + type = "UNKNOWN_SEVERITY"; } // print the log message. @@ -449,10 +453,10 @@ die_e(char *fmt, ...) err_no = errno; - va_start(args, fmt); - xlog_e(COMPLAIN_LEVEL, -1, fmt, args); - va_end(args); - if (getpid() == daemon_pid) { + va_start(args, fmt); + xlog_e(COMPLAIN_LEVEL, -1, fmt, args); + va_end(args); + if (getpid() == daemon_pid) { error("Aborted"); } else { diff --git a/log.h b/log.h index d163cd3..f7b31af 100644 --- a/log.h +++ b/log.h @@ -26,8 +26,8 @@ #define __LOG_H__ extern char debug_opt; -extern char *logfile_path; /* path to a file to log to. Set to NULL to disable logging to a file */ -extern int dosyslog; /* set to 1 when we log messages to syslog, else 0 */ +extern char *logfile_path; /* path to a file to log to. Set to NULL to disable logging to a file */ +extern int dosyslog; /* set to 1 when we log messages to syslog, else 0 */ /* functions prototypes */ extern void xopenlog(void); diff --git a/subs.c b/subs.c index 7d95aed..b5a29be 100644 --- a/subs.c +++ b/subs.c @@ -127,7 +127,7 @@ open_as_user(const char *pathname, uid_t openuid, gid_t opengid, int flags, ...) /* if open() didn't fail make sure we opened a 'normal' file */ if (fd >= 0) { - if ( fstat(fd, &s) < 0 ) { + if (fstat(fd, &s) < 0) { saved_errno = errno; error_e("open_as_user(): could not fstat %s", pathname); if (close(fd) < 0) @@ -213,12 +213,12 @@ open_as_user(const char *pathname, uid_t openuid, gid_t opengid, int flags, ...) return fd; /* if open() didn't fail make sure we opened a 'normal' file */ - if ( fstat(fd, &s) < 0 ) { + if (fstat(fd, &s) < 0) { saved_errno = errno; error_e("open_as_user(): could not fstat %s", pathname); goto err; } - if ( ! S_ISREG(s.st_mode) || s.st_nlink != 1 ) { + if (!S_ISREG(s.st_mode) || s.st_nlink != 1) { saved_errno = errno; error_e("open_as_user(): file %s is not a regular file", pathname); goto err; @@ -231,8 +231,8 @@ open_as_user(const char *pathname, uid_t openuid, gid_t opengid, int flags, ...) if (!(s.st_mode & S_IROTH || (s.st_uid == openuid && s.st_mode & S_IRUSR) || (s.st_gid == opengid && s.st_mode & S_IRGRP))) { error("open_as_user(): file %s does not pass the security test: " - "uid=%d gid=%d mode=%lo openuid=%d opengid=%d", - pathname, s.st_uid, s.st_gid, s.st_mode, openuid, opengid); + "uid=%d gid=%d mode=%lo openuid=%d opengid=%d", + pathname, s.st_uid, s.st_gid, s.st_mode, openuid, opengid); saved_errno = EACCES; goto err; } @@ -243,9 +243,10 @@ open_as_user(const char *pathname, uid_t openuid, gid_t opengid, int flags, ...) * then we will end up changing the ownership even if the seteuid() * version of that function wouldn't have. That shouldn't break * anything though. */ - if ( (flags & O_CREAT) && fchown(fd, openuid, opengid) != 0) { + if ((flags & O_CREAT) && fchown(fd, openuid, opengid) != 0) { saved_errno = errno; - error_e("Could not fchown %s to uid:%d gid:%d", pathname, openuid, opengid); + error_e("Could not fchown %s to uid:%d gid:%d", pathname, openuid, + opengid); goto err; } -- 2.40.0