Dmitrij D. Czarkoff said: > This version uses fork+execl. FWIW I am getting convinced that just > disabling this functionality is the best approach: it is basically used > for detecting music files with wrong filename suffixes. Very few > legitimate use cases for this are better handled through renaming files.
Updated version with feedback from espie@. As Michael Seyfert mentioned, this code path is not enabled by default. Comments? OKs? For ease of review the added code follows (between #else and #endif): |/* Given a file name, return the mime type or NULL. */ |char *file_mime_type (const char *file) |{ | char *result = NULL; | | assert (file != NULL); | |#ifdef HAVE_LIBMAGIC [...] |#else | int std_out[2]; | int status; | pid_t pid; | FILE *stream; | char *out; | size_t len; | | if (pipe (std_out) == -1) { | logit ("Error interrogating file: %s", strerror (errno)); | return result; | } | | pid = fork(); | if (pid == -1) { | logit ("Error interrogating file: %s", strerror (errno)); | return result; | } else if (pid == 0) { | close (std_out[0]); | if (dup2 (std_out[1], STDOUT_FILENO) == -1) | _exit(1); | close(std_out[1]); | | execlp ("/usr/bin/file", "file", "-bi", file, NULL); | logit ("Error interrogating file: %s", strerror (errno)); | _exit(1); | } | | close (std_out[1]); | | if ((stream = fdopen (std_out[0], "r")) == NULL) { | logit ("Error interrogating file: %s", strerror (errno)); | close(std_out[0]); | return result; | } | | if ((out = fgetln (stream, &len)) == NULL) { | logit ("Error interrogating file: %s", strerror (errno)); | fclose(stream); | return result; | } | | if (len == 0) { | logit ("Error interrogating file: file(1) failed"); | return result; | } | out[len - 1] = '\0'; | result = xstrdup (out); | | fclose (stream); | | waitpid (pid, &status, 0); |#endif | | return result; |} -- Dmitrij D. Czarkoff
moc-2.5.0.tgz
Description: application/tar-gz