Commit ab9e5d99 authored by Andrey Filippov's avatar Andrey Filippov

initial files

parent ee4ddd26
html/*
attic/*
.project
.cproject
.pydevproject
.settings
*.directory
generated*
sysroots
bitbake-logs
\ No newline at end of file
This diff is collapsed.
PROGS = autocampars launch_php_script
PHPSCRIPTS = autocampars.php
SRCS = autocampars.c launch_php_script.c
OBJS = $(SRC:.c=.o)
#OBJS = autocampars.o launch_php_script.o
BINDIR = $(DESTDIR)/usr/bin/
SYSCONFDIR = $(DESTDIR)/etc/
DOCUMENTROOT = $(DESTDIR)/www/pages
INSTALL = install
INSTMODE = 0755
INSTDOCS = 0644
OWN = -o root -g root
INCDIR = $(STAGING_DIR_HOST)/usr/include-uapi/elphel
CFLAGS += -Wall -I$(INCDIR)
all: $(PROGS)
$(PROGS): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
install: $(PROGS)
$(INSTALL) -d $(BINDIR)
$(INSTALL) -d $(DOCUMENTROOT)
$(INSTALL) -d $(SYSCONFDIR)
$(INSTALL) $(OWN) -m $(INSTMODE) $(PROGS) $(BINDIR)
$(INSTALL) $(OWN) -m $(INSTMODE) $(PHPSCRIPTS) $(DOCUMENTROOT)
clean:
rm -rf $(PROGS) *.o core
configsubs:
/*!***************************************************************************
*! FILE NAME : autocampars.c
*! DESCRIPTION: Daemon to save/restore parameter (calls autocampars.php)
*! This program is needed not to have an extra instance of
*! PHP (2+ MB) just waiting as a daemon.
*! Copyright (C) 2008 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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 3 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, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: autocampars.c,v $
*! Revision 1.2 2008/12/08 08:13:37 elphel
*! added one more error check
*!
*! Revision 1.1.1.1 2008/11/27 20:04:01 elphel
*!
*!
*! Revision 1.4 2008/11/22 05:52:47 elphel
*! added TODO
*!
*! Revision 1.3 2008/11/18 07:37:10 elphel
*! snapshot
*!
*! Revision 1.2 2008/11/17 23:42:59 elphel
*! snapshot
*!
*! Revision 1.1 2008/11/17 06:41:20 elphel
*! 8.0.alpha18 - started autocampars - camera parameters save/restore/init manager
*!
*!
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <asm/elphel/c313a.h>
int main (int argc, char *argv[]) {
const char framepars_driver_name[]="/dev/frameparsall";
// const char php_path[]="/usr/local/sbin/php";
const char script_path[]="/usr/html/autocampars.php";
int fd_fparmsall= open(framepars_driver_name, O_RDWR);
unsigned long write_data[4];
int rslt;
if (fd_fparmsall <0) {
ELP_FERR(fprintf(stderr, "Open failed: (%s)\n", framepars_driver_name));
exit (1);
}
///TODO: Use it to re-running ccamftp.php
/// see if any arguments are provided. If they are - they are bit number, sleep time in seconds and command/arguments of an external program
/// to be launched. Usually - a php script, so it makes sense not to keep the php instance in memory if it is not used most of the time
/// (done so for ccamftp.php)
///
/// Daemon loop - waiting for being enabled, run autocampars.php
/// NOTE: Requires sequencers and sensor to be running, to reset everything if stuck - use autocampars.php directly
int pid;
while (1) {
lseek(fd_fparmsall, LSEEK_DAEMON_FRAME+DAEMON_BIT_AUTOCAMPARS, SEEK_END); /// wait for autocampars bit to be enabled (let it sleep if not)
write_data[0]= FRAMEPARS_SETFRAMEREL;
write_data[1]= 1;
write_data[2]= P_DAEMON_EN_AUTOCAMPARS;
write_data[3]= 0;
rslt=write(fd_fparmsall, write_data, sizeof(write_data));
if (rslt < sizeof(write_data)) {
ELP_FERR(fprintf(stderr, "Failed writing to %s\n", framepars_driver_name));
exit (1);
}
fprintf(stderr, "autocampars triggered\n");
signal(SIGCHLD, SIG_IGN); // no zombies
//! do we need any fork at all if we now serve images to one client at a time?
if (((pid=fork())) <0) { /// error
ELP_FERR(fprintf(stderr, "fork() failed\n"));
exit (1);
} else if (pid == 0) { /// child
fflush(stdout);
fflush(stderr);
// rslt= execl(php_path, "-q", script_path, "", "--daemon", (char *) NULL); /// We do not need to pass any parameters here, but if we had to - first argument is lost (probably to "-q" in the script line 1
rslt= execl(script_path, "", "--daemon", (char *) NULL); /// We do not need to pass any parameters here, but if we had to - first argument is lost (probably to "-q" in the script line 1
ELP_FERR(fprintf(stderr, "execl failed, returned %d, errno=%d\n", rslt,errno));
_exit(2);/// comes here only if error
} // end of child process
lseek(fd_fparmsall, LSEEK_FRAME_WAIT_REL+1, SEEK_END); /// skip 1 frame before returning
}
return 0;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/*!***************************************************************************
*! FILE NAME : launch_php_script.c
*! DESCRIPTION: Companion to PHP scripts used as daemons (currently camftp.php)
*! to save memory when script is disabled. When the specidied bit
*! is set in P_DAEMON_EN it launches the script and waits for it
*! to finish, then sleeps (if the enable bit is off)
*! The script is supposed to monitor enable bit and termonate when
*! it is off
*! Copyright (C) 2008 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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 3 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, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*!
*! $Log: launch_php_script.c,v $
*! Revision 1.1 2008/12/08 08:12:42 elphel
*! added launch_php_script - a companion program to the php scripts used as daemons (like ccamftp.php) - it is used to reduce memory footprint when daemon is disabled
*!
*!
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
#include <asm/elphel/c313a.h>
int main (int argc, char *argv[]) {
if (argc < 3) {
printf (" This is a companion program that works with PHP scripts to make a daemon,\n"
"conserving memory footprint when disabled.\n"
"It waits for the the specified bit in the global daemon control word (P_DAEMON_EN)\n"
"to be set (using driver functionality) and then launches the specified script\n"
"with optional parameters, blocking itself until the script terminates.\n\n"
" After that it sleeps again until the bit is reenabled (normally script exits\n"
"when this bit is cleared) and launches the script again. That reduces memory usage\n"
"when the script is disabled - no need to keep PHP interpreter in teh memory (>2MB)\n\n"
"Usage:\n"
"%s <bit_number> <command> [<parameter>...]\n",argv[0]);
exit (1);
}
int pid, status;
int en_bit=strtol(argv[1], NULL, 10);
if ((en_bit<0) || (en_bit>31)) {printf ("Invalid bit number %d (should be 0..31)\n", en_bit); exit (1);}
const char framepars_driver_name[]="/dev/frameparsall";
int fd_fparmsall= open(framepars_driver_name, O_RDONLY);
int rslt;
if (fd_fparmsall <0) {
ELP_FERR(fprintf(stderr, "Open failed: (%s)\n", framepars_driver_name));
exit (1);
}
/// Daemon loop - waiting for being enabled, run script
//int execv(const char *path, char *const argv[]);
while (1) {
lseek(fd_fparmsall, LSEEK_DAEMON_FRAME+en_bit, SEEK_END); /// wait for the specified bit in P_DAEMON_EN to be enabled (and sleep while not)
signal(SIGCHLD, SIG_IGN); // no zombies
//! do we need any fork at all if we now serve images to one client at a time?
if (((pid=fork())) <0) { /// error
ELP_FERR(fprintf(stderr, "fork() failed\n"));
exit (1);
} else if (pid == 0) { /// child
fflush(stdout);
fflush(stderr);
rslt= execv(argv[2], &argv[2]); /// script path, all parameters starting with the script path
ELP_FERR(fprintf(stderr, "execl failed, returned %d, errno=%d\n", rslt,errno));
_exit(2);/// comes here only if error
} /// Only parent will get below here
wait(&status); // always returns -1, errno=10 - no child processes
/// lseek(fd_fparmsall, LSEEK_FRAME_WAIT_REL+1, SEEK_END); /// skip 1 frame before returning
}
return 0; ///will never get here
}
#!/bin/bash
args="$@"
while (( "$#" )); do
shift
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Launching bitbake $args"
cd $DIR/../../poky
. ./oe-init-build-env
bitbake $args | sed -u 's@| @@'
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment