return -errno;
if (sa.sa.sa_family == AF_UNIX) {
- struct ucred ucred = {};
+ struct ucred ucred = UCRED_INVALID;
/* UNIX connection sockets are anonymous, so let's use
* PID/UID as pretty credentials instead */
}
int socket_get_mtu(int fd, int af, size_t *ret);
+
+/* an initializer for struct ucred that initialized all fields to the invalid value appropriate for each */
+#define UCRED_INVALID { .pid = 0, .uid = UID_INVALID, .gid = GID_INVALID }
#include "syslog-util.h"
#include "tmpfile-util.h"
#include "unit-name.h"
+#include "user-util.h"
#define STDOUT_STREAMS_MAX 4096
*stream = (StdoutStream) {
.fd = -1,
.priority = LOG_INFO,
+ .ucred = UCRED_INVALID,
};
xsprintf(stream->id_field, "_STREAM_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id));
}
if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) {
- struct ucred u;
+ struct ucred u = UCRED_INVALID;
- r = getpeercred(fd, &u);
+ (void) getpeercred(fd, &u);
/* By closing fd here we make sure that the client won't wait too long for journald to
* gather all the data it adds to the error message to find out that the connection has
*/
fd = safe_close(fd);
- server_driver_message(s, r < 0 ? 0 : u.pid, NULL, LOG_MESSAGE("Too many stdout streams, refusing connection."), NULL);
+ server_driver_message(s, u.pid, NULL, LOG_MESSAGE("Too many stdout streams, refusing connection."), NULL);
return 0;
}
.original_pid = getpid_cached(),
.n_groups = SIZE_MAX,
.close_on_exit = true,
+ .ucred = UCRED_INVALID,
};
/* We guarantee that wqueue always has space for at least one entry */
}
_public_ int sd_peer_get_session(int fd, char **session) {
- struct ucred ucred = {};
+ struct ucred ucred = UCRED_INVALID;
int r;
assert_return(fd >= 0, -EBADF);
.state = _VARLINK_STATE_INVALID,
- .ucred.uid = UID_INVALID,
- .ucred.gid = GID_INVALID,
+ .ucred = UCRED_INVALID,
.timestamp = USEC_INFINITY,
.timeout = VARLINK_DEFAULT_TIMEOUT_USEC
int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret) {
_cleanup_(varlink_unrefp) Varlink *v = NULL;
+ struct ucred ucred = UCRED_INVALID;
bool ucred_acquired;
- struct ucred ucred;
int r;
assert_return(server, -EINVAL);