Set errno when service does not exist better.

This commit is contained in:
Roy Marples 2009-02-28 14:12:03 +00:00
parent f38ef00939
commit 907ca8a89f

View File

@ -392,22 +392,32 @@ rc_service_exists(const char *service)
int len; int len;
struct stat buf; struct stat buf;
if (!service) if (!service) {
errno = EINVAL;
return false; return false;
}
len = strlen(service); len = strlen(service);
/* .sh files are not init scripts */ /* .sh files are not init scripts */
if (len > 2 && service[len - 3] == '.' && if (len > 2 && service[len - 3] == '.' &&
service[len - 2] == 's' && service[len - 2] == 's' &&
service[len - 1] == 'h') service[len - 1] == 'h') {
errno = EINVAL;
return false; return false;
}
if (!(file = rc_service_resolve(service))) if (!(file = rc_service_resolve(service))) {
errno = ENOENT;
return false; return false;
}
if (stat(file, &buf) == 0 && buf.st_mode & S_IXUGO) if (stat(file, &buf) == 0) {
if (buf.st_mode & S_IXUGO)
retval = true; retval = true;
else
errno = ENOEXEC;
}
free(file); free(file);
return retval; return retval;
} }