commit
76c887fdaa
|
@ -28,6 +28,8 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
|
|||
|
||||
assert(p);
|
||||
assert(ret);
|
||||
/* Those two don't make sense together. */
|
||||
assert(!FLAGS_SET(flags, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE));
|
||||
|
||||
/* Bail early if called after last value or with no input */
|
||||
if (!*p)
|
||||
|
|
|
@ -526,71 +526,57 @@ int terminal_vhangup(const char *name) {
|
|||
}
|
||||
|
||||
int vt_disallocate(const char *name) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *e, *n;
|
||||
unsigned u;
|
||||
const char *e;
|
||||
int r;
|
||||
|
||||
/* Deallocate the VT if possible. If not possible
|
||||
* (i.e. because it is the active one), at least clear it
|
||||
* entirely (including the scrollback buffer) */
|
||||
* entirely (including the scrollback buffer). */
|
||||
|
||||
e = path_startswith(name, "/dev/");
|
||||
if (!e)
|
||||
return -EINVAL;
|
||||
|
||||
if (!tty_is_vc(name)) {
|
||||
/* So this is not a VT. I guess we cannot deallocate
|
||||
* it then. But let's at least clear the screen */
|
||||
if (tty_is_vc(name)) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
unsigned u;
|
||||
const char *n;
|
||||
|
||||
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
|
||||
n = startswith(e, "tty");
|
||||
if (!n)
|
||||
return -EINVAL;
|
||||
|
||||
r = safe_atou(n, &u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (u <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Try to deallocate */
|
||||
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
loop_write(fd,
|
||||
"\033[r" /* clear scrolling region */
|
||||
"\033[H" /* move home */
|
||||
"\033[2J", /* clear screen */
|
||||
10, false);
|
||||
return 0;
|
||||
r = ioctl(fd, VT_DISALLOCATE, u);
|
||||
if (r >= 0)
|
||||
return 0;
|
||||
if (errno != EBUSY)
|
||||
return -errno;
|
||||
}
|
||||
|
||||
n = startswith(e, "tty");
|
||||
if (!n)
|
||||
return -EINVAL;
|
||||
/* So this is not a VT (in which case we cannot deallocate it),
|
||||
* or we failed to deallocate. Let's at least clear the screen. */
|
||||
|
||||
r = safe_atou(n, &u);
|
||||
if (r < 0)
|
||||
return r;
|
||||
_cleanup_close_ int fd2 = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
|
||||
if (fd2 < 0)
|
||||
return fd2;
|
||||
|
||||
if (u <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Try to deallocate */
|
||||
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
r = ioctl(fd, VT_DISALLOCATE, u);
|
||||
fd = safe_close(fd);
|
||||
|
||||
if (r >= 0)
|
||||
return 0;
|
||||
|
||||
if (errno != EBUSY)
|
||||
return -errno;
|
||||
|
||||
/* Couldn't deallocate, so let's clear it fully with
|
||||
* scrollback */
|
||||
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
loop_write(fd,
|
||||
"\033[r" /* clear scrolling region */
|
||||
"\033[H" /* move home */
|
||||
"\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */
|
||||
10, false);
|
||||
(void) loop_write(fd2,
|
||||
"\033[r" /* clear scrolling region */
|
||||
"\033[H" /* move home */
|
||||
"\033[3J", /* clear screen including scrollback, requires Linux 2.6.40 */
|
||||
10, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -305,9 +305,7 @@ static int retrieve(const void *data,
|
|||
if (!v)
|
||||
return log_oom();
|
||||
|
||||
free(*var);
|
||||
*var = v;
|
||||
|
||||
free_and_replace(*var, v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -740,9 +738,22 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
|
|||
|
||||
/* Look for a coredump on disk first. */
|
||||
r = sd_journal_get_data(j, "COREDUMP_FILENAME", (const void**) &data, &len);
|
||||
if (r == 0)
|
||||
retrieve(data, len, "COREDUMP_FILENAME", &filename);
|
||||
else {
|
||||
if (r == 0) {
|
||||
r = retrieve(data, len, "COREDUMP_FILENAME", &filename);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(r > 0);
|
||||
|
||||
if (access(filename, R_OK) < 0)
|
||||
return log_error_errno(errno, "File \"%s\" is not readable: %m", filename);
|
||||
|
||||
if (path && !endswith(filename, ".xz") && !endswith(filename, ".lz4")) {
|
||||
*path = TAKE_PTR(filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (r != -ENOENT)
|
||||
return log_error_errno(r, "Failed to retrieve COREDUMP_FILENAME field: %m");
|
||||
/* Check that we can have a COREDUMP field. We still haven't set a high
|
||||
|
@ -756,17 +767,6 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
|
|||
return log_error_errno(r, "Failed to retrieve COREDUMP field: %m");
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
if (access(filename, R_OK) < 0)
|
||||
return log_error_errno(errno, "File \"%s\" is not readable: %m", filename);
|
||||
|
||||
if (path && !endswith(filename, ".xz") && !endswith(filename, ".lz4")) {
|
||||
*path = TAKE_PTR(filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (path) {
|
||||
const char *vt;
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ int config_parse_match_strv(
|
|||
for (;;) {
|
||||
_cleanup_free_ char *word = NULL, *k = NULL;
|
||||
|
||||
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
|
||||
if (r == 0)
|
||||
return 0;
|
||||
if (r == -ENOMEM)
|
||||
|
|
|
@ -305,7 +305,7 @@ _public_ const char* sd_bus_track_first(sd_bus_track *track) {
|
|||
track->modified = false;
|
||||
track->iterator = ITERATOR_FIRST;
|
||||
|
||||
hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
|
||||
(void) hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ _public_ const char* sd_bus_track_next(sd_bus_track *track) {
|
|||
if (track->modified)
|
||||
return NULL;
|
||||
|
||||
hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
|
||||
(void) hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
@ -1540,7 +1540,6 @@ int device_properties_prepare(sd_device *device) {
|
|||
|
||||
_public_ const char *sd_device_get_property_first(sd_device *device, const char **_value) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
int r;
|
||||
|
||||
assert_return(device, NULL);
|
||||
|
@ -1552,16 +1551,12 @@ _public_ const char *sd_device_get_property_first(sd_device *device, const char
|
|||
device->properties_iterator_generation = device->properties_generation;
|
||||
device->properties_iterator = ITERATOR_FIRST;
|
||||
|
||||
ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key);
|
||||
|
||||
if (_value)
|
||||
*_value = value;
|
||||
(void) ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)_value, (const void**)&key);
|
||||
return key;
|
||||
}
|
||||
|
||||
_public_ const char *sd_device_get_property_next(sd_device *device, const char **_value) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
int r;
|
||||
|
||||
assert_return(device, NULL);
|
||||
|
@ -1573,10 +1568,7 @@ _public_ const char *sd_device_get_property_next(sd_device *device, const char *
|
|||
if (device->properties_iterator_generation != device->properties_generation)
|
||||
return NULL;
|
||||
|
||||
ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key);
|
||||
|
||||
if (_value)
|
||||
*_value = value;
|
||||
(void) ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)_value, (const void**)&key);
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,14 @@ static void test_config_parse_match_strv(void) {
|
|||
assert_se(config_parse_match_strv("network", "filename", 1, "section", 1, "Name", 0,
|
||||
"KEY=val \"KEY2=val with space\" \"KEY3=val with \\\"quotation\\\"\"", &names, NULL) == 0);
|
||||
|
||||
strv_equal(names, STRV_MAKE("!hoge", "!hogehoge", "!foo", "!baz", "KEY=val", "KEY2=val with space", "KEY3=val with \"quotation\""));
|
||||
assert_se(strv_equal(names,
|
||||
STRV_MAKE("!hoge",
|
||||
"!hogehoge",
|
||||
"!foo",
|
||||
"!baz",
|
||||
"KEY=val",
|
||||
"KEY2=val with space",
|
||||
"KEY3=val with \"quotation\"")));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
|
@ -2092,13 +2092,9 @@ static int oci_hook_timeout(const char *name, JsonVariant *v, JsonDispatchFlags
|
|||
uintmax_t k;
|
||||
|
||||
k = json_variant_unsigned(v);
|
||||
if (k == 0)
|
||||
return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Hook timeout cannot be zero.");
|
||||
|
||||
if (k > (UINT64_MAX-1/USEC_PER_SEC))
|
||||
return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Hook timeout too large.");
|
||||
if (k == 0 || k > (UINT64_MAX-1)/USEC_PER_SEC)
|
||||
return json_log(v, flags, SYNTHETIC_ERRNO(ERANGE),
|
||||
"Hook timeout value out of range.");
|
||||
|
||||
*u = k * USEC_PER_SEC;
|
||||
return 0;
|
||||
|
|
|
@ -1282,7 +1282,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
|
||||
case ARG_RLIMIT: {
|
||||
const char *eq;
|
||||
char *name;
|
||||
_cleanup_free_ char *name = NULL;
|
||||
int rl;
|
||||
|
||||
if (streq(optarg, "help")) {
|
||||
|
|
|
@ -190,7 +190,7 @@ static void wait_for_item_check_ready(WaitForItem *item) {
|
|||
BusWaitForUnits *d;
|
||||
|
||||
assert(item);
|
||||
assert(d = item->parent);
|
||||
assert_se(d = item->parent);
|
||||
|
||||
if (FLAGS_SET(item->flags, BUS_WAIT_FOR_MAINTENANCE_END)) {
|
||||
|
||||
|
|
|
@ -758,7 +758,7 @@ int config_parse_strv(
|
|||
for (;;) {
|
||||
char *word = NULL;
|
||||
|
||||
r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == -ENOMEM)
|
||||
|
|
|
@ -83,6 +83,30 @@ static void test_extract_first_word(void) {
|
|||
free(t);
|
||||
assert_se(isempty(p));
|
||||
|
||||
p = original = "KEY=val \"KEY2=val with space\" \"KEY3=val with \\\"quotation\\\"\"";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY2=val with space"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1);
|
||||
assert_se(streq(t, "KEY3=val with \"quotation\""));
|
||||
free(t);
|
||||
assert_se(isempty(p));
|
||||
|
||||
p = original = "KEY=val \"KEY2=val space\" \"KEY3=val with \\\"quotation\\\"\"";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "KEY=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "\"KEY2=val"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1);
|
||||
assert_se(streq(t, "space\""));
|
||||
free(t);
|
||||
assert_se(startswith(p, "\"KEY3="));
|
||||
|
||||
p = original = "\'fooo";
|
||||
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == -EINVAL);
|
||||
assert_se(p == original + 5);
|
||||
|
|
Loading…
Reference in a new issue