bonjour
je cherche à comprendre le fonctionnement d'un programme . (hddtemp)
si je le lance en ligne de commande , j'obtiens ceci :
/dev/sda: ST2000DM001-9YN164: 30°C
donc , çà fonctionne .
strace donne ceci :
sudo strace hddtemp /dev/sda
[sudo] Mot de passe de alain :
execve("/usr/sbin/hddtemp", ["hddtemp", "/dev/sda"], 0x7ffc8ab4ae98 /* 15 vars */) = 0
brk(NULL) = 0x55afbfefd000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=173980, ...}) = 0
mmap(NULL, 173980, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f59dcf02000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260A\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1824496, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f59dcf00000
mmap(NULL, 1837056, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f59dcd3f000
mprotect(0x7f59dcd61000, 1658880, PROT_NONE) = 0
mmap(0x7f59dcd61000, 1343488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f59dcd61000
mmap(0x7f59dcea9000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16a000) = 0x7f59dcea9000
mmap(0x7f59dcef6000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f59dcef6000
mmap(0x7f59dcefc000, 14336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f59dcefc000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f59dcf01580) = 0
mprotect(0x7f59dcef6000, 16384, PROT_READ) = 0
mprotect(0x55afbeaf3000, 4096, PROT_READ) = 0
mprotect(0x7f59dcf54000, 4096, PROT_READ) = 0
munmap(0x7f59dcf02000, 173980) = 0
rt_sigaction(SIGSEGV, {sa_handler=0x55afbe8f0ff0, sa_mask=[ILL BUS], sa_flags=SA_RESTORER|SA_RESETHAND|SA_SIGINFO, sa_restorer=0x7f59dcd76940}, NULL, 8) = 0
rt_sigaction(SIGILL, {sa_handler=0x55afbe8f0ff0, sa_mask=[BUS SEGV], sa_flags=SA_RESTORER|SA_RESETHAND|SA_SIGINFO, sa_restorer=0x7f59dcd76940}, NULL, 8) = 0
rt_sigaction(SIGBUS, {sa_handler=0x55afbe8f0ff0, sa_mask=[ILL SEGV], sa_flags=SA_RESTORER|SA_RESETHAND|SA_SIGINFO, sa_restorer=0x7f59dcd76940}, NULL, 8) = 0
brk(NULL) = 0x55afbfefd000
brk(0x55afbff1e000) = 0x55afbff1e000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3031728, ...}) = 0
mmap(NULL, 3031728, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f59dca5a000
close(3) = 0
openat(AT_FDCWD, "/dev/sda", O_RDONLY|O_NONBLOCK) = 3
ioctl(3, SCSI_IOCTL_GET_BUS_NUMBER, 0x7ffc61c7c6e8) = 0
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_FROM_DEV, cmd_len=6, cmdp="\x12\x00\x00\x00\x24\x00", mx_sb_len=0, iovec_count=0, dxfer_len=36, timeout=3000, flags=0, dxferp="\x00\x00\x05\x02\x5b\x00\x00\x02\x41\x54\x41\x20\x20\x20\x20\x20\x53\x54\x32\x30\x30\x30\x44\x4d\x30\x30\x31\x2d\x39\x59\x4e\x31"..., status=0, masked_status=0, msg_status=0, sb_len_wr=0, sbp=NULL, host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_FROM_DEV, cmd_len=16, cmdp="\x85\x08\x2e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xec\x00", mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=3000, flags=0, dxferp="\x5a\x0c\xff\x3f\x37\xc8\x10\x00\x00\x00\x00\x00\x3f\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"..., status=0x2, masked_status=0x1, msg_status=0, sb_len_wr=22, sbp="\x72\x01\x00\x1d\x00\x00\x00\x0e\x09\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50", host_status=0, driver_status=0x8, resid=0, duration=0, info=SG_INFO_CHECK}) = 0
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_FROM_DEV, cmd_len=16, cmdp="\x85\x08\x2e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xec\x00", mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=3000, flags=0, dxferp="\x5a\x0c\xff\x3f\x37\xc8\x10\x00\x00\x00\x00\x00\x3f\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"..., status=0x2, masked_status=0x1, msg_status=0, sb_len_wr=22, sbp="\x72\x01\x00\x1d\x00\x00\x00\x0e\x09\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50", host_status=0, driver_status=0x8, resid=0, duration=0, info=SG_INFO_CHECK}) = 0
openat(AT_FDCWD, "/etc/hddtemp.db", O_RDONLY) = 4
read(4, "#\n# Insert a regular expression "..., 1024) = 1024
read(4, "20420A 19.9GB\n# SEAGATE ST330610"..., 1011) = 1011
read(4, "####\n\n# DJSA serie is using F0h "..., 988) = 988
read(4, "[04568]H1\"\t\t\t\t??? C \"Maxtor Fi"..., 1007) = 1007
read(4, " TM2110A\"\n\n\n####################"..., 971) = 971
read(4, "dalist 10240 Ultra ATA-3\"\n\"ST320"..., 990) = 990
read(4, "UA1\" \t\t\t\t 0 C \"Weste"..., 1008) = 757
read(4, "", 1024) = 0
close(4) = 0
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=26402, ...}) = 0
mmap(NULL, 26402, PROT_READ, MAP_SHARED, 4, 0) = 0x7f59dcf26000
close(4) = 0
brk(0x55afbff3f000) = 0x55afbff3f000
ioctl(3, HDIO_DRIVE_CMD, 0x7ffc61c7c8d4) = 0
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_NONE, cmd_len=16, cmdp="\x85\x06\x20\x00\xd8\x00\x00\x00\x00\x00\x4f\x00\xc2\x00\xb0\x00", mx_sb_len=32, iovec_count=0, dxfer_len=0, timeout=3000, flags=0, status=0x2, masked_status=0x1, msg_status=0, sb_len_wr=22, sbp="\x72\x01\x00\x1d\x00\x00\x00\x0e\x09\x0c\x00\x00\x00\x00\x00\x00\x00\x4f\x00\xc2\x00\x50", host_status=0, driver_status=0x8, resid=0, duration=0, info=SG_INFO_CHECK}) = 0
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_FROM_DEV, cmd_len=16, cmdp="\x85\x08\x2e\x00\xd0\x00\x01\x00\x00\x00\x4f\x00\xc2\x00\xb0\x00", mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=3000, flags=0, dxferp="\x0a\x00\x01\x0f\x00\x72\x63\x70\x74\x47\x04\x00\x00\x00\x03\x03\x00\x5f\x5e\x00\x00\x00\x00\x00\x00\x00\x04\x32\x00\x60\x60\x50"..., status=0x2, masked_status=0x1, msg_status=0, sb_len_wr=22, sbp="\x72\x01\x00\x1d\x00\x00\x00\x0e\x09\x0c\x00\x00\x00\x01\x00\x00\x00\x4f\x00\xc2\x00\x50", host_status=0, driver_status=0x8, resid=0, duration=60, info=SG_INFO_CHECK}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
write(1, "/dev/sda: ST2000DM001-9YN164: 30"..., 36/dev/sda: ST2000DM001-9YN164: 30°C
) = 36
exit_group(0) = ?
+++ exited with 0 +++
là aussi çà fonctionne
sudo strace -c hddtemp /dev/sda
/dev/sda: ST2000DM001-9YN164: 27°C
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
0,00 0,000000 0 9 read
0,00 0,000000 0 1 write
0,00 0,000000 0 5 close
0,00 0,000000 0 5 fstat
0,00 0,000000 0 9 mmap
0,00 0,000000 0 4 mprotect
0,00 0,000000 0 1 munmap
0,00 0,000000 0 4 brk
0,00 0,000000 0 3 rt_sigaction
0,00 0,000000 0 7 ioctl
0,00 0,000000 0 1 1 access
0,00 0,000000 0 1 execve
0,00 0,000000 0 1 arch_prctl
0,00 0,000000 0 6 openat
------ ----------- ----------- --------- --------- ----------------
100.00 0,000000 57 1 total
sudo strace -e access hddtemp /dev/sda
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (Aucun fichier ou dossier de ce type)
/dev/sda: ST2000DM001-9YN164: 27°C
+++ exited with 0 +++
avec gdb :
sudo gdb hddtemp /dev/sda
GNU gdb (Debian 8.2-1) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hddtemp...Reading symbols from /usr/lib/debug/.build-id/38/4b9079ea3410d8039631a88ae8255da965c95c.debug...done.
done.
"/dev/sda" is not a core dump: file format not recognized
(gdb) run /dev/sda
Starting program: /usr/sbin/hddtemp /dev/sda
/dev/sda: ST2000DM001-9YN164: 30°C
[Inferior 1 (process 1609) exited normally]
(gdb) quit
là encore , pas de lézard .
par contre , avec ddd :
GDB Console :
GNU DDD 3.3.12 (x86_64-pc-linux-gnu), by Dorothea LReading symbols from hddtemp...Reading symbols from /usr/lib/debug/.build-id/38/4b9079ea3410d8039631a88ae8255da965c95c.debug...done.
done.
/dev/sda: Permission non accordée.
(gdb)
Source Window
1 /*
2 * Copyright (C) 2002 Emmanuel VARAGNAT <hddtemp@guzu.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /*
20 * Added some SCSI support: Frederic LOCHON <lochon@roulaise.net>
21 *
22 */
23
24 // Include file generated by ./configure
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 // Gettext includes
30 #if ENABLE_NLS
31 #include <libintl.h>
32 #define _(String) gettext (String)
33 #else
34 #define _(String) (String)
35 #endif
36
37 // Standard includes
38 #include <unistd.h>
39 #include <stdlib.h>
40 #include <fcntl.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <sys/ioctl.h>
44 #include <sys/types.h>
45 #include <sys/socket.h>
46 #include <arpa/inet.h>
47 #include <netdb.h>
48 #include <getopt.h>
49 #include <signal.h>
50 #include <errno.h>
51 #include <locale.h>
52 #include <time.h>
53 #include <netinet/in.h>
54 #include <linux/hdreg.h>
55 #include <ctype.h>
56 #include <assert.h>
57
58 // Application specific includes
59 #include "ata.h"
60 #include "utf8.h"
61 #include "sata.h"
62 #include "scsi.h"
63 #include "db.h"
64 #include "hddtemp.h"
65 #include "backtrace.h"
66 #include "daemon.h"
67
68
69 #define PORT_NUMBER 7634
70 #define SEPARATOR '|'
71
72 char * database_path = DEFAULT_DATABASE_PATH;
73 long portnum, syslog_interval;
74 char * listen_addr;
75 char separator = SEPARATOR;
76
77 struct bustype * bus[BUS_TYPE_MAX];
78 int tcp_daemon, debug, quiet, numeric, wakeup, foreground, af_hint;
79
80 static enum { DEFAULT, CELSIUS, FAHRENHEIT } unit;
81
82 /*******************************************************
83 *******************************************************/
84
85 static void init_bus_types() {
86 bus[BUS_SATA] = &sata_bus;
87 bus[BUS_ATA] = &ata_bus;
88 bus[BUS_SCSI] = &scsi_bus;
89 }
90
91 /*******************************************************
92 *******************************************************/
93
94 int value_to_unit(struct disk *dsk) {
95 switch(unit) {
96 case CELSIUS:
97 if(dsk->db_entry->unit == 'F')
98 return F_to_C(dsk->value);
99 break;
100 case FAHRENHEIT:
101 if(dsk->db_entry->unit == 'C')
102 return C_to_F(dsk->value);
103 default:
104 break;
105 }
106
107 return dsk->value;
108 }
109
110 char get_unit(struct disk *dsk) {
111 switch(unit) {
112 case CELSIUS:
113 return 'C';
114 case FAHRENHEIT:
115 return 'F';
116 default:
117 return dsk->db_entry->unit;
118 }
119 }
120
121
122
123 static enum e_bustype probe_bus_type(struct disk *dsk) {
124 /* SATA disks answer to both ATA and SCSI commands so
125 they have to be probed first in order to be detected */
126 if(bus[BUS_SATA]->probe(dsk->fd))
127 return BUS_SATA;
128 else if(bus[BUS_ATA]->probe(dsk->fd))
129 return BUS_ATA;
130 else if(bus[BUS_SCSI]->probe(dsk->fd))
131 return BUS_SCSI;
132 else
133 return BUS_UNKNOWN;
134 }
135
136 /*
137 static int get_smart_threshold_values(int fd, unsigned char* buff) {
138 unsigned char cmd[516] = { WIN_SMART, 0, SMART_READ_THRESHOLDS, 1 };
139 int ret;
140
141 ret = ioctl(fd, HDIO_DRIVE_CMD, cmd);
142 if(ret)
143 return ret;
144
145 memcpy(buff, cmd+4, 512);
146 return 0;
147 }
148 */
149
150
151 static void display_temperature(struct disk *dsk) {
152 enum e_gettemp ret;
153 char *degree;
154
155 if(dsk->type != ERROR && debug ) {
156 printf(_("\n================= hddtemp %s ==================\n"
157 "Model: %s\n\n"), VERSION, dsk->model);
158 /* return;*/
159 }
160
161 if(dsk->type == ERROR
162 || bus[dsk->type]->get_temperature == NULL
163 || (ret = bus[dsk->type]->get_temperature(dsk)) == GETTEMP_ERROR )
164 {
165 fprintf(stderr, "%s: %s\n", dsk->drive, dsk->errormsg);
166 return;
167 }
168
169 if(debug)
170 return;
171
172 degree = degree_sign();
173 switch(ret) {
174 case GETTEMP_ERROR:
175 /* see above */
176 break;
177 case GETTEMP_NOT_APPLICABLE:
178
179 if (numeric && quiet)
180 printf("0\n");
181 else
182 printf("%s: %s: %s\n", dsk->drive, dsk->model, dsk->errormsg);
183
184 break;
185 case GETTEMP_UNKNOWN:
186
187 if(!quiet)
188 fprintf(stderr,
189 _("WARNING: Drive %s doesn't seem to have a temperature sensor.\n"
190 "WARNING: This doesn't mean it hasn't got one.\n"
191 "WARNING: If you are sure it has one, please contact me (hddtemp@guzu.net).\n"
192 "WARNING: See --help, --debug and --drivebase options.\n"), dsk->drive);
193
194 if (numeric && quiet)
195 printf("0\n");
196 else
197 fprintf(stderr, _("%s: %s: no sensor\n"), dsk->drive, dsk->model);
198
199 break;
200 case GETTEMP_KNOWN:
201
202 if (! numeric)
203 printf("%s: %s: %d%s%c\n",
204 dsk->drive,
205 dsk->model,
206 value_to_unit(dsk),
207 degree,
208 get_unit(dsk)
209 );
210 else
211 printf("%d\n", value_to_unit(dsk));
212
213 break;
214 case GETTEMP_DRIVE_SLEEP:
215
216 if (numeric && quiet)
217 printf("0\n");
218 else
219 fprintf(stderr, _("%s: %s: drive is sleeping\n"), dsk->drive, dsk->model);
220
221 break;
222 case GETTEMP_NOSENSOR:
223 if (numeric && quiet)
224 printf("0\n");
225 else
226 fprintf(stderr, _("%s: %s: drive supported, but it doesn't have a temperature sensor.\n"), dsk->drive, dsk->model);
227
228 break;
229 default:
230 fprintf(stderr, _("ERROR: %s: %s: unknown returned status\n"), dsk->drive, dsk->model);
231 break;
232 }
233 free(degree);
234 }
235
236
237 void do_direct_mode(struct disk *ldisks) {
238 struct disk *dsk;
239
240 for(dsk = ldisks; dsk; dsk = dsk->next) {
241 display_temperature(dsk);
242 }
243
244 if(debug) {
245 printf(_("\n"
246 "If one of the field value seems to match the temperature, be sure to read\n"
247 "the hddtemp man page before sending a report (section REPORT). Thanks.\n"
248 ));
249 }
250 }
251
252
253 int main(int argc, char* argv[]) {
254 int i, c, lindex = 0, db_loaded = 0;
255 int ret = 0;
256 int show_db;
257 struct disk * ldisks;
258
259 backtrace_sigsegv();
260 backtrace_sigill();
261 backtrace_sigbus();
262
263 setlocale (LC_ALL, "");
264 bindtextdomain (PACKAGE, LOCALEDIR);
265 textdomain (PACKAGE);
266
267 show_db = debug = numeric = quiet = wakeup = af_hint = syslog_interval = foreground = 0;
268 unit = DEFAULT;
269 portnum = PORT_NUMBER;
270 listen_addr = NULL;
271
272 /* Parse command line */
273 optind = 0;
274 while (1) {
275 static struct option long_options[] = {
276 {"help", 0, NULL, 'h'},
277 {"quiet", 0, NULL, 'q'},
278 {"daemon", 0, NULL, 'd'},
279 {"drivebase", 0, NULL, 'b'},
280 {"debug", 0, NULL, 'D'},
281 {"file", 1, NULL, 'f'},
282 {"foreground", 0, NULL, 'F'},
283 {"listen", 1, NULL, 'l'},
284 {"version", 0, NULL, 'v'},
285 {"port", 1, NULL, 'p'},
286 {"separator", 1, NULL, 's'},
287 {"numeric", 0, NULL, 'n'},
288 {"unit", 1, NULL, 'u'},
289 {"syslog", 1, NULL, 'S'},
290 {"wake-up", 0, NULL, 'w'},
291 {0, 0, 0, 0}
292 };
293
294 c = getopt_long (argc, argv, "bDdf:l:hp:qs:u:vnw46FS:", long_options, &lindex);
295 if (c == -1)
296 break;
297
298 switch (c) {
299 case 'q':
300 quiet = 1;
301 break;
302 case '4':
303 af_hint = AF_INET;
304 break;
305 case '6':
306 af_hint = AF_INET6;
307 break;
308 case 'b':
309 show_db = 1;
310 break;
311 case 'd':
312 tcp_daemon = 1;
313 break;
314 case 'D':
315 debug = 1;
316 break;
317 case 'f':
318 database_path = optarg;
319 break;
320 case 's':
321 separator = optarg[0];
322 if(separator == '\0') {
323 fprintf(stderr, _("ERROR: invalid separator.\n"));
324 exit(1);
325 }
326 break;
327 case 'p':
328 {
329 char *end = NULL;
330
331 portnum = strtol(optarg, &end, 10);
332
333 if(errno == ERANGE || end == optarg || *end != '\0' || portnum < 1) {
334 fprintf(stderr, _("ERROR: invalid port number.\n"));
335 exit(1);
336 }
337 }
338 break;
339 case 'u':
340 switch(*optarg) {
341 case 'c':
342 case 'C':
343 unit = CELSIUS;
344 break;
345 case 'f':
346 case 'F':
347 unit = FAHRENHEIT;
348 break;
349 }
350 break;
351 case 'l':
352 listen_addr = optarg;
353 break;
354 case '?':
355 case 'h':
356 printf(_(" Usage: hddtemp [OPTIONS] [TYPE:]DISK1 [[TYPE:]DISK2]...\n"
357 "\n"
358 " hddtemp displays the temperature of drives supplied in argument.\n"
359 " Drives must support S.M.A.R.T.\n"
360 "\n"
361 " TYPE could be SATA, PATA or SCSI. If omitted hddtemp will try to guess.\n"
362 "\n"
363 " -b --drivebase : display database file content that allow hddtemp to\n"
364 " recognize supported drives.\n"
365 " -D --debug : display various S.M.A.R.T. fields and their values.\n"
366 " Useful to find a value that seems to match the\n"
367 " temperature and/or to send me a report.\n"
368 " (done for every drive supplied).\n"
369 " -d --daemon : run hddtemp in TCP/IP daemon mode (port %d by default.)\n"
370 " -f --file=FILE : specify database file to use.\n"
371 " -F --foreground : don't daemonize, stay in foreground.\n"
372 " -l --listen=addr : listen on a specific interface (in TCP/IP daemon mode).\n"
373 " -n --numeric : print only the temperature.\n"
374 " -p --port=# : port to listen to (in TCP/IP daemon mode).\n"
375 " -s --separator=C : separator to use between fields (in TCP/IP daemon mode).\n"
376 " -S --syslog=s : log temperature to syslog every s seconds.\n"
377 " -u --unit=[C|F] : force output temperature either in Celsius or Fahrenheit.\n"
378 " -q --quiet : do not check if the drive is supported.\n"
379 " -v --version : display hddtemp version number.\n"
380 " -w --wake-up : wake-up the drive if need.\n"
381 " -4 : listen on IPv4 sockets only.\n"
382 " -6 : listen on IPv6 sockets only.\n"
383 "\n"
384 "Report bugs or new drives to <hddtemp@guzu.net>.\n"),
385 PORT_NUMBER);
386 break;
387 case 'v':
388 printf(_("hddtemp version %s\n"), VERSION);
389 exit(0);
390 break;
391 case 'n':
392 numeric = 1;
393 break;
394 case 'w':
395 wakeup = 1;
396 break;
397 case 'S':
398 {
399 char *end = NULL;
400
401 syslog_interval = strtol(optarg, &end, 10);
402
403 if(errno == ERANGE || end == optarg || *end != '\0' || syslog_interval < 1) {
404 fprintf(stderr, _("ERROR: invalid interval.\n"));
405 exit(1);
406 }
407 }
408 break;
409 case 'F':
410 foreground = 1;
411 break;
412 default:
413 exit(1);
414 }
415 }
416
417 if(show_db) {
418 load_database(database_path);
419 display_supported_drives();
420 exit(0);
421 }
422
423 if(argc - optind <= 0) {
424 fprintf(stderr, _("Too few arguments: you must specify one drive, at least.\n"));
425 exit(1);
426 }
427
428 if(debug) {
429 /* argc = optind + 1;*/
430 quiet = 1;
431 }
432
433 if(debug && (tcp_daemon || syslog_interval != 0)) {
434 fprintf(stderr, _("ERROR: can't use --debug and --daemon or --syslog options together.\n"));
435 exit(1);
436 }
437
438 init_bus_types();
439
440 /* collect disks informations */
441 ldisks = NULL;
442 for(i = argc - 1; i >= optind; i--) {
443 struct disk *dsk = (struct disk *) malloc(sizeof(struct disk));
444 char *p;
445
446 assert(dsk);
447
448 memset(dsk, 0, sizeof(*dsk));
449
450 p = strchr(argv[i], ':');
451 if(p == NULL)
452 dsk->drive = argv[i];
453 else {
454 char *q;
455 int j;
456
457 /* upper case type */
458 for(q = argv[i]; q != p; q++)
459 *q = (char) toupper(*q);
460
461 /* force bus type */
462 for(j = 0; j < BUS_TYPE_MAX; j++) {
463 if(bus[j] &&
464 bus[j]->name &&
465 strncmp(bus[j]->name, argv[i], p - argv[i] - 1) == 0)
466 {
467 dsk->type = j;
468 break;
469 }
470 }
471
472 dsk->drive = p + 1;
473 }
474
475 dsk->next = ldisks;
476 ldisks = dsk;
477
478 errno = 0;
479 dsk->errormsg[0] = '\0';
480 if( (dsk->fd = open(dsk->drive, O_RDONLY | O_NONBLOCK)) < 0) {
481 snprintf(dsk->errormsg, MAX_ERRORMSG_SIZE, "open: %s\n", strerror(errno));
482 dsk->type = ERROR;
483 ret = 1;
484 continue;
485 }
486
487 if( ! dsk->type ) {
488 dsk->type = probe_bus_type(dsk);
489 }
490
491 if(dsk->type == BUS_UNKNOWN) {
492 fprintf(stderr, _("ERROR: %s: can't determine bus type (or this bus type is unknown)\n"), dsk->drive);
493
494 ldisks = dsk->next;
495 free(dsk);
496 ret = 1;
497 continue;
498 }
499
500 dsk->model = bus[dsk->type]->model(dsk->fd);
501 dsk->value = -1;
502 if(dsk->type != BUS_SCSI) {
503 struct harddrive_entry *dbe;
504
505 if(!db_loaded) {
506 load_database(database_path);
507 db_loaded = 1;
508 }
509
510 dsk->db_entry = (struct harddrive_entry *)malloc(sizeof(struct harddrive_entry));
511 dbe = is_a_supported_drive(dsk->model);
512 if(dbe)
513 memcpy(dsk->db_entry, dbe, sizeof(struct harddrive_entry));
514 else {
515 dsk->db_entry->regexp = "";
516 dsk->db_entry->description = "";
517 dsk->db_entry->attribute_id = DEFAULT_ATTRIBUTE_ID;
518 dsk->db_entry->unit = 'C';
519 dsk->db_entry->next = NULL;
520 }
521 }
522 }
523
524 free_database();
525 if(tcp_daemon || syslog_interval != 0) {
526 do_daemon_mode(ldisks);
527 }
528 else {
529 do_direct_mode(ldisks);
530 }
531
532 return ret;
533 }
Machine Code Window
Dump of assembler code from 0x4e7b to 0x4f7b:
0x0000000000004e7b <do_direct_mode+171>: add $0x8,%rsp
0x0000000000004e7f <do_direct_mode+175>: pop %rbx
0x0000000000004e80 <do_direct_mode+176>: pop %rbp
0x0000000000004e81 <do_direct_mode+177>: pop %r12
0x0000000000004e83 <do_direct_mode+179>: pop %r13
0x0000000000004e85 <do_direct_mode+181>: pop %r14
0x0000000000004e87 <do_direct_mode+183>: pop %r15
0x0000000000004e89 <do_direct_mode+185>: retq
0x0000000000004e8a <do_direct_mode+186>: nopw 0x0(%rax,%rax,1)
0x0000000000004e90 <do_direct_mode+192>: mov 0x18(%rbx),%r13
0x0000000000004e94 <do_direct_mode+196>: lea 0x1cf5(%rip),%rsi # 0x6b90
0x0000000000004e9b <do_direct_mode+203>: xor %edi,%edi
0x0000000000004e9d <do_direct_mode+205>: mov $0x5,%edx
0x0000000000004ea2 <do_direct_mode+210>: callq 0x2800 <dcgettext@plt>
0x0000000000004ea7 <do_direct_mode+215>: lea 0x1b6c(%rip),%rdx # 0x6a1a
0x0000000000004eae <do_direct_mode+222>: mov %rax,%rsi
0x0000000000004eb1 <do_direct_mode+225>: mov %r13,%rcx
0x0000000000004eb4 <do_direct_mode+228>: xor %eax,%eax
0x0000000000004eb6 <do_direct_mode+230>: mov $0x1,%edi
0x0000000000004ebb <do_direct_mode+235>: callq 0x2a80 <__printf_chk@plt>
0x0000000000004ec0 <do_direct_mode+240>: mov 0x20(%rbx),%eax
0x0000000000004ec3 <do_direct_mode+243>: test %eax,%eax
0x0000000000004ec5 <do_direct_mode+245>: jne 0x4e0e <do_direct_mode+62>
0x0000000000004ecb <do_direct_mode+251>: jmpq 0x4e47 <do_direct_mode+119>
0x0000000000004ed0 <do_direct_mode+256>: xor %eax,%eax
0x0000000000004ed2 <do_direct_mode+258>: callq 0x6550 <degree_sign>
0x0000000000004ed7 <do_direct_mode+263>: cmp $0x5,%r13d
0x0000000000004edb <do_direct_mode+267>: mov %rax,%r14
0x0000000000004ede <do_direct_mode+270>: ja 0x5070 <do_direct_mode+672>
0x0000000000004ee4 <do_direct_mode+276>: movslq (%r12,%r13,4),%rax
0x0000000000004ee8 <do_direct_mode+280>: add %r12,%rax
0x0000000000004eeb <do_direct_mode+283>: jmpq *%rax
0x0000000000004eed <do_direct_mode+285>: nopl (%rax)
0x0000000000004ef0 <do_direct_mode+288>: lea 0x1e39(%rip),%rsi # 0x6d30
0x0000000000004ef7 <do_direct_mode+295>: xor %edi,%edi
0x0000000000004ef9 <do_direct_mode+297>: mov $0x5,%edx
0x0000000000004efe <do_direct_mode+302>: callq 0x2800 <dcgettext@plt>
0x0000000000004f03 <do_direct_mode+307>: add $0x8,%rsp
0x0000000000004f07 <do_direct_mode+311>: mov %rax,%rsi
0x0000000000004f0a <do_direct_mode+314>: mov $0x1,%edi
0x0000000000004f0f <do_direct_mode+319>: pop %rbx
0x0000000000004f10 <do_direct_mode+320>: pop %rbp
0x0000000000004f11 <do_direct_mode+321>: pop %r12
0x0000000000004f13 <do_direct_mode+323>: pop %r13
0x0000000000004f15 <do_direct_mode+325>: pop %r14
0x0000000000004f17 <do_direct_mode+327>: pop %r15
0x0000000000004f19 <do_direct_mode+329>: xor %eax,%eax
0x0000000000004f1b <do_direct_mode+331>: jmpq 0x2a80 <__printf_chk@plt>
0x0000000000004f20 <do_direct_mode+336>: mov 0x205b46(%rip),%esi # 0x20aa6c <numeric>
0x0000000000004f26 <do_direct_mode+342>: test %esi,%esi
0x0000000000004f28 <do_direct_mode+344>: je 0x4f38 <do_direct_mode+360>
0x0000000000004f2a <do_direct_mode+346>: mov 0x205b40(%rip),%ecx # 0x20aa70 <quiet>
0x0000000000004f30 <do_direct_mode+352>: test %ecx,%ecx
0x0000000000004f32 <do_direct_mode+354>: jne 0x5108 <do_direct_mode+824>
0x0000000000004f38 <do_direct_mode+360>: mov 0x18(%rbx),%r15
0x0000000000004f3c <do_direct_mode+364>: mov 0x10(%rbx),%r13
0x0000000000004f40 <do_direct_mode+368>: mov $0x5,%edx
0x0000000000004f45 <do_direct_mode+373>: lea 0x1d74(%rip),%rsi # 0x6cc0
0x0000000000004f4c <do_direct_mode+380>: jmpq 0x5084 <do_direct_mode+692>
0x0000000000004f51 <do_direct_mode+385>: nopl 0x0(%rax)
0x0000000000004f58 <do_direct_mode+392>: mov 0x205b0d(%rip),%r8d # 0x20aa6c <numeric>
0x0000000000004f5f <do_direct_mode+399>: test %r8d,%r8d
0x0000000000004f62 <do_direct_mode+402>: je 0x4f72 <do_direct_mode+418>
0x0000000000004f64 <do_direct_mode+404>: mov 0x205b06(%rip),%edi # 0x20aa70 <quiet>
0x0000000000004f6a <do_direct_mode+410>: test %edi,%edi
0x0000000000004f6c <do_direct_mode+412>: jne 0x5108 <do_direct_mode+824>
0x0000000000004f72 <do_direct_mode+418>: mov 0x18(%rbx),%r15
0x0000000000004f76 <do_direct_mode+422>: mov 0x10(%rbx),%r13
0x0000000000004f7a <do_direct_mode+426>: mov $0x5,%edx
End of assembler dump.
comprends plus .
je voulais savoir quel code est éxécuté et quand ?
comment hddtemp va t il chercher les infos S.M.A.R.T. des disques ?
à quelles routines fait il appel ?
je comprends rien ...
peut être je suis pas encore prêt au débuggage .?
si pour vous tout çà est clair , pour moi pas du tout !
peut être je sais pas me servir des outils ?
Dernière modification par Debian Alain (16-02-2019 16:15:22)