jeudi 12 juillet 2012

Debugging with strace

There are times when your software is failing but it doesn't output any error messages. Maybe you are getting a 500 error when you load a cgi script but the log is not telling you why. Strace can often help in situations like this.

Strace does not trace the internals of your application, it only knows about syscalls, or calls into the kernel. This can be enough in many cases to show you when your application might be trying to look for a file that is not there, or when it cannot allocate memory or some other error.

Generally I call strace with option -f so it will follow child processes, and then the name of the command to trace. To save the output to a file, use -o.

Code:
[josephw@myhost ~]$ strace -f -o strace.out ls /
bin   dev  home    lib         media  mnt  proc  sbin     space  sys  usr
boot  etc  initrd  lost+found  misc   opt  root  selinux  srv    tmp  var


[josephw@myhost ~]$ less strace.out
6368  execve("/bin/ls", ["ls", "/"], [/* 17 vars */]) = 0
6368  uname({sys="Linux", node="dss03.spry.com", ...}) = 0
6368  brk(0)                            = 0x8cc5000
6368  access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
6368  open("/etc/ld.so.cache", O_RDONLY) = 3
6368  fstat64(3, {st_mode=S_IFREG|0644, st_size=36486, ...}) = 0
6368  old_mmap(NULL, 36486, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f8f000
6368  close(3)                          = 0
6368  open("/lib/tls/librt.so.1", O_RDONLY) = 3

....output trimmed....
The first column shows the process id, and then you see the syscall and its result. Here it opens /etc/ld.so.cache in readonly mode, and the result is file descriptor 3. After this it calls fstat64 and old_mmap on file descriptor 3. Then it closes file descriptor 3. Once it has been closed, it can be reused as you see in the next call where it opens /lib/tls/librt.so.1.

In cases where you want to trace a process that is already running, pass the -p option to strace. I will run strace on Apache.
Code:
[josephw@myhost ~]$ ps aux |grep http
apache    6457  0.0  0.5 18764 5456 ?        S    Oct31   0:00 /usr/sbin/httpd
apache    6498  0.0  0.5 18764 5464 ?        S    Oct31   0:00 /usr/sbin/httpd
apache    6500  0.0  0.5 18768 6000 ?        S    Oct31   0:00 /usr/sbin/httpd
apache    6505  0.0  0.5 18768 6080 ?        S    Oct31   0:00 /usr/sbin/httpd
apache    6507  0.0  0.5 18764 5464 ?        S    Oct31   0:00 /usr/sbin/httpd
Here I have the process IDs for apache running on my box. Which one to trace? Pick one, then keep reloading your web site until the process you are tracing is the one that serves up your page. If the process does not belong to you, you will probably need to be root in order to trace it.
Code:
[root@myhost ~]# strace -f -o strace.out -p 6457 &
[root@myhost ~]# tail -f strace.out

....output trimmed....

21361 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/i686/sse2/libperl.so", O_RDONLY) = -1 ENOENT
 (No such file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/i686/sse2", 0xbfeca780) = -1 ENOENT (No su
ch file or directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/i686/libperl.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/i686", 0xbfeca780) = -1 ENOENT (No such fi
le or directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/sse2/libperl.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/sse2", 0xbfeca780) = -1 ENOENT (No such fi
le or directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls/libperl.so", O_RDONLY) = -1 ENOENT (No such
file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/tls", 0xbfeca780) = -1 ENOENT (No such file or
 directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/i686/sse2/libperl.so", O_RDONLY) = -1 ENOENT (No
 such file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/i686/sse2", 0xbfeca780) = -1 ENOENT (No such f
ile or directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/i686/libperl.so", O_RDONLY) = -1 ENOENT (No such
 file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/i686", 0xbfeca780) = -1 ENOENT (No such file o
r directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/sse2/libperl.so", O_RDONLY) = -1 ENOENT (No such
 file or directory)
21361 stat64("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/sse2", 0xbfeca780) = -1 ENOENT (No such file o
r directory)
21361 open("/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so", O_RDONLY) = 3

....output trimmed....
I ran strace in the background by using & so I could view the output of strace.out with tail -f. This way I could know when my process was the one that was doing the work. Then I reloaded my site about 5 times until it cycled around to process 6457.

In the beginning of the output shown, it may look like there is an error, because it keeps showing "No such file or directory" while trying to load libperl.so. But you can see that it is looking for the library in multiple paths and eventually it does find it in the directory /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/. In this case, the page was loaded without any errors. I will do it again, but this time I will try to load a page that does not exist, in this case http://10.2.4.15/test.
Code:
....output trimmed....

6457  lstat64("/usr/local/www/test", 0xbffb3104) = -1 ENOENT (No such file or directory)

....output trimmed....

6457  read(18, 0xbffb3270, 512)         = -1 ECONNRESET (Connection reset by peer)
6457  close(18)                         = 0
6457  read(5, 0xbffb347f, 1)            = -1 EAGAIN (Resource temporarily unavailable)
6457  semop(7307267, 0x1c9740, 1 <unfinished ...>
It tried to find /usr/local/www/test but could not so it failed in the end.
 
Source : http://forums.spry.com/howtos/1502-debugging-strace.html

vendredi 29 juin 2012

How to install nTOP 4 on CentOS 6 by RPM

nTOP is a Network Tap program. It displays a summary of network usage by machines on your network in a format reminiscent of the unix top utility. It can also be run in web mode, which allows the display to be browsed with a web browser.
1. Install RPMforge repo :
# rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Note : you can find the lastest of rpmforge repo at http://pkgs.repoforge.org/rpmforge-release
2. Install necessary packages for nTOP :
# yum install graphviz rrdtool rrdtool-devel geoip geoip-devel net-snmp-libs gdbm gdbm-devel
3. Install nTOP :
# cd /usr/src
# wget http://dl.marmotte.net/rpms/redhat/el6/x86_64/ntop-4.0.3-1.el6/ntop-4.0.3-1.el6.x86_64.rpm
# rpm -ivh ntop-4.0.3-1.el6.x86_64.rpm
# chkconfig ntop on
4. Set Admin password :
# ntop -A
5. Start nTOP service :
# service ntop start
6. Confirm nTOP is working :
# lsof -i :3000
# lsof -i :3001
Note : TCP 3000 for HTTP and TCP 3001 for HTTPs
7. Secure ntop access from outside :
a. Browse to https://ip-address.your.nTOP.server:3001
b. Click “Admin” > “Configure” > “Protect URLs”
c. Enter username “admin” and your password (set in step 4 above) when prompted.
d. Click “Add URL” then “Add URL” again.
NOTE: This will require a username and password to access https://ip-address.your.nTOP.server:3001

source  :  http://saroot.org/blog/how-to-install-ntop-4-on-centos-6-by-rmp-package/

jeudi 1 mars 2012

Cacti on Centos 5.7 en 10 étapes

1) Installer CentOS
2) Ajouter le dépot rpmforge :

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm

rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

3) Installer cacti et mysql-server :

yum install cacti mysql-server

4) Démarrer mysql-server :

/etc/init.d/mysql-server start

5) Config de sql-server :

/usr/bin/mysqladmin -u root password 'yourpassword'
/usr/bin/mysqladmin -u root -p create cacti

puis,

[root@cacti-appliance ~]# /usr/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.0.95 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'CACTIUSER-PASSWORD-GOES-HERE';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

5) Création de la base sql : 

/usr/bin/mysql cacti -u cactiuser -p < /var/www/cacti/cacti.sql

6) Modifier /var/www/cacti/include/config.php en indiquant le bon utilisateur (cactiuser) et le mot de passe


7) Modifier le fichier /etc/httpd/conf.d/cacti.conf pour permettre l'accès au serveur depuis d'autres machines/réseau

8) Démarrer le serveur web :  /etc/init.d/httpd start

9) Naviguer à l'adresse http://@IPduserveur/cacti/

10) Se laisser guider...

mercredi 30 novembre 2011

La recherche d'images inversées

Afin de savoir où l'on peut retrouver une image donnée sur sur le web, il existe des moteurs de recherche inversé.
Deux manières de faire :
- indiquer l'url de l'image
- uploader l'image recherchée dans le moteur

Plusieurs sites proposent ce système : Tineye et bien sur Google Image (en cliquant sur l'appareil photo afin de charger une image ou indiquer une url)





lundi 24 octobre 2011

Masquer son numéro de téléphone sans modifier la configuration de son téléphone

Il est facile de masquer son numéro sans pour autant modifier les paramètres de son téléphone.


Pour ce faire, il faut juste ajouter le préfixe #31# avant le numéro à composer.

vendredi 21 octobre 2011

Comment tomber directement sur le répondeur de son interlocuteur

Il est possible de tomber directement sur le répondeur d'un abonné SFR/Orange/Bouygues.








1) Identifier l'opérateur associé au numéro de téléphone. Il y a encore quelques années il était possible de déduire l'opérateur en se basant sur le début du numéro de téléphone. Avec la portabilité du numéro, cette méthode est de plus en plus aléatoire.

