Index: conf.h =================================================================== --- conf.h (revisión: 114) +++ conf.h (copia de trabajo) @@ -118,6 +118,7 @@ int text_double; const char *despeckle; int minimum_motion_frames; + char *pid_file; // int debug_parameter; int argc; char **argv; Index: conf.c =================================================================== --- conf.c (revisión: 114) +++ conf.c (copia de trabajo) @@ -134,6 +134,7 @@ text_double: 0, despeckle: NULL, minimum_motion_frames: 1, + pid_file: NULL, // debug_parameter: 0 }; @@ -168,6 +169,13 @@ print_bool }, { + "pid_file", + "# File to store the process ID. (default: /var/run/motion.pid)", + CONF_OFFSET(pid_file), + copy_string, + print_string + }, + { "setup_mode", "############################################################\n" "# Basic Setup Mode\n" @@ -1197,7 +1205,7 @@ * if necessary. This is accomplished by calling mystrcpy(); * see this function for more information. */ - while ((c=getopt(conf->argc, conf->argv, "c:d:hns?"))!=EOF) + while ((c=getopt(conf->argc, conf->argv, "c:d:hns?p"))!=EOF) switch (c) { case 'c': if (thread==-1) strcpy(cnt->conf_filename, optarg); @@ -1212,6 +1220,9 @@ /* no validation - just take what user gives */ debug_level = atoi(optarg); break; + case 'p': + cnt->conf.pid_file = mystrcpy(cnt->conf.pid_file, optarg); + break; case 'h': case '?': default: @@ -1319,8 +1330,8 @@ /* trim space between command and argument */ beg++; - if (strlen(beg) > 0) { - while (*beg == ' ' || *beg == '\t' || *beg == '=') { + if (strlen(beg) > 0){ + while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') { beg++; } Index: motion.h =================================================================== --- motion.h (revisión: 114) +++ motion.h (copia de trabajo) @@ -138,6 +138,7 @@ #define DEF_JPEGPATH "%v-%Y%m%d%H%M%S-%q" #define DEF_MPEGPATH "%v-%Y%m%d%H%M%S" #define DEF_TIMEPATH "%Y%m%d-timelapse" +#define DEF_PIDPATH "/var/run/motion.pid" #define DEF_TIMELAPSE_MODE "daily" Index: motion.c =================================================================== --- motion.c (revisión: 114) +++ motion.c (copia de trabajo) @@ -1548,6 +1548,7 @@ static void become_daemon(void) { int i; + FILE *pidf; struct sigaction sig_ign_action; /* Setup sig_ign_action */ @@ -1559,11 +1560,28 @@ sig_ign_action.sa_handler = SIG_IGN; sigemptyset(&sig_ign_action.sa_mask); + /* fork */ if (fork()) { motion_log(-1, 0, "Motion going to daemon mode"); exit(0); } + + /* Create the pid file , if failed exit */ + if (!cnt_list[0]->conf.pid_file) + cnt_list[0]->conf.pid_file = strdup(DEF_PIDPATH); + pidf = fopen(cnt_list[0]->conf.pid_file, "w+"); + + if ( pidf ){ + (void) fprintf(pidf, "%d\n", getpid()); + motion_log(-1, 0, "Creating pid file %s",cnt_list[0]->conf.pid_file); + fclose(pidf); + }else{ + motion_log(-1, 1, "Exit motion, cannot create a pid file"); + exit(0); + } + + /* changing dir to root enables people to unmount a disk without having to stop Motion */ if (chdir("/")) { @@ -1576,6 +1594,7 @@ setpgrp(); #endif /* BSD */ + if ((i = open("/dev/tty", O_RDWR)) >= 0) { ioctl(i, TIOCNOTTY, NULL); close(i); @@ -1655,6 +1674,11 @@ static void motion_shutdown(void) { int i = -1; + + if (cnt_list[0]->daemon && cnt_list[0]->conf.setup_mode == 0) { + unlink(cnt_list[0]->conf.pid_file); + } + while (cnt_list[++i]){ context_destroy(cnt_list[i]); } Index: motion-dist.conf =================================================================== --- motion-dist.conf (revisión: 114) +++ motion-dist.conf (copia de trabajo) @@ -10,6 +10,9 @@ # Start in daemon (background) mode and release terminal (default: off) daemon on +# File to store the process ID. (default: /var/run/motion.pid) +pid_file /home/gstreamer/motion.pid + ############################################################ # Basic Setup Mode ############################################################