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

Wednesday, May 11, 2011

printk within uptime

All you have to do:
Turn on the CONFIG_PRINTK_TIME kernel option

Wala~You get it!

Sunday, January 09, 2011

select function does not stop

I use named FIFO and select function to do IPC programming. When program execute to "if(select(myfd+d, myfdSet, NULL, NULL, &waittime) > 0 && IS_SET(myfdSet))", it always fulfill condition even there is no any process wrote into named FIFO.
After I examin again, I find out that I open file as "O_RDONLY". Refer to Linux's man page, there is a section to discript it:


Under Linux, select() may report a socket file descriptor as "ready for reading", while nevertheless a subsequent read blocks.

Hence, I modify open statement from myfd = open("/tmp/a", O_RDONLY) to myfd = open("/tmp/a", O_RDWR|O_NONBLOCK). Everything is perfect right.

Tuesday, May 18, 2010

oldmenuconfig

When we build linux kernel, we have to configure via menuconfig, gconfig or xconfig first. “make menuconfig” generate some auto header files(include/linux/autoconf.h, include/config/auto.conf, include/config/autoconf.cmd … etc). In my developing environment, we have pre-configure file and copy this pre-configure to Linux kernel source directory. Unfortunate, we also have old auto header files and they are not updated. Once I compile kernel modules before I update auto header files, the outcome is incorrect. In this case, we issue “make oldconfig” once before we compile kernel modules.

FYI:
linuxtopia:Chapter 7. Upgrading a kernel: http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/ch07s03.html

Thursday, August 20, 2009

PPP dial on Demand

We set a set of private IP address for local and remote. When users request a connection, device sends a packet to remove to launch PPP dialing up.

In general case, we always the same dummy IP address set such as 10.64.64.64 for local and 10.112.112.112 for remote (Please refer to IPCP). There are a lot of user may confuse why my device always sends strange traffic to 10.112.112.112. Some applications of PPP use the previously IP which is assigned by PPP server to prevent this occurs.
We can also start to negotiate via using address 0.0.0.0 rather than 10.64.64.64. If you use PPP in linux, you can modify "ifaddr" as following configurations:

set ifaddr 10.64.64.64/0 10.112.112.112/0 255.255.255.255

Tuesday, December 02, 2008

some gcc extensions in the linux kernel

Here are some gcc extensions syntax in the linux kernel.
1. typeof(VARIABLE): You can find this at list_head related macros
2.range extension
3.zero-length arrays. IEEE 1394.
4. __builtin_expect. Layer II entry point use likely() and unlikely()
5.__builtin_prefetch. You can find this at list_head related macros

More details, visit IBM developer works
FYI:
IBM GCC hacks in the linux kernel

Monday, October 20, 2008

Communication over ethernet mac layer without TCP/IP part 1

I use two different o.s. at a embedded system. Altohough, there are so many solutations such as broadcast, IP sockets, non-reliable IP-less protocol and so on, but they can not meet our requerments.

Here are my concept:
A protocol must base on ethernet layer II and has capability to do TCP-friendly stuff. The requerments are below:
  • Can set or get system parameter between A and B.
  • This protocol must be extendable from dual systems to multiple systems.
  • It can not fix at client and server mode. These two (or more) system can be client and server at the same time.
  • We can transfer large file or multipart request/response over a transaction. And the upper layer applications do not have to worry about fragmentations.
  • This protocol must provide Event/Notify. A could register events which is occurred at B. After registation, B must send notify while some events happened.
Here are issues:
  1. How to define session and transations?
  2. How to encoding payload ?
  3. How to implement re-transmit ?
  4. others

Tuesday, October 14, 2008

Change pipe to non-blocking mode

The default pipe(...) is one blocking fd. If you need non-blocking IO, you can refer fowling sample code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(void) {
int fd[2], pipeAttr;
/*fd[0] for reader, fd[1] for writer*/
pipe(fd);
fnctl(fd[0], pipeAttr, F_GETFL);
pipeAttr |= O_NONBLOCK;
fnctl(fd[0], F_SETFL,
pipeAttr);
do_something(fd);
close(fd[0]);
close(fd[1]);
}
viod do_something(int fd[]) {
/*......*/
}

Zombie while create child thread

I use pthread_create(...) to generate child thread. The child thread becomes zombie after I termite program. After some "google" pages, the answer comes out: join child thread at main process.

errno.h

If you want to use errno at c program, you must include errno.h not declare "extern int errno".

char *strerror(int) is used to display error text.

There are two related header files at kernel source directory:
include/$(ARCH)/errno.h
asm-generic/errno-base.h

Thursday, July 24, 2008

10 essential tricks for admins from IBM

Vallard Benincosa posted article about how to administrate linux. Here are one of ticks:
Trick 3: Collaboration with screen

David, the high-maintenance user from product engineering, calls: "I need you to help me understand why I can't compile supercode.c on these new machines you deployed."

"Fine," you say. "What machine are you on?"

David responds: " Posh." (Yes, this fictional company has named its five production servers in honor of the Spice Girls.) OK, you say. You exercise your godlike root powers and on another machine become David:

# su - david

