Time discrepancy between 'dmesg' and 'date' in Linux - c

I have some kernel module which prints to log like
printk(KERN_INFO "Something\n");
When module was loaded I found that the time in dmesg outruns the current time in date:
-bash-4.4$ dmesg -T | grep some_driver
[Sat May 16 22:25:03 2020] some_driver: Something
-bash-4.4$ date
Sat May 16 22:22:02 UTC 2020
What could be the reason?
P.S. Linux kernel version is 4.4, it lives in VMware vSphere VM.

Related

In Ubuntu 18.04 after installing clamav, clamscan not working. After googling I did freshclam, that's failing download

I have installed clamav in Ubuntu 18.04 using
'''sudo apt-get install clamav'''
and tried clamscan but showing the error as follows:
LibClamAV Error: cli_loaddbdir(): No supported database files found in /var/lib/clamav
ERROR: Can't open file or directory
----------- SCAN SUMMARY -----------
Known viruses: 0
Engine version: 0.102.1
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 0.004 sec (0 m 0 s)
***
After googling I removed entire clamav, installed again and tried sudo freshclam command, but showing the following error all times when clamav is updating:
Mon Jan 27 21:51:53 2020 -> ^Download failed (28) Mon Jan 27 21:51:53 2020 -> ^ Message: Timeout was reached
Mon Jan 27 21:51:53 2020 -> ^getcvd: Can't download daily.cvd from https://database.clamav.net/daily.cvd
Mon Jan 27 21:51:53 2020 -> Trying again in 5 secs...
^CMon Jan 27 21:51:57 2020 -> Update process terminated
It consumed my entire data and at final I terminated the process. I tried it more that 5 times, same result persist. Anybody please help me to figure out this issue.
Also I need to know which AV is better for Ubuntu Clamav or Comodo?
Thanks
It seems to be timing out getting the virus definition database. Are you able to connect directly to https://database.clamav.net/daily.cvd
It's a fairly large file (~58 MB) so it might not work if you're on a limited connection.

C program delivers only the UTC time as localtime on Linux using GCC

I have a C program that runs on two different RHEL6 servers that are configured with the same timezone. The C program uses the time functions from time.h. On one of the servers the local time is correctly determined, on the other one the UTC (default) time is displayed independent from the configured timezone.
I've tried to see if the link to /etc/localtime is broken but it's a correct softlink to /usr/share/zoneinfo/<timezone> (in this case Europe/Berlin).
I've inspected the timezone file with zdump and the content of the file is correct. The timezone and time of the system is also correctly displayed using date. There is no definition of the $TZ variable in my bash or anywhere else!
As an additional test I have run the follwing code with and without a $TZ variable:
::time_t aclock;
::tm tm_tmp;
::tm *newtime;
setenv("TZ", "Europe/Berlin", 1);
tzset();
::time( &aclock );
newtime = ::localtime_r( &aclock, &tm_tmp );
printf("\nDEBUG TIME: %d ", aclock);
printf("\nDEBUG TIMEZONE: %s \n", newtime->tm_zone);
printf("DEBUG HOUR: %d \n", newtime->tm_hour);
Using the code above and setting TZ parameter differently I get the following outputs on the faulty server, assuming that the server time is Europe/Berlin, CEST at this moment:
without setenv:
DEBUG TIME: 1524241319
DEBUG TIMEZONE: UTC
DEBUG HOUR: 16
setenv("TZ", "Europe/Berlin", 1);
DEBUG TIME: 1524241319
DEBUG TIMEZONE: Europe
DEBUG HOUR: 16
setenv("TZ", "/etc/localtime", 1);
DEBUG TIME: 1524241319
DEBUG TIMEZONE: CEST
DEBUG HOUR: 18
So it looks like the "Europe/Berlin" time cannot be found, as the UTC time is displayed and the timezone "Europe" is invalid.
As I said the output / behavior on the other machine is the expected one:
without setenv:
DEBUG TIME: 1524241711
DEBUG TIMEZONE: CEST
DEBUG HOUR: 18
setenv("TZ", "Europe/Berlin", 1);
DEBUG TIME: 1524241711
DEBUG TIMEZONE: CEST
DEBUG HOUR: 18
setenv("TZ", "/etc/localtime", 1);
DEBUG TIME: 1524241711
DEBUG TIMEZONE: CEST
DEBUG HOUR: 18
P.S. the same gcc version 4.4.7 is used on both machines.
Is it possible that my timezone database is corrupt on the faulty server? Has someone faced similar problem and solve it?
I finally figured out, that the problem was the libc.so library, which was differently compiled for one of the machines and only used for some C applications excepting linux himself. This explains why date delivers the wright output but the C program not.
Using ldd libc.so I've found out that the linker was also set to be at the path /home/mqm/lib as default, which dosn't fit to my server /home/mqm/lib/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2. To resume, here is the full solution:
Problem: Your Linux system is delivering the wright date and time using date or some applications but wrong output using C programs.
Solution: After ensuring that there is no programming error in your code, check with
strace -e trace=open,close,read,write,connect,accept yourCProgram
which path is used to get the time/timezone. You can also check ldd libc.so to see where the default path of the linker is.
If the paths are not corresponding to your linux system configuration, consider recompiling the C library to fit to your system configuration or set $TZ='fullpathtotimezone' as a hotfix / workaround.

