Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/systemd/pyutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>
/* Work around bug in Python.h:
* it tries to redefine defines already defined by /usr/include/features.h,
* without calling #undef first, causing a warning to be emitted.
* (https://github.com/python/cpython/issues/61322). */
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
# include <Python.h>
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 800
#define _POSIX_C_SOURCE 202405L

void cleanup_Py_DECREFp(PyObject **p);
PyObject* absolute_timeout(uint64_t t);
Expand Down
18 changes: 9 additions & 9 deletions src/systemd/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,16 @@ static int assign_address(const char *s,

int parse_sockaddr(const char *s,
union sockaddr_union *addr, unsigned *addr_len) {

char *e, *n;
unsigned u;
int r;

if (*s == '[') {
/* IPv6 in [x:.....:z]:p notation */

e = strchr(s+1, ']');
const char *e = strchr(s + 1, ']');
if (!e)
return -EINVAL;

n = strndupa(s+1, e-s-1);
char *n = strndupa(s+1, e-s-1);

errno = 0;
if (inet_pton(AF_INET6, n, &addr->in6.sin6_addr) <= 0)
Expand All @@ -116,8 +113,9 @@ int parse_sockaddr(const char *s,
if (*e) {
if (*e != ':')
return -EINVAL;

e++;

unsigned u;
r = safe_atou(e, &u);
if (r < 0)
return r;
Expand All @@ -132,19 +130,21 @@ int parse_sockaddr(const char *s,
*addr_len = sizeof(struct sockaddr_in6);

} else {
e = strchr(s, ':');
const char *e = strchr(s, ':');
if (e) {
r = safe_atou(e+1, &u);
unsigned u;
r = safe_atou(e + 1, &u);
if (r < 0)
return r;

if (u <= 0 || u > 0xFFFF)
return -EINVAL;

n = strndupa(s, e-s);
char *n = strndupa(s, e-s);
return assign_address(n, u, addr, addr_len);

} else {
unsigned u;
r = safe_atou(s, &u);
if (r < 0)
return assign_address(s, 0, addr, addr_len);
Expand Down
Loading