From cc0f62df89d5aed7af052cf6b63ad45eecd62f38 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:27:59 +0000 Subject: [PATCH 1/6] Update: Log PID on process startup. --- src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.c b/src/main.c index 7ee01a5a..ccf8d0ef 100644 --- a/src/main.c +++ b/src/main.c @@ -582,6 +582,7 @@ int main(int argc, char **argv) } ICECAST_LOG_INFO("%s server started", ICECAST_VERSION_STRING); + ICECAST_LOG_INFO("Server's PID is %lli", (long long int)getpid()); __log_system_name(); /* REM 3D Graphics */ From 8a69db3ab734542f83cd1e9812c7d1abdac0521a Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:28:42 +0000 Subject: [PATCH 2/6] Update: Allow running as root IF Icecast has PID=1 --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index ccf8d0ef..fe12b3a1 100644 --- a/src/main.c +++ b/src/main.c @@ -563,7 +563,7 @@ int main(int argc, char **argv) #ifdef HAVE_SETUID /* We'll only have getuid() if we also have setuid(), it's reasonable to * assume */ - if(!getuid()) /* Running as root! Don't allow this */ + if(!getuid() && getpid() != 1) /* Running as root! Don't allow this */ { fprintf(stderr, "ERROR: You should not run icecast2 as root\n"); fprintf(stderr, "Use the changeowner directive in the config file\n"); From beb4523b842ccc9ce4dc854b0b39d4a3b442127d Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:29:51 +0000 Subject: [PATCH 3/6] Cleanup: Replaced magic number with sizeof() --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index fe12b3a1..a971a858 100644 --- a/src/main.c +++ b/src/main.c @@ -499,7 +499,7 @@ int main(int argc, char **argv) /* parse the '-c icecast.xml' option ** only, so that we can read a configfile */ - res = _parse_config_opts(argc, argv, filename, 512); + res = _parse_config_opts(argc, argv, filename, sizeof(filename)); if (res == 1) { #if !defined(_WIN32) || defined(_CONSOLE) || defined(__MINGW32__) || defined(__MINGW64__) /* startup all the modules */ From 452c2b17d38a4b92cee4e3dafd89502a6b9c4ada Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:30:42 +0000 Subject: [PATCH 4/6] Fix: Use size_t not int --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index a971a858..91cf406d 100644 --- a/src/main.c +++ b/src/main.c @@ -162,7 +162,7 @@ void shutdown_subsystems(void) xslt_shutdown(); } -static int _parse_config_opts(int argc, char **argv, char *filename, int size) +static int _parse_config_opts(int argc, char **argv, char *filename, size_t size) { int i = 1; int config_ok = 0; From 2b3f07e9b0efcdca8e4c83075280a6755f6c2b94 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:33:14 +0000 Subject: [PATCH 5/6] Feature: Allow using default config filename. This uses the new configure option --with-default-config=PATH. --- src/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 91cf406d..1218aabf 100644 --- a/src/main.c +++ b/src/main.c @@ -168,7 +168,13 @@ static int _parse_config_opts(int argc, char **argv, char *filename, size_t size int config_ok = 0; background = 0; - if (argc < 2) return -1; + if (argc < 2) { + if (filename[0] != 0) { + return 1; + } else { + return -1; + } + } while (i < argc) { if (strcmp(argv[i], "-b") == 0) { @@ -493,7 +499,11 @@ int main(int argc, char **argv) #endif { int res, ret; - char filename[512]; +#ifdef ICECAST_DEFAULT_CONFIG + char filename[512] = ICECAST_DEFAULT_CONFIG; +#else + char filename[512] = ""; +#endif char pbuf[1024]; /* parse the '-c icecast.xml' option From be0bf035c72fa3a2d2fa9bc3c9933d12f81919d7 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 16 Jun 2018 17:38:35 +0000 Subject: [PATCH 6/6] Update: Added comments to make code easier to understand --- src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.c b/src/main.c index 1218aabf..89ed2552 100644 --- a/src/main.c +++ b/src/main.c @@ -170,8 +170,10 @@ static int _parse_config_opts(int argc, char **argv, char *filename, size_t size background = 0; if (argc < 2) { if (filename[0] != 0) { + /* We have a default filename, so we can work with no options. */ return 1; } else { + /* We need at least a config filename. */ return -1; } }