From 907ca8a89f47c8982249dd93d1f1d6f9e567f01c Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sat, 28 Feb 2009 14:12:03 +0000 Subject: Set errno when service does not exist better. --- src/librc/librc.c | 20 +++++++++++++++----- 1 file 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; } -- cgit v1.2.3