Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCarpintero authored and AngelCarpintero committed Apr 3, 2010
1 parent 3dd5e31 commit 79cf297
Show file tree
Hide file tree
Showing 28 changed files with 1,379 additions and 1,200 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Features
* Add authentication methods 'Basic Authentication' and 'Digest Authentication'
to the "Live Stream Server". (Michael Finsterbusch)
http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionStreamAuthPatch
* Implemented new logging system
http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionLog (Angel Carpintero)


Bugfixes
Expand Down
7 changes: 4 additions & 3 deletions CODE_STANDARD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void * mymalloc(size_t nbytes)
void *dummy = malloc(nbytes);
if (!dummy) {
printf("Could not allocate %llu bytes of memory!\n", (unsigned long long) nbytes);
syslog(LOG_EMERG, "Could not allocate %llu bytes of memory!", (unsigned long long) nbytes);
syslog(EMERG, TYPE_ALL, "%s: Could not allocate %llu bytes of memory!",
__FUNCTION__, (unsigned long long) nbytes);
exit(1);
}

Expand All @@ -41,8 +42,8 @@ void * mymalloc(size_t nbytes)
if (!dummy) {
printf("Could not allocate %llu bytes of memory!\n",
(unsigned long long) nbytes);
syslog(LOG_EMERG, "Could not allocate %llu bytes of memory!",
(unsigned long long) nbytes);
syslog(EMERG, TYPE_ALL,"Could not allocate %llu bytes of memory!",
__FUNCTION__, (unsigned long long) nbytes);
exit(1);
}

Expand Down
14 changes: 6 additions & 8 deletions alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,9 @@ static int alg_labeling(struct context *cnt)
labelsize = iflood(ix, iy, width, height, out, labels, current_label, 0);

if (labelsize > 0) {
if (debug_level >= CAMERA_VERBOSE)
motion_log(LOG_DEBUG, 0,"%s: Label: %i (%i) Size: %i (%i,%i)",
__FUNCTION__, current_label, cnt->current_image->total_labels,
labelsize, ix, iy);
motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Label: %i (%i) Size: %i (%i,%i)",
__FUNCTION__, current_label, cnt->current_image->total_labels,
labelsize, ix, iy);

/* Label above threshold? Mark it again (add 32768 to labelnumber) */
if (labelsize > cnt->threshold) {
Expand All @@ -559,10 +558,9 @@ static int alg_labeling(struct context *cnt)
pixelpos++; /* compensate for ix<width-1 */
}

if (debug_level >= CAMERA_VERBOSE)
motion_log(LOG_DEBUG, 0,"%s: %i Labels found. Largest connected Area: %i Pixel(s). "
"Largest Label: %i", __FUNCTION__, imgs->largest_label, imgs->labelsize_max,
cnt->current_image->total_labels);
motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: %i Labels found. Largest connected Area: %i Pixel(s). "
"Largest Label: %i", __FUNCTION__, imgs->largest_label, imgs->labelsize_max,
cnt->current_image->total_labels);

/* return group of significant labels */
return imgs->labelgroup_max;
Expand Down
82 changes: 56 additions & 26 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ struct config conf_template = {
minimum_motion_frames: 1,
pid_file: NULL,
log_file: NULL,
log_level: LEVEL_DEFAULT,
log_type_str: NULL,
};


Expand Down Expand Up @@ -213,6 +215,22 @@ config_param config_params[] = {
print_string
},
{
"log_level",
"# Level of log messages [1..9] (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). (default: 4 / ERR)",
1,
CONF_OFFSET(log_level),
copy_int,
print_int
},
{
"log_type",
"# Filter to log messages by type (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). (default: ALL)",
1,
CONF_OFFSET(log_type_str),
copy_string,
print_string
},
{
"videodevice",
"\n###########################################################\n"
"# Capture device options\n"
Expand Down Expand Up @@ -1475,7 +1493,7 @@ config_param config_params[] = {
{ NULL, NULL, 0, 0, NULL, NULL }
};

/* conf_cmdline sets the conf struct options as defined by the command line.
/* conf_cmdline sets the conf struct options as defined by the Command-line.
* Any option already set from a config file are overridden.
*/
static void conf_cmdline(struct context *cnt, int thread)
Expand All @@ -1487,7 +1505,7 @@ static void conf_cmdline(struct context *cnt, int thread)
* if necessary. This is accomplished by calling mystrcpy();
* see this function for more information.
*/
while ((c = getopt(conf->argc, conf->argv, "c:d:hns?pl:")) != EOF)
while ((c = getopt(conf->argc, conf->argv, "c:d:hns?p:k:l:")) != EOF)
switch (c) {
case 'c':
if (thread == -1)
Expand All @@ -1501,8 +1519,13 @@ static void conf_cmdline(struct context *cnt, int thread)
break;
case 'd':
/* no validation - just take what user gives */
debug_level = (unsigned int)atoi(optarg);
if (thread == -1)
debug_level = (unsigned int)atoi(optarg);
break;
case 'k':
if (thread == -1)
strcpy(cnt->log_type_str, optarg);
break;
case 'p':
if (thread == -1)
strcpy(cnt->pid_file, optarg);
Expand Down Expand Up @@ -1565,7 +1588,8 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
}

/* We reached the end of config_params without finding a matching option */
motion_log(LOG_ERR, 0, "%s: Unknown config option \"%s\"", __FUNCTION__, cmd);
motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"",
__FUNCTION__, cmd);

