Project

General

Profile

Bug #167 » errors_to_stderr.patch

M W, 12/04/2012 03:09 AM

View differences:

bisect_iv.c
1425 1425
	orig_mac = ether_aton(orig_name_tmp);
1426 1426

  
1427 1427
	if (!orig_mac) {
1428
		printf("Error - the originator is not a mac address or bat-host name: %s\n", orig_name);
1428
		fprintf(stderr, "Error - the originator is not a mac address or bat-host name: %s\n", orig_name);
1429 1429
		goto err;
1430 1430
	}
1431 1431

  
......
1509 1509
	}
1510 1510

  
1511 1511
	if (argc <= found_args + 1) {
1512
		printf("Error - need at least 2 log files to compare\n");
1512
		fprintf(stderr, "Error - need at least 2 log files to compare\n");
1513 1513
		bisect_iv_usage();
1514 1514
		goto err;
1515 1515
	}
......
1517 1517
	node_hash = hash_new(64, compare_name, choose_name);
1518 1518

  
1519 1519
	if (!node_hash) {
1520
		printf("Error - could not create node hash table\n");
1520
		fprintf(stderr, "Error - could not create node hash table\n");
1521 1521
		goto err;
1522 1522
	}
1523 1523

  
......
1525 1525
	num_parsed_files = 0;
1526 1526

  
1527 1527
	if ((rt_orig_ptr) && (trace_orig_ptr)) {
1528
		printf("Error - the 'print routing table' option can't be used together with the the 'trace seqno' option\n");
1528
		fprintf(stderr, "Error - the 'print routing table' option can't be used together with the the 'trace seqno' option\n");
1529 1529
		goto err;
1530 1530
	} else if ((loop_orig_ptr) && (trace_orig_ptr)) {
1531
		printf("Error - the 'loop detection' option can't be used together with the the 'trace seqno' option\n");
1531
		fprintf(stderr, "Error - the 'loop detection' option can't be used together with the the 'trace seqno' option\n");
1532 1532
		goto err;
1533 1533
	} else if ((loop_orig_ptr) && (rt_orig_ptr)) {
1534
		printf("Error - the 'loop detection' option can't be used together with the the 'print routing table' option\n");
1534
		fprintf(stderr, "Error - the 'loop detection' option can't be used together with the the 'print routing table' option\n");
1535 1535
		goto err;
1536 1536
	} else if (rt_orig_ptr) {
1537 1537
		res = get_orig_addr(rt_orig_ptr, orig);
......
1555 1555
		seqno_max = seqno_min;
1556 1556

  
1557 1557
	if (seqno_min > seqno_max) {
1558
		printf("Error - the sequence range minimum (%lli) should be smaller than the maximum (%lli)\n",
1558
		fprintf(stderr, "Error - the sequence range minimum (%lli) should be smaller than the maximum (%lli)\n",
1559 1559
		       seqno_min, seqno_max);
1560 1560
		goto err;
1561 1561
	}
......
1577 1577
	}
1578 1578

  
1579 1579
	if (num_parsed_files < 2) {
1580
		printf("Error - need at least 2 log files to compare\n");
1580
		fprintf(stderr, "Error - need at least 2 log files to compare\n");
1581 1581
		goto err;
1582 1582
	}
1583 1583

  
debug.c
117 117
			}
118 118

  
119 119
			if (!sscanf(optarg, "%f", &watch_interval)) {
120
				printf("Error - provided argument of '-%c' is not a number\n", optchar);
120
				fprintf(stderr, "Error - provided argument of '-%c' is not a number\n", optchar);
121 121
				return EXIT_FAILURE;
122 122
			}
123 123
			break;
124 124
		case 't':
125 125
			if (debug_table != BATCTL_TABLE_ORIGINATORS) {
126
				printf("Error - unrecognised option '-%c'\n", optchar);
126
				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
127 127
				debug_table_usage(debug_table);
128 128
				return EXIT_FAILURE;
129 129
			}
130 130

  
131 131
			read_opt |= NO_OLD_ORIGS;