Then you go over to posh:

# ssh posh

Once you are there, you run:

# screen -S foo

Then you holler at David:

"Hey David, run the following command on your terminal: # screen -x foo."

This will cause your and David's sessions to be joined together in the holy Linux shell. You can type or he can type, but you'll both see what the other is doing. This saves you from walking to the other floor and lets you both have equal control. The benefit is that David can watch your troubleshooting skills and see exactly how you solve problems.

At last you both see what the problem is: David's compile script hard-coded an old directory that does not exist on this new server. You mount it, recompile, solve the problem, and David goes back to work. You then go back to whatever lazy activity you were doing before.

The one caveat to this trick is that you both need to be logged in as the same user. Other cool things you can do with the screen command include having multiple windows and split screens. Read the man pages for more on that.

But I'll give you one last tip while you're in your screen session. To detach from it and leave it open, type: Ctrl-A D . (I mean, hold down the Ctrl key and strike the A key. Then push the D key.)

You can then reattach by running the screen -x foo command again.



FYI:
Lazy Linux: 10 essential tricks for admins (http://www.ibm.com/developerworks/linux/library/l-10sysadtips/index.html)

Monday, June 30, 2008

Wine

I need to use IE sometimes, and there is one thing, I should run IE on Linux. The first thought is "Setup a Microsoft windows", but I do not setup one. So, I need a package to be a VM or provide Windows API on Linux. Finally, Wine is my best choose.

By Wine, it is easy for you to use windows applications on Linux platform. Here are inductions from Wine web site:

Wine is an Open Source implementation of the Windows API on top of X, OpenGL, and Unix.

Think of Wine as a compatibility layer for running Windows programs. Wine does not require Microsoft Windows, as it is a completely free alternative implementation of the Windows API consisting of 100% non-Microsoft code, however Wine can optionally use native Windows DLLs if they are available. Wine provides both a development toolkit for porting Windows source code to Unix as well as a program loader, allowing many unmodified Windows programs to run on x86-based Unixes, including Linux, FreeBSD, Mac OS X, and Solaris.

More information can be read in the articles Why Wine is so important, and Debunking Wine Myths. If you are wondering how well a particular application works in Wine, please examine the Applications Database. For installation instructions and step-by-step help with running Wine, take a look at the User Guide.

Wine is free software. The licensing terms are the GNU Lesser General Public License version 2.1.



FYI:
http://www.winehq.org/

Thursday, June 12, 2008

SELinux enable smab and ftp login

setsebool -P samba_enable_home_dirs=1
setsebool -P ftp_home_dir=1

Saturday, May 17, 2008

Chang default IGMP version in Linux

Set default IGMP version of your NICs is 2:

echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version

Set default IGMP version of your NICs is 3:

echo 3 > /proc/sys/net/ipv4/conf/all/force_igmp_version

jiffies comparison

If you want to compare time in kernel module, you can user flowing macro to avoid jiffies overflow :
/*in kernel/linux/include/linux/jiffies.h*/
time_after(a,b)
time_before(a,b)
time_after_eq(a,b)
time_before_eq(a,b)

If you compare jiffies directly, you will get wrong result sometimes.

Monday, February 18, 2008

Ask user change password at first login

After you add a user and set default password. If you want to this user change his/her password at first time login, there are some command you can issue:

1.usermod -L USERNAME
2.chage -d 0 USERNAME
3.usermod -U USERNAME


FYI:
Red Hat Knowledgebase

Thursday, January 24, 2008

group file and shadow file

I manually modify /etc/group file, so the shadow file does not up-to-date. The will be fine when I use this server, but if I edit user/group information by GUI tool, it will pop up complain message. There are some commands to solve this problem pwconv, pwunconv, grpconv, and grpunconv. From man page, you can totally know how to use it.
FYI:
pwconv creates shadow from passwd and an optionally existing shadow.

pwunconv creates passwd from passwd and shadow and then removes shadow.

grpconv creates gshadow from group and an optionally existing gshadow.

grpunconv creates group from group and gshadow and then removes

Sunday, January 13, 2008

PHP permission denied

If you use SeLinux, there is a little bit modification. Because the security problmes, you must tell your system that which modules is trusted. After you run "apachectl start" and the unhappy error shows below:
XXXX. PHP5 cannot restore segment prot afterreloc: Permission denied
You should disable SELinux or issue "chcon -t texrel_shlib_t /usr/local/apache2/modules/*.so"

Tuesday, December 25, 2007

The wrong settings in fstab crash

I modified file /etc/fstab and the modification was incorrect. The tragedy happened. I can not boot normal. When boot sequences go to mount device which record in fstab, then system boot failed. When system failed, there are two choices : one is entering fix state the other is booting again. In fix state, the file system is read only, so, you can do nothing about that. Finally, I use boot-disk and choose "linux rescue" to solve this stupid problem.

Friday, December 14, 2007

Iptables allow BOOTPS/PC

dhcp use udp with port 67 and 68.


iptables -t filter -FORWARD -p udp --dport 67:68 --sport 67:68 -j ACCEPT

FYI:
Iptables Tutorial 1.1.19