-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMachineData.cpp
More file actions
697 lines (611 loc) · 21.5 KB
/
MachineData.cpp
File metadata and controls
697 lines (611 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
#include "TkUtil/MachineData.h"
#include "TkUtil/MemoryError.h"
#include "TkUtil/NumericServices.h"
#include "TkUtil/Exception.h"
#include "TkUtil/NumericConversions.h"
#include "TkUtil/Process.h"
#include "TkUtil/UTF8String.h"
#include "TkUtil/UtilInfos.h"
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h> // getenv
#include <float.h> // FLT_DIG, DBL_DIG
#include <errno.h>
#include <sys/utsname.h>
#include <limits>
#include <string.h>
#include <iostream>
#include <strstream>
#include <iomanip>
#include <memory>
USING_STD
BEGIN_NAMESPACE_UTIL
static const Charset charset ("àéèùô");
// ============================================================================
// LA CLASSE OperatingSystem
// ============================================================================
OperatingSystem * OperatingSystem::_currentOS = 0;
OperatingSystem::OperatingSystem ( )
: _name ( ), _distribution (OS_DISTRIBUTION), _version ("0.0.0"), _infos ( ), _numericInfos ( )
{
errno = 0;
struct utsname osInfos;
int retVal = uname (&osInfos);
if (-1 == retVal)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << strerror (errno) << ".";
errno = 0;
} // if (-1 == retVal)
else
{
setName (osInfos.sysname);
try
{
setVersion (Version (osInfos.release));
}
catch (const Exception& exc)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << exc.getFullMessage ( ) << ".";
}
catch (...)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << "Erreur non documentée." << ".";
}
setInformations (osInfos.version);
} // else if (0 != retVal)
try
{
UTF8String numericInfos (charset);
numericInfos
<< "Reels double precision : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::doubleSize << '\n'
<< "Max ........................... : "
<< NumericServices::doubleMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::doubleMachMin ( )
<< '\n'
<< "Infini ........................ : "
<< NumericServices::doubleMachInfinity ( )
<< '\n'
<< "Epsilon ....................... : "
<< NumericServices::doubleMachEpsilon ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::doubleDigitsMax
<< " (mantisse complete)" << '\n'
<< "Reels double precision longs : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::longDoubleSize << '\n'
<< "Max ........................... : "
<< NumericServices::longDoubleMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::longDoubleMachMin ( )
<< '\n'
<< "Infini ........................ : "
<< NumericServices::longDoubleMachInfinity ( )
<< '\n'
<< "Epsilon ....................... : "
<< NumericServices::longDoubleMachEpsilon ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< " (mantisse complete)" << NumericServices::longDoubleDigitsMax
<< '\n'
<< "Reels simple precision : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::floatSize << '\n'
<< "Max ........................... : "
<< NumericServices::floatMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::floatMachMin ( )
<< '\n'
<< "Infini ........................ : "
<< NumericServices::floatMachInfinity ( )
<< '\n'
<< "Epsilon ....................... : "
<< NumericServices::floatMachEpsilon ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::floatDigitsMax
<< " (mantisse complete)" << '\n'
<< "Caracteres (char) : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::charSize << '\n'
<< "Max ........................... : "
<< NumericConversions::toStr (
(short)NumericServices::charMachMax ( ))
<< '\n'
<< "Min ........................... : "
<< NumericConversions::toStr (
(short)NumericServices::charMachMin ( ))
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::charDigitsMax
<< '\n'
<< "Caracteres non signes (unsigned char) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::unsignedCharSize
<< '\n'
<< "Max ........................... : "
<< NumericConversions::toStr (
(unsigned short)NumericServices::unsignedCharMachMax ( ))
<< '\n'
<< "Min ........................... : "
<< NumericConversions::toStr (
(unsigned short)NumericServices::unsignedCharMachMin ( ))
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::unsignedCharDigitsMax
<< '\n'
<< "Caracteres longs non signes (wchar_t, usage unicode) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::wcharSize << '\n'
<< "Max ........................... : "
<< NumericConversions::toStr (
(WChar_t)NumericServices::wcharMachMax ( ))
<< '\n'
<< "Min ........................... : "
<< NumericConversions::toStr (
(WChar_t)NumericServices::wcharMachMin ( ))
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::wcharDigitsMax
<< '\n'
<< "Entiers courts (short) : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::shortSize << '\n'
<< "Max ........................... : "
<< NumericServices::shortMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::shortMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::shortDigitsMax
<< '\n'
<< "Entiers courts non signes (unsigned short) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::unsignedShortSize
<< '\n'
<< "Max ........................... : "
<< NumericConversions::toStr (
NumericServices::unsignedShortMachMax ( ))
<< '\n'
<< "Min ........................... : "
<< NumericConversions::toStr (
NumericServices::unsignedShortMachMin ( ))
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::unsignedShortDigitsMax
<< '\n'
<< "Entiers (int) : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::intSize << '\n'
<< "Max ........................... : "
<< (long)NumericServices::intMachMax ( )
<< '\n'
<< "Min ........................... : "
<< (long)NumericServices::intMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::intDigitsMax
<< '\n'
<< "Entiers non signes (unsigned int) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::unsignedIntSize
<< '\n'
<< "Max ........................... : "
<< (unsigned long)NumericServices::unsignedIntMachMax ( )
<< '\n'
<< "Min ........................... : "
<< (unsigned long)NumericServices::unsignedIntMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::unsignedIntDigitsMax
<< '\n'
<< "Entiers longs (long) : " << '\n'
<< "Taille en octets .............. : "
<< NumericServices::longSize << '\n'
<< "Max ........................... : "
<< NumericServices::longMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::longMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::longDigitsMax
<< '\n'
<< "Entiers longs non signes (unsigned long) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::unsignedLongSize
<< '\n'
<< "Max ........................... : "
<< NumericServices::unsignedLongMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::unsignedLongMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::unsignedLongDigitsMax
<< '\n'
<< "Entiers longs longs (long long) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::longLongSize << '\n'
<< "Max ........................... : "
<< NumericServices::longLongMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::longLongMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::longLongDigitsMax
<< '\n'
<< "Entiers longs longs non signes (unsigned long long) : "
<< '\n'
<< "Taille en octets .............. : "
<< NumericServices::unsignedLongLongSize
<< '\n'
<< "Max ........................... : "
<< NumericServices::unsignedLongLongMachMax ( )
<< '\n'
<< "Min ........................... : "
<< NumericServices::unsignedLongLongMachMin ( )
<< '\n'
<< "Chiffres significatifs garantis : "
<< NumericServices::unsignedLongLongDigitsMax
<< '\n';
// numericInfos.utf8 ( ) : copie directe du buffer, mais ne doit contenir que des caractères ASCII.
setNumericInformations (numericInfos.utf8 ( ));
}
catch (const Exception& exc)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations numériques sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << exc.getFullMessage ( ) << ".";
}
catch (const exception& e)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations numériques sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << e.what ( ) << ".";
}
catch (...)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations numériques sur le système d'exploitation de la machine "
<< MachineData::instance ( ).getCurrentHostName ( ) << " : " << co_endl << "Erreur non documentée." << ".";
}
} // OperatingSystem::OperatingSystem
OperatingSystem::OperatingSystem (const string& name, const Version& version, const string& infos, const string& numericInfos)
: _name (name), _version (version), _distribution (OS_DISTRIBUTION), _infos (infos), _numericInfos (numericInfos)
{
} // OperatingSystem::OperatingSystem
OperatingSystem::OperatingSystem (const OperatingSystem& os)
: _name (os._name), _distribution (OS_DISTRIBUTION), _version (os._version), _infos (os._infos), _numericInfos (os._numericInfos)
{
} // OperatingSystem::OperatingSystem
const OperatingSystem& OperatingSystem::instance ( )
{
if (0 == _currentOS)
_currentOS = new OperatingSystem ( );
return *_currentOS;
} // OperatingSystem::instance
// ============================================================================
// LA CLASSE MachineData
// ============================================================================
MachineData* MachineData::_currentMachine = 0;
bool MachineData::_instanciated = false; // Lib non instanciée
MachineData::MachineData ( )
: NetworkData ( ), _processorNum ((size_t)-1), _operatingSystem (OperatingSystem::instance ( )), _hardware ( )
{
// LE CODE DOIT ETRE LE MEME DANS MachineData::MachineData (char) POUR MachineData::_currentMachine.
long nbProcs = -1;
#ifdef _SC_NPROCESSORS_ONLN
nbProcs = sysconf (_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
nbProcs = sysconf (_SC_NPROC_ONLN);
#else
ConsoleOutput::cout ( )
<< "ERREUR dans MachineData::MachineData : détermination impossible du nombre de processeurs de la machine " << getHostName ( ) << co_endl << "\a";
#endif // _SC_NPROCESSORS_ONLN
_processorNum = (size_t)nbProcs;
errno = 0;
struct utsname osInfos;
int retVal = uname (&osInfos);
if (-1 == retVal)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations sur le système matériel de la machine "
<< getCurrentHostName ( ) << " : " << co_endl << strerror (errno) << ".";
errno = 0;
} // if (-1 == retVal)
else
_hardware = osInfos.machine;
} // MachineData::MachineData ( )
MachineData::MachineData (const MachineData& machine)
: NetworkData (machine), _processorNum (machine._processorNum), _operatingSystem (machine._operatingSystem), _hardware (machine._hardware)
{
} // MachineData::MachineData (const MachineData&)
MachineData::MachineData (char)
: NetworkData ( ), _processorNum ((size_t)-1), _operatingSystem (OperatingSystem::instance ( )), _hardware ( )
{
if (true == _instanciated) // v 2.27.0
{ // Protection contre les (dé)chargements multiples de la bibliothèque
UTF8String message (charset);
message << "ATTENTION. Chargement de la version " << UtilInfos::getVersion ( ).getVersion ( )
<< " de la bibliothèque TkUtil. Cette bibliothèque est déjà chargée, et ce second chargement risque de provoquer un "
<< "comportement anormal, voire un plantage, du logiciel."
<< "\nErreur détectée en ligne " << (unsigned long)__LINE__ << " du fichier " << (unsigned long)__FILE__ << "\n";
ConsoleOutput::cout ( ) << message << co_endl;
} // if (true == _instanciated)
_instanciated = true;
// CODE IDENTIQUE MachineData::MachineData ( ) :
long nbProcs = -1;
#ifdef _SC_NPROCESSORS_ONLN
nbProcs = sysconf (_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
nbProcs = sysconf (_SC_NPROC_ONLN);
#else
ConsoleOutput::cout ( )
<< "ERREUR dans MachineData::MachineData : détermination impossible du nombre de processeurs de la machine " << getHostName ( ) << co_endl << "\a";
#endif // _SC_NPROCESSORS_ONLN
_processorNum = (size_t)nbProcs;
errno = 0;
struct utsname osInfos;
int retVal = uname (&osInfos);
if (-1 == retVal)
{
ConsoleOutput::cout ( )
<< "Erreur lors de l'initialisation des informations sur le système matériel de la machine "
<< getCurrentHostName ( ) << " : " << co_endl << strerror (errno) << ".";
errno = 0;
} // if (-1 == retVal)
else
_hardware = osInfos.machine;
// FIN CODE IDENTIQUE MachineData::MachineData ( ) :
} // MachineData::MachineData
MachineData& MachineData::operator = (const MachineData& machine)
{
if (&machine != this)
{
_processorNum = machine._processorNum;
_operatingSystem = machine._operatingSystem;
_hardware = machine._hardware;
} // if (&machine != this)
return *this;
} // MachineData::operator =
MachineData::~MachineData ( )
{
if (_currentMachine == this) // v 2.27.0
{ // Protection contre les (dé)chargements multiples de la bibliothèque
if (false == _instanciated)
{
ConsoleOutput::cout ( )
<< "ATTENTION. Déchargement de la version " << UtilInfos::getVersion ( ).getVersion ( )
<< " de la bibliothèque TkUtil. Cette bibliothèque est déjà déchargée, et ce second déchargement risque de provoquer "
<< "comportement anormal, voire un plantage, du logiciel." << co_endl
<< "Erreur détectée en ligne " << (unsigned long)__LINE__ << " du fichier " << (unsigned long)__FILE__ << co_endl;
} // if (false == _instanciated)
_instanciated = false;
} // if (_currentMachine == this)
} // MachineData::~MachineData
const MachineData& MachineData::instance ( ) // v 4.0.0
{
if (0 == _currentMachine)
_currentMachine = new MachineData ((char)0);
return *_currentMachine;
} // MachineData::instance
bool MachineData::isRemoteHost ( )
{
size_t pos = 0;
// SSH_CLIENT :
// En cas de connexion sur une autre machine :
// IP_départ Port_départ Port_machine où départ est la machine
// d'où l'on vient et machine celle où est effectué le getenv.
const char* sshClient = getenv ("SSH_CLIENT");
const string strSClient (NULL == sshClient ? "" : sshClient);
// SSH_CONNECTION :
// En cas de connexion sur une autre machine :
// IP_départ Port_départ IP_machine Port_machine où départ est la machine
// d'où l'on vient et machine celle où est effectué le getenv.
const char* sshConnection = getenv ("SSH_CONNECTION");
const string strSConnection (NULL == sshConnection ? "" : sshConnection);
// SSH_AUTH_SOCK :
// Identifie le socket de communication avec l'agent ssh => semble
// unique sur la station de login, quelque soit le screen, et absent si on
// est logué sur une autre machine.
// Non testé
// const char* sshAuthSock = getenv ("SSH_AUTH_SOCK");
// const string strSAuthSock (NULL == sshAuthSock ? "" : sshAuthSock);
// Cette machine :
NetworkData localHost;
const vector<string> localIPs = localHost.getInetAddr ( );
// On souhaite être sous SSH :
if ((NULL != sshClient) || (NULL != sshConnection))
{
string cltIP;
if (false == strSClient.empty ( ))
{
pos = strSClient.find (' ');
if (string::npos != pos)
cltIP = strSClient.substr (0, pos);
} // if (false == strSClient.empty ( ))
if (true == cltIP.empty ( ))
{
pos = strSConnection.find (' ');
if (string::npos != pos)
cltIP = strSConnection.substr (0, pos);
} // if (true == cltIP.empty ( ))
if (false == cltIP.empty ( ))
{
for (vector<string>::const_iterator it = localIPs.begin ( );
it != localIPs.end ( ); it++)
if (*it == cltIP)
// Hautement improbable, suppose qu'on ait fait ssh départ
return false;
// Pas trouvé => on s'est logué sur une autre machine.
return true;
} // if (false == cltIP.empty ( ))
} // if ((NULL != sshClient) || (NULL != sshConnection))
// Peut être n'est on pas sous SSH.
const char* display = getenv ("DISPLAY");
const string strDisplay (NULL == display ? "" : display);
if (0 == strDisplay.find (":0"))
return false;
pos = strDisplay.find (":");
string machine = strDisplay.substr (0, pos);
if (false == machine.empty ( ))
{
if (machine == "localhost") // SSH pour X11 tunneling
return true;
NetworkData displayHost (machine);
const vector<string> displayIPs = displayHost.getInetAddr ( );
for (vector<string>::const_iterator itd = displayIPs.begin ( );
displayIPs.end ( ) != itd; itd++)
for (vector<string>::const_iterator itl = localIPs.begin ( );
itl != localIPs.end ( ); itl++)
if (*itl == *itd)
return false;
// Pas d'IP commune alors qu'elles devraient toutes être communes :
return true;
} // if (false == machine.empty ( ))
return false;
} // MachineData::isRemoteHost
bool MachineData::isVirtualMachine ( ) // v 5.12.0
{
static bool first = true;
static bool vm = false;
if (true == first)
{
string output, line;
if (false == vm)
{
try
{ // v 5.12.1 : facter
unique_ptr<Process> facter (new Process ("facter"));
CHECK_NULL_PTR_ERROR (facter.get ( ))
facter->getOptions ( ).addOption ("virtual");
facter->enableChildToSonCommunications ( );
facter->execute (false);
line = facter->getChildLine ( ); // physical, kvm, ovirt, ...
output.clear ( );
while (false == line.empty ( ))
{
output += line;
try
{
line = facter->getChildLine ( );
}
catch (...)
{
line.clear ( );
}
} // while (false == line.empty ( ))
if (NULL != strcasestr (output.c_str ( ), "physical"))
vm = false;
}
catch (...)
{
cerr << "Détection du caractère virtuel de la machine courante : commande facter non trouvée." << endl;
}
} // if (false == vm)
if (false == vm)
{
try
{
unique_ptr<Process> dmesg (new Process ("dmesg"));
CHECK_NULL_PTR_ERROR (dmesg.get ( ))
/* Rem : le | ne semble pas fonctionner via la classe Process. Enchaînement de processus ?
dmesg->getOptions ( ).addOption ("|");
dmesg->getOptions ( ).addOption ("grep");
dmesg->getOptions ( ).addOption ("-i");
dmesg->getOptions ( ).addOption ("hypervisor detected"); */
dmesg->enableChildToSonCommunications ( );
dmesg->execute (false);
line = dmesg->getChildLine ( );
output.clear ( );
while (false == line.empty ( ))
{
output += line;
try
{
line = dmesg->getChildLine ( );
}
catch (...)
{
line.clear ( );
}
} // while (false == line.empty ( ))
if (NULL != strcasestr (output.c_str ( ), "hypervisor detected"))
vm = true;
}
catch (...)
{
cerr << "Détection du caractère virtuel de la machine courante : commande dmesg non trouvée." << endl;
}
} // if (false == vm)
if (false == vm)
{
try
{
unique_ptr<Process> lshw (new Process ("lshw"));
CHECK_NULL_PTR_ERROR (lshw.get ( ))
/* Rem : le | ne semble pas fonctionner via la classe Process. Enchaînement de processus ?
lshw->getOptions ( ).addOption ("|");
lshw->getOptions ( ).addOption ("grep");
lshw->getOptions ( ).addOption ("-i");
lshw->getOptions ( ).addOption ("qemu"); */
lshw->enableChildToSonCommunications ( );
lshw->execute (false);
string line = lshw->getChildLine ( );
output.clear ( );
while (false == line.empty ( ))
{
output += line;
try
{
line = lshw->getChildLine ( );
}
catch (...)
{
line.clear ( );
}
} // while (false == line.empty ( ))
if (NULL != strcasestr (output.c_str ( ), "qemu"))
vm = true;
}
catch (...)
{
cerr << "Détection du caractère virtuel de la machine courante : commande lshw non trouvée." << endl;
}
} // if (false == vm)
first = false;
} // if (true == first)
return vm;
} // MachineData::isVirtualMachine
unsigned short MachineData::floatSignificantNumeral ( )
{
return FLT_DIG;
} // MachineData::floatSignificantNumeral
unsigned short MachineData::doubleSignificantNumeral ( )
{
return DBL_DIG;
} // MachineData::doubleSignificantNumeral
END_NAMESPACE_UTIL