This code spews a multitude of warnings with glibc (unchecked return values), some of them possibly warranted. Furthermore, the deamonisation is not suitable for use with typical startup scripts as it does not provide the PID of the daemon in any way. Users wishing to run avserver as a daemon can still do so using start-stop-daemon or equivalent tools.
Showing the changes to avserver.c (1 of 4 files). Show all
Unified · Split
| @@ -301,12 +301,10 @@ static int rtp_new_av_stream(HTTPContext *c, · 300 unmodified lines | |||
| 301 | HTTPContext *rtsp_c); | 301 | HTTPContext *rtsp_c); |
| 302 | 302 | ||
| 303 | static const char *my_program_name; | 303 | static const char *my_program_name; |
| 304 | static const char *my_program_dir; | ||
| 305 | 304 | ||
| 306 | static const char *config_filename = "/etc/avserver.conf"; | 305 | static const char *config_filename = "/etc/avserver.conf"; |
| 307 | 306 | ||
| 308 | static int avserver_debug; | 307 | static int avserver_debug; |
| 309 | static int avserver_daemon; | ||
| 310 | static int no_launch; | 308 | static int no_launch; |
| 311 | static int need_to_start_children; | 309 | static int need_to_start_children; |
| 312 | 310 | ||
| @@ -524,9 +522,6 @@ static void start_children(FFStream *feed) · 211 unmodified lines | |||
| 524 | } | 522 | } |
| 525 | } | 523 | } |
| 526 | 524 | ||
| 527 | /* This is needed to make relative pathnames work */ | ||
| 528 | chdir(my_program_dir); | ||
| 529 | |||
| 530 | signal(SIGPIPE, SIG_DFL); | 525 | signal(SIGPIPE, SIG_DFL); |
| 531 | 526 | ||
| 532 | execvp(pathname, feed->child_argv); | 527 | execvp(pathname, feed->child_argv); |
| @@ -4081,8 +4076,6 @@ static int parse_ffconfig(const char *filename) · 3548 unmodified lines | |||
| 4081 | if (resolve_host(&my_http_addr.sin_addr, arg) != 0) { | 4076 | if (resolve_host(&my_http_addr.sin_addr, arg) != 0) { |
| 4082 | ERROR("%s:%d: Invalid host/IP address: %s\n", arg); | 4077 | ERROR("%s:%d: Invalid host/IP address: %s\n", arg); |
| 4083 | } | 4078 | } |
| 4084 | } else if (!av_strcasecmp(cmd, "NoDaemon")) { | ||
| 4085 | avserver_daemon = 0; | ||
| 4086 | } else if (!av_strcasecmp(cmd, "RTSPPort")) { | 4079 | } else if (!av_strcasecmp(cmd, "RTSPPort")) { |
| 4087 | get_arg(arg, sizeof(arg), &p); | 4080 | get_arg(arg, sizeof(arg), &p); |
| 4088 | val = atoi(arg); | 4081 | val = atoi(arg); |
| @@ -4655,7 +4648,6 @@ static void handle_child_exit(int sig) · 566 unmodified lines | |||
| 4655 | static void opt_debug(void) | 4648 | static void opt_debug(void) |
| 4656 | { | 4649 | { |
| 4657 | avserver_debug = 1; | 4650 | avserver_debug = 1; |
| 4658 | avserver_daemon = 0; | ||
| 4659 | logfilename[0] = '-'; | 4651 | logfilename[0] = '-'; |
| 4660 | } | 4652 | } |
| 4661 | 4653 | ||
| @@ -4686,8 +4678,6 @@ int main(int argc, char **argv) · 24 unmodified lines | |||
| 4686 | show_banner(); | 4678 | show_banner(); |
| 4687 | 4679 | ||
| 4688 | my_program_name = argv[0]; | 4680 | my_program_name = argv[0]; |
| 4689 | my_program_dir = getcwd(0, 0); | ||
| 4690 | avserver_daemon = 1; | ||
| 4691 | 4681 | ||
| 4692 | parse_options(NULL, argc, argv, options, NULL); | 4682 | parse_options(NULL, argc, argv, options, NULL); |
| 4693 | 4683 | ||
| @@ -4719,37 +4709,9 @@ int main(int argc, char **argv) · 25 unmodified lines | |||
| 4719 | 4709 | ||
| 4720 | compute_bandwidth(); | 4710 | compute_bandwidth(); |
| 4721 | 4711 | ||
| 4722 | /* put the process in background and detach it from its TTY */ | ||
| 4723 | if (avserver_daemon) { | ||
| 4724 | int pid; | ||
| 4725 | |||
| 4726 | pid = fork(); | ||
| 4727 | if (pid < 0) { | ||
| 4728 | perror("fork"); | ||
| 4729 | exit(1); | ||
| 4730 | } else if (pid > 0) { | ||
| 4731 | /* parent : exit */ | ||
| 4732 | exit(0); | ||
| 4733 | } else { | ||
| 4734 | /* child */ | ||
| 4735 | setsid(); | ||
| 4736 | close(0); | ||
| 4737 | open("/dev/null", O_RDWR); | ||
| 4738 | if (strcmp(logfilename, "-") != 0) { | ||
| 4739 | close(1); | ||
| 4740 | dup(0); | ||
| 4741 | } | ||
| 4742 | close(2); | ||
| 4743 | dup(0); | ||
| 4744 | } | ||
| 4745 | } | ||
| 4746 | |||
| 4747 | /* signal init */ | 4712 | /* signal init */ |
| 4748 | signal(SIGPIPE, SIG_IGN); | 4713 | signal(SIGPIPE, SIG_IGN); |
| 4749 | 4714 | ||
| 4750 | if (avserver_daemon) | ||
| 4751 | chdir("/"); | ||
| 4752 | |||
| 4753 | if (http_server() < 0) { | 4715 | if (http_server() < 0) { |
| 4754 | http_log("Could not start server\n"); | 4716 | http_log("Could not start server\n"); |
| 4755 | exit(1); | 4717 | exit(1); |