Commit baee2d0c authored by Philipp Schafft's avatar Philipp Schafft 🦁
Browse files

subset of my earlier patch so it can go into 2.4.1: disconnects stdio of...

subset of my earlier patch so it can go into 2.4.1: disconnects stdio of <on-[dis]connect> scripts from random filehandles. closes #2087

svn path=/icecast/trunk/icecast/; revision=19313
parent d06b6b18
...@@ -34,6 +34,12 @@ ...@@ -34,6 +34,12 @@
#define snprintf _snprintf #define snprintf _snprintf
#endif #endif
#ifndef _WIN32
/* for __setup_empty_script_environment() */
#include <sys/stat.h>
#include <fcntl.h>
#endif
#include "thread/thread.h" #include "thread/thread.h"
#include "avl/avl.h" #include "avl/avl.h"
#include "httpp/httpp.h" #include "httpp/httpp.h"
...@@ -1311,6 +1317,33 @@ void source_client_callback (client_t *client, void *arg) ...@@ -1311,6 +1317,33 @@ void source_client_callback (client_t *client, void *arg)
#ifndef _WIN32 #ifndef _WIN32
/* this sets up the new environment for script execution.
* We ignore most failtures as we can not handle them anyway.
*/
static inline void __setup_empty_script_environment(void) {
int i;
/* close at least the first 1024 handles */
for (i = 0; i < 1024; i++)
close(i);
/* open null device */
i = open("/dev/null", O_RDWR);
if (i != -1) {
/* attach null device to stdin, stdout and stderr */
if (i != 0)
dup2(i, 0);
if (i != 1)
dup2(i, 1);
if (i != 2)
dup2(i, 2);
/* close null device */
if (i > 2)
close(i);
}
}
static void source_run_script (char *command, char *mountpoint) static void source_run_script (char *command, char *mountpoint)
{ {
pid_t pid, external_pid; pid_t pid, external_pid;
...@@ -1326,10 +1359,15 @@ static void source_run_script (char *command, char *mountpoint) ...@@ -1326,10 +1359,15 @@ static void source_run_script (char *command, char *mountpoint)
ICECAST_LOG_ERROR("Unable to fork %s (%s)", command, strerror (errno)); ICECAST_LOG_ERROR("Unable to fork %s (%s)", command, strerror (errno));
break; break;
case 0: /* child */ case 0: /* child */
if (access(command, R_OK|X_OK) != 0) {
ICECAST_LOG_ERROR("Unable to run command %s (%s)", command, strerror(errno));
exit(1);
}
ICECAST_LOG_DEBUG("Starting command %s", command); ICECAST_LOG_DEBUG("Starting command %s", command);
execl (command, command, mountpoint, (char *)NULL); __setup_empty_script_environment();
ICECAST_LOG_ERROR("Unable to run command %s (%s)", command, strerror (errno)); /* consider to add action here as well */
exit(0); execl(command, command, mountpoint, (char *)NULL);
exit(1);
default: /* parent */ default: /* parent */
break; break;
} }
......
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