Don't fail when removing label from file, that doesn't have it.
authorRafal Krypa <r.krypa@samsung.com>
Tue, 5 Feb 2013 11:08:14 +0000 (12:08 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 7 Feb 2013 11:09:56 +0000 (12:09 +0100)
Functions smack_?setlabel() will return successfully after trying to remove
from file a label, that wasn't set.

Change-Id: Ic7396e3efe457bceca39c8fc5ab9b1151552e795

libsmack/libsmack.c

index c747acd..37843b9 100644 (file)
@@ -400,6 +400,7 @@ static int internal_setlabel(void* file, const char* label,
                setxattr_func setfunc, removexattr_func removefunc)
 {
        char* xattr_name = get_xattr_name(type);
+       int ret;
 
        /* Check validity of labels for LABEL_TRANSMUTE */
        if (type == SMACK_LABEL_TRANSMUTE && label != NULL) {
@@ -412,7 +413,10 @@ static int internal_setlabel(void* file, const char* label,
        }
 
        if (label == NULL || label[0] == '\0') {
-               return removefunc(file, xattr_name);
+               ret = removefunc(file, xattr_name);
+               if (ret == -1 && errno == ENODATA)
+                       return 0;
+               return ret;
        } else {
                int len = strnlen(label, SMACK_LABEL_LEN + 1);
                if (len > SMACK_LABEL_LEN)