#include "hexdecoct.h"
#include "install.h"
#include "log.h"
+#include "main-func.h"
#include "mkdir.h"
#include "path-lookup.h"
#include "path-util.h"
* means they are shut down anyway at system power off if running. */
};
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
typedef struct SysvStub {
char *name;
_cleanup_free_ char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL;
char *description;
bool supports_reload = false;
- char l[LINE_MAX];
assert(s);
log_debug("Loading SysV script %s", s->path);
- FOREACH_LINE(l, f, goto fail) {
+ for (;;) {
+ _cleanup_free_ char *l = NULL;
char *t;
+ r = read_line(f, LONG_LINE_MAX, &l);
+ if (r < 0)
+ return log_error_errno(r, "Failed to read configuration file '%s': %m", s->path);
+ if (r == 0)
+ break;
+
line++;
t = strstrip(l);
/* Try to figure out whether this init script supports
* the reload operation. This heuristic looks for
* "Usage" lines which include the reload option. */
- if ( state == USAGE_CONTINUATION ||
+ if (state == USAGE_CONTINUATION ||
(state == NORMAL && strcasestr(t, "usage"))) {
if (usage_contains_reload(t)) {
supports_reload = true;
s->loaded = true;
return 0;
-
-fail:
- return log_error_errno(errno, "Failed to read configuration file '%s': %m", s->path);
}
static int fix_order(SysvStub *s, Hashmap *all_services) {
if (strv_isempty(l)) {
strv_free(l);
- l = strv_new(def, NULL);
+ l = strv_new(def);
if (!l)
return log_oom();
}
continue;
}
- fpath = strjoin(*path, "/", de->d_name);
+ fpath = path_join(*path, de->d_name);
if (!fpath)
return log_oom();
_cleanup_free_ char *path = NULL;
struct dirent *de;
- path = strjoin(*p, "/", rcnd_table[i].path);
+ path = path_join(*p, rcnd_table[i].path);
if (!path) {
r = log_oom();
goto finish;
if (a < 0 || b < 0)
continue;
- fpath = strjoin(*p, "/", de->d_name);
+ fpath = path_join(*p, de->d_name);
if (!fpath) {
r = log_oom();
goto finish;
return r;
}
-int main(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
_cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
SysvStub *service;
Iterator j;
int r;
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return EXIT_FAILURE;
- }
-
- if (argc > 1)
- arg_dest = argv[3];
-
- log_set_prohibit_ipc(true);
- log_set_target(LOG_TARGET_AUTO);
- log_parse_environment();
- log_open();
-
- umask(0022);
+ assert_se(arg_dest = dest_late);
r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
- if (r < 0) {
- log_error_errno(r, "Failed to find lookup paths: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to find lookup paths: %m");
all_services = hashmap_new(&string_hash_ops);
- if (!all_services) {
- r = log_oom();
- goto finish;
- }
+ if (!all_services)
+ return log_oom();
r = enumerate_sysv(&lp, all_services);
if (r < 0)
- goto finish;
+ return r;
r = set_dependencies_from_rcnd(&lp, all_services);
if (r < 0)
- goto finish;
+ return r;
HASHMAP_FOREACH(service, all_services, j)
(void) load_sysv(service);
(void) generate_unit_file(service);
}
- r = 0;
-
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return 0;
}
+
+DEFINE_MAIN_GENERATOR_FUNCTION(run);