Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/procps/sysctl.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/procps/sysctl.c

    r821 r1765  
    1515 */
    1616
    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"
    2718
    2819/*
     
    3728 *    Globals...
    3829 */
    39 static const char PROC_PATH[] = "/proc/sys/";
    40 static const char DEFAULT_PRELOAD[] = "/etc/sysctl.conf";
     30static const char PROC_PATH[] ALIGN1 = "/proc/sys/";
     31static const char DEFAULT_PRELOAD[] ALIGN1 = "/etc/sysctl.conf";
    4132
    4233/* 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[] =
     34static const char ERR_UNKNOWN_PARAMETER[] ALIGN1 =
     35    "error: Unknown parameter '%s'\n";
     36static const char ERR_MALFORMED_SETTING[] ALIGN1 =
     37    "error: Malformed setting '%s'\n";
     38static const char ERR_NO_EQUALS[] ALIGN1 =
    4639    "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[] =
     40static const char ERR_INVALID_KEY[] ALIGN1 =
     41    "error: '%s' is an unknown key\n";
     42static const char ERR_UNKNOWN_WRITING[] ALIGN1 =
    4943    "error: unknown error %d setting key '%s'\n";
    50 static const char ERR_UNKNOWN_READING[] =
     44static const char ERR_UNKNOWN_READING[] ALIGN1 =
    5145    "error: unknown error %d reading key '%s'\n";
    52 static const char ERR_PERMISSION_DENIED[] =
     46static const char ERR_PERMISSION_DENIED[] ALIGN1 =
    5347    "error: permission denied on key '%s'\n";
    54 static const char ERR_PRELOAD_FILE[] =
    55     "error: unable to open preload file '%s'\n";
    56 static const char WARN_BAD_LINE[] =
     48static const char ERR_PRELOAD_FILE[] ALIGN1 =
     49    "error: cannot open preload file '%s'\n";
     50static const char WARN_BAD_LINE[] ALIGN1 =
    5751    "warning: %s(%d): invalid syntax, continuing...\n";
    5852
     
    6660 *    sysctl_main()...
    6761 */
     62int sysctl_main(int argc, char **argv);
    6863int sysctl_main(int argc, char **argv)
    6964{
     
    139134
    140135    while (fgets(oneline, sizeof(oneline) - 1, fp)) {
    141         oneline[sizeof(oneline) - 1] = 0;
     136        oneline[sizeof(oneline) - 1] = '\0';
    142137        lineno++;
    143138        trim(oneline);
     
    166161        while ((*value == ' ' || *value == '\t') && *value != 0)
    167162            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);
    171165        sysctl_write_setting(buffer, output);
    172166    }
     
    203197    }
    204198
    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));
    207201
    208202    while ((cptr = strchr(tmpname, '.')) != NULL)
     
    212206        *cptr = '.';
    213207
    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) {
    215210        switch (errno) {
    216211        case ENOENT:
     
    259254
    260255    tmpname = concat_path_file(PROC_PATH, name);
    261     outname = bb_xstrdup(tmpname + strlen(PROC_PATH));
     256    outname = xstrdup(tmpname + strlen(PROC_PATH));
    262257
    263258    while ((cptr = strchr(tmpname, '.')) != NULL)
     
    310305    struct stat ts;
    311306
    312     if (!(dp = bb_opendir(path))) {
     307    dp = opendir(path);
     308    if (!dp) {
    313309        retval = -1;
    314310    } else {
    315311        while ((de = readdir(dp)) != NULL) {
    316312            tmpdir = concat_subpath_file(path, de->d_name);
    317             if(tmpdir == NULL)
     313            if (tmpdir == NULL)
    318314                continue;
    319             if ((retval2 = stat(tmpdir, &ts)) != 0)
     315            retval2 = stat(tmpdir, &ts);
     316            if (retval2 != 0)
    320317                bb_perror_msg(tmpdir);
    321318            else {
Note: See TracChangeset for help on using the changeset viewer.