diff --git a/man/systemd.generator.xml b/man/systemd.generator.xml index 1f916ac65eb..d837afb6f9d 100644 --- a/man/systemd.generator.xml +++ b/man/systemd.generator.xml @@ -26,8 +26,8 @@ /path/to/generator normal-dir - early-dir - late-dir + early-dir + late-dir @@ -56,13 +56,13 @@ that they can extend the unit file hierarchy the service manager subsequently loads and operates on. - Each generator is called with three directory paths that are to be used for generator output. In - these three directories, generators may dynamically generate unit files (regular ones, instances, as well - as templates), unit file .d/ drop-ins, and create symbolic links to unit files to - add additional dependencies, create aliases, or instantiate existing templates. Those directories are - included in the unit load path of - systemd1, allowing - generated configuration to extend or override existing definitions. + systemd will call each generator with three directory paths that are to be used + for generator output. In these three directories, generators may dynamically generate unit files (regular + ones, instances, as well as templates), unit file .d/ drop-ins, and create symbolic + links to unit files to add additional dependencies, create aliases, or instantiate existing templates. + Those directories are included in the unit load path, allowing generated configuration to extend or + override existing definitions. For tests, generators may be called with just one argument; the generator + should assume that all three paths are the same in that case. Directory paths for generator output differ by priority: …/generator.early has priority higher than the admin configuration in /etc/, while @@ -96,7 +96,8 @@ Generators are invoked with three arguments: paths to directories where generators can place their generated unit files or symlinks. By default those paths are runtime directories that are included in the search path of systemd, but a generator may be called with different paths for - debugging purposes. + debugging purposes. If only one argument is provided, the generator should use the same directory as the + the three output paths. diff --git a/src/shared/generator.h b/src/shared/generator.h index bd768daf491..1b4f36ac53c 100644 --- a/src/shared/generator.h +++ b/src/shared/generator.h @@ -3,6 +3,7 @@ #include +#include "macro.h" #include "main-func.h" int generator_open_unit_file( @@ -86,11 +87,11 @@ void log_setup_generator(void); _DEFINE_MAIN_FUNCTION( \ ({ \ log_setup_generator(); \ - if (argc > 1 && argc != 4) \ + if (!IN_SET(argc, 2, 4)) \ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), \ - "This program takes zero or three arguments."); \ + "This program takes one or three arguments."); \ }), \ - impl(argc > 1 ? argv[1] : "/tmp", \ - argc > 1 ? argv[2] : "/tmp", \ - argc > 1 ? argv[3] : "/tmp"), \ + impl(argv[1], \ + argv[argc == 4 ? 2 : 1], \ + argv[argc == 4 ? 3 : 1]), \ r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)