Click here

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, April 20, 2018

ldconfig , to set library path in linux

LDCONFIG
( Where are the Libs ? )


Sometimes when you install a program from source it can complain that a certain library is missing . . . and still you know that the lib it is complaining about is actually installed on your system. But most likely it is not on the default place ( /usr/lib ) where the program looks for the lib.

There is a file on your system where all the paths to the libraries are mentioned: the /etc/ld.so.conf file. Here is an example of the /etc/ld.so.conf file on Slackware:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib


So, what's the solution ?

1). First locate the lib the program is complaining about, maybe it is in /usr/lib/qt/lib or in /usr/include or any other odd location.

2). Next add the path to that lib in the /etc/ld.so.conf file. So, for our example the /etc/ld.so.conf file would look like:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib
/usr/lib/qt/lib
/usr/include

3). Finally to let the system know that you updated the /etc/ld.so.conf file and make it use the new values give the command:
CODE
# ldconfig

Tuesday, March 14, 2017

Debugging Signals- Log the PID of the sender

Suppose if your program randomly crashes  and you find that some process is sending SIGTERM to your program , you can find the process ID of the sender using "sigaction"


 You need to use sigaction call to set up your signal handler instead of signal. Doing so will let you set up a signal handler that takes three parameters:

  • An int, for the signal number (just like signal)
  • A siginfo_t *, which is a structure containing all sorts of information about the source of the signal, including the pid of the sender if applicable. (It also includes some information about the cause of the signal for automatic signals like SIGSEGV.)
  • A ucontext_t *, which has to do with which thread got the signal. Mostly ignorable


Example code and steps:

1) catchsignal.c

"/* Example of using sigaction() to setup a signal handler with 3 arguments
 * including siginfo_t.
 */
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
 
static void hdl (int sig, siginfo_t *siginfo, void *context)
{
 printf ("Sending PID: %ld, UID: %ld\n",
   (long)siginfo->si_pid, (long)siginfo->si_uid);
}
 
int main (int argc, char *argv[])
{
 struct sigaction act;
 
 memset (&act, '\0', sizeof(act));
 
 /* Use the sa_sigaction field because the handles has two additional parameters */
 act.sa_sigaction = &hdl;
 
 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
 act.sa_flags = SA_SIGINFO;
 
 if (sigaction(SIGTERM, &act, NULL) < 0) {
  perror ("sigaction");
  return 1;
 }
 
 while (1)
  sleep (10);
 
 return 0;
}

2) Compile the program 
    gcc -o catchsignal catchsignal.c


3) Shell script to trigger a signal 

sendsig.sh
#!/bin/sh
while [ 1 ]
do
    pidof=`ps -ef | grep catchsignal | grep -v "grep" | awk  '{print $2}'`
    if [ ! -z $pidof ]
    then
        kill $pidof
    fi
sleep 10
done

4) Execute the script
   sh sendsig.sh

5) Run the program 
    ./catchsignal


6) Output of the program


Sending PID: 18532, UID: 0 
Sending PID: 18532, UID: 0
Sending PID: 18532, UID: 0



Sunday, February 9, 2014

Compiling and Running 32 bit UML on 64 bit Debian operating system

Steps followed
============
1) apt-get install uml-utilities
2) sudo apt-get install gcc-multilib
C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
http://stackoverflow.com/questions/12591629/gcc-cannot-find-bits-predefs-h-on-i686
Since we are compiling the UML kernel for 32 bit in 64 bit operating system, we need a gcc-multilib package to solve the library issues
3) #include<sys/stat.h> in ./arch/um/os-Linux/mem.c
http://stackoverflow.com/questions/5918539/c-warning-implicit-declaration-of-function-fchmod
4) The below patch needs to be applied
 In some cases gcc >= 4.5.2 will optimize away current_thread_info().
To prevent gcc from doing so the stack address has to be obtained
via inline asm.

LKML-Reference: http://marc.info/?i=201104132150.05623.richard@...>

Acked-by: Kirill A. Shutemov <kirill@...>
Signed-off-by: Richard Weinberger <richard@...>
---
 arch/um/include/asm/thread_info.h |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h
index e2cf786..5bd1bad 100644
--- a/arch/um/include/asm/thread_info.h
+++ b/arch/um/include/asm/thread_info.h
@@ -49,7 +49,10 @@ static inline struct thread_info *current_thread_info(void)
 {
         struct thread_info *ti;
         unsigned long mask = THREAD_SIZE - 1;
-       ti = (struct thread_info *) (((unsigned long) &ti) & ~mask);
+       void *p;
+
+       asm volatile ("" : "=r" (p) : "0" (&ti));
+       ti = (struct thread_info *) (((unsigned long)p) & ~mask);
         return ti;
 }

--
1.7.4.2

http://sourceforge.net/mailarchive/message.php?msg_id=27397459

Compilation steps
================
1) make mrproper ARCH=um
2) make menuconfig ARCH=um SUBARCH=i386
http://uml.devloop.org.uk/faq.html
3) make ARCH=um SUBARCH=i386

Friday, January 10, 2014

Useful Linux commands - Part 1


11) apropos : To find the related command for the given string
e.g. apropos “wireless” listed the wireless related commands as given below
# apropos wireless
crda (8)             - send to the kernel a wireless regulatory domain for a given ISO / IEC 3166 alpha2
iw (8)               - show / manipulate wireless devices and their configuration
pbmtowbmp (1)        - convert a portable bitmap to a wireless bitmap (wbmp) file
regulatory.bin (5)   - The Linux wireless regulatory database
wbmptopbm (1)        - convert a wireless bitmap (wbmp) file to a portable bitmap (pbm)

22) lsusb : To see mounted USB devices.
33) lspci : To see mounted pci devices.
44) df : To see disk usage and mount point
55) cat /proc/tty/driver/usbserial : To list all the connected GSM m

Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunda...