aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/perf_counter/config.c')
-rw-r--r--Documentation/perf_counter/config.c95
1 files changed, 1 insertions, 94 deletions
diff --git a/Documentation/perf_counter/config.c b/Documentation/perf_counter/config.c
index 672d53959334..3dd13faa6a27 100644
--- a/Documentation/perf_counter/config.c
+++ b/Documentation/perf_counter/config.c
@@ -15,7 +15,6 @@ static FILE *config_file;
15static const char *config_file_name; 15static const char *config_file_name;
16static int config_linenr; 16static int config_linenr;
17static int config_file_eof; 17static int config_file_eof;
18static int zlib_compression_seen;
19 18
20const char *config_exclusive_filename = NULL; 19const char *config_exclusive_filename = NULL;
21 20
@@ -533,14 +532,6 @@ static int store_aux(const char* key, const char* value, void *cb)
533 return 0; 532 return 0;
534} 533}
535 534
536static int write_error(const char *filename)
537{
538 error("failed to write new configuration file %s", filename);
539
540 /* Same error code as "failed to rename". */
541 return 4;
542}
543
544static int store_write_section(int fd, const char* key) 535static int store_write_section(int fd, const char* key)
545{ 536{
546 const char *dot; 537 const char *dot;
@@ -673,7 +664,7 @@ int perf_config_set_multivar(const char* key, const char* value,
673{ 664{
674 int i, dot; 665 int i, dot;
675 int fd = -1, in_fd; 666 int fd = -1, in_fd;
676 int ret; 667 int ret = 0;
677 char* config_filename; 668 char* config_filename;
678 const char* last_dot = strrchr(key, '.'); 669 const char* last_dot = strrchr(key, '.');
679 670
@@ -872,90 +863,6 @@ write_err_out:
872 863
873} 864}
874 865
875static int section_name_match (const char *buf, const char *name)
876{
877 int i = 0, j = 0, dot = 0;
878 for (; buf[i] && buf[i] != ']'; i++) {
879 if (!dot && isspace(buf[i])) {
880 dot = 1;
881 if (name[j++] != '.')
882 break;
883 for (i++; isspace(buf[i]); i++)
884 ; /* do nothing */
885 if (buf[i] != '"')
886 break;
887 continue;
888 }
889 if (buf[i] == '\\' && dot)
890 i++;
891 else if (buf[i] == '"' && dot) {
892 for (i++; isspace(buf[i]); i++)
893 ; /* do_nothing */
894 break;
895 }
896 if (buf[i] != name[j++])
897 break;
898 }
899 return (buf[i] == ']' && name[j] == 0);
900}
901
902/* if new_name == NULL, the section is removed instead */
903int perf_config_rename_section(const char *old_name, const char *new_name)
904{
905 int ret = 0, remove = 0;
906 char *config_filename;
907 int out_fd;
908 char buf[1024];
909
910 if (config_exclusive_filename)
911 config_filename = strdup(config_exclusive_filename);
912 else
913 config_filename = perf_pathdup("config");
914 if (out_fd < 0) {
915 ret = error("could not lock config file %s", config_filename);
916 goto out;
917 }
918
919 if (!(config_file = fopen(config_filename, "rb"))) {
920 /* no config file means nothing to rename, no error */
921 goto unlock_and_out;
922 }
923
924 while (fgets(buf, sizeof(buf), config_file)) {
925 int i;
926 int length;
927 for (i = 0; buf[i] && isspace(buf[i]); i++)
928 ; /* do nothing */
929 if (buf[i] == '[') {
930 /* it's a section */
931 if (section_name_match (&buf[i+1], old_name)) {
932 ret++;
933 if (new_name == NULL) {
934 remove = 1;
935 continue;
936 }
937 store.baselen = strlen(new_name);
938 if (!store_write_section(out_fd, new_name)) {
939 goto out;
940 }
941 continue;
942 }
943 remove = 0;
944 }
945 if (remove)
946 continue;
947 length = strlen(buf);
948 if (write_in_full(out_fd, buf, length) != length) {
949 goto out;
950 }
951 }
952 fclose(config_file);
953 unlock_and_out:
954 out:
955 free(config_filename);
956 return ret;
957}
958
959/* 866/*
960 * Call this to report error for your variable that should not 867 * Call this to report error for your variable that should not
961 * get a boolean value (i.e. "[my] var" means "true"). 868 * get a boolean value (i.e. "[my] var" means "true").