summaryrefslogtreecommitdiffstats
path: root/urunlevel/runlevel/remove_initd.c
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/runlevel/remove_initd.c')
-rw-r--r--urunlevel/runlevel/remove_initd.c108
1 files changed, 102 insertions, 6 deletions
diff --git a/urunlevel/runlevel/remove_initd.c b/urunlevel/runlevel/remove_initd.c
index 1224b03..1adda10 100644
--- a/urunlevel/runlevel/remove_initd.c
+++ b/urunlevel/runlevel/remove_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,11 +32,103 @@
28 32
29int remove_initd_main(int argc, char **argv) 33int remove_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
37 argv += optind;
38 if (!*argv)
39 bb_show_usage();
40 else {
41 int in_init = 0;
42 llist_t *current = NULL;
43 llist_t *previous = NULL;
44 llist_t *unsorted = get_scripts();
45 init_d_info_t *info = NULL;
46 char *info_text = NULL;
47 char *pathname = NULL;
48 RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
49
50 bb_xasprintf(&pathname, "%s", *argv);
51 if ((*argv)[0] != '/') {
52 char *cwd = xgetcwd(NULL);
53
54 if (cwd) {
55 free(pathname);
56 bb_xasprintf(&pathname, "%s/%s", cwd, *argv);
57 }
58 }
59
60 if (realpath(pathname, resolved_path) != NULL) {
61 if (strncmp("/etc/init.d/", resolved_path, 12) == 0)
62 in_init = 1;
63 } else {
64 bb_perror_msg("%s", pathname);
65 }
66
67 info_text = get_init_info(pathname);
68 info = parse_init_info(info_text, bb_get_last_path_component(pathname));
69
70 current = unsorted;
71 while (current) {
72 init_d_info_t *this_one = (init_d_info_t *) current->data;
73
74 if (strcmp(this_one->path, info->path) == 0) {
75 current = llist_delete(&unsorted, previous, current);
76 break;
77 }
78 previous = current;
79 current = current->link;
80 }
81
82 sort_scripts(unsorted, NULL);
83 result = EXIT_SUCCESS;
84 current = unsorted;
85 while (current) {
86 int k;
87 init_d_info_t *this_one = (init_d_info_t *) current->data;
88
89 if (this_one) {
90 for (k = 0; k < info->sizes[0]; k++) {
91 int i;
92
93 for (i = 0; i < this_one->sizes[1]; i++) {
94 if (strcmp(this_one->reqstart[i], info->provides[k]) == 0) {
95 result = EXIT_FAILURE;
96 bb_error_msg("%s is required by %s.", pathname, this_one->path);
97 break;
98 }
99 }
100 if (result == EXIT_FAILURE)
101 break;
102 }
103 }
104
105 current = current->link;
106 }
107
108 /* This is not LSB compliant, the LSB package manager is supposed to remove it, but...
109 * We may have created it, so we should remove it.
110 * LSB says that init.d scripts are "configuration files", I disagree, they are executables.
111 * LSB further says that config files are left behind after package removal. This is a
112 * contradiction with "package manager is supposed to remove it".
113 *
114 * Safest thing to do is zap it.
115 */
116 if ((in_init) && (result == EXIT_SUCCESS)) {
117 free(info_text);
118 bb_xasprintf(&info_text, "/etc/init.d/%s", bb_get_last_path_component(pathname));
119 remove_file(info_text, FILEUTILS_FORCE);
120 }
121
122 if (result == EXIT_FAILURE)
123 bb_error_msg("Unable to remove the %s init.d script.", pathname);
124
125#ifdef CONFIG_FEATURE_CLEAN_UP
126 RELEASE_CONFIG_BUFFER(resolved_path);
127#endif
128 free(info);
129 free(pathname);
130 free(info_text);
131 }
33 132
34// Should remove this script from unsorted. 133 return result;
35 sorted = sort_scripts(unsorted);
36// Should return 1 if there are unsatisfied dependencies if this is removed.
37 return EXIT_SUCCESS;
38} 134}