85
85
ExecCommand *c = NULL, *c1;
88
r = config_parse_exec("fake", 1, "section",
88
r = config_parse_exec(NULL, "fake", 1, "section",
89
89
"LValue", 0, "/RValue r1",
92
92
check_execcommand(c, "/RValue", "/RValue", "r1", false);
94
r = config_parse_exec("fake", 2, "section",
94
r = config_parse_exec(NULL, "fake", 2, "section",
95
95
"LValue", 0, "/RValue///slashes/// r1",
127
127
"/RValue/slashes4", "argv0b", "r1", true);
129
129
/* ignore && ignore */
130
r = config_parse_exec("fake", 4, "section",
130
r = config_parse_exec(NULL, "fake", 4, "section",
131
131
"LValue", 0, "--/RValue argv0 r1",
133
133
assert_se(r == 0);
134
134
assert_se(c1->command_next == NULL);
136
136
/* ignore && ignore */
137
r = config_parse_exec("fake", 4, "section",
137
r = config_parse_exec(NULL, "fake", 4, "section",
138
138
"LValue", 0, "-@-/RValue argv0 r1",
140
140
assert_se(r == 0);
141
141
assert_se(c1->command_next == NULL);
144
r = config_parse_exec("fake", 5, "section",
144
r = config_parse_exec(NULL, "fake", 5, "section",
146
146
"-@/RValue argv0 r1 ; "
180
180
exec_command_free_list(c);
197
197
#define env_file_3 \
198
198
"#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\\n" \
199
199
"#--nouser-config \\\n" \
205
"HWMON_MODULES=\"coretemp f71882fg\"\n" \
207
"# For compatibility reasons\n" \
209
"MODULE_0=coretemp\n" \
202
213
static void test_load_env_file_1(void) {
203
char _cleanup_strv_free_ **data = NULL;
214
_cleanup_strv_free_ char **data = NULL;
206
217
char name[] = "/tmp/test-load-env-file.XXXXXX";
207
int _cleanup_close_ fd = mkstemp(name);
218
_cleanup_close_ int fd = mkstemp(name);
209
220
assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
211
r = load_env_file(name, &data);
222
r = load_env_file(name, NULL, &data);
213
assert(streq(data[0], "a"));
214
assert(streq(data[1], "bc"));
215
assert(streq(data[2], "def"));
216
assert(streq(data[3], "g\\"));
217
assert(streq(data[4], "h"));
218
assert(streq(data[5], "i\\"));
224
assert(streq(data[0], "a=a"));
225
assert(streq(data[1], "b=bc"));
226
assert(streq(data[2], "d=def"));
227
assert(streq(data[3], "g=g "));
228
assert(streq(data[4], "h=h"));
229
assert(streq(data[5], "i=i"));
219
230
assert(data[6] == NULL);
223
234
static void test_load_env_file_2(void) {
224
char _cleanup_strv_free_ **data = NULL;
235
_cleanup_strv_free_ char **data = NULL;
227
238
char name[] = "/tmp/test-load-env-file.XXXXXX";
228
int _cleanup_close_ fd = mkstemp(name);
239
_cleanup_close_ int fd = mkstemp(name);
230
241
assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
232
r = load_env_file(name, &data);
243
r = load_env_file(name, NULL, &data);
234
assert(streq(data[0], "a"));
245
assert(streq(data[0], "a=a"));
235
246
assert(data[1] == NULL);
239
250
static void test_load_env_file_3(void) {
240
char _cleanup_strv_free_ **data = NULL;
251
_cleanup_strv_free_ char **data = NULL;
243
254
char name[] = "/tmp/test-load-env-file.XXXXXX";
244
int _cleanup_close_ fd = mkstemp(name);
255
_cleanup_close_ int fd = mkstemp(name);
246
257
assert_se(write(fd, env_file_3, sizeof(env_file_3)) == sizeof(env_file_3));
248
r = load_env_file(name, &data);
259
r = load_env_file(name, NULL, &data);
250
261
assert(data == NULL);
265
static void test_load_env_file_4(void) {
266
_cleanup_strv_free_ char **data = NULL;
269
char name[] = "/tmp/test-load-env-file.XXXXXX";
270
_cleanup_close_ int fd = mkstemp(name);
272
assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));
274
r = load_env_file(name, NULL, &data);
276
assert(streq(data[0], "HWMON_MODULES=coretemp f71882fg"));
277
assert(streq(data[1], "MODULE_0=coretemp"));
278
assert(streq(data[2], "MODULE_1=f71882fg"));
279
assert(data[3] == NULL);
254
284
#pragma GCC diagnostic push
255
285
#pragma GCC diagnostic ignored "-Wnonnull"
257
287
static void test_install_printf(void) {
258
288
char name[] = "name.service",
259
path[] = "/run/systemd/systemd/name.service",
289
path[] = "/run/systemd/system/name.service",
260
290
user[] = "xxxx-no-such-user";
261
291
InstallInfo i = {name, path, user};
262
292
InstallInfo i2 = {name, path, NULL};
263
293
char name3[] = "name@inst.service",
264
path3[] = "/run/systemd/systemd/name.service";
294
path3[] = "/run/systemd/system/name.service";
265
295
InstallInfo i3 = {name3, path3, user};
266
296
InstallInfo i4 = {name3, path3, NULL};
268
char _cleanup_free_ *mid, *bid, *host;
298
_cleanup_free_ char *mid, *bid, *host;
270
300
assert_se((mid = specifier_machine_id('m', NULL, NULL)));
271
301
assert_se((bid = specifier_boot_id('b', NULL, NULL)));
272
302
assert_se((host = gethostname_malloc()));
274
304
#define expect(src, pattern, result) \
276
char _cleanup_free_ *t = install_full_printf(&src, pattern); \
277
char _cleanup_free_ \
306
_cleanup_free_ char *t = install_full_printf(&src, pattern); \
307
_cleanup_free_ char \
278
308
*d1 = strdup(i.name), \
279
309
*d2 = strdup(i.path), \
280
310
*d3 = strdup(i.user); \