132 132
			if (!sscanf(optarg, "%f", &orig_timeout)) {
133
				printf("Error - provided argument of '-%c' is not a number\n", optchar);
133
				fprintf(stderr, "Error - provided argument of '-%c' is not a number\n", optchar);
134 134
				return EXIT_FAILURE;
135 135
			}
136 136
			break;
......
139 139
			break;
140 140
		case '?':
141 141
			if (optopt == 't')
142
				printf("Error - option '-t' needs a number as argument\n");
142
				fprintf(stderr, "Error - option '-t' needs a number as argument\n");
143 143

  
144 144
			else if (optopt == 'w') {
145 145
				read_opt |= CLR_CONT_READ;
146 146
				break;
147 147
			}
148 148
			else
149
				printf("Error - unrecognised option: '-%c'\n", optopt);
149
				fprintf(stderr, "Error - unrecognised option: '-%c'\n", optopt);
150 150

  
151 151
			return EXIT_FAILURE;
152 152
		default:
......
157 157

  
158 158
	debugfs_mnt = debugfs_mount(NULL);
159 159
	if (!debugfs_mnt) {
160
		printf("Error - can't mount or find debugfs\n");
160
		fprintf(stderr, "Error - can't mount or find debugfs\n");
161 161
		return EXIT_FAILURE;
162 162
	}
163 163

  
......
197 197

  
198 198
	debugfs_mnt = debugfs_mount(NULL);
199 199
	if (!debugfs_mnt) {
200
		printf("Error - can't mount or find debugfs\n");
200
		fprintf(stderr, "Error - can't mount or find debugfs\n");
201 201
		return EXIT_FAILURE;
202 202
	}
203 203

  
debugfs.c
85 85
	/* give up and parse /proc/mounts */
86 86
	fp = fopen("/proc/mounts", "r");
87 87
	if (fp == NULL) {
88
		printf("Error - can't open /proc/mounts for read: %s\n",
88
		fprintf(stderr, "Error - can't open /proc/mounts for read: %s\n",
89 89
		       strerror(errno));
90 90
		return NULL;
91 91
	}
functions.c
130 130

  
131 131
	if (strstr(dir, "/sys/")) {
132 132
		if (stat("/sys/", &st) != 0) {
133
			printf("Error - the folder '/sys/' was not found on the system\n");
134
			printf("Please make sure that the sys filesystem is properly mounted\n");
133
			fprintf(stderr, "Error - the folder '/sys/' was not found on the system\n");
134
			fprintf(stderr, "Please make sure that the sys filesystem is properly mounted\n");
135 135
			return;
136 136
		}
137 137
	}
138 138

  
139 139
	if (!file_exists(module_ver_path)) {
140
		printf("Error - batman-adv module has not been loaded\n");
140
		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
141 141
		return;
142 142
	}
143 143

  
144 144
	if (!file_exists(dir)) {
145
		printf("Error - mesh has not been enabled yet\n");
146
		printf("Activate your mesh by adding interfaces to batman-adv\n");
145
		fprintf(stderr, "Error - mesh has not been enabled yet\n");
146
		fprintf(stderr, "Activate your mesh by adding interfaces to batman-adv\n");
147 147
		return;
148 148
	}
149 149

  
......
154 154
		break;
155 155
	}
156 156

  
157
	printf("Error - can't open file '%s': %s\n", full_path, strerror(errno));
157
	fprintf(stderr, "Error - can't open file '%s': %s\n", full_path, strerror(errno));
158 158
	if (*ptr) {
159
		printf("The option you called seems not to be compiled into your batman-adv kernel module.\n");
160
		printf("Consult the README if you wish to learn more about compiling options into batman-adv.\n");
159
		fprintf(stderr, "The option you called seems not to be compiled into your batman-adv kernel module.\n");
160
		fprintf(stderr, "Consult the README if you wish to learn more about compiling options into batman-adv.\n");
161 161
	}
162 162
}
163 163

  
......
318 318
		write_len = write(fd, arg1, strlen(arg1) + 1);