Quelques exemples :

SFR :
0603
0605
0606
0609 à 0629
0634 à 0636
0655

ORANGE :
0607 à 0608
0630 à 0633
0637
0642
0643
0645
0654
0670 à 0689

Bouygues Telecom :
0650
0653
0659
0660 à 0669
0698 à 0699

  • Est ce un abonné SFR ? https://monprofil.sfr.fr/monprofilWEB/publique/PNMAccueil
  • Est ce un abonné Orange ?
  • Est ce un abonné Bouygues ?
2) Ensuite, en fonction de l'opérateur la marche à suivre est différente :
  • Orange, composer le 06 80 80 80 80 
  • SFR, composer le  06 1000 1000
  • Bouygues, composer le 06 60 66 0001 
Dans les 3 cas, après avoir composer le numéro: il suffira ensuite de se laisser guider par le système qui demandera de composer le numéro de téléphone de la personne à qui l’ on veut laisser un message vocal sur le répondeur… et hop, on accède directement à la messagerie vocale sans que le téléphone de la personne ait sonné. 

Coté coût, c'est le même tarif que de téléphoner sur un portable.

 A noter qu'il existe des méthodes vraiment payante facilement trouvable sur le net.

mercredi 19 octobre 2011

Change timezone on CentOS - RedHat - Fedora

For exemple, for Paris :

cp /usr/share/zoneinfo/Europe/Paris /etc/localtime

Enjoy :)

jeudi 13 octobre 2011

Frédéric Lefebvre - Qu'est ce que le web 2.0 ?

Dire que ce brave messieurs nous fait de long discours sur le net.....encore une fois ça fait mal !




Emmanuel Todd

Sarkozy et l'identité nationale, décrypatge :




Hum un nouveau lan, qu'est ce qui se passe par là ?

1) Nmap

nmap -v -sP 192.168.240.0/24 | grep -v "appears to be down" | grep Host

mardi 11 octobre 2011

Accoustic...encore

Dans la continuité du précédent post, le site madmoizelle.tv propose quelques belles sessions acoustiques.

En passant un titre de Nneka "come with me"

TV5 Monde, Acoustic

J'ai découvert cette année cette émission qui passe sur TV5 monde...merci youtube.

Il est possible de revoir certains passages sur le site de TV5 et bien sur youtube


Au passage un hommage à la très regretté Lhassa


The Serge Gainsbourg Expérience aux trois baudets

Une découverte sur Arte en milieu d'année....raté d'un poil aux trois baudets...l'histoire se termina au bar :)


Il y en a qui maitrise....






Foutaises (court metrage de Jean-Pierre Jeunet)

Ca commence à dater un peu mais j'adore ce court métrage de Mister Jeunet

Visti & Meyland


Un chouette album un peu disco créé par des danois....à découvir


Une critique sur ce site

lundi 10 octobre 2011

Annuaire des revendeurs en matériels électoniques (Paris, Europe, Monde)

