Issues with syslog on Raspbian using gnu c++ 11 - c

Ok so I am having problems with syslog on Raspbian Stretch. I am trying to write to /var/log/blah.log using local0 as my facility. I am using gnu C++ 11 As the application is being written in C++ so I trying to create a logging class.
My /etc/syslog.conf has the following entry
local0.* /var/log/blah.log
... and I have restarted the service and the Pi.
My code to open the log is as follows:
setlogmask(LOG_UPTO(LOG_DEBUG));
openlog(blah, LOG_PERROR | LOG_CONS | LOG_NDELAY, LOG_LOCAL0);
...and my logging code is:
syslog(LOG_INFO | LOG_LOCAL0, fullMessage.c_str());
There is no /var/log/blah.log file created and no log entries written, although the message is written to the console as I am using LOG_CONS.
If I replace LOG_LOCAL0 with LOG_USER I am successfully able write to user.log.
I do want to be able to write to the custom log file because:
a) it is easy to ask a user to look at that file for debugging purposes
b) it should work!!
As I have stated I have looked through the numerous posts on this site and others and still cannot get it top work so posting links to man pages and other articles won't help!

Related

What is the difference between kobject, device_create and my code?

I am currently reading a book entitled "Linux device drivers" from O'Reilly.
Thing is that this book imo isn't really a guide on how to write drivers but it instead explains all the apis and their prinicples.
So I tried writing a small driver -which doesn't do anything interesting -with what I read so far.
Thing is:
I don't know which file I can execute cat on or echo to in order to invoke my callback functions
it looks nothing like all the other code snippets I found online
The different pieces of code:
my code (https://paste.ubuntu.com/p/8tVyTJTPBQ/)
creates:
$ls /sys/module/main/
oresize holders initsize initstate notes refcnt sections srcversion taint uevent
no new entry in /dev
code snippet using device_create: https://paste.ubuntu.com/p/cJxjdyXjhX/ source
creates:
$ ls /sys/module/main/
coresize holders initsize initstate notes refcnt sections srcversion taint uevent
$ ls -l /dev/ebbchar
crw------- 1 root root 238, 0 Mai 28 07:52 /dev/ebbchar
code using kobjects: https://paste.ubuntu.com/p/nt3XvZs7vF/ source
creates:
$ls -l /sys/kernel/
drwxr-xr-x 2 root root 0 Dec 17 16:29 etx_sysfs
I can see that my code successfully created a bunch of files under /sys/kernel. Now what is the difference in endgoal between my code and the two other snippets? Should I use device_create/kobjects or maybe none of those? The book I am reading doesn't mention anywhere the functions used by the 2 other pieces of code. So not sure which way I am supposed to follow...
Thanks_xe
device_create() creates a device and registers it with sysfs, and create necessary kobjects.
To create necessary kobjects, kobject-related functions(kobject_init(), kobject_add(), ...) are called in device_create().
If you need to create a device, you should call one of device creation functions like device_create().
Answering your question of how to keep up with latest api- Most api if renamed or updated retain similar name and reside mostly in the same header file so a quick grep on the source or easier is http://elixir.bootlin.com/ and search the source doc for a particular function in the Linux release you are working on. if you cant find the API in that release then go through the header to find the new API as the name will almost be the same for example when you will read the Timer chapter , you will find that setup_timer() has been changed to timer_setup(). and few other changes here and there.
If you feel like you can keep up with the latest discussion by subscribing to the kernel maillist or reading the documentation.

C program exits giving error ORA-12162: TNS:net service name is incorrectly specified

I am working on a remote red-hat server and there I'm developing a c application to insert data in to a remote oracle database. So first i installed the OCI instant client rpm on the server and tried to compile a sample program. after certain linkages I could compile it. But then when I am going to run it. It exits giving an error saying
ORA-12162: TNS:net service name is incorrectly specified
The sample code I used is from the blog (refer to this code in case you need to clarify the things.where I’m quoting only few pieces to this post) René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle
(refer to this code in case you need to clarify the things.where I’m quoting only few pieces to this post)
In the code I added some prints to check for the error And it seems like It gets stuck in the OCIServerAttach() function r gives a printed walue of -1
r=OCIServerAttach(srv, err, dbname, strlen(dbname), (ub4) OCI_DEFAULT);
printf("r value %d",r);
if (r != OCI_SUCCESS) {
checkerr(err, r);
goto clean_up;
}
Another point is that in the compilation process it gives a warning saying that a certain libry is not include. but the exicutable file is created. Here is the massage I get in the compilation process.
[laksithe#loancust ~]$ gcc -L$ORACLE_HOME/lib/ -L$ORACLE_HOME/rdbms/lib/ -o oci_test oci_test.o -L/usr/lib/oracle/12.1/client64/lib -lclntsh `cat $ORACLE_HOME/lib/sysliblist`
cat: /lib/sysliblist: No such file or directory
Going through the web I found that by creating a tnsnames.ora file with the connection details I could solve the problem. But even It didn't work for me. Here is the link for that blog blog
It has been a week since this error and I cold'nt solve it. could someone please help me.
connection string format I used is abc.ghi.com:1521/JKLMN
My recommendation is to bypass tnsnames completely. Oracle has always allowed you to put in the direct connection details, but EZConnect makes that even easier.
When you format your connection string, instead of listing the TNS name, use the actual connection properties in the following format:
servername:port/service name
For Example
MyOracle.MyCompany.Com:1521/SalesReporting
Your connection string might also require direct=true, but I'm honestly not sure.
I like the idea of tnsnames, but it's a double edged sword. When it works, it's great. When it doesn't, you want to throw something. With EZConnect, it always works.
By the way, if you don't know the properties of the three items above, find a machine that connect via tnsnames and:
tnsping <your TNS-named database>

How to read the kernel log messages in c?

I want to develop a C function that the return the last 5 messages of the kernel log (dmesg).
How I can do that?
I think you want klogctl. An example of usage is in the busybox source for dmesg.c.

Can't Find "Syslog.conf" in linux kernal 2.6.37.6 created with BuysBox v1.19.3

I created a tiny OS for my controller with Linux kernel 2.6.37.6 with the help of BusyBox and tool chain. I am writing a logging module(C program) in it and i want customized logs(customized path for different logs) like in /log/.
I have syslogd in my machine and /etc/syslog.conf supposed to present in my machine but it's not it the place. I created new syslog.conf under /etc but still i can't find my logs in desired place.
But if i run command syslogd -O /log/Controller.log all logs started to redirect to this (specified file). So i want to know where is the configuration file for this syslogd i can't find the configuration file for it.
Is there any way that i can write a module(program) for LOGS without requiring syslog.conf and yes of course traditional printf way. Problem is that for customized paths for log we need to give keyname LOG_LOCAL1 in openlog() as a argument but it's not working
I followed procedure from this examples http://www.codealias.info/technotes/syslog_simple_example
If you are using Busybox's syslogd then there is no support of syslog.conf,all logs are written to /var/log/messages by default.
You can modify code of syslogd in busybox which is located in busybox/sysklogd/syslogd.c for your desire behaviour
You can change code of syslogd like this
static const struct init_globals init_data = {
.logFile = {
.path = "your desire path",
.fd = -1,
},

Streaming a remote file

i'm new to fmod, and I'm trying to use it for a simple application.
I just need to open a remote music file (mostly mp3, and if that can help I can transcode on the server to always have mp3).
When I try to
FMOD_System_CreateSound(system, "http://somewhere.com/song.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &song);
That works fine, it open and play the mp3 fine.
But, when I try to do what I realy need :
FMOD_System_CreateSound(system, "http://somewhere.com/somepage.view?id=4324324324556546456457567456ef3345&var=thing", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &song);
It just don't works.
That link for example would return a stream.mp3 file, but FMOD just fail on it.
Is there a way to make it works ?
I guess the problem is FMOD just don't find the filename in the link, but I can't change the link :/
If it's not possible, is there a way to make fmod works with curl (curl download the file perfectly), like a function to call for each part of the file ?
Thanks
The main issue with session ID based URLs is they can get quite long. Old versions of FMOD only supported 256 characters (causing truncation and failure to load), but any recent supported version allows up to 1024 characters.
I would recommend updating to a more recent version of FMOD and report back if you have any troubles.

Resources