How to mount the huge tlb (huge page) as a file system?

Here is my machine details (ubuntu):
$uname -a
Linux rex-think 3.13.0-46-generic #76-Ubuntu SMP Thu Feb 26 18:52:13 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
I have enabled huge page in root user with:
$echo 20 > /proc/sys/vm/nr_hugepages
Now I want to mount huge page as a file system and open it for read/write, e.g., using the C API below
#define FILE_NAME "/mnt/hugepages/hello"
fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755); // writing to huge page using file sys API
But I am not sure how to mount the huge page. In /proc/sys/vm/, I can see
hugetlb_shm_group
hugepages_treat_as_movable
but from the description here, I dont think they are the files I am looking for.
To mount huge tlp as file system use the below command
mount -t hugetlbfs nodev /mnt/huge

bumblebee + wine + directx9 not working

I'm trying to run dxdiag or any other DX9 game from bumblebee+wine and no luck. These games works well without bumblebee in integrated graphic card. And no wine soft works well with bumblebee.
primusrun
$ primusrun bash
$ wine dxdiag
primus: warning: recreating incompatible pbuffer
primus: warning: recreating incompatible pbuffer
$
syslog output:
rtkit-daemon[2489]: Successfully made thread 23036 of process 23036 (n/a) owned by '1000' RT at priority 3.
rtkit-daemon[2489]: Supervising 1 threads of 1 processes of 1 users.
kernel: [147774.078061] bbswitch: enabling discrete graphics
kernel: [147774.221739] pci 0000:01:00.0: power state changed by ACPI to D0
kernel: [147774.245670] vgaarb: device changed decodes: PCI:0000:01:00.0,olddecodes=none,decodes=none:owns=none
kernel: [147774.245900] NVRM: loading NVIDIA UNIX x86_64 Kernel Module 304.88 Wed Mar 27 14:26:46 PDT 2013
acpid: client 23009[0:1002] has disconnected
acpid: client 23009[0:1002] has disconnected
acpid: client connected from 23066[0:1002]
acpid: 1 client rule loaded
acpid: client connected from 23066[0:1002]
acpid: 1 client rule loaded
bumblebeed[11391]: [XORG] (WW) NVIDIA(0): Unable to get display device for DPI computation.
rtkit-daemon[2489]: Successfully made thread 23071 of process 23033 (n/a) owned by '1000' RT at priority 2.
rtkit-daemon[2489]: Supervising 2 threads of 2 processes of 1 users.
kernel: [147778.018119] bbswitch: disabling discrete graphics
kernel: [147778.030858] pci 0000:01:00.0: Refused to change power state, currently in D0
kernel: [147778.030896] pci 0000:01:00.0: power state changed by ACPI to D3cold
optirun has similar result:
$ optirun bash
$ wine dxdiag
[VGL] NOTICE: Pixel format of 2D X server does not match pixel format of
[VGL] Pbuffer. Disabling PBO readback.
$
The syslog has the same error with optirun:
bumblebeed[11391]: [XORG] (WW) NVIDIA(0): Unable to get display device for DPI computation.
Any help? thank you!
This may or may not help, but try installing the primus-libs-ia32 package, it may be a 32 bit application you're trying to run (if you're on a 64 bit system, this could be the problem).

Adding some extra info in uname -v output string in linux kernel

On my Linux machine when i run
uname -v
it gives me
#83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012
Now i am building my custom kernel and i need to show some flag/text info about build in this string ..
i want something like
if some config are on then add BUILD-XYZ in that string
#83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012 BUILD-XYZ
if not then add BUILD-ABC in that.
#83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012 BUILD-ABC
The variable CONFIG_LOCALVERSION (inside your kernel .config file) let you set a custom string that will be appended to the kernel release number, thus shown when using 'uname'.
Is that what you want?
There's a few ways to do this using GNU awk, here's one:
uname -v | awk '{ printf (/some config/) ? $0" BUILD-XYZ\n" : $0" BUILD-ABC\n" }'

Resources