Changeset 2768
- Timestamp:
- 11/21/04 22:36:10 (9 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/prog/sensors/main.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/sensors/main.c
r2767 r2768 36 36 #define DEFAULT_CONFIG_FILE_NAME "sensors.conf" 37 37 38 static char *config_file_name = NULL;39 38 FILE *config_file; 40 39 extern const char *libsensors_version; … … 44 43 static void print_long_help(void); 45 44 static void print_version(void); 46 static void open_config_file(void);47 static int open_this_config_file(char *filename);48 45 static void do_a_print(sensors_chip_name name); 49 46 static int do_a_set(sensors_chip_name name); … … 95 92 /* This examines global var config_file, and leaves the name there too. 96 93 It also opens config_file. */ 97 void open_config_file(void) 98 { 99 #define MAX_FILENAME_LEN 1024 100 char *filename; 101 char buffer[MAX_FILENAME_LEN]; 102 int res; 103 104 if (config_file_name && !strcmp(config_file_name,"-")) { 94 void open_config_file(const char* config_file_name) 95 { 96 if (!strcmp(config_file_name,"-")) { 105 97 config_file = stdin; 106 98 return; 107 } else if (config_file_name && index(config_file_name,'/')) { 108 if ((res = open_this_config_file(config_file_name))) { 109 fprintf(stderr,"Could not locate or open config file\n"); 110 fprintf(stderr,"%s: %s\n",config_file_name,strerror(-res)); 111 exit(1); 112 } 113 } 114 else { 115 if (config_file_name) 116 filename = config_file_name; 117 else 118 filename = DEFAULT_CONFIG_FILE_NAME; 119 if ((snprintf(buffer,MAX_FILENAME_LEN, 120 "%s/%s", ETCDIR, filename)) < 1) { 121 fprintf(stderr, 122 "open_config_file: ridiculous long config file name!\n"); 123 exit(1); 124 } 125 if (!open_this_config_file(buffer)) { 126 free(config_file_name); 127 config_file_name = strdup(buffer); 128 return; 129 } 130 fprintf(stderr,"Could not locate or open config file!\n"); 99 } 100 101 config_file = fopen(config_file_name, "r"); 102 if (!config_file) { 103 fprintf(stderr, "Could not open config file\n"); 104 perror(config_file_name); 131 105 exit(1); 132 106 } 133 107 } 134 108 135 int open_this_config_file(char *filename) 136 { 137 config_file = fopen(filename,"r"); 138 if (! config_file) 139 return -errno; 140 return 0; 141 } 142 143 void close_config_file(void) 144 { 145 if (fclose(config_file)) { 109 void close_config_file(const char* config_file_name) 110 { 111 if (fclose(config_file) == EOF) { 146 112 fprintf(stderr,"Could not close config file\n"); 147 fprintf(stderr,"%s: %s\n",config_file_name,strerror(errno)); 148 } 149 150 free(config_file_name); 113 perror(config_file_name); 114 } 151 115 } 152 116 … … 179 143 { 180 144 int c,res,i,error; 145 char *config_file_name = NULL; 181 146 182 147 struct option long_opts[] = { … … 259 224 260 225 261 open_config_file(); 226 if (config_file_name == NULL) 227 config_file_name = strdup(ETCDIR "/" DEFAULT_CONFIG_FILE_NAME); 228 open_config_file(config_file_name); 262 229 263 230 if ((res = sensors_init(config_file))) { … … 272 239 } 273 240 274 close_config_file(); 241 close_config_file(config_file_name); 242 free(config_file_name); 275 243 276 244 /* build the degrees string */