319 319

  
320 320
	if (write_len < 0) {
321
		printf("Error - can't write to file '%s': %s\n", full_path, strerror(errno));
321
		fprintf(stderr, "Error - can't write to file '%s': %s\n", full_path, strerror(errno));
322 322
		goto out;
323 323
	}
324 324

  
ioctl.c
50 50
	ifr->ifr_data = (caddr_t)&drvinfo;
51 51
	err = ioctl(fd, SIOCETHTOOL, ifr);
52 52
	if (err < 0) {
53
		printf("Error - can't open driver information: %s\n", strerror(errno));
53
		fprintf(stderr, "Error - can't open driver information: %s\n", strerror(errno));
54 54
		goto out;
55 55
	}
56 56

  
......
64 64
	strings = calloc(1, sz_str + sizeof(struct ethtool_gstrings));
65 65
	stats = calloc(1, sz_stats + sizeof(struct ethtool_stats));
66 66
	if (!strings || !stats) {
67
		printf("Error - out of memory\n");
67
		fprintf(stderr, "Error - out of memory\n");
68 68
		goto out;
69 69
	}
70 70

  
......
74 74
	ifr->ifr_data = (caddr_t)strings;
75 75
	err = ioctl(fd, SIOCETHTOOL, ifr);
76 76
	if (err < 0) {
77
		printf("Error - can't get stats strings information: %s\n", strerror(errno));
77
		fprintf(stderr, "Error - can't get stats strings information: %s\n", strerror(errno));
78 78
		goto out;
79 79
	}
80 80

  
......
83 83
	ifr->ifr_data = (caddr_t) stats;
84 84
	err = ioctl(fd, SIOCETHTOOL, ifr);
85 85
	if (err < 0) {
86
		printf("Error - can't get stats information: %s\n", strerror(errno));
86
		fprintf(stderr, "Error - can't get stats information: %s\n", strerror(errno));
87 87
		goto out;
88 88
	}
89 89

  
......
111 111

  
112 112
	fd = socket(AF_INET, SOCK_DGRAM, 0);
113 113
	if (fd < 0) {
114
		printf("Error - can't open socket: %s\n", strerror(errno));
114
		fprintf(stderr, "Error - can't open socket: %s\n", strerror(errno));
115 115
		goto out;
116 116
	}
117 117

  
main.c
99 99

  
100 100
	if ((argc > 1) && (strcmp(argv[1], "-m") == 0)) {
101 101
		if (argc < 3) {
102
			printf("Error - the option '-m' needs a parameter\n");
102
			fprintf(stderr, "Error - the option '-m' needs a parameter\n");
103 103
			goto err;
104 104
		}
105 105

  
......
110 110
	}
111 111

  
112 112
	if (argc < 2) {
113
		printf("Error - no command specified\n");
113
		fprintf(stderr, "Error - no command specified\n");
114 114
		goto err;
115 115
	}
116 116

  
117
	if (strcmp(argv[1], "-h") == 0)
118
		goto err;
117
	if (strcmp(argv[1], "-h") == 0) {
118
		print_usage();
119
		exit(EXIT_SUCCESS);
120
	}
119 121

  
120 122
	if (strcmp(argv[1], "-v") == 0) {
121 123
		printf("batctl %s [batman-adv: ", SOURCE_VERSION);
......
206 208
			goto out;
207 209
		}
208 210

  
209
		printf("Error - no valid command or debug table specified: %s\n", argv[1]);
211
		fprintf(stderr, "Error - no valid command or debug table specified: %s\n", argv[1]);
210 212
		print_usage();
211 213
	}
212 214

  
ping.c
124 124
	}
125 125

  
126 126
	if (argc <= found_args) {
127
		printf("Error - target mac address or bat-host name not specified\n");
127
		fprintf(stderr, "Error - target mac address or bat-host name not specified\n");
128 128
		ping_usage();
129 129
		return EXIT_FAILURE;
130 130
	}
......
140 140
		dst_mac = resolve_mac(dst_string);
