RTMP commandline, sigpipe signal catching, and init script changes

This commit is contained in:
Thulinma 2010-11-21 23:06:54 +01:00
parent 47370e9621
commit d43d041d5e
2 changed files with 46 additions and 37 deletions

View file

@ -1,32 +1,22 @@
#!/bin/sh #!/bin/sh
# #
# chkconfig: 345 92 8
# description: DDVTech RTMP Connector # description: DDVTech RTMP Connector
#
# processname: Connector_RTMP # processname: Connector_RTMP
. /etc/rc.d/init.d/functions
prog="Connector_RTMP" prog="Connector_RTMP"
fullprog="/usr/bin/Connector_RTMP" fullprog="/usr/bin/Connector_RTMP"
RETVAL=0 RETVAL=0
start() { start() {
gprintf "Starting %s: " $prog echo "Starting $prog"
daemon --user=root $fullprog $fullprog
RETVAL=$? return $?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
} }
stop() { stop() {
gprintf "Stopping %s: " $prog echo "Stopping $prog"
killproc $fullprog killall $prog
RETVAL=$? return $?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
} }
case "$1" in case "$1" in
@ -40,18 +30,8 @@ case "$1" in
stop stop
start start
;; ;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status $fullprog
RETVAL=$?
;;
*) *)
gprintf "Usage: %s {start|stop|restart|status}" $0 echo "Usage: $0 {start|stop|restart}"
RETVAL=1 RETVAL=1
esac esac

View file

@ -14,6 +14,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <getopt.h>
//for connection to server //for connection to server
bool ready4data = false;//set to true when streaming starts bool ready4data = false;//set to true when streaming starts
@ -49,20 +50,48 @@ int main(int argc, char ** argv){
new_action.sa_handler = termination_handler; new_action.sa_handler = termination_handler;
sigemptyset (&new_action.sa_mask); sigemptyset (&new_action.sa_mask);
new_action.sa_flags = 0; new_action.sa_flags = 0;
sigaction (SIGINT, &new_action, NULL); sigaction(SIGINT, &new_action, NULL);
sigaction (SIGHUP, &new_action, NULL); sigaction(SIGHUP, &new_action, NULL);
sigaction (SIGTERM, &new_action, NULL); sigaction(SIGTERM, &new_action, NULL);
sigaction(SIGPIPE, &new_action, NULL);
int listen_port = 1935;
bool daemon_mode = true;
int opt = 0;
static const char *optString = "np:h?";
static const struct option longOpts[] = {
{"help",0,0,'h'},
{"port",1,0,'p'},
{"no-daemon",0,0,'n'}
};
while ((opt = getopt_long(argc, argv, optString, longOpts, 0)) != -1){
switch (opt){
case 'p':
listen_port = atoi(optarg);
break;
case 'n':
daemon_mode = false;
break;
case 'h':
case '?':
printf("Options: -h[elp], -?, -n[o-daemon], -p[ort] #\n");
return 1;
break;
}
}
server_socket = DDV_Listen(1935);
fprintf(stderr, "Made a listening socket on port 1936..."); server_socket = DDV_Listen(listen_port);
if ((argc < 2) || (strcmp(argv[1], "nd") != 0)){ fprintf(stderr, "Made a listening socket on port %i...\n", listen_port);
if (server_socket > 0){ if (server_socket > 0){
if (daemon_mode){
daemon(1, 0); daemon(1, 0);
fprintf(stderr, "Going into background mode..."); fprintf(stderr, "Going into background mode...");
}else{
fprintf(stderr, "Error: could not make listening socket");
return 1;
} }
}else{
fprintf(stderr, "Error: could not make listening socket");
return 1;
} }
int status; int status;
while (server_socket > 0){ while (server_socket > 0){