static void full_write2_str(const char *str) { xwrite_str(STDERR_FILENO, str); }
/* Open file and write string str to it, close file. * Die on any open or write error. */ void FAST_FUNC xopen_xwrite_close(const char* file, const char* str) { int fd = xopen(file, O_WRONLY); xwrite_str(fd, str); close(fd); }
static int sysctl_act_on_setting(char *setting) { int fd, retval = EXIT_SUCCESS; char *cptr, *outname; char *value = value; /* for compiler */ outname = xstrdup(setting); cptr = outname; while (*cptr) { if (*cptr == '/') *cptr = '.'; cptr++; } if (option_mask32 & FLAG_WRITE) { cptr = strchr(setting, '='); if (cptr == NULL) { bb_error_msg("error: '%s' must be of the form name=value", outname); retval = EXIT_FAILURE; goto end; } value = cptr + 1; /* point to the value in name=value */ if (setting == cptr || !*value) { bb_error_msg("error: malformed setting '%s'", outname); retval = EXIT_FAILURE; goto end; } *cptr = '\0'; outname[cptr - setting] = '\0'; /* procps 3.2.7 actually uses these flags */ fd = open(setting, O_WRONLY|O_CREAT|O_TRUNC, 0666); } else { fd = open(setting, O_RDONLY); } if (fd < 0) { switch (errno) { case ENOENT: if (option_mask32 & FLAG_SHOW_KEY_ERRORS) bb_error_msg("error: '%s' is an unknown key", outname); break; default: bb_perror_msg("error %sing key '%s'", option_mask32 & FLAG_WRITE ? "sett" : "read", outname); break; } retval = EXIT_FAILURE; goto end; } if (option_mask32 & FLAG_WRITE) { //TODO: procps 3.2.7 writes "value\n", note trailing "\n" xwrite_str(fd, value); close(fd); if (!(option_mask32 & FLAG_QUIET)) { if (option_mask32 & FLAG_SHOW_KEYS) printf("%s = ", outname); puts(value); } } else { char c; value = cptr = xmalloc_read(fd, NULL); close(fd); if (value == NULL) { bb_perror_msg("error reading key '%s'", outname); goto end; } /* dev.cdrom.info and sunrpc.transports, for example, * are multi-line. Try "sysctl sunrpc.transports" */ while ((c = *cptr) != '\0') { if (option_mask32 & FLAG_SHOW_KEYS) printf("%s = ", outname); while (1) { fputc(c, stdout); cptr++; if (c == '\n') break; c = *cptr; if (c == '\0') break; } } free(value); } end: free(outname); return retval; }