Merge pull request #14368 from poettering/repart

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-01-23 19:07:02 +01:00
32 changed files with 4154 additions and 34 deletions
+1
View File
@@ -515,6 +515,7 @@ DEFINE_PARSER(long, long, safe_atoli);
DEFINE_PARSER(uint8, uint8_t, safe_atou8);
DEFINE_PARSER(uint16, uint16_t, safe_atou16);
DEFINE_PARSER(uint32, uint32_t, safe_atou32);
DEFINE_PARSER(int32, int32_t, safe_atoi32);
DEFINE_PARSER(uint64, uint64_t, safe_atou64);
DEFINE_PARSER(unsigned, unsigned, safe_atou);
DEFINE_PARSER(double, double, safe_atod);
+1
View File
@@ -115,6 +115,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_long);
CONFIG_PARSER_PROTOTYPE(config_parse_uint8);
CONFIG_PARSER_PROTOTYPE(config_parse_uint16);
CONFIG_PARSER_PROTOTYPE(config_parse_uint32);
CONFIG_PARSER_PROTOTYPE(config_parse_int32);
CONFIG_PARSER_PROTOTYPE(config_parse_uint64);
CONFIG_PARSER_PROTOTYPE(config_parse_double);
CONFIG_PARSER_PROTOTYPE(config_parse_iec_size);
+51 -1
View File
@@ -4,12 +4,15 @@
#include <net/if.h>
#include <unistd.h>
#include "sd-id128.h"
#include "alloc-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-table.h"
#include "format-util.h"
#include "gunicode.h"
#include "id128-util.h"
#include "in-addr-util.h"
#include "locale-util.h"
#include "memory-util.h"
@@ -94,6 +97,7 @@ typedef struct TableData {
int percent; /* we use 'int' as datatype for percent values in order to match the result of parse_percent() */
int ifindex;
union in_addr_union address;
sd_id128_t id128;
/* … add more here as we start supporting more cell data types … */
};
} TableData;
@@ -289,6 +293,10 @@ static size_t table_data_size(TableDataType type, const void *data) {
case TABLE_IN6_ADDR:
return sizeof(struct in6_addr);
case TABLE_UUID:
case TABLE_ID128:
return sizeof(sd_id128_t);
default:
assert_not_reached("Uh? Unexpected cell type");
}
@@ -335,7 +343,6 @@ static bool table_data_matches(
k = table_data_size(type, data);
l = table_data_size(d->type, d->data);
if (k != l)
return false;
@@ -778,6 +785,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
int ifindex;
bool b;
union in_addr_union address;
sd_id128_t id128;
} buffer;
switch (type) {
@@ -901,6 +909,12 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
data = &buffer.address.in6;
break;
case TABLE_UUID:
case TABLE_ID128:
buffer.id128 = va_arg(ap, sd_id128_t);
data = &buffer.id128;
break;
case TABLE_SET_MINIMUM_WIDTH: {
size_t w = va_arg(ap, size_t);
@@ -1137,6 +1151,10 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
case TABLE_IN6_ADDR:
return memcmp(&a->address.in6, &b->address.in6, FAMILY_ADDRESS_SIZE(AF_INET6));
case TABLE_UUID:
case TABLE_ID128:
return memcmp(&a->id128, &b->id128, sizeof(sd_id128_t));
default:
;
}
@@ -1451,6 +1469,28 @@ static const char *table_data_format(Table *t, TableData *d) {
break;
}
case TABLE_ID128: {
char *p;
p = new(char, SD_ID128_STRING_MAX);
if (!p)
return NULL;
d->formatted = sd_id128_to_string(d->id128, p);
break;
}
case TABLE_UUID: {
char *p;
p = new(char, ID128_UUID_STRING_MAX);
if (!p)
return NULL;
d->formatted = id128_to_uuid_string(d->id128, p);
break;
}
default:
assert_not_reached("Unexpected type?");
}
@@ -2155,6 +2195,16 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
case TABLE_IN6_ADDR:
return json_variant_new_array_bytes(ret, &d->address, FAMILY_ADDRESS_SIZE(AF_INET6));
case TABLE_ID128: {
char buf[SD_ID128_STRING_MAX];
return json_variant_new_string(ret, sd_id128_to_string(d->id128, buf));
}
case TABLE_UUID: {
char buf[ID128_UUID_STRING_MAX];
return json_variant_new_string(ret, id128_to_uuid_string(d->id128, buf));
}
default:
return -EINVAL;
}
+2
View File
@@ -35,6 +35,8 @@ typedef enum TableDataType {
TABLE_IFINDEX,
TABLE_IN_ADDR, /* Takes a union in_addr_union (or a struct in_addr) */
TABLE_IN6_ADDR, /* Takes a union in_addr_union (or a struct in6_addr) */
TABLE_ID128,
TABLE_UUID,
_TABLE_DATA_TYPE_MAX,
/* The following are not really data types, but commands for table_add_cell_many() to make changes to