Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/procps/sysctl.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/procps/sysctl.c
r821 r1770 15 15 */ 16 16 17 #include "busybox.h" 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <unistd.h> 21 #include <sys/stat.h> 22 #include <sys/types.h> 23 #include <dirent.h> 24 #include <string.h> 25 #include <errno.h> 26 #include <fcntl.h> 17 #include "libbb.h" 27 18 28 19 /* … … 37 28 * Globals... 38 29 */ 39 static const char PROC_PATH[] = "/proc/sys/";40 static const char DEFAULT_PRELOAD[] = "/etc/sysctl.conf";30 static const char PROC_PATH[] ALIGN1 = "/proc/sys/"; 31 static const char DEFAULT_PRELOAD[] ALIGN1 = "/etc/sysctl.conf"; 41 32 42 33 /* error messages */ 43 static const char ERR_UNKNOWN_PARAMETER[] = "error: Unknown parameter '%s'\n"; 44 static const char ERR_MALFORMED_SETTING[] = "error: Malformed setting '%s'\n"; 45 static const char ERR_NO_EQUALS[] = 34 static const char ERR_UNKNOWN_PARAMETER[] ALIGN1 = 35 "error: Unknown parameter '%s'\n"; 36 static const char ERR_MALFORMED_SETTING[] ALIGN1 = 37 "error: Malformed setting '%s'\n"; 38 static const char ERR_NO_EQUALS[] ALIGN1 = 46 39 "error: '%s' must be of the form name=value\n"; 47 static const char ERR_INVALID_KEY[] = "error: '%s' is an unknown key\n"; 48 static const char ERR_UNKNOWN_WRITING[] = 40 static const char ERR_INVALID_KEY[] ALIGN1 = 41 "error: '%s' is an unknown key\n"; 42 static const char ERR_UNKNOWN_WRITING[] ALIGN1 = 49 43 "error: unknown error %d setting key '%s'\n"; 50 static const char ERR_UNKNOWN_READING[] =44 static const char ERR_UNKNOWN_READING[] ALIGN1 = 51 45 "error: unknown error %d reading key '%s'\n"; 52 static const char ERR_PERMISSION_DENIED[] =46 static const char ERR_PERMISSION_DENIED[] ALIGN1 = 53 47 "error: permission denied on key '%s'\n"; 54 static const char ERR_PRELOAD_FILE[] =55 "error: unable toopen preload file '%s'\n";56 static const char WARN_BAD_LINE[] =48 static const char ERR_PRELOAD_FILE[] ALIGN1 = 49 "error: cannot open preload file '%s'\n"; 50 static const char WARN_BAD_LINE[] ALIGN1 = 57 51 "warning: %s(%d): invalid syntax, continuing...\n"; 58 52 … … 66 60 * sysctl_main()... 67 61 */ 62 int sysctl_main(int argc, char **argv); 68 63 int sysctl_main(int argc, char **argv) 69 64 { … … 139 134 140 135 while (fgets(oneline, sizeof(oneline) - 1, fp)) { 141 oneline[sizeof(oneline) - 1] = 0;136 oneline[sizeof(oneline) - 1] = '\0'; 142 137 lineno++; 143 138 trim(oneline); … … 166 161 while ((*value == ' ' || *value == '\t') && *value != 0) 167 162 value++; 168 strcpy(buffer, name); 169 strcat(buffer, "="); 170 strcat(buffer, value); 163 /* safe because sizeof(oneline) == sizeof(buffer) */ 164 sprintf(buffer, "%s=%s", name, value); 171 165 sysctl_write_setting(buffer, output); 172 166 } … … 203 197 } 204 198 205 tmpname = bb_xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);206 outname = bb_xstrdup(tmpname + strlen(PROC_PATH));199 tmpname = xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name); 200 outname = xstrdup(tmpname + strlen(PROC_PATH)); 207 201 208 202 while ((cptr = strchr(tmpname, '.')) != NULL) … … 212 206 *cptr = '.'; 213 207 214 if ((fd = open(tmpname, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { 208 fd = open(tmpname, O_WRONLY | O_CREAT | O_TRUNC, 0666); 209 if (fd < 0) { 215 210 switch (errno) { 216 211 case ENOENT: … … 259 254 260 255 tmpname = concat_path_file(PROC_PATH, name); 261 outname = bb_xstrdup(tmpname + strlen(PROC_PATH));256 outname = xstrdup(tmpname + strlen(PROC_PATH)); 262 257 263 258 while ((cptr = strchr(tmpname, '.')) != NULL) … … 310 305 struct stat ts; 311 306 312 if (!(dp = bb_opendir(path))) { 307 dp = opendir(path); 308 if (!dp) { 313 309 retval = -1; 314 310 } else { 315 311 while ((de = readdir(dp)) != NULL) { 316 312 tmpdir = concat_subpath_file(path, de->d_name); 317 if (tmpdir == NULL)313 if (tmpdir == NULL) 318 314 continue; 319 if ((retval2 = stat(tmpdir, &ts)) != 0) 315 retval2 = stat(tmpdir, &ts); 316 if (retval2 != 0) 320 317 bb_perror_msg(tmpdir); 321 318 else {
Note:
See TracChangeset
for help on using the changeset viewer.