coccinelle: make use of SYNTHETIC_ERRNO

Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-11-22 10:54:38 +01:00
parent 52d86690d6
commit baaa35ad70
129 changed files with 1932 additions and 2311 deletions
+30 -40
View File
@@ -94,69 +94,60 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) {
log_error("Failed to resolve user %s.", user);
return -ESRCH;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Failed to resolve user %s.", user);
if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m");
(void) wait_for_terminate_and_check("getent passwd", pid, WAIT_LOG);
x = strchr(line, ':');
if (!x) {
log_error("/etc/passwd entry has invalid user field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid user field.");
u = strchr(x+1, ':');
if (!u) {
log_error("/etc/passwd entry has invalid password field.");
return -EIO;
}
if (!u)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid password field.");
u++;
g = strchr(u, ':');
if (!g) {
log_error("/etc/passwd entry has invalid UID field.");
return -EIO;
}
if (!g)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid UID field.");
*g = 0;
g++;
x = strchr(g, ':');
if (!x) {
log_error("/etc/passwd entry has invalid GID field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid GID field.");
*x = 0;
h = strchr(x+1, ':');
if (!h) {
log_error("/etc/passwd entry has invalid GECOS field.");
return -EIO;
}
if (!h)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid GECOS field.");
h++;
x = strchr(h, ':');
if (!x) {
log_error("/etc/passwd entry has invalid home directory field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid home directory field.");
*x = 0;
r = parse_uid(u, &uid);
if (r < 0) {
log_error("Failed to parse UID of user.");
return -EIO;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to parse UID of user.");
r = parse_gid(g, &gid);
if (r < 0) {
log_error("Failed to parse GID of user.");
return -EIO;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to parse GID of user.");
home = strdup(h);
if (!home)
@@ -176,10 +167,9 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) {
log_error("Failed to resolve user %s.", user);
return -ESRCH;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Failed to resolve user %s.", user);
if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m");