141 141

  
142 142
		if (!dst_mac) {
143
			printf("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
143
			fprintf(stderr, "Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
144 144
			goto out;
145 145
		}
146 146
	}
......
154 154

  
155 155
	debugfs_mnt = debugfs_mount(NULL);
156 156
	if (!debugfs_mnt) {
157
		printf("Error - can't mount or find debugfs\n");
157
		fprintf(stderr, "Error - can't mount or find debugfs\n");
158 158
		goto out;
159 159
	}
160 160

  
......
163 163
	ping_fd = open(icmp_socket, O_RDWR);
164 164

  
165 165
	if (ping_fd < 0) {
166
		printf("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
166
		fprintf(stderr, "Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
167 167
				icmp_socket, strerror(errno));
168 168
		printf("Check whether the module is loaded and active.\n");
169 169
		goto out;
......
203 203
		icmp_packet_out.seqno = htons(++seq_counter);
204 204

  
205 205
		if (write(ping_fd, (char *)&icmp_packet_out, packet_len) < 0) {
206
			printf("Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
206
			fprintf(stderr, "Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
207 207
			goto sleep;
208 208
		}
209 209

  
......
231 231
		read_len = read(ping_fd, (char *)&icmp_packet_in, packet_len);
232 232

  
233 233
		if (read_len < 0) {
234
			printf("Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
234
			fprintf(stderr, "Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
235 235
			goto sleep;
236 236
		}
237 237

  
......
298 298
			printf("From %s: Time to live exceeded (icmp_seq %hu)\n", dst_string, ntohs(icmp_packet_in.seqno));
299 299
			break;
300 300
		case BATADV_PARAMETER_PROBLEM:
301
			printf("Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
301
			fprintf(stderr, "Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
302 302
					icmp_packet_in.header.version, BATADV_COMPAT_VERSION);
303 303
			printf("Please make sure to use compatible versions!\n");
304 304
			goto out;
sys.c
116 116
	int res;
117 117

  
118 118
	if (!file_exists(module_ver_path)) {
119
		printf("Error - batman-adv module has not been loaded\n");
119
		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
120 120
		goto err;
121 121
	}
122 122

  
123 123
	path_buff = malloc(PATH_BUFF_LEN);
124 124
	if (!path_buff) {
125
		printf("Error - could not allocate path buffer: out of memory ?\n");
125
		fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
126 126
		goto err;
127 127
	}
128 128

  
129 129
	iface_base_dir = opendir(SYS_IFACE_PATH);
130 130
	if (!iface_base_dir) {
131
		printf("Error - the directory '%s' could not be read: %s\n",
131
		fprintf(stderr, "Error - the directory '%s' could not be read: %s\n",
132 132
		       SYS_IFACE_PATH, strerror(errno));
133
		printf("Is the batman-adv module loaded and sysfs mounted ?\n");
133
		fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n");
134 134
		goto err_buff;
135 135
	}
136 136

  
......
199 199

  
200 200
	if ((strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "a") != 0) &&
201 201
	    (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0)) {
202
		printf("Error - unknown argument specified: %s\n", argv[1]);
202
		fprintf(stderr, "Error - unknown argument specified: %s\n", argv[1]);
203 203
		interface_usage();
204 204
		goto err;
205 205
	}
206 206

  
207 207
	if (argc == 2) {
208
		printf("Error - missing interface name(s) after '%s'\n", argv[1]);
208
		fprintf(stderr, "Error - missing interface name(s) after '%s'\n", argv[1]);
209 209
		interface_usage();
210 210
		goto err;
211 211
	}
212 212

  
213 213
	path_buff = malloc(PATH_BUFF_LEN);
214 214
	if (!path_buff) {
215
		printf("Error - could not allocate path buffer: out of memory ?\n");
215
		fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
216 216
		goto err;
217 217
	}
218 218

  
......
225 225
			path_buff[PATH_BUFF_LEN - 1] = '\0';
226 226

  
227 227
			if (!file_exists(path_buff)) {
228
				printf("Error - interface does not exist: %s\n", argv[i]);
228
				fprintf(stderr, "Error - interface does not exist: %s\n", argv[i]);
229 229
				continue;
230 230
			}
231 231

  
232 232
			if (!file_exists(module_ver_path)) {
233
				printf("Error - batman-adv module has not been loaded\n");
233
				fprintf(stderr, "Error - batman-adv module has not been loaded\n");
234 234
				goto err;
235 235
			}
236 236

  
237
			printf("Error - interface type not supported by batman-adv: %s\n", argv[i]);
237
			fprintf(stderr, "Error - interface type not supported by batman-adv: %s\n", argv[i]);
238 238
			continue;
239 239
		}
240 240

  
......
404 404
		ptr++;
405 405
	}
406 406

  
407
	printf("Error - the supplied argument is invalid: %s\n", argv[1]);
408
	printf("The following values are allowed:\n");
407
	fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]);
408
	fprintf(stderr, "The following values are allowed:\n");
409 409

  
410 410
	ptr = batctl_settings[setting].params;
411 411
	while (*ptr) {
......
533 533
	goto out;
534 534

  
535 535
opt_err:
536
	printf("Error - the supplied argument is invalid: %s\n", argv[1]);
537
	printf("The following values are allowed:\n");
536
	fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]);
537
	fprintf(stderr, "The following values are allowed:\n");
538 538

  
539 539
	ptr = sysfs_param_server;
540 540
	while (*ptr) {
traceroute.c
86 86
	}
87 87

  
88 88
	if (argc <= found_args) {
89
		printf("Error - target mac address or bat-host name not specified\n");
89
		fprintf(stderr, "Error - target mac address or bat-host name not specified\n");
90 90
		traceroute_usage();
91 91
		return EXIT_FAILURE;
92 92
	}
......
102 102
		dst_mac = resolve_mac(dst_string);
103 103

  
104 104
		if (!dst_mac) {
105
			printf("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
105
			fprintf(stderr, "Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
106 106
			goto out;
107 107
		}
108 108
	}
......
114 114

  
115 115
	debugfs_mnt = debugfs_mount(NULL);
116 116
	if (!debugfs_mnt) {
117
		printf("Error - can't mount or find debugfs\n");
117
		fprintf(stderr, "Error - can't mount or find debugfs\n");
118 118
		goto out;
119 119
	}
120 120

  
......
123 123
	trace_fd = open(icmp_socket, O_RDWR);
124 124

  
125 125
	if (trace_fd < 0) {
126
		printf("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
126
		fprintf(stderr, "Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
127 127
				icmp_socket, strerror(errno));
128
		printf("Check whether the module is loaded and active.\n");
128
		fprintf(stderr, "Check whether the module is loaded and active.\n");
129 129
		goto out;
130 130
	}
131 131

  
......
148 148
			time_delta[i] = 0.0;
149 149

  
150 150
			if (write(trace_fd, (char *)&icmp_packet_out, sizeof(icmp_packet_out)) < 0) {
151
				printf("Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
151
				fprintf(stderr, "Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
152 152
				continue;
153 153
			}
154 154

  
......
169 169
			read_len = read(trace_fd, (char *)&icmp_packet_in, sizeof(icmp_packet_in));
170 170

  
171 171
			if (read_len < 0) {
172
				printf("Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
172
				fprintf(stderr, "Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
173 173
				continue;
174 174
			}
175 175

  
......
202 202
				printf("%s: Destination Host Unreachable\n", dst_string);
203 203
				goto out;
204 204
			case BATADV_PARAMETER_PROBLEM:
205
				printf("Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
205
				fprintf(stderr, "Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
206 206
						icmp_packet_in.header.version, BATADV_COMPAT_VERSION);
207
				printf("Please make sure to use compatible versions!\n");
207
				fprintf(stderr, "Please make sure to use compatible versions!\n");
208 208
				goto out;
209 209
			default:
210 210
				printf("Unknown message type %d len %zd received\n", icmp_packet_in.msg_type, read_len);
vis.c
171 171

  
172 172
	debugfs_mnt = debugfs_mount(NULL);
173 173
	if (!debugfs_mnt) {
174
		printf("Error - can't mount or find debugfs\n");
174
		fprintf(stderr, "Error - can't mount or find debugfs\n");
175 175
		return NULL;
176 176
	}
177 177

  
(1-1/2)