Linux2010. 1. 11. 09:42
fork-exec로 실행한 프로그램의 리턴값을 받는 방법이다.
예를 들어 mount를 쉘에서 실행하고 그 결과값을 받고 싶을때 사용한다.

#include <sys/types.h>
#include <sys/wait.h>

WEXITSTATUS
(status)
    returns the exit status of the child. This consists of the least significant 16-8 bits of the status argument that the child specified in a call to exit() or _exit() or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.

[링크 : http://linux.die.net/man/2/waitpid]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/waitpid]
Posted by 구차니
Linux2010. 1. 8. 16:26
# mount -t ntfs-3g

머.. 이런식으로 실행하면 자동으로 mount.ntfs-3g 라는 파일을 찾아서 실행을 한다.
처음에는 오 졸라 신기해!!! 하면서 뻘짓으로 ..

make 과정중에 나온 intall-exec-hook 인줄 알고 파고 들었다가 웬걸 ㄱ-
아무튼 install-exec-hook은 설치후 trigger 식으로 실행해주는 루틴을 의미할 뿐,
execution hook 이랑은 연관이 없다. (젠장 된장 미네랄!)
[링크 : http://wiki.kldp.org/wiki.php/DocbookSgml/Autotools-KLDP]

아무튼, linux kernel utils 를 검색해서 mount.c 를 열어보니 busybox와는 다른 확연한 차이가 있었다.
일단 exec() 패밀리와 fork()를 사용하는 루틴의 존재유무

util-linux-2.12r/mount/mount.c

static int
check_special_mountprog(const char *spec, const char *node, const char *type,
			int flags, char *extra_opts, int *status) {
  char mountprog[120];
  struct stat statbuf;
  int res;

  if (!external_allowed)
      return 0;

  if (type && strlen(type) < 100) {
       sprintf(mountprog, "/sbin/mount.%s", type);
       if (stat(mountprog, &statbuf) == 0) {
	    res = fork();
	    if (res == 0) {
		 const char *oo, *mountargs[10];
		 int i = 0;

		 setuid(getuid());
		 setgid(getgid());
		 oo = fix_opts_string (flags, extra_opts, NULL);
		 mountargs[i++] = mountprog;
		 mountargs[i++] = spec;
		 mountargs[i++] = node;
		 if (nomtab)
		      mountargs[i++] = "-n";
		 if (verbose)
		      mountargs[i++] = "-v";
		 if (oo && *oo) {
		      mountargs[i++] = "-o";
		      mountargs[i++] = oo;
		 }
		 mountargs[i] = NULL;
		 execv(mountprog, (char **) mountargs);
		 exit(1);	/* exec failed */
	    } else if (res != -1) {
		 int st;
		 wait(&st);
		 *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
		 return 1;
	    } else {
	    	 int errsv = errno;
		 error(_("mount: cannot fork: %s"), strerror(errsv));
	    }
       }
  }
  return 0;
}

위에 소스에서 보면

sprintf(mountprog, "/sbin/mount.%s", type);
res = fork();
execv(mountprog, (char **) mountargs);

mount -t ntfs 는 mount.ntfs 로
mount -t cifs 는 mount.cifs 로

-t type 으로 받은 인자를 이용하여 실행을 넘겨준다.



결론 : busybox에서는 mount 소스가 많이 간략화 되어있으므로
         표준 mount 파일에서 지원하는 mount.type 실행치환 기능을 지원하지 않는다.

[링크 : ftp://ftp.kernel.org/pub/linux/utils/util-linux/] 리눅스용 mount.c
[링크 : http://www.koders.com/c/fid840A8124E3B838F1EC7B690C35A7A6F9BF10277B.aspx] busybox용 mount.c

'Linux' 카테고리의 다른 글

linux에 연결된 HDD의 IO 상태보기  (0) 2010.01.11
fork-exec 종료시 리턴값  (0) 2010.01.11
ntfs-3g 크로스 컴파일 하기 (ntfs-3g cross compile)  (0) 2010.01.07
FUSE 넌 머냐?  (0) 2010.01.07
ntfs-3g at Tuxera  (0) 2010.01.06
Posted by 구차니
Linux2010. 1. 7. 14:23
이녀석.. 미운 4살도 아닌데 크로스 컴파일 대책이 제대로 안되어 있는지 한큐에 안된다 ㄱ-

i686 linux에서는 참 쉽게 한다.

./configure
make
make install

[링크 : http://www.tuxera.com/community/ntfs-3g-download/]

세줄 끝.. 참 쉽죠잉~



그.런.데 크로스컴파일은 악몽의 시작이었다.
sh4-linux 에서 크로스컴파일은 산넘어 산이었는데..

crash 1.
# export CC=gsh4-linux-gcc
# ./configure --host-=i686 --target=sh4-linux
..
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
..
# make
...
Making install in libntfs-3g
test -z "/usr/local/lib" || /bin/mkdir -p "/home/morpheuz/st7109/target/usr/local/lib"
 /bin/sh ../libtool   --mode=install /usr/bin/install -c  'libntfs-3g.la' '/home/morpheuz/st7109/target/usr/local/lib/libntfs-3g.la'
/usr/bin/install -c .libs/libntfs-3g.lai /home/morpheuz/st7109/target/usr/local/lib/libntfs-3g.la
/usr/bin/install -c .libs/libntfs-3g.a /home/morpheuz/st7109/target/usr/local/lib/libntfs-3g.a
chmod 644 /home/morpheuz/st7109/target/usr/local/lib/libntfs-3g.a
ranlib /home/morpheuz/st7109/target/usr/local/lib/libntfs-3g.a
libtool: install: warning: remember to run `libtool --finish /usr/local/lib'
make  install-exec-hook
test -z "/lib" || /bin/mkdir -p "/home/morpheuz/st7109/target/lib"
if [ ! "/lib" -ef "/usr/local/lib" ]; then \
/bin/mv -f "/home/morpheuz/st7109/target//usr/local/lib"/libntfs-3g.so* "/home/morpheuz/st7109/target//lib";  \
fi
/bin/mv: cannot stat `/home/morpheuz/st7109/target//usr/local/lib/libntfs-3g.so*': No such file or directory
make[3]: *** [install-exec-hook] Error 1
make[2]: *** [install-exec-am] Error 2
make[1]: *** [install-am] Error 2
make: *** [install-recursive] Error 1

머.. 간단해 보이지만 대책이 안선다 ㄱ-
일단은 so 파일도 생성하지 못하면서, so 파일을 옮길려고 하면서 죽는다..
미네랄!

아무튼 해결책은 아래와 같다.

Step 1. 혹시 모르니 liunx kernel의 FUSE 지원여부를 확인한다.
Step 2. 환경설정
# unset CC
# ./configure

# vi Makefile
# vi src/Makefile
# vi libntfs-3g/Makefile
# vi libfuse-lite/Makefile

에서
AR = ar
CC = gcc
CPP = gcc -E
CXX = g++
CXXCPP = g++ -E
ac_ct_CC = gcc
ac_ct_CXX = g++
를 찾아 sh4-linux- 접두를 붙여준다.

# vi libtool
에서
AR="ar"
LTCC="gcc"
CC="gcc"
OBJDUMP="objdump"
AS="as"
를 찾아 sh4-linux- 접두를 붙여준다.

이렇게 수정후에는 마음 편하게

# make

만약 make 시에 secaudio.c 에러가 발생하면
<attr/xattr.h> 를 <sys/xattr.h>로 수정한다.

# vi src/secaudit.c
 261 #ifdef HAVE_SETXATTR
 262 #include <sys/xattr.h>
 263 #else
 264 #warning "The extended attribute package is not available"
 265 #endif /* HAVE_SETXATTR */

아무래도 target 경로가 다를테니 DESTDIR을 넣고 목적지를 정해준다.

# make DESTDIR={target path} install

설치후 생성되는 파일목록
/sbin/mount.ntfs-3g -> /bin/ntfs-3g
/bin/ntfs-3g
/usr/local/bin/ntfs-3g.probe
/usr/local/bin/ntfs-3g.secaudit
/usr/local/bin/ntfs-3g.usermap

/lib/libntfs-3g.so -> libntfs-3g.so.71.0.0
/lib/libntfs-3g.so.71 -> libntfs-3g.so.71.0.0
/lib/libntfs-3g.so.71.0.0

/usr/local/share/man/man8/mount.ntfs-3g.8 -> ntfs-3g.8
/usr/local/share/man/man8/ntfs-3g.8
/usr/local/share/man/man8/ntfs-3g.probe.8
/usr/local/share/man/man8/ntfs-3g.secaudit.8
/usr/local/share/man/man8/ntfs-3g.usermap.8

/usr/local/lib/libntfs-3g.a
/usr/local/lib/libntfs-3g.la
/usr/local/lib/libntfs-3g.so -> /lib/libntfs-3g.so


실행결과
# mount -t ntfs-3g /dev/sda1 /root/sda1
mount: mounting /dev/sda1 on /root/sda1 failed: No such device

# ntfs-3g /dev/sda1 /root/sda1
WARNING: Deficient Linux kernel detected. Some driver features are
         not available (swap file on NTFS, boot from NTFS by LILO), and
         unmount is not safe unless it's made sure the ntfs-3g process
         naturally terminates after calling 'umount'. If you wish this
         message to disappear then you should upgrade to at least kernel
         version 2.6.20, or request help from your distribution to fix
         the kernel problem. The below web page has more information:
         http://ntfs-3g.org/support.html#fuse26

# mount
rootfs on / type rootfs (rw)
/dev/root on / type nfs (rw,noatime,vers=2,rsize=4096,wsize=4096,hard,nolock,proto=tcp,timeo=600,retrans=2,addr=192.168.10.10)
proc on /proc type proc (rw)
usbfs on /proc/bus/usb type usbfs (rw)
sysfs on /sys type sysfs (rw)
/dev/sda1 on /root/sda1 type fuse (rw,user_id=0,group_id=0,allow_other)

'Linux' 카테고리의 다른 글

fork-exec 종료시 리턴값  (0) 2010.01.11
mount.cifs mount.ntfs 등 자동연결의 비밀(?)  (0) 2010.01.08
FUSE 넌 머냐?  (0) 2010.01.07
ntfs-3g at Tuxera  (0) 2010.01.06
웹캠 VLC에서 테스트(Ubuntu 9.10)  (0) 2009.12.29
Posted by 구차니
Linux2010. 1. 7. 14:07

허전해서 붙이긴 했지만. 안드로메다 언어라 이해는 못하고.. (먼산)
이른대로 Filesystem을 Userspace에서 구현을 한다는 것이다.

일단, ntfs-3g 라는 ntfs 드라이버가 이 녀석을 사용하고,
그로 인해서 kernel에서 Filesystem in userspace support 를 켜주어야 했다.

[링크 : http://fuse.sourceforge.net/]
[링크 : http://en.wikipedia.org/wiki/Filesystem_in_Userspace]
Posted by 구차니
Linux2010. 1. 6. 13:54
음.. NTFS 드라이버라는데
신기하게(?)도 리부팅 없이, FC6 에서 바로 사용이 가능하다.

특이하게(?)도 FS는 mount 후에 fuseblk로 인식한다.

# mount -t ntfs-3g /dev/sda1 /mnt/old
# mount
/dev/hda5 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hda3 on /var type ext3 (rw)
/dev/hdb on /home/samba type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sda1 on /mnt/old type fuseblk (rw,allow_other,blksize=4096)

Stable Source Release 2009.11.14 << 소스 다운로드

[링크 : http://www.tuxera.com/community/ntfs-3g-download/]


Can I use NTFS-3G on Linux 2.4 kernels?

Yes. You need to use NTFS-3G 1.2506 or later and the FUSE kernel module from the FUSE 2.5.3 package. Please see more details in the FUSE README file.

[링크 : http://www.tuxera.com/community/ntfs-3g-faq/#kernel24]

Posted by 구차니
Linux2009. 12. 29. 23:01
  [CAMEL PC-100 : http://blog.danawa.com/prod/?prod_c=956003]
  [더불정보기술 X-LUK DBC-UP : http://blog.d

[링크 : http://minimonk.tistory.com/1084]

예전에 구매했던 웹캠 두마리를 Ubuntu 9.10을 설치하면서
VLC를 덤으로 설치하고 제대로 인식을 하나 테스트 해보았다.


잘된다. 그런데 기본설정으로 사용할때는 확실히 비싼게 좋다고, 더불정보기술의 녀석이
프레임도 빠르고, 부드럽게 나온다.

VLC 상에서 확인해 보면

X-LUK DBC-UP 는 JPEG 640x480
CAMEL PC-100 는 YUV2 640x480 로 나온다.

일단, 기본으로는 DBC-UP가 좋다.(음.. 하나더 지를까..)
그런데 더불꺼는 별도의 오디오도 없고, LED도 없다(없는게 나을지도?)

'Linux' 카테고리의 다른 글

FUSE 넌 머냐?  (0) 2010.01.07
ntfs-3g at Tuxera  (0) 2010.01.06
swapon을 이용하여 파일로 스왑하기  (0) 2009.12.23
DNS / Host Lookup 관련 파일  (0) 2009.12.22
OOM - Out of Memory  (2) 2009.12.15
Posted by 구차니
Linux/Ubuntu2009. 12. 26. 00:01
build-essential 을 설치해야지 gcc 및 각종 include 파일들이 설치된다.

추가적으로 추천하는 패키지는
meld
codeblocks
cvs/subversion

정도면 충분?!

[링크 : http://mwultong.blogspot.com/2006/10/gcc-c-ubuntu-linux-gcc-install.html]
Posted by 구차니
Linux2009. 12. 23. 11:11
스왑이 부족한데, 파티션 조정은 힘드니 파일로 스왑을 하는 방법이 있다고 한다.
dd if=/dev/zero of=/swapfile bs=1024 count=1000
mkswap /swapfile
swapon /swapfile
dd 로 생성할때는 bs는 Blocksize로 byte 단위이다.

[링크 : http://ask.nate.com/qna/view.html?n=8735836]
[링크 : http://linux.die.net/man/8/swapon]


스왑파일은 어디서 생성하던 상관은 없지만,
NFS Client 일 경우에는, 외부 디스크에만 스왑이 되는 듯한 현상이 발생했다.

# swapon swapfile
swapon: swapfile has holes
swapon: swapfile: Invalid argument
안될때는 이렇게 나오고(NFS 상의 디렉토리에서 수행)

# swapon swapfile
Adding 992k swap on swapfile.  Priority:-1 extents:1 across:992k
되면 이렇게 곱게 나와주신다. (USB 로 파일 이전후 시도)


swap filesystem을 지원하지 않아서 그런것 같다는 말도 있긴 하지만,
단순하게 디스크를 옮김으로서 해결이 된것봐서는, swapfile의 위치 제약이 존재하는 듯 하다.
[링크 : http://www.0x61.com/forum/busybox-linux-f110/filesystem-v1-10-0-swapon-swapfile-has-holes-blocksize-t50097.html]

+
2021.01.18
swapon 으로 상황을 볼 수 있다.

[링크 : https://www.snoopybox.co.kr/1964]

'Linux' 카테고리의 다른 글

ntfs-3g at Tuxera  (0) 2010.01.06
웹캠 VLC에서 테스트(Ubuntu 9.10)  (0) 2009.12.29
DNS / Host Lookup 관련 파일  (0) 2009.12.22
OOM - Out of Memory  (2) 2009.12.15
Linux 에서 malloc 으로 할당된 memory 크기를 알 수 있는 방법  (2) 2009.12.14
Posted by 구차니
Linux2009. 12. 22. 17:49
resolv.conf 는 DNS 서버의 아이피가 들어감
nsswitch.conf 는 호스트 이름을 resolve할 순서를 정의함
hosts 는 static 한 resolve 이름을 정의한다. (예를 들어 리눅스 로컬 서버들끼리의 alias)

삼바에서는
lmhossts 파일을 통해 할 수 있고,
smb.conf 에서 resolve할 순서를 정의할 수 있다.

[링크 : http://linux.die.net/man/5/resolv.conf]
[링크 : http://linux.die.net/man/5/nsswitch.conf]
[링크 : http://linux.die.net/man/5/hosts]
[링크 : http://linux.die.net/man/5/hosts.allow]
[링크 : http://linux.die.net/man/5/hosts.deny]

[링크 : http://linux.die.net/man/7/samba]
[링크 : http://linux.die.net/man/5/smb.conf]
[링크 : http://linux.die.net/man/5/lmhosts]
Posted by 구차니
Linux2009. 12. 15. 18:13
OOM Logo

삼바가 죽는다. 이유는 모르겠다.
아무튼, oom-killer 라길래 검색해 보니 out of memory의 약자인데,
문제는.. 메모리 부족시에는 랜덤하게 process를 kill한다고 한다.(random이 이렇게 무섭게 느껴지다니)

oom-killer: gfp_mask=0x201d0, order=0

Call trace:
[<846467ae>] out_of_memory+0x14e/0x200
[<84648cc6>] __alloc_pages+0x306/0x340
[<846449f8>] read_cache_page+0x98/0x260
[<84641660>] find_get_page+0x0/0xe0
[<84641d00>] add_to_page_cache_lru+0x0/0x40
[<84673aa0>] blkdev_readpage+0x0/0x20
[<846da4ca>] cramfs_read+0x14a/0x260
[<84789eb8>] radix_tree_preload+0x18/0x100
[<846dabd4>] cramfs_readpage+0x154/0x1a0
[<848c78c0>] mutex_unlock+0x0/0x60
[<8464af2a>] __do_page_cache_readahead+0x20a/0x380
[<84641b80>] add_to_page_cache+0x0/0x180
[<846452ec>] filemap_nopage+0x10c/0x4c0
[<84652306>] __handle_mm_fault+0xc6/0xa40
[<847b7326>] asc_transmit_chars+0x186/0x1e0
[<84613842>] do_page_fault+0x102/0x3e0
[<84616760>] default_wake_function+0x0/0x20
[<84799f5c>] tty_write+0x13c/0x280
[<8479778c>] tty_ldisc_deref+0x4c/0xe0
[<84799ec6>] tty_write+0xa6/0x280
[<8468167c>] do_ioctl+0x5c/0x80
[<848c82c2>] unlock_kernel+0x22/0x80
[<84681682>] do_ioctl+0x62/0x80
[<846816f2>] vfs_ioctl+0x52/0x3e0
[<8466a496>] fget_light+0x96/0xe0
[<84681aae>] sys_ioctl+0x2e/0x80
[<84605068>] ret_from_exception+0x0/0x8
[<84605000>] tlb_miss_load+0x0/0x4

Mem-info:
DMA per-cpu:
cpu 0 hot: high 18, batch 3 used:2
cpu 0 cold: high 6, batch 1 used:0
DMA32 per-cpu: empty
Normal per-cpu: empty
HighMem per-cpu: empty
Free pages:        1212kB (0kB HighMem)
Active:1514 inactive:6105 dirty:4417 writeback:1689 unstable:0 free:303 slab:2039 mapped:1513 pagetables:81
DMA free:1212kB min:972kB low:1212kB high:1456kB active:6056kB inactive:24420kB present:59392kB pages_scanned:7433 all_unreclaimable
? no
lowmem_reserve[]: 0 0 0 0
DMA32 free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
HighMem free:0kB min:128kB low:128kB high:128kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
DMA: 33*4kB 35*8kB 6*16kB 0*32kB 1*64kB 1*128kB 0*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 1212kB
DMA32: empty
Normal: empty
HighMem: empty
Swap cache: add 0, delete 0, find 0/0, race 0+0
Free swap  = 0kB
Total swap = 0kB
Free swap:            0kB
14848 pages of RAM
3075 reserved pages
6389 pages shared
0 pages swap cached



[링크 : http://linux-mm.org/OOM_Killer]
[링크 : http://linux-mm.org/OOM]
Posted by 구차니