Skip to content

Commit

Permalink
Avoid segfault when motion cannot create a logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCarpintero authored and AngelCarpintero committed Mar 25, 2010
1 parent 597dd34 commit 66dc7dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Bugfixes
weird header Content-Lenght 0. (Angel Carpintero)
* Only use post capture when we setup to record videos with external pipe or ffmpeg. (Angel Carpintero)
* Fix introduced bug for Content-Lenght = 0 in svn r476. (Angel Carpintero)
* Avoid segfault when motion cannot create a logfile. (Angel Carpintero)

3.2.12 Summary of Changes

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 trunk-r488.
# Generated by GNU Autoconf 2.64 for motion trunk-r490.
#
# 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='trunk-r488'
PACKAGE_STRING='motion trunk-r488'
PACKAGE_VERSION='trunk-r490'
PACKAGE_STRING='motion trunk-r490'
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 trunk-r488 to adapt to many kinds of systems.
\`configure' configures motion trunk-r490 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 trunk-r488:";;
short | recursive ) echo "Configuration of motion trunk-r490:";;
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 trunk-r488
motion configure trunk-r490
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 trunk-r488, which was
It was created by motion $as_me trunk-r490, 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 trunk-r488, which was
This file was extended by motion $as_me trunk-r490, 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 trunk-r488
motion config.status trunk-r490
configured by $0, generated by GNU Autoconf 2.64,
with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Expand Down
11 changes: 9 additions & 2 deletions logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "logger.h" /* already includes motion.h */
#include <stdarg.h>

static int log_mode = 1;
static int log_mode = LOGMODE_SYSLOG;
static FILE *logfile;

/**
Expand All @@ -33,7 +33,14 @@ void set_log_mode(int mode)
*/
FILE * set_logfile(const char *logfile_name)
{
return logfile = myfopen(logfile_name, "a", 0);
log_mode = LOGMODE_SYSLOG; /* Setup temporary to let log if myfopen fails */
logfile = myfopen(logfile_name, "a", 0);

/* If logfile was opened correctly */
if (logfile)
log_mode = LOGMODE_FILE;

return logfile;
}


Expand Down
4 changes: 3 additions & 1 deletion logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "motion.h"
#include <syslog.h>


/* Logging mode */
#define LOGMODE_FILE 0 /* Log messages to file */
#define LOGMODE_SYSLOG 1 /* Log messages to syslog */

/* Debug levels */
#define CAMERA_ALERT 1 /* alerts only */
Expand Down
17 changes: 11 additions & 6 deletions motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -2335,21 +2335,26 @@ static void motion_startup(int daemonize, int argc, char *argv[])
*/
cntlist_create(argc, argv);

if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file,"syslog",6))) {
set_log_mode(0);
motion_log(LOG_INFO, 0, "%s: Motion "VERSION" Started", __FUNCTION__);

if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) {
set_log_mode(LOGMODE_FILE);
ptr_logfile = set_logfile(cnt_list[0]->conf.log_file);
if (ptr_logfile) {

if (ptr_logfile) {
set_log_mode(LOGMODE_SYSLOG);
motion_log(LOG_INFO, 0, "%s: Logging to file (%s)", __FUNCTION__,
cnt_list[0]->conf.log_file);
set_log_mode(LOGMODE_FILE);
} else {
motion_log(LOG_ERR, 1, "%s: Exit motion, cannot create log file %s",
__FUNCTION__, cnt_list[0]->conf.log_file);
exit(0);
}

} else {
motion_log(LOG_INFO, 0, "%s: Logging to syslog", __FUNCTION__);
}

motion_log(LOG_INFO, 0, "%s: Motion "VERSION" Started", __FUNCTION__);

initialize_chars();

if (daemonize) {
Expand Down

0 comments on commit 66dc7dc

Please sign in to comment.