diff options
Diffstat (limited to 'urunlevel/runlevel/install_initd.c')
-rw-r--r-- | urunlevel/runlevel/install_initd.c | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/urunlevel/runlevel/install_initd.c b/urunlevel/runlevel/install_initd.c index 4b9ab88..270e4d0 100644 --- a/urunlevel/runlevel/install_initd.c +++ b/urunlevel/runlevel/install_initd.c | |||
@@ -3,6 +3,9 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au | 4 | * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au |
5 | * | 5 | * |
6 | * Clean room implementation of LSB init.d specs. | ||
7 | * I didn't steal any of this, honest B-). | ||
8 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 11 | * the Free Software Foundation; either version 2 of the License, or |
@@ -20,6 +23,7 @@ | |||
20 | * | 23 | * |
21 | */ | 24 | */ |
22 | 25 | ||
26 | #include <string.h> | ||
23 | #include <unistd.h> | 27 | #include <unistd.h> |
24 | 28 | ||
25 | #include "busybox.h" | 29 | #include "busybox.h" |
@@ -28,21 +32,74 @@ | |||
28 | 32 | ||
29 | int install_initd_main(int argc, char **argv) | 33 | int install_initd_main(int argc, char **argv) |
30 | { | 34 | { |
31 | llist_t *sorted = NULL; | 35 | int result = EXIT_FAILURE; |
32 | llist_t *unsorted = get_scripts(); | 36 | |
33 | // char *info_text = NULL; | 37 | argv += optind; |
34 | // char *pathname = NULL; | 38 | if (!*argv) |
35 | // init_d_info_t *info = NULL; | 39 | bb_show_usage(); |
36 | 40 | else { | |
37 | // bb_xasprintf(&pathname, "/etc/init.d/%s", script->d_name); | 41 | int in_init = 0; |
38 | // info_text = get_init_info(pathname); | 42 | llist_t *current = NULL; |
39 | // info = parse_init_info(info_text, script->d_name); | 43 | llist_t *unsorted = get_scripts(); |
40 | // if (info) | 44 | init_d_info_t *info = NULL; |
41 | // result = llist_add_to(result, (char *) info); | 45 | char *info_text = NULL; |
42 | 46 | char *pathname = NULL; | |
43 | sorted = sort_scripts(unsorted); | 47 | RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX); |
44 | // Should return 1 if this script is in unsorted. | 48 | |
45 | 49 | bb_xasprintf(&pathname, "%s", *argv); | |
46 | // free(info_text); | 50 | if ((*argv)[0] != '/') { |
47 | return EXIT_SUCCESS; | 51 | char *cwd = xgetcwd(NULL); |
52 | |||
53 | if (cwd) { | ||
54 | free(pathname); | ||
55 | bb_xasprintf(&pathname, "%s/%s", cwd, *argv); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | if (realpath(pathname, resolved_path) != NULL) { | ||
60 | if (strncmp("/etc/init.d/", resolved_path, 12) == 0) | ||
61 | in_init = 1; | ||
62 | } else { | ||
63 | bb_perror_msg("%s", pathname); | ||
64 | } | ||
65 | |||
66 | if (!in_init) { | ||
67 | bb_xasprintf(&info_text, "/etc/init.d/%s", bb_get_last_path_component(pathname)); | ||
68 | symlink(pathname, info_text); | ||
69 | free(info_text); | ||
70 | } | ||
71 | |||
72 | info_text = get_init_info(pathname); | ||
73 | info = parse_init_info(info_text, bb_get_last_path_component(pathname)); | ||
74 | |||
75 | sort_scripts(unsorted, info); | ||
76 | current = unsorted; | ||
77 | result = EXIT_SUCCESS; | ||
78 | while (current) { | ||
79 | init_d_info_t *this_one = (init_d_info_t *) current->data; | ||
80 | |||
81 | if (this_one) { | ||
82 | if (strcmp(this_one->path, info->path) == 0) { | ||
83 | result = EXIT_FAILURE; | ||
84 | free(info_text); | ||
85 | bb_xasprintf(&info_text, "/etc/init.d/%s", bb_get_last_path_component(pathname)); | ||
86 | remove_file(info_text, FILEUTILS_FORCE); | ||
87 | break; | ||
88 | } | ||
89 | } | ||
90 | current = current->link; | ||
91 | } | ||
92 | |||
93 | if (result == EXIT_FAILURE) | ||
94 | bb_error_msg("Unable to install the %s init.d script.", pathname); | ||
95 | |||
96 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
97 | RELEASE_CONFIG_BUFFER(resolved_path); | ||
98 | #endif | ||
99 | free(info); | ||
100 | free(pathname); | ||
101 | free(info_text); | ||
102 | } | ||
103 | |||
104 | return result; | ||
48 | } | 105 | } |