return cnt;
}
Expand Down Expand Up @@ -1656,7 +1680,7 @@ void conf_print(struct context **cnt)
FILE *conffile;

for (thread = 0; cnt[thread]; thread++) {
motion_log(LOG_INFO, 0, "%s: Writing config file to %s",
motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s",
__FUNCTION__, cnt[thread]->conf_filename);

conffile = myfopen(cnt[thread]->conf_filename, "w", 0);
Expand Down Expand Up @@ -1710,7 +1734,7 @@ void conf_print(struct context **cnt)
/**************************************************************************
* conf_load is the main function, called from motion.c
* The function sets the important context structure "cnt" including
* loading the config parameters from config files and command line.
* loading the config parameters from config files and Command-line.
* The following takes place in the function:
* - The default start values for cnt stored in the struct conf_template
* are copied to cnt[0] which is the default context structure common to
Expand All @@ -1721,8 +1745,8 @@ void conf_print(struct context **cnt)
* - motion.conf is opened and processed. The process populates the cnt[0] and
* for each thread config file it populates a cnt[1], cnt[2]... for each
* thread
* - Finally it process the options given in the command line. This is done
* for each thread cnt[i] so that the command line options overrides any
* - Finally it process the options given in the Command-line. This is done
* for each thread cnt[i] so that the Command-line options overrides any
* option given by motion.conf or a thread config file.
**************************************************************************/
struct context **conf_load(struct context **cnt)
Expand All @@ -1745,7 +1769,7 @@ struct context **conf_load(struct context **cnt)
* 2. Copy the conf_template given string to the reserved memory
* 3. Change the cnt[0] member (char*) pointing to the string in reserved memory
* This ensures that we can free and malloc the string when changed
* via http remote control or config file or command line options
* via http remote control or config file or Command-line options
*/
malloc_strings(cnt[0]);

Expand All @@ -1754,33 +1778,33 @@ struct context **conf_load(struct context **cnt)
cnt[0]->conf.argc = argc;

/* Open the motion.conf file. We try in this sequence:
* 1. commandline
* 1. Command-line
* 2. current working directory
* 3. $HOME/.motion/motion.conf
* 4. sysconfig/motion.conf
*/
/* Get filename , pid file & log file from commandline */
/* Get filename , pid file & log file from Command-line */
cnt[0]->log_type_str[0] = 0;
cnt[0]->conf_filename[0] = 0;
cnt[0]->pid_file[0] = 0;
cnt[0]->log_file[0] = 0;


conf_cmdline(cnt[0], -1);

if (cnt[0]->conf_filename[0]) { /* User has supplied filename on commandline*/
if (cnt[0]->conf_filename[0]) { /* User has supplied filename on Command-line*/
strcpy(filename, cnt[0]->conf_filename);
fp = fopen (filename, "r");
}

if (!fp) { /* Commandline didn't work, try current dir */
if (!fp) { /* Command-line didn't work, try current dir */
char *path = NULL;

if (cnt[0]->conf_filename[0])
motion_log(0, 1, "%s: Configfile %s not found - trying defaults.",
motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.",
__FUNCTION__, filename);

if ((path = get_current_dir_name()) == NULL) {
motion_log(LOG_ERR, 1, "%s: Error get_current_dir_name", __FUNCTION__);
motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error get_current_dir_name", __FUNCTION__);
exit(-1);
}

Expand All @@ -1798,20 +1822,20 @@ struct context **conf_load(struct context **cnt)
fp = fopen(filename, "r");

if (!fp) /* there is no config file.... use defaults */
motion_log(0, 1, "%s: could not open configfile %s",
motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s",
__FUNCTION__, filename);
}
}

/* Now we process the motion.conf config file and close it */
if (fp) {
strcpy(cnt[0]->conf_filename, filename);
motion_log(LOG_INFO, 0, "%s: Processing thread 0 - config file %s",
motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s",
__FUNCTION__, filename);
cnt = conf_process(cnt, fp);
myfclose(fp);
} else {
motion_log(LOG_INFO, 0, "%s: Not config file to process using default values",
motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values",
__FUNCTION__);
}

Expand All @@ -1822,21 +1846,25 @@ struct context **conf_load(struct context **cnt)
* cnt[0] is the default context structure
* cnt[1], cnt[2], ... are context structures for each thread
* Command line options always wins over config file options
* so we go through each thread and overrides any set command line
* so we go through each thread and overrides any set Command-line
* options
*/
i = -1;

while (cnt[++i])
conf_cmdline(cnt[i], i);

/* if pid file was passed from command line copy to main thread conf struct */
/* if pid file was passed from Command-line copy to main thread conf struct */
if (cnt[0]->pid_file[0])
cnt[0]->conf.pid_file = mystrcpy(cnt[0]->conf.pid_file, cnt[0]->pid_file);

if (cnt[0]->log_file[0])
cnt[0]->conf.log_file = mystrcpy(cnt[0]->conf.log_file, cnt[0]->log_file);

if (cnt[0]->log_type_str[0])
cnt[0]->conf.log_type_str = mystrcpy(cnt[0]->conf.log_type_str, cnt[0]->log_type_str);


return cnt;
}

Expand Down Expand Up @@ -2167,7 +2195,7 @@ static struct context **config_thread(struct context **cnt, const char *str,
fp = fopen(str, "r");

if (!fp) {
motion_log(LOG_ERR, 1, "%s: Thread config file %s not found",
motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found",
__FUNCTION__, str);
return cnt;
}
Expand All @@ -2183,7 +2211,7 @@ static struct context **config_thread(struct context **cnt, const char *str,
* First thread is 0 so the number of threads is i+1
* plus an extra for the NULL pointer. This gives i+2
*/
cnt = myrealloc(cnt, sizeof(struct context *)*(i+2), "config_thread");
cnt = myrealloc(cnt, sizeof(struct context *) * (i + 2), "config_thread");

/* Now malloc space for an additional context structure for thread nr. i */
cnt[i] = mymalloc(sizeof(struct context));
Expand All @@ -2201,11 +2229,12 @@ static struct context **config_thread(struct context **cnt, const char *str,
malloc_strings(cnt[i]);

/* Mark the end if the array of pointers to context structures */
cnt[i+1] = NULL;
cnt[i + 1] = NULL;

/* process the thread's config file and notify user on console */
strcpy(cnt[i]->conf_filename, str);
motion_log(LOG_INFO, 0, "%s: Processing config file %s", __FUNCTION__, str);
motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s",
__FUNCTION__, str);
conf_process(cnt+i, fp);

/* Finally we close the thread config file */
Expand All @@ -2223,7 +2252,8 @@ static void usage()
printf("-n\t\t\tRun in non-daemon mode.\n");
printf("-s\t\t\tRun in setup mode.\n");
printf("-c config\t\tFull path and filename of config file.\n");
printf("-d level\t\tDebug mode.\n");
printf("-d level\t\tLog level (1-9) (EMR, ALR, CRT, ERR, WRN, NTC, ERR, DBG, ALL). default: 4 / ERR.\n");
printf("-k type\t\t\tType of log (STR, ENC, NET, DBL, EVT, TRK, VID, ALL). default: ALL.\n");
printf("-p process_id_file\tFull path and filename of process id file (pid file).\n");
printf("-l log file \t\tFull path and filename of log file.\n");
printf("-h\t\t\tShow this screen.\n");
Expand Down
4 changes: 3 additions & 1 deletion conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* More parameters may be added later.
*/
struct config {
unsigned int log_level;
char *log_type_str;
char *log_file;
int setup_mode;
int width;
Expand All @@ -40,7 +42,7 @@ struct config {
int frame_limit;
int quiet;
int useextpipe; /* ext_pipe on or off */
const char *extpipe; /* full command line for pipe -- must accept YUV420P images */
const char *extpipe; /* full Command-line for pipe -- must accept YUV420P images */
const char *picture_type;
int noise;
int noise_tune;
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.64 for motion trunkREV500.
# Generated by GNU Autoconf 2.64 for motion trunkREV501.
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
Expand Down Expand Up @@ -546,8 +546,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='motion'
PACKAGE_TARNAME='motion'
PACKAGE_VERSION='trunkREV500'
PACKAGE_STRING='motion trunkREV500'
PACKAGE_VERSION='trunkREV501'
PACKAGE_STRING='motion trunkREV501'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

Expand Down Expand Up @@ -1210,7 +1210,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures motion trunkREV500 to adapt to many kinds of systems.
\`configure' configures motion trunkREV501 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1271,7 +1271,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of motion trunkREV500:";;
short | recursive ) echo "Configuration of motion trunkREV501:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1412,7 +1412,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
motion configure trunkREV500
motion configure trunkREV501
generated by GNU Autoconf 2.64
Copyright (C) 2009 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2009,7 +2009,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by motion $as_me trunkREV500, which was
It was created by motion $as_me trunkREV501, which was
generated by GNU Autoconf 2.64. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -5790,7 +5790,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by motion $as_me trunkREV500, which was
This file was extended by motion $as_me trunkREV501, which was
generated by GNU Autoconf 2.64. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -5850,7 +5850,7 @@ Report bugs to the package provider."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_version="\\
motion config.status trunkREV500
motion config.status trunkREV501
configured by $0, generated by GNU Autoconf 2.64,
with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Expand Down
Loading

0 comments on commit 79cf297

Please sign in to comment.