hostname-util: get rid of unused parameter of hostname_cleanup()
All users are now setting lowercase=false.
This commit is contained in:
parent
17eb9a9ddb
commit
ae691c1d93
|
@ -105,7 +105,7 @@ bool hostname_is_valid(const char *s, bool relax) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* hostname_cleanup(char *s, bool lowercase) {
|
char* hostname_cleanup(char *s) {
|
||||||
char *p, *d;
|
char *p, *d;
|
||||||
bool dot;
|
bool dot;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ char* hostname_cleanup(char *s, bool lowercase) {
|
||||||
*(d++) = '.';
|
*(d++) = '.';
|
||||||
dot = true;
|
dot = true;
|
||||||
} else if (hostname_valid_char(*p)) {
|
} else if (hostname_valid_char(*p)) {
|
||||||
*(d++) = lowercase ? tolower(*p) : *p;
|
*(d++) = *p;
|
||||||
dot = false;
|
dot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ int read_hostname_config(const char *path, char **hostname) {
|
||||||
truncate_nl(l);
|
truncate_nl(l);
|
||||||
if (l[0] != '\0' && l[0] != '#') {
|
if (l[0] != '\0' && l[0] != '#') {
|
||||||
/* found line with value */
|
/* found line with value */
|
||||||
name = hostname_cleanup(l, false);
|
name = hostname_cleanup(l);
|
||||||
name = strdup(name);
|
name = strdup(name);
|
||||||
if (!name)
|
if (!name)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
@ -30,7 +30,7 @@ bool hostname_is_set(void);
|
||||||
char* gethostname_malloc(void);
|
char* gethostname_malloc(void);
|
||||||
|
|
||||||
bool hostname_is_valid(const char *s, bool relax) _pure_;
|
bool hostname_is_valid(const char *s, bool relax) _pure_;
|
||||||
char* hostname_cleanup(char *s, bool lowercase);
|
char* hostname_cleanup(char *s);
|
||||||
|
|
||||||
bool is_localhost(const char *hostname);
|
bool is_localhost(const char *hostname);
|
||||||
|
|
||||||
|
|
|
@ -392,7 +392,7 @@ static int prompt_hostname(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get rid of the trailing dot that we allow, but don't want to see */
|
/* Get rid of the trailing dot that we allow, but don't want to see */
|
||||||
arg_hostname = hostname_cleanup(h, false);
|
arg_hostname = hostname_cleanup(h);
|
||||||
h = NULL;
|
h = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -786,7 +786,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname_cleanup(optarg, false);
|
hostname_cleanup(optarg);
|
||||||
if (free_and_strdup(&arg_hostname, optarg) < 0)
|
if (free_and_strdup(&arg_hostname, optarg) < 0)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
|
|
|
@ -273,13 +273,13 @@ static int set_hostname(sd_bus *bus, char **args, unsigned n) {
|
||||||
if (arg_static && hostname_is_valid(hostname, true)) {
|
if (arg_static && hostname_is_valid(hostname, true)) {
|
||||||
p = "";
|
p = "";
|
||||||
/* maybe get rid of trailing dot */
|
/* maybe get rid of trailing dot */
|
||||||
hostname = hostname_cleanup(hostname, false);
|
hostname = hostname_cleanup(hostname);
|
||||||
} else {
|
} else {
|
||||||
p = h = strdup(hostname);
|
p = h = strdup(hostname);
|
||||||
if (!p)
|
if (!p)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
hostname_cleanup(hostname, false);
|
hostname_cleanup(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = set_simple_string(bus, "SetPrettyHostname", p);
|
r = set_simple_string(bus, "SetPrettyHostname", p);
|
||||||
|
|
|
@ -797,7 +797,7 @@ static int request_handler_machine(
|
||||||
"\"cutoff_to_realtime\" : \"%"PRIu64"\" }\n",
|
"\"cutoff_to_realtime\" : \"%"PRIu64"\" }\n",
|
||||||
SD_ID128_FORMAT_VAL(mid),
|
SD_ID128_FORMAT_VAL(mid),
|
||||||
SD_ID128_FORMAT_VAL(bid),
|
SD_ID128_FORMAT_VAL(bid),
|
||||||
hostname_cleanup(hostname, false),
|
hostname_cleanup(hostname),
|
||||||
os_name ? os_name : "Linux",
|
os_name ? os_name : "Linux",
|
||||||
v ? v : "bare",
|
v ? v : "bare",
|
||||||
usage,
|
usage,
|
||||||
|
|
|
@ -1527,7 +1527,7 @@ static int setup_keys(void) {
|
||||||
hn = gethostname_malloc();
|
hn = gethostname_malloc();
|
||||||
|
|
||||||
if (hn) {
|
if (hn) {
|
||||||
hostname_cleanup(hn, false);
|
hostname_cleanup(hn);
|
||||||
fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine));
|
fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine));
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine));
|
fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine));
|
||||||
|
|
|
@ -845,7 +845,7 @@ int config_parse_hostname(const char *unit,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*hostname = hostname_cleanup(hn, false);
|
*hostname = hostname_cleanup(hn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4005,7 +4005,7 @@ static int determine_names(void) {
|
||||||
if (!arg_machine)
|
if (!arg_machine)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
hostname_cleanup(arg_machine, false);
|
hostname_cleanup(arg_machine);
|
||||||
if (!machine_name_is_valid(arg_machine)) {
|
if (!machine_name_is_valid(arg_machine)) {
|
||||||
log_error("Failed to determine machine name automatically, please use -M.");
|
log_error("Failed to determine machine name automatically, please use -M.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -65,37 +65,37 @@ static void test_hostname_cleanup(void) {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
s = strdupa("foobar");
|
s = strdupa("foobar");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foobar"));
|
assert_se(streq(hostname_cleanup(s), "foobar"));
|
||||||
s = strdupa("foobar.com");
|
s = strdupa("foobar.com");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foobar.com"));
|
assert_se(streq(hostname_cleanup(s), "foobar.com"));
|
||||||
s = strdupa("foobar.com.");
|
s = strdupa("foobar.com.");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foobar.com"));
|
assert_se(streq(hostname_cleanup(s), "foobar.com"));
|
||||||
s = strdupa("fooBAR");
|
s = strdupa("fooBAR");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "fooBAR"));
|
assert_se(streq(hostname_cleanup(s), "fooBAR"));
|
||||||
s = strdupa("fooBAR.com");
|
s = strdupa("fooBAR.com");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "fooBAR.com"));
|
assert_se(streq(hostname_cleanup(s), "fooBAR.com"));
|
||||||
s = strdupa("fooBAR.");
|
s = strdupa("fooBAR.");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "fooBAR"));
|
assert_se(streq(hostname_cleanup(s), "fooBAR"));
|
||||||
s = strdupa("fooBAR.com.");
|
s = strdupa("fooBAR.com.");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "fooBAR.com"));
|
assert_se(streq(hostname_cleanup(s), "fooBAR.com"));
|
||||||
s = strdupa("fööbar");
|
s = strdupa("fööbar");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "fbar"));
|
assert_se(streq(hostname_cleanup(s), "fbar"));
|
||||||
s = strdupa("");
|
s = strdupa("");
|
||||||
assert_se(isempty(hostname_cleanup(s, false)));
|
assert_se(isempty(hostname_cleanup(s)));
|
||||||
s = strdupa(".");
|
s = strdupa(".");
|
||||||
assert_se(isempty(hostname_cleanup(s, false)));
|
assert_se(isempty(hostname_cleanup(s)));
|
||||||
s = strdupa("..");
|
s = strdupa("..");
|
||||||
assert_se(isempty(hostname_cleanup(s, false)));
|
assert_se(isempty(hostname_cleanup(s)));
|
||||||
s = strdupa("foobar.");
|
s = strdupa("foobar.");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foobar"));
|
assert_se(streq(hostname_cleanup(s), "foobar"));
|
||||||
s = strdupa(".foobar");
|
s = strdupa(".foobar");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foobar"));
|
assert_se(streq(hostname_cleanup(s), "foobar"));
|
||||||
s = strdupa("foo..bar");
|
s = strdupa("foo..bar");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foo.bar"));
|
assert_se(streq(hostname_cleanup(s), "foo.bar"));
|
||||||
s = strdupa("foo.bar..");
|
s = strdupa("foo.bar..");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "foo.bar"));
|
assert_se(streq(hostname_cleanup(s), "foo.bar"));
|
||||||
s = strdupa("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
s = strdupa("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||||
assert_se(streq(hostname_cleanup(s, false), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
|
assert_se(streq(hostname_cleanup(s), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_read_hostname_config(void) {
|
static void test_read_hostname_config(void) {
|
||||||
|
|
Loading…
Reference in a new issue