X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=7281b703abbd5a63ef230f63dfe4f20c349c59a6;hb=5de6b302196f3a708a0ed36d88abd9e17bbc9d52;hp=ec5c7ca91aacbb19c807015c402fc5baed38cba1;hpb=6319292f15478f763777738c9a98faa99ae819c1;p=elogind.git diff --git a/src/util.c b/src/util.c index ec5c7ca91..7281b703a 100644 --- a/src/util.c +++ b/src/util.c @@ -62,11 +62,11 @@ static struct selabel_handle *label_hnd = NULL; -static inline int use_selinux(void) { +static inline bool use_selinux(void) { static int use_selinux_ind = -1; - if (use_selinux_ind == -1) - use_selinux_ind = (is_selinux_enabled() == 1); + if (use_selinux_ind < 0) + use_selinux_ind = is_selinux_enabled() > 0; return use_selinux_ind; } @@ -84,6 +84,8 @@ static int label_get_file_label_from_path( r = getfilecon(path, &dir_con); if (r >= 0) { r = -1; + errno = EINVAL; + if ((sclass = string_to_security_class(class)) != 0) r = security_compute_create((security_context_t) label, dir_con, sclass, fcon); } @@ -1934,6 +1936,12 @@ char *format_timespan(char *buf, size_t l, usec_t t) { if (t == (usec_t) -1) return NULL; + if (t == 0) { + snprintf(p, l, "0"); + p[l-1] = 0; + return p; + } + /* The result of this function can be parsed with parse_usec */ for (i = 0; i < ELEMENTSOF(table); i++) {