diff options
-rw-r--r-- | src/librc/librc.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/librc/librc.c b/src/librc/librc.c index 204e07f3..b7ab9203 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -392,22 +392,32 @@ rc_service_exists(const char *service) int len; struct stat buf; - if (!service) + if (!service) { + errno = EINVAL; return false; + } len = strlen(service); /* .sh files are not init scripts */ if (len > 2 && service[len - 3] == '.' && service[len - 2] == 's' && - service[len - 1] == 'h') + service[len - 1] == 'h') { + errno = EINVAL; return false; + } - if (!(file = rc_service_resolve(service))) + if (!(file = rc_service_resolve(service))) { + errno = ENOENT; return false; + } - if (stat(file, &buf) == 0 && buf.st_mode & S_IXUGO) - retval = true; + if (stat(file, &buf) == 0) { + if (buf.st_mode & S_IXUGO) + retval = true; + else + errno = ENOEXEC; + } free(file); return retval; } |