X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftest%2Ftest-fileio.c;h=b08e796b7d0dbdc7e414c96462806bc8537394c7;hp=d56f7cc8562aa7aceeb616d1014af2b62ba3b0b8;hb=68fee104e630eb19f04b8196a83c14c2c9c469e7;hpb=cba38758b4d49c6fe7c2f0eea255e11ee9df23eb;ds=sidebyside diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index d56f7cc85..b08e796b7 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -139,7 +139,42 @@ static void test_parse_env_file(void) { unlink("/tmp/test-fileio"); } +static void test_executable_is_script(void) { + char t[] = "/tmp/test-executable-XXXXXX"; + int fd, r; + FILE *f; + char *command; + + fd = mkostemp(t, O_CLOEXEC); + assert_se(fd >= 0); + + f = fdopen(fd, "w"); + assert_se(f); + + fputs("#! /bin/script -a -b \ngoo goo", f); + fflush(f); + + r = executable_is_script(t, &command); + assert_se(r > 0); + assert_se(streq(command, "/bin/script")); + free(command); + + r = executable_is_script("/bin/sh", &command); + assert_se(r == 0); + + r = executable_is_script("/usr/bin/yum", &command); + assert_se(r > 0 || r == -ENOENT); + if (r > 0) { + assert_se(startswith(command, "/")); + free(command); + } + + fclose(f); + unlink(t); +} + int main(int argc, char *argv[]) { test_parse_env_file(); + test_executable_is_script(); return 0; }