along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "strv.h"
#include "fileio.h"
#include "test-helper.h"
+#include "hostname-util.h"
static int test_unit_file_get_set(void) {
int r;
const char* argv1,
const char* argv2,
bool ignore) {
+ size_t n;
+
assert_se(c);
log_info("expect: \"%s\" [\"%s\" \"%s\" \"%s\"]",
path, argv0 ?: path, argv1, argv2);
+ n = strv_length(c->argv);
log_info("actual: \"%s\" [\"%s\" \"%s\" \"%s\"]",
- c->path, c->argv[0], c->argv[1], c->argv[2]);
+ c->path, c->argv[0], n > 0 ? c->argv[1] : NULL, n > 1 ? c->argv[2] : NULL);
assert_se(streq(c->path, path));
assert_se(streq(c->argv[0], argv0 ?: path));
- assert_se(streq_ptr(c->argv[1], argv1));
- assert_se(streq_ptr(c->argv[2], argv2));
+ if (n > 0)
+ assert_se(streq_ptr(c->argv[1], argv1));
+ if (n > 1)
+ assert_se(streq_ptr(c->argv[2], argv2));
assert_se(c->ignore == ignore);
}
static void test_config_parse_exec(void) {
/* int config_parse_exec(
+ const char *unit,
const char *filename,
unsigned line,
const char *section,
c1 = c1->command_next;
check_execcommand(c1, "/RValue/slashes2", "///argv0", "r1", NULL, false);
+ log_info("/* honour_argv0, no args */");
+ r = config_parse_exec(NULL, "fake", 3, "section", 1,
+ "LValue", 0, "@/RValue",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
+ log_info("/* no command, check for bad memory access */");
+ r = config_parse_exec(NULL, "fake", 3, "section", 1,
+ "LValue", 0, " ",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
log_info("/* ignore && honour_argv0 */");
r = config_parse_exec(NULL, "fake", 4, "section", 1,
"LValue", 0, "-@/RValue///slashes3 argv0a r1",
assert_se(r == 0);
assert_se(c1->command_next == NULL);
+ log_info("/* missing ending ' */");
+ r = config_parse_exec(NULL, "fake", 4, "section", 1,
+ "LValue", 0, "/path 'foo",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
+ log_info("/* missing ending ' with trailing backslash */");
+ r = config_parse_exec(NULL, "fake", 4, "section", 1,
+ "LValue", 0, "/path 'foo\\",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
+ log_info("/* invalid space between modifiers */");
+ r = config_parse_exec(NULL, "fake", 4, "section", 1,
+ "LValue", 0, "- /path",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
+ log_info("/* only modifiers, no path */");
+ r = config_parse_exec(NULL, "fake", 4, "section", 1,
+ "LValue", 0, "-",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c1->command_next == NULL);
+
+ log_info("/* empty argument, reset */");
+ r = config_parse_exec(NULL, "fake", 4, "section", 1,
+ "LValue", 0, "",
+ &c, NULL);
+ assert_se(r == 0);
+ assert_se(c == NULL);
+
exec_command_free_list(c);
}
char name[] = "name.service",
path[] = "/run/systemd/system/name.service",
user[] = "xxxx-no-such-user";
- InstallInfo i = {name, path, user};
- InstallInfo i2 = {name, path, NULL};
+ UnitFileInstallInfo i = {name, path, user};
+ UnitFileInstallInfo i2 = {name, path, NULL};
char name3[] = "name@inst.service",
path3[] = "/run/systemd/system/name.service";
- InstallInfo i3 = {name3, path3, user};
- InstallInfo i4 = {name3, path3, NULL};
+ UnitFileInstallInfo i3 = {name3, path3, user};
+ UnitFileInstallInfo i4 = {name3, path3, NULL};
_cleanup_free_ char *mid, *bid, *host;