Commit Diff


commit - c4a8987ff963246782c67693fba85acb5ad7b41e
commit + dfe2ad9662a4763c47a79b3f907e4d33c6d3536d
blob - 56aea43e121542cf119487af5bdd22c5cf02cb34
blob + b74f792e8186849c3c42f05b095a2acbe32adae8
--- amused.c
+++ amused.c
@@ -17,6 +17,7 @@
 #include <sys/types.h>
 #include <sys/queue.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/uio.h>
 #include <sys/wait.h>
 
@@ -353,15 +354,28 @@ main_send_player(uint16_t type, int fd, const void *da
 int
 main_play_song(const char *song)
 {
+	struct stat sb;
 	char path[PATH_MAX] = { 0 };
 	int fd;
 
 	strlcpy(path, song, sizeof(path));
 	if ((fd = open(path, O_RDONLY)) == -1) {
 		log_warn("open %s", path);
+		return 0;
+	}
+
+	if (fstat(fd, &sb) == -1) {
+		log_warn("failed to stat %s", path);
+		close(fd);
 		return 0;
 	}
 
+	if (S_ISDIR(sb.st_mode)) {
+		log_info("skipping a directory: %s", path);
+		close(fd);
+		return 0;
+	}
+
 	play_state = STATE_PLAYING;
 	imsg_compose_event(iev_player, IMSG_PLAY, 0, 0, fd,
 	    path, sizeof(path));