Does VxWorks support strptime()? In Linux, I have a string that I would like to convert into the time structure, however I don't see that function in VxWorks. Do I have to roll my own?
Currently, no such function exists in VxWorks.
Related
I want to change system time on window os but i don't want to use kernel32.dll because my os will write an log entry ##
Pls help me.
In Python, you can try using the win32api.SetSystemTime. That is part of pywin32
Basically I'm wondering if I can compile code that a user inputs in a mac app (I'm trying to make an OCaml text editor that compiles your code) using executables that are already available in the user's system, such as ocamlc etc. I don't have any code to show or anything because I'm still figuring out if/how I could build this mac app. Not really sure what other info I should include, so just ask. Thanks!
You can use either Sys.command "<your shell command>" or Unix.open_process* and Unix.create_process commands. See man Sys and man Unix for more information.
In Objective-C, C, and C++, and a multitude of other languages, use system(3). Also see:
exec(3)
popen(3)
If you are using Objective-C, check out NSTask.
If not, look at popen. popen gives your parent process control over the I/O streams.
I'm trying to do ioctl command through Mono framework, but I cant find what I'm looking for.
I'm trying to send command to a DVB card that has a kernel module. I hope someone can link or explain clearly how this can be done. Any example with Mono using kernel modules would be useful I guess.
Mono does not contain a wrapper for ioctl in Mono.Unix, because ioctl call parameters vary greatly and such a wrapper would be almost useless. You should declare a DllImport for each ioctl you need.
You probably don't need a helper library written in C, however, you may need it during development to extract actual values hidden behind different C preprocessor macros. For example, to expand C header:
#define FE_GET_INFO _IOR('o', 61, struct dvb_frontend_info)
compile and execute this helper:
#include <linux/dvb/frontend.h>
#include <stdio.h>
int main()
{
printf("const int FE_GET_INFO = %d;\n", FE_GET_INFO);
return 0;
}
A short mono mailing list discussion on the topic.
ioctl isn't supported by Mono AFAIK. Too OS-specific and parameter list depends on actual request. You could try DLLImport
Interop with Native Libraries
You should write a wrapper library for your exact calls. Look at how Mono.Unix wraps syscalls (google codesearch for Mono.Unix Syscall.cs) to get the idea. Then create a wrapper for each specific ioctl command, which uses your own representation of the data.
As jitter said - you'll need to DLLImport the ioctl itself.
Check for my similar question, and later question on the subject. In this case I'm trying to wrap the Videl4Linux interface, that could be of interest for you.
I really suggest those readings.
I would like to be able to do one or more of the following from the shell:
- call any function from the program not only the main
- pass parameters that are not only strings (not only argv)
- have a program return not only int (the return code from main)
- assign returned values to shell-level variables to be able to pass them to other programs
You get the idea.
For instance python toplevel allow this for python programs.
What about C++?
Or a ELF replacement on linux that would allow that?
If you looking for an operating system that does this - the vxWorks shell/C interpreter does this.
But, it's vxWorks - a realtime operating system (no GUI).
It's not too difficult to come up with an app that allows you to call certain functions by name from dynamic libraries such as DLLs under Windows, provided those functions take only a limited selection of parameter types such as ints, floats and fixed strings.
However, for most C++ programs this is not sufficient. For example, suppose your C++ function takes s std::map of dynamic string to socket as a parameter - how are you going to create the map, to say nothing of its contents in your shell?
But if you can forgo C++, there is one language cum operating system that does exactly what you suggest - Smalltalk. If you are interested in this paradigm, take a look at Squeak, which is free software.
Under Windows, there is RUNDLL32 to call DLL function, eg
RUNDLL32.EXE USER32.DLL,SwapMouseButton
Have you looked at c-repl?
The system would have to be completely interpreted, right? And how would you know the function signatures of the things you were calling?
I'm writing a Linux kernel module that needs to open and read files. What's the best way to accomplish that?
Can I ask why are you trying to open a file?
I like to follow Linux development (out of curiosity, I'm not a kernel developer, I do Java), and I've seen discussion of this question before. I was able to find a LKML message about this, basically mentioning it's usually a bad idea. I'm almost positive that LWN covered it in the last year, but I'm having trouble finding the article.
If this is a private module (like for some custom hardware and the module won't be distributed) then you can do this, but I'm under the impression that if you are going to submit your code to the mainline then it may not be accepted.
Evan Teran mentioned sysfs, which seems like a good idea to me. If you really need to do harder custom stuff you could always make new ioctrls.
EDIT:
OK, I found the article I was looking for, it's from Linux Journal. It explains why doing this kind of stuff is generally a bad idea, then goes on to tell you exactly how to do it anyway.
assuming you can get pointers to the relavent function pointers to the open/read/close system calls, you can do something like this:
mm_segment_t fs = get_fs();
set_fs(KERNEL_DS);
fd = (*syscall_open)(file, flags, mode);
if(fd != -1) {
(*syscall_read)(fd, buf, size);
(*syscall_close)(fd);
}
set_fs(fs);
you will need to create the "syscall_*" function pointers I have shown though. I am sure there is a better way, but I believe that this would work.
Generally speaking, if you need to read/write files from a kernel module, you're doing something wrong architecturally.
There exist mechanisms (netlink for example - or just register a character device) to allow a kernel module to talk to a userspace helper process. That userspace helper process can do whatever it wants.
You could also implement a system call (or such like) to take a file descriptor opened in userspace and read/write it from the kernel.
This would probably be neater than trying to open files in kernel space.
There are some other things which already open files from kernel space, you could look at them (the loop driver springs to mind?).
/proc filesystem is also good for private use, and it's easy.
http://www.linuxtopia.org/online_books/Linux_Kernel_Module_Programming_Guide/x773.html
All of the kernel developers say that file I/O from kernel space is bad (especially if you're referring to these files by their paths) but the mainstream kernel does this when you load firmware. If you just need to read from files, use the
kernel_read_file_from_path(const char *path, void **buf, loff_t *size, loff_t max_size, enum kernel_read_file_id id)
function, which is what the firmware loader code uses, declared in include/linux/fs.h. This function returns a negative value on error.
I'm not really sure of the point of the id variable at the end, if you look at the code it's not really used, so just put something like READING_FIRMWARE there (no quotes).
buf is not null terminated, instead refer to its size in size. If you need it to be null terminated, create a string size + 1 bytes long and copy it over or rewrite the kernel_read_file() function (used by kernel_read_file_from_path(), defined in fs/exec.c) and add one to i_size where memory is allocated. (If you want to do this, you can redefine the kernel_read_file() function in your module with a different function name to avoid modifying the whole kernel.)
If you need to write to files, there is a kernel_write() function (analogous to kernel_read(), which is used by kernel_read_file() and therefore also by kernel_read_file_from_path()), but there is no kernel_write_file() or kernel_write_file_from_path() function. You can look at the code in the fs/exec.c file in the Linux kernel source tree where kernel_read_file() and kernel_read_file_from_path() are defined to write your own kernel_write_file() and kernel_write_file_from_path() functions that you can include in your module.
And as always, you can store a file's contents in a char pointer instead of a void pointer with this function by casting it.
You can also find some informations about sys_call_open in this Linux Kernel Module Programing Guide.