RTMP commandline, sigpipe signal catching, and init script changes
This commit is contained in:
parent
47370e9621
commit
d43d041d5e
2 changed files with 46 additions and 37 deletions
|
@ -1,32 +1,22 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# chkconfig: 345 92 8
|
||||
# description: DDVTech RTMP Connector
|
||||
#
|
||||
# processname: Connector_RTMP
|
||||
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
prog="Connector_RTMP"
|
||||
fullprog="/usr/bin/Connector_RTMP"
|
||||
RETVAL=0
|
||||
|
||||
start() {
|
||||
gprintf "Starting %s: " $prog
|
||||
daemon --user=root $fullprog
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
|
||||
return $RETVAL
|
||||
echo "Starting $prog"
|
||||
$fullprog
|
||||
return $?
|
||||
}
|
||||
|
||||
stop() {
|
||||
gprintf "Stopping %s: " $prog
|
||||
killproc $fullprog
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
|
||||
return $RETVAL
|
||||
echo "Stopping $prog"
|
||||
killall $prog
|
||||
return $?
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
@ -40,18 +30,8 @@ case "$1" in
|
|||
stop
|
||||
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
|
||||
esac
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <getopt.h>
|
||||
|
||||
//for connection to server
|
||||
bool ready4data = false;//set to true when streaming starts
|
||||
|
@ -49,21 +50,49 @@ int main(int argc, char ** argv){
|
|||
new_action.sa_handler = termination_handler;
|
||||
sigemptyset (&new_action.sa_mask);
|
||||
new_action.sa_flags = 0;
|
||||
sigaction (SIGINT, &new_action, NULL);
|
||||
sigaction (SIGHUP, &new_action, NULL);
|
||||
sigaction (SIGTERM, &new_action, NULL);
|
||||
sigaction(SIGINT, &new_action, NULL);
|
||||
sigaction(SIGHUP, &new_action, NULL);
|
||||
sigaction(SIGTERM, &new_action, NULL);
|
||||
sigaction(SIGPIPE, &new_action, NULL);
|
||||
|
||||
server_socket = DDV_Listen(1935);
|
||||
fprintf(stderr, "Made a listening socket on port 1936...");
|
||||
if ((argc < 2) || (strcmp(argv[1], "nd") != 0)){
|
||||
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(listen_port);
|
||||
fprintf(stderr, "Made a listening socket on port %i...\n", listen_port);
|
||||
if (server_socket > 0){
|
||||
if (daemon_mode){
|
||||
daemon(1, 0);
|
||||
fprintf(stderr, "Going into background mode...");
|
||||
}
|
||||
}else{
|
||||
fprintf(stderr, "Error: could not make listening socket");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
int status;
|
||||
while (server_socket > 0){
|
||||
waitpid((pid_t)-1, &status, WNOHANG);
|
||||
|
|
Loading…
Add table
Reference in a new issue