Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Check if the provided directory exists before serving it through 'pkg serve'
Marin Atanasov Nikolov committed 13 years ago
commit 22f3ec3b081fec63bff4c8f24beafa4981976167
parent d3186165f52cf328ef6fab08bf960546eafacdda
1 file changed +11 -1
modified plugins/pkg-plugins-serve/plugin/serve.c
@@ -24,6 +24,9 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include <sys/types.h>
+
#include <sys/stat.h>
+

#include <stdio.h>
#include <sysexits.h>
#include <unistd.h>
@@ -67,6 +70,7 @@ int
plugin_serve_callback(int argc, char **argv)
{
	struct mg_context *ctx = NULL;
+
	struct stat st;
	const char *wwwroot = NULL;
	const char *port = NULL;
        int ch;
@@ -92,7 +96,13 @@ plugin_serve_callback(int argc, char **argv)
		port = "8080";

	if (wwwroot == NULL) {
-
		fprintf(stderr, "You need to specify a directory for serving");
+
		fprintf(stderr, ">>> You need to specify a directory for serving");
+
		return (EX_USAGE);
+
	}
+

+
	stat(wwwroot, &st);
+
	if (S_ISDIR(st.st_mode) == 0) {
+
		fprintf(stderr, ">>> '%s' is not a directory\n", wwwroot);
		return (EX_USAGE);
	}