Pour Paris  
  • Selectronic, 11 Pl Nation, 75012, 01 55 25 88 00. Néon, Leds superbrite, ...
  • RAM, 131 bd Diderot 75012, 01 43 07 62 45, place nation. Matérial audio, cables, jack, pas mal de récup
  • St Quentin radio, 6 rue de St Quentin, 75010, 01 40 37 70 74, Gare du Nord. Beaux cable, bon matériel electro
  • Les Cyclades (Gare de Lyon) 11 bd Diderot 75012 PARIS, 01 46 28 91 54 . www.cyclades-elec.fr/ . Guirlande lumineuse 220v à découper, LEDs Varatech...
  • EspaceComposantElectro, 66 Rue de Montreuil 75011, 01 43 72 30 64 pas mal de recup, tres bon conseils
  • Pyrennées composants, rue des Pyrennées 75020, . www.compopyrennees.com/ . Cartes à puce, affaire sur les HP, ...
  • Les chinois de Arts et Metiers. Cable (casque walkman), leds blanches (torches), ...
  • Empire Electronique. Metro Anvers
  • Intercomposants, 127 Rue De Paris 91300 Massy
  • Electronic Diffusion, 43 r Victor Hugo 92240 MALAKOFF, 01 46 57 68 33 (pas mal de trucs genre QT...)
  • Perlor Radio Electronique, 25 rue Hérold 75001 Paris, 01 42 36 65 50 (grave les plaques, des fers a souder pas mal..)
  • Lextronic (http://www.lextronic.fr) 36/40 rue du Gal de Gaulle, 94510 La Queue en Brie , 01 45 76 83 88 (des compos exotiques, très riche, SchmartBoards, PCB...)

Specialized on Paris

  • Mille et une piles , nation, tout pour les portables, les batteries, les piles bizarres... de très bon conseil!
  • Girard et Sudron, Metro chemin vert, Bd beaumarchais ? ... tout sur les ampoules spécialisées (tech ou déco).

"Gros" (mean be a corporation to buy from 'em)

  • Orbitec (Clichy près Rue de Paris) : leds, BIG leds, matrice de leds, inter, microrupteurs (ceux des joy d'arcade), ...
  • Hervé (villemonble) : gradateurs lumière, DMX ...
  • Diltronic (St Germain en Laye), http://www.diltronic.com : importateur FTDI, acceleros...
  • gros catalogue détaillé par fournitures (info industriel) pour les commandes en gros ...

Catalogs

Source : http://www.arduino.cc/playground/Main/Resources

Vous trouverez sur ce site des informations pour les autres pays.

Remplacer la prise jack d'un casque

La prise jack de mon Sennheiser PX-100 étant capricieuse, l'article précédent est déjà obsolète pour moi.

Sur le site suivant (en anglais) un etre sympathique décortique les différentes étapes pour remplacer la prise jack de casque.

Source : http://boredass.blogspot.com/2008/05/sennheiser-px100.html

Sennheiser PX100

Yesterday, I busted my PX100, which was barely 1 month old. I was listening to music on the computer with my headphones on when I tried to stand up to walk to a nearby drawer. Obviously, the headphone's cables stopped me well short, the headphones themselves hanging haphazardly about my face after the strong jerk. The headphones are just too light for their own good: this has happened many many times, something that I never experienced with my old Phillips. But this time, I noticed something different after putting them back on properly on my ears. THERE IS NO SOUND FROM THE LEFT CHANNEL!
"Oh no!"- That was my first thought. Immediately, my hands went to the 3.5mm sound jack and I realized that the wire sticking out from the jack isn't straight as it was supposed to be. Timidly, I gave the wire a poke, straightening it and immediately the left channel went back on. The relief I felt after that was short lived due to the fact that dratted left went quiet again. That was when I realized that the jerk has broken free the left channel's wire from its solder.

Being a sea away from the nearest Sennheiser repair shop, I decided to go to some local electrical-supplies shop for help. What they told me is that I would need to replace the plug since there isn't a way for them to reach the wires without destroying the stock plug. Reluctantly, I gave them the green light and I watched in horror as one of them cut open the beautiful rubber protective cover of the plug revealing its insides. Surprisingly, the whole of the plug beneath the rubber coat is a huge chunk of white hard plastic and the guy decided that the whole thing has to go as well and went at it with a pair of ugly wire cutters. Now all that's left is the frayed wires- green and copper from one plus red and copper from the other. So he took out his soldering gun plus solder and tested it on my wire. After a few tries to gave everything back to me, frayed wires, broken 3.5mm jack and plastic coverings, telling me he can't help me since my wires wouldn't can't be soldered. Quoting him, "Those are special wires, our solders are not working on them."

Feeling rather dejected, I went back to my car with the 'junk' in my hands. At home I tried to find a short term solution to the problem by connecting the wires to the wires of a cut 3.5mm jack. Found out online that Red= right, Green= left and the copper wires from both wires are ground. No matter how sure I was about my set up, I just couldn't get sound to come out from the headphones. And so I called the Authorized dealer for Sennheiser products in Brunei and they directed me to another repair shop.

Next day I brought it to that place and the technician got down to work immediately. I was wondering about why he was using a blade to scrape at something on the frayed wires and he told me that these wires have a protective covering over them which must go before it can be soldered. He showed me what he meant and truly the unsolderable wires could be soldered after a few scrapes with a blade. Also he removed the yellowish fiber in the core of the individual wires.

And so, after a few minutes, 5 bucks and about 5 cm of the length of my cable, the headphones are working again.











































New 3.5mm jack , old 3.5mm jack with fiber, and green and red wires with plastic protector














Old jack and wires. Fibers coming out from the core of the green wire.













New jack with heat-shrink.



Autre lien :
http://bonplangratos.fr/soudure-prise-jack
http://forum.wda-fr.org/viewtopic.php?f=13